Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-13737: Allows to Update and Retry Rejected Capture and Rufund documents #381

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading