Skip to content

Commit

Permalink
PT-13737: Allows to Update and Retry Rejected Capture and Rufund docu…
Browse files Browse the repository at this point in the history
…ments (#381)

feat: Allows to Update and Retry Rejected Capture document with same Transaction Id.
feat: Allows to Update and Retry Rejected Refund document with same Transaction Id.
feat: Added Transaction Id and Outer Id on Capture details blade.
feat: Added Transaction Id and Outer Id on Refund details blade.
  • Loading branch information
OlegoO authored Oct 2, 2023
1 parent 68dde60 commit 782f211
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 68 deletions.
65 changes: 59 additions & 6 deletions src/VirtoCommerce.OrdersModule.Data/Services/PaymentFlowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,23 @@ protected virtual async Task<RefundOrderPaymentResult> CreateRefundDocument(Refu
return result;
}

var refund = CreateRefund(paymentInfo.Payment, paymentInfo.Store, request);

paymentInfo.Payment.Refunds ??= new List<Refund>();
paymentInfo.Payment.Refunds.Add(refund);

// Allows to Update and Retry Rejected Refund document.
var refund = paymentInfo.Payment.Refunds.FirstOrDefault(r => r.TransactionId == request.TransactionId
&& r.Status == RefundStatus.Rejected.ToString());

if (refund != null)
{
UpdateRefund(refund, paymentInfo.Payment, paymentInfo.Store, request);
}
else
{
refund = CreateRefund(paymentInfo.Payment, paymentInfo.Store, request);
paymentInfo.Payment.Refunds.Add(refund);
}


await _customerOrderService.SaveChangesAsync(new[] { paymentInfo.CustomerOrder });

result.Succeeded = true;
Expand Down Expand Up @@ -157,10 +170,22 @@ public virtual async Task<CaptureOrderPaymentResult> CreateCaptureDocument(Captu
return result;
}

var capture = CreateCapture(paymentInfo.Payment, paymentInfo.Store, request);

paymentInfo.Payment.Captures ??= new List<Capture>();
paymentInfo.Payment.Captures.Add(capture);

// Allows to Update and Retry Rejected Capture document.
var capture = paymentInfo.Payment.Captures.FirstOrDefault(c => c.TransactionId == request.TransactionId
&& c.Status == CaptureStatus.Rejected.ToString());

if (capture != null)
{
UpdateCapture(capture, paymentInfo.Payment, paymentInfo.Store, request);
}
else
{
capture = CreateCapture(paymentInfo.Payment, paymentInfo.Store, request);
paymentInfo.Payment.Captures.Add(capture);
}

await _customerOrderService.SaveChangesAsync(new[] { paymentInfo.CustomerOrder });

result.Succeeded = true;
Expand Down Expand Up @@ -314,6 +339,21 @@ protected virtual Refund CreateRefund(PaymentIn payment, Store store, RefundOrde
return refund;
}

protected virtual void UpdateRefund(Refund refund, PaymentIn payment, Store store, RefundOrderPaymentRequest request)
{
refund.Amount = request.Amount ?? payment.Sum;
refund.ReasonCode = EnumUtility.SafeParse(request.ReasonCode, RefundReasonCode.Other);
refund.ReasonMessage = request.ReasonMessage;
refund.Comment = request.ReasonMessage;
refund.OuterId = request.OuterId;
refund.TransactionId = request.TransactionId;

refund.Status = RefundStatus.Pending.ToString();
refund.Currency = payment.Currency;
refund.CustomerOrderId = payment.OrderId;
refund.VendorId = payment.VendorId;
}

protected virtual Capture CreateCapture(PaymentIn payment, Store store, CaptureOrderPaymentRequest request)
{
var capture = AbstractTypeFactory<Capture>.TryCreateInstance();
Expand All @@ -334,6 +374,19 @@ protected virtual Capture CreateCapture(PaymentIn payment, Store store, CaptureO
return capture;
}

protected virtual void UpdateCapture(Capture capture, PaymentIn payment, Store store, CaptureOrderPaymentRequest request)
{
capture.Amount = request.Amount ?? payment.Sum;
capture.Comment = request.CaptureDetails;
capture.OuterId = request.OuterId;
capture.TransactionId = request.TransactionId;

capture.Status = CaptureStatus.Pending.ToString();
capture.Currency = payment.Currency;
capture.CustomerOrderId = payment.OrderId;
capture.VendorId = payment.VendorId;
}

private static void FillPaymentRequestBase(OrderPaymentInfo paymentInfo, PaymentRequestBase result)
{
result.OrderId = paymentInfo.CustomerOrder.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
"reasonCode": "Select..."
}
},
"refund-detail": {
"labels": {
"transactionId": "Transaction Id",
"outerId": "Outer Id"
}
},
"capture-add": {
"title": "Create a capture",
"labels": {
Expand Down Expand Up @@ -170,72 +176,78 @@
"vendor": "Select..."
}
},
"transactions-list": {
"title": "Payment gateway transactions",
"subtitle": "List of all payment gateway interactions"
},
"transaction-detail": {
"title": "Transaction details",
"subtitle": "Raw transaction data "
},
"shipment-detail": {
"title": "Shipment #{{number}}",
"title-new": "New shipment",
"subtitle": "Edit shipment details",
"capture-detail": {
"labels": {
"shipment-method": "Shipment method",
"approved": "Approved",
"shipment-number": "Shipment ID",
"status": "Status",
"fulfillment-center": "Fulfillment center",
"from": "Date and time",
"employee": "Assigned to",
"price": "Shipment amount",
"price-with-tax": "Shipment amount with tax",
"shipment-method-option": "Shipment method",
"tracking-number": "Tracking number",
"tracking-url": "Tracking URL",
"delivery-date": "Delivery date",
"vendor": "Vendor"
"transactionId": "Transaction Id",
"outerId": "Outer Id"
}
},
"transactions-list": {
"title": "Payment gateway transactions",
"subtitle": "List of all payment gateway interactions"
},
"transaction-detail": {
"title": "Transaction details",
"subtitle": "Raw transaction data "
},
"shipment-detail": {
"title": "Shipment #{{number}}",
"title-new": "New shipment",
"subtitle": "Edit shipment details",
"labels": {
"shipment-method": "Shipment method",
"approved": "Approved",
"shipment-number": "Shipment ID",
"status": "Status",
"fulfillment-center": "Fulfillment center",
"from": "Date and time",
"employee": "Assigned to",
"price": "Shipment amount",
"price-with-tax": "Shipment amount with tax",
"shipment-method-option": "Shipment method",
"tracking-number": "Tracking number",
"tracking-url": "Tracking URL",
"delivery-date": "Delivery date",
"vendor": "Vendor"
},
"placeholders": {
"status": "Select...",
"shipment-method": "Select...",
"fulfillment-center": "Select or search a center...",
"shipment-method-option": "Default shipment method",
"vendor": "Select..."
}
},
"shipment-items": {
"title": "{{title}} line items",
"subtitle": "Edit shipment items",
"labels": {
"item": "Item",
"status": "Status",
"quantity": "Qty",
"price": "Price",
"total": "Total"
}
},
"catalog-items-select": {
"title": "Add item to order"
},
"newOperation-wizard": {
"title": "New operation",
"subtitle": "Select operation type",
"menu": {
"shipment-operation": {
"description": "Shipment document"
},
"placeholders": {
"status": "Select...",
"shipment-method": "Select...",
"fulfillment-center": "Select or search a center...",
"shipment-method-option": "Default shipment method",
"vendor": "Select..."
}
},
"shipment-items": {
"title": "{{title}} line items",
"subtitle": "Edit shipment items",
"labels": {
"item": "Item",
"status": "Status",
"quantity": "Qty",
"price": "Price",
"total": "Total"
}
},
"catalog-items-select": {
"title": "Add item to order"
},
"newOperation-wizard": {
"title": "New operation",
"subtitle": "Select operation type",
"menu": {
"shipment-operation": {
"description": "Shipment document"
},
"payment-operation": {
"description": "Incoming payment document"
},
"refund-operation": {
"description": "Refund document"
}
"payment-operation": {
"description": "Incoming payment document"
},
"refund-operation": {
"description": "Refund document"
}
}
},
}
},
"widgets": {
"notifications": {
"title": "Notification feed",
Expand Down
25 changes: 25 additions & 0 deletions src/VirtoCommerce.OrdersModule.Web/Scripts/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ angular.module(moduleName, [
isReadOnly: true,
title: "orders.blades.payment-detail.labels.from",
valueType: "DateTime"
},
{
name: 'transactionId',
isReadOnly: true,
title: "orders.blades.refund-detail.labels.transactionId",
valueType: "ShortText"
},
{
name: 'outerId',
isReadOnly: true,
title: "orders.blades.refund-detail.labels.outerId",
valueType: "ShortText"
}
]
}
Expand All @@ -235,6 +247,19 @@ angular.module(moduleName, [
isReadOnly: true,
title: "orders.blades.payment-detail.labels.from",
valueType: "DateTime"
},
{
name: 'transactionId',
isReadOnly: true,
title: "orders.blades.capture-detail.labels.transactionId",
valueType: "ShortText"
}
,
{
name: 'outerId',
isReadOnly: true,
title: "orders.blades.capture-detail.labels.outerId",
valueType: "ShortText"
}
]
}
Expand Down

0 comments on commit 782f211

Please sign in to comment.