Skip to content

Commit

Permalink
Handle case where payment data is not loaded for reversal
Browse files Browse the repository at this point in the history
  • Loading branch information
btalma committed Mar 15, 2024
1 parent 48b3cb5 commit 825f2ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
- Handle case where payment data is not loaded for reversal

## [1.21.0] - 2024-03-01

### Fixed
Expand Down
25 changes: 22 additions & 3 deletions dotnet/Services/CybersourcePaymentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,13 @@ public async Task<CancelPaymentResponse> CancelPayment(CancelPaymentRequest canc
return cancelPaymentResponse;
}

string referenceNumber = await _vtexApiService.GetOrderId(paymentData.CreatePaymentRequest.OrderId);
string orderId = cancelPaymentRequest.PaymentId; // Default in case we can't get the order id
if(paymentData != null && paymentData.CreatePaymentRequest != null && !string.IsNullOrEmpty(paymentData.CreatePaymentRequest.OrderId))
{
orderId = await _vtexApiService.GetOrderId(paymentData.CreatePaymentRequest.OrderId);
}

string referenceNumber = orderId;
string orderSuffix = string.Empty;
MerchantSettings merchantSettings = await _cybersourceRepository.GetMerchantSettings();
string merchantName = paymentData.CreatePaymentRequest.MerchantName;
Expand All @@ -879,6 +885,12 @@ public async Task<CancelPaymentResponse> CancelPayment(CancelPaymentRequest canc
orderSuffix = merchantSettings.OrderSuffix.Trim();
}

decimal value = 0M;
if(paymentData != null)
{
value = paymentData.Value;
}

Payments payment = new Payments
{
clientReferenceInformation = new ClientReferenceInformation
Expand All @@ -896,13 +908,20 @@ public async Task<CancelPaymentResponse> CancelPayment(CancelPaymentRequest canc
{
amountDetails = new AmountDetails
{
totalAmount = paymentData.Value.ToString()
totalAmount = value.ToString()
},
//reason = "34" // 34: suspected fraud
}
};

PaymentsResponse paymentsResponse = await _cybersourceApi.ProcessReversal(payment, paymentData.AuthorizationId, merchantSettings);

string authId = cancelPaymentRequest.AuthorizationId;
if(paymentData != null && !string.IsNullOrEmpty(paymentData.AuthorizationId))
{
authId = paymentData.AuthorizationId;
}

PaymentsResponse paymentsResponse = await _cybersourceApi.ProcessReversal(payment, authId, merchantSettings);
if (paymentsResponse != null)
{
cancelPaymentResponse = new CancelPaymentResponse
Expand Down

0 comments on commit 825f2ba

Please sign in to comment.