fix(medusa): Payment status on refunds (#2770)
This commit is contained in:
1 parent
b2ea8b7d45
commit
3464617553
4 files changed
+127
-2
No files matched your search
@@ -1461,6 +1461,8 @@ class OrderService extends TransactionBaseService {
|
||||
const { no_notification } = config
|
||||
|
||||
return await this.atomicPhase_(async (manager) => {
|
||||
const orderRepo = manager.getCustomRepository(this.orderRepository_)
|
||||
|
||||
const order = await this.retrieve(orderId, {
|
||||
select: ["refundable_amount", "total", "refunded_total"],
|
||||
relations: ["payments"],
|
||||
@@ -1484,7 +1486,22 @@ class OrderService extends TransactionBaseService {
|
||||
.withTransaction(manager)
|
||||
.refundPayment(order.payments, refundAmount, reason, note)
|
||||
|
||||
const result = await this.retrieve(orderId)
|
||||
let result = await this.retrieveWithTotals(orderId, {
|
||||
relations: ["payments"],
|
||||
})
|
||||
|
||||
if (result.refunded_total > 0 && result.refundable_amount > 0) {
|
||||
result.payment_status = PaymentStatus.PARTIALLY_REFUNDED
|
||||
result = await orderRepo.save(result)
|
||||
}
|
||||
|
||||
if (
|
||||
result.paid_total > 0 &&
|
||||
result.refunded_total === result.paid_total
|
||||
) {
|
||||
result.payment_status = PaymentStatus.REFUNDED
|
||||
result = await orderRepo.save(result)
|
||||
}
|
||||
|
||||
const evaluatedNoNotification =
|
||||
no_notification !== undefined ? no_notification : order.no_notification
|
||||
|
||||
@@ -589,6 +589,7 @@ export default class PaymentProviderService extends TransactionBaseService {
|
||||
const paymentRepo = transactionManager.getCustomRepository(
|
||||
this.paymentRepository_
|
||||
)
|
||||
|
||||
let paymentToRefund = payments.find(
|
||||
(payment) => payment.amount - payment.amount_refunded > 0
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user