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

Add digit handling for country-specific currencies #288

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 3 additions & 4 deletions src/blocks/credit-card/use-payment-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
getSquareServerData,
handleErrors,
log,
logData,
logData,
convertAmount,
} from '../square-utils';
import { PAYMENT_METHOD_NAME } from './constants';

Expand Down Expand Up @@ -58,9 +59,7 @@ export const usePaymentForm = (
};

if ( intent === 'CHARGE' ) {
newVerificationDetails.amount = (
billing.cartTotal.value / 100
).toString();
newVerificationDetails.amount = convertAmount(billing.cartTotal.value, billing.currency.code).toString();
newVerificationDetails.currencyCode = billing.currency.code;
}
return newVerificationDetails;
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/digital-wallets/submission-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { select, dispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import { getSquareServerData } from '../square-utils';
import { getSquareServerData, convertAmount } from '../square-utils';

/**
* Returns the AJAX URL for a given action.
Expand Down Expand Up @@ -138,7 +138,7 @@ export const createPaymentRequest = async ( payments ) => {
export const buildVerificationDetails = ( billing ) => {
return {
intent: 'CHARGE',
amount: ( billing.cartTotal.value / 100 ).toString(),
amount: convertAmount(billing.cartTotal.value, billing.currency.code).toString(),
currencyCode: billing.currency.code,
billingContact: {
familyName: billing.billingData.last_name || '',
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/digital-wallets/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getSquareServerData } from '../square-utils';
import { getSquareServerData, convertAmount } from '../square-utils';

export const buildVerificationDetails = ( billing ) => {
return {
intent: 'CHARGE',
amount: ( billing.cartTotal.value / 100 ).toString(),
amount: convertAmount(billing.cartTotal.value, billing.currency.code).toString(),
currencyCode: billing.currency.code,
billingContact: {
familyName: billing.billingData.last_name || '',
Expand Down
27 changes: 26 additions & 1 deletion src/blocks/square-utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,29 @@ const log = ( data, type = 'notice' ) => {
}
};

export { getSquareServerData, handleErrors, log, logData };
const convertAmount = (amount, currencyCode) => {
switch (currencyCode) {
case 'BIF':
case 'CLP':
case 'DJF':
case 'GNF':
case 'HUF':
case 'JPY':
case 'KMF':
case 'KRW':
case 'MGA':
case 'PYG':
case 'RWF':
case 'VND':
case 'VUV':
case 'XAF':
case 'XOF':
case 'XPF':
return amount;

default:
return amount / 100;
};
};

export { getSquareServerData, handleErrors, log, logData, convertAmount };