fix: account for lowest currency unit in paypal (#761)
* fix: account for lowest currency unit in paypal * fix: currency rounding
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
import _ from "lodash"
|
||||
import { humanizeAmount, zeroDecimalCurrencies } from "medusa-core-utils"
|
||||
import PayPal from "@paypal/checkout-server-sdk"
|
||||
import { PaymentService } from "medusa-interfaces"
|
||||
|
||||
function roundToTwo(num, currency) {
|
||||
if (zeroDecimalCurrencies.includes(currency.toLowerCase())) {
|
||||
return `${num}`
|
||||
}
|
||||
return num.toFixed(2)
|
||||
}
|
||||
|
||||
class PayPalProviderService extends PaymentService {
|
||||
static identifier = "paypal"
|
||||
|
||||
@@ -101,7 +109,10 @@ class PayPalProviderService extends PaymentService {
|
||||
custom_id: cart.id,
|
||||
amount: {
|
||||
currency_code: currency_code.toUpperCase(),
|
||||
value: (amount / 100).toFixed(2),
|
||||
value: roundToTwo(
|
||||
humanizeAmount(amount, currency_code),
|
||||
currency_code
|
||||
),
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -193,7 +204,10 @@ class PayPalProviderService extends PaymentService {
|
||||
value: {
|
||||
amount: {
|
||||
currency_code: currency_code.toUpperCase(),
|
||||
value: (cart.total / 100).toFixed(2),
|
||||
value: roundToTwo(
|
||||
humanizeAmount(cart.total, currency_code),
|
||||
currency_code
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -254,7 +268,10 @@ class PayPalProviderService extends PaymentService {
|
||||
request.requestBody({
|
||||
amount: {
|
||||
currency_code: payment.currency_code.toUpperCase(),
|
||||
value: (amountToRefund / 100).toFixed(2),
|
||||
value: roundToTwo(
|
||||
humanizeAmount(amountToRefund, payment.currency_code),
|
||||
payment.currency_code
|
||||
),
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user