Skip to content

Commit 5728781

Browse files
committed
fix: issues with braintree and rounding
1 parent 286b5eb commit 5728781

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

plugins/braintree-payment/package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
"lambdacurry"
3131
],
3232
"devDependencies": {
33-
"@medusajs/admin-sdk": "2.8.2",
34-
"@medusajs/cli": "2.8.2",
35-
"@medusajs/framework": "2.8.2",
36-
"@medusajs/icons": "2.8.2",
37-
"@medusajs/medusa": "2.8.2",
38-
"@medusajs/test-utils": "2.8.2",
39-
"@medusajs/ui": "4.0.3",
33+
"@medusajs/admin-sdk": "^2.8.2",
34+
"@medusajs/cli": "^2.8.2",
35+
"@medusajs/framework": "^2.8.2",
36+
"@medusajs/icons": "^2.8.2",
37+
"@medusajs/medusa": "^2.8.2",
38+
"@medusajs/test-utils": "^2.8.2",
39+
"@medusajs/ui": "^4.0.3",
4040
"@swc/core": "1.5.7",
4141
"@types/braintree": "^3.3.14"
4242
},
@@ -46,13 +46,13 @@
4646
"prepublishOnly": "npx medusa plugin:build"
4747
},
4848
"peerDependencies": {
49-
"@medusajs/admin-sdk": "2.8.2",
50-
"@medusajs/cli": "2.8.2",
51-
"@medusajs/framework": "2.8.2",
52-
"@medusajs/icons": "2.8.2",
49+
"@medusajs/admin-sdk": "^2.8.2",
50+
"@medusajs/cli": "^2.8.2",
51+
"@medusajs/framework": "^2.8.2",
52+
"@medusajs/icons": "^2.8.2",
5353
"@medusajs/medusa": "2.8.2",
54-
"@medusajs/test-utils": "2.8.2",
55-
"@medusajs/ui": "4.0.3"
54+
"@medusajs/test-utils": "^2.8.2",
55+
"@medusajs/ui": "^4.0.3"
5656
},
5757
"engines": {
5858
"node": ">=20"

plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import type {
4343
import type { Transaction, TransactionNotification, TransactionStatus } from 'braintree';
4444
import Braintree from 'braintree';
4545
import type { BraintreeOptions, CustomFields } from '../types';
46+
import { getSmallestUnit } from '../utils/get-smallest-unit';
4647

4748
export interface BraintreePaymentSessionData {
4849
clientToken: string;
@@ -346,11 +347,12 @@ class BraintreeBase extends AbstractPaymentProvider<BraintreeOptions> {
346347

347348
const { data } = input;
348349
const tokenData = await this.gateway.clientToken.generate({});
350+
349351
const dataToSave: BraintreePaymentSessionData & { medusaPaymentSessionId: string } = {
350352
clientToken: tokenData.clientToken,
351353
medusaPaymentSessionId: paymentSessionId as string,
352354
paymentMethodNonce: data?.paymentMethodNonce as string,
353-
amount: input.amount as number,
355+
amount: getSmallestUnit(input.amount, input.currency_code),
354356
currency_code: input.currency_code,
355357
};
356358

@@ -615,7 +617,7 @@ class BraintreeBase extends AbstractPaymentProvider<BraintreeOptions> {
615617
throw new MedusaError(MedusaError.Types.NOT_FOUND, 'Braintree transaction not found');
616618
}
617619

618-
const refundAmount = Number.parseFloat(input.amount.toString());
620+
const refundAmount = getSmallestUnit(input.amount, sessionData.currency_code);
619621

620622
if (braintreeTransaction.status === 'submitted_for_settlement' || braintreeTransaction.status === 'authorized') {
621623
const cancelledTransaction = await this.gateway.transaction.void(braintreeTransaction.id);

0 commit comments

Comments
 (0)