-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pricing decimal formatting for tokenized cart (#8998)
Co-authored-by: Timur Karimov <[email protected]>
- Loading branch information
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: fix | ||
Comment: fix: tokenized PRB with zero decimal currency | ||
|
||
|
54 changes: 54 additions & 0 deletions
54
client/tokenized-payment-request/transformers/__tests__/wc-to-stripe.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { transformPrice } from '../wc-to-stripe'; | ||
|
||
global.wcpayPaymentRequestParams = {}; | ||
global.wcpayPaymentRequestParams.checkout = {}; | ||
|
||
describe( 'wc-to-stripe transformers', () => { | ||
describe( 'transformPrice', () => { | ||
afterEach( () => { | ||
delete global.wcpayPaymentRequestParams.checkout.currency_decimals; | ||
} ); | ||
|
||
it( 'transforms the price', () => { | ||
expect( transformPrice( 180, { currency_minor_unit: 2 } ) ).toBe( | ||
180 | ||
); | ||
} ); | ||
|
||
it( 'transforms the price if the currency is configured with one decimal', () => { | ||
// with one decimal, `180` would mean `18.0`. | ||
// But since Stripe expects the price to be in cents, the return value should be `1800` | ||
expect( transformPrice( 180, { currency_minor_unit: 1 } ) ).toBe( | ||
1800 | ||
); | ||
} ); | ||
|
||
it( 'transforms the price if the currency is configured with two decimals', () => { | ||
// with two decimals, `1800` would mean `18.00`. | ||
// But since Stripe expects the price to be in cents, the return value should be `1800` | ||
expect( transformPrice( 1800, { currency_minor_unit: 2 } ) ).toBe( | ||
1800 | ||
); | ||
} ); | ||
|
||
it( 'transforms the price if the currency is a zero decimal currency (e.g.: Yen)', () => { | ||
global.wcpayPaymentRequestParams.checkout.currency_decimals = 0; | ||
// with zero decimals, `18` would mean `18`. | ||
expect( transformPrice( 18, { currency_minor_unit: 0 } ) ).toBe( | ||
18 | ||
); | ||
} ); | ||
|
||
it( 'transforms the price if the currency a zero decimal currency (e.g.: Yen) but it is configured with one decimal', () => { | ||
global.wcpayPaymentRequestParams.checkout.currency_decimals = 0; | ||
// with zero decimals, `18` would mean `18`. | ||
// But since Stripe expects the price to be in the minimum currency amount, the return value should be `18` | ||
expect( transformPrice( 180, { currency_minor_unit: 1 } ) ).toBe( | ||
18 | ||
); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters