Skip to content

Commit c588a45

Browse files
committed
added multi-currency support for GooglePay and updated the doc
1 parent eabf299 commit c588a45

File tree

12 files changed

+290
-255
lines changed

12 files changed

+290
-255
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
- **Description:** Cybersource, a Visa solution, is the only global, modular payment management platform built on secure Visa infrastructure with the payment reach and fraud insights of a massive $500B+ global processing network. You can find out more about what Cybersource does [here](https://www.cybersource.com/en-gb.html)
44
- **Categories:** Payment Processing, Fraud Detection, Address Validation, Tax Computation
5-
- **Version:** 25.2.0
6-
- **Last Certification Date:** March 2025
5+
- **Version:** 25.3.0
6+
- **Last Certification Date:** May 2025
77
- **Supports SFRA v7.0**
88
- **JavaScript Controllers Friendly:** **YES**
99

cartridges/int_cybs_sfra/cartridge/client/default/js/googlePay.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,30 @@ function addGooglePayButton() {
145145
}
146146
}
147147

148+
149+
// Function to format money based on input
150+
function formatInputMoney(input) {
151+
var standardNumber = input;
152+
if (input.indexOf(",") > input.indexOf(".") || (input.indexOf(",") !== -1 && input.indexOf(".") === -1)) {
153+
standardNumber = parseFloat(input.replace(".", "").replace(",", ".").replace(/[^0-9.]/g, ''));
154+
} else {
155+
standardNumber = parseFloat(input.replace(/[^0-9.]/g, ''));
156+
}
157+
return standardNumber;
158+
}
159+
148160
/**
149161
* @returns {*} *
150162
*/
151163
function getGoogleTransactionInfo() {
164+
var totalPriceRaw = $('body').find('.row.grand-total').find('.grand-total-sum').text();
165+
var totalPrice = formatInputMoney(totalPriceRaw);
166+
152167
return {
153-
countryCode: 'US',
154-
currencyCode: 'USD',
168+
countryCode: window.googlepayval.countryCode,
169+
currencyCode: window.googlepayval.currencyCode,
155170
totalPriceStatus: 'FINAL',
156-
totalPrice: $('body').find('.row.grand-total').find('.grand-total-sum').text()
157-
.replace('$', '').replace(',', '')
171+
totalPrice: totalPrice.toString()
158172
};
159173
}
160174
/**
@@ -163,7 +177,7 @@ function prefetchGooglePaymentData() {
163177
var paymentDataRequest = getGooglePaymentDataRequest();
164178
paymentDataRequest.transactionInfo = {
165179
totalPriceStatus: 'NOT_CURRENTLY_KNOWN',
166-
currencyCode: 'USD'
180+
currencyCode: window.googlepayval.currencyCode
167181
};
168182
// eslint-disable-next-line no-shadow
169183
var paymentsClient = getGooglePaymentsClient();

cartridges/int_cybs_sfra/cartridge/client/default/js/googlePayBilling.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,29 @@ var cardPaymentMethod = {
4646
};
4747
var paymentsClient = null;
4848

49+
// Function to format money based on input
50+
function formatInputMoney(input) {
51+
var standardNumber = input;
52+
if (input.indexOf(",") > input.indexOf(".") || (input.indexOf(",") !== -1 && input.indexOf(".") === -1)) {
53+
standardNumber = parseFloat(input.replace(".", "").replace(",", ".").replace(/[^0-9.]/g, ''));
54+
} else {
55+
standardNumber = parseFloat(input.replace(/[^0-9.]/g, ''));
56+
}
57+
return standardNumber;
58+
}
59+
4960
/**
5061
* @returns {*} *
5162
*/
5263
function getGoogleTransactionInfo() {
64+
var totalPrice = '';
65+
var totalPriceRaw = $('.checkout-continue').find('#carttotal').val() != null ? $('.checkout-continue').find('#carttotal').val().replace('$', '') : '';
66+
totalPrice = formatInputMoney(totalPriceRaw);
5367
return {
54-
countryCode: 'US',
55-
currencyCode: 'USD',
68+
countryCode: window.googlepayval.countryCode,
69+
currencyCode: window.googlepayval.currencyCode,
5670
totalPriceStatus: 'FINAL',
57-
totalPrice: $('.checkout-continue').find('#carttotal').val() != null ? $('.checkout-continue').find('#carttotal').val().replace('$', '').replace(',', '') : ''
71+
totalPrice: totalPrice.toString()
5872
};
5973
}
6074

@@ -113,7 +127,7 @@ function prefetchGooglePaymentData() {
113127
var paymentDataRequest = getGooglePaymentDataRequest();
114128
paymentDataRequest.transactionInfo = {
115129
totalPriceStatus: 'NOT_CURRENTLY_KNOWN',
116-
currencyCode: 'USD'
130+
currencyCode: window.googlepayval.currencyCode
117131
};
118132
// eslint-disable-next-line no-shadow
119133
var paymentsClient = getGooglePaymentsClient();

cartridges/int_cybs_sfra/cartridge/templates/default/common/layout/page.isml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<isinclude template="/components/modules" sf-toolkit="off" />
33
<isset name="enableGooglePayOnMiniCart" value="${require('*/cartridge/configuration/index').enableGooglePayOnMiniCart}" scope="page" />
44
<isset name="enableGooglePayOnCart" value="${require('*/cartridge/configuration/index').enableGooglePayOnCart}" scope="page" />
5+
<isset name="countryCode" value="${require('dw/util/Locale').getLocale(request.getLocale()).getCountry()}" scope="page" />
56

67
<!DOCTYPE html>
78
<html lang="${require('dw/util/Locale').getLocale(request.getLocale()).getLanguage()}">
@@ -41,11 +42,11 @@
4142
<script>
4243
var googlePayVariables = {
4344
currencyCode: "${session.getCurrency().getCurrencyCode()}",
45+
countryCode: "${countryCode}",
4446
totalPriceStatus: 'FINAL',
4547
sessionCallBack : "${dw.web.URLUtils.url('CheckoutServices-GetGooglePayToken')}",
4648
returnURL : "${dw.web.URLUtils.https('Checkout-Begin', 'stage', 'placeOrder')}",
4749
cartURL : "${dw.web.URLUtils.https('Checkout-Begin', 'stage', 'payment','payerAuthError', Resource.msg('message.payerAuthError', 'error', null))}"
48-
//"${dw.web.URLUtils.https('Cart-Show')}",
4950
}
5051
window.googlepayval = googlePayVariables;
5152
</script>

cartridges/int_cybs_sfra/cartridge/templates/default/common/scripts.isml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<isset name="merchantIDPref" value="${require('*/cartridge/configuration/index').merchantID}" scope="page" />
1515
<isset name="googlePayEnabled" value="${require('*/cartridge/configuration/index').googlePayEnabled}" scope="page" />
1616
<isset name="googlePayEnvironmentPref" value="${require('*/cartridge/configuration/index').googlePayEnvironment}" scope="page" />
17+
<isset name="countryCode" value="${require('dw/util/Locale').getLocale(request.getLocale()).getCountry()}" scope="page" />
1718

1819
<input type="hidden" name="googlePayMerchantID" id="googlePayMerchantID" value="${googlePayMerchantIdPref}"/>
1920
<input type="hidden" name="googlePaygatewayMerchantId" id="googlePaygatewayMerchantId" value="${merchantIDPref}"/>
@@ -26,13 +27,12 @@
2627

2728
var googlePayVariables = {
2829
currencyCode: "${session.getCurrency().getCurrencyCode()}",
30+
countryCode: "${countryCode}",
2931
totalPriceStatus: 'FINAL',
3032
sessionCallBack : "${dw.web.URLUtils.url('CheckoutServices-SubmitPaymentGP')}",
3133
submitURL : "${dw.web.URLUtils.https('Checkout-Begin', 'stage', 'placeOrder')}"
3234
}
3335

34-
 
35-
                   
3636
window.googlepayval = googlePayVariables;
3737

3838
</script>

cartridges/int_cybs_sfra_base/cartridge/apiClient/constants.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ module.exports = {
3232
PRODUCTION_RUN_ENV: "cybersource.environment.production",
3333
APPLICATION_NAME: "Salesforce B2C(REST)",
3434
APPLICATION_VERSION: "25.3.0",
35-
35+
3636
/* Digest Constants*/
3737
SIGNATURE_ALGORITHAM: "SHA-256=",
3838
HmacSHA256: "HmacSHA256",
3939

4040
/* Flex microform constants */
41-
ENCRYPTION_TYPE: "RsaOaep256",
4241
CLIENT_VERSION : "v2",
4342

4443

cartridges/int_cybs_sfra_base/cartridge/configuration/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var LogfileMaxSize = '5242880'; // 10 MB In Bytes
2323
* Send this value in all requests that are sent through the partner solution. CyberSource assigns the ID to the partner.
2424
* Note When you see a partner ID of 999 in reports, the partner ID that was submitted is incorrect.
2525
*/
26-
var SolutionId = 'GTIWK1VH';
26+
var SolutionId = 'I1YMGX8S';
2727

2828
var CruiseDDCEndPoint = {
2929
Stage: 'https://centinelapistag.cardinalcommerce.com/V1/Cruise/Collect',

cartridges/int_cybs_sfra_base/cartridge/scripts/http/payments.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ function createFlexKey() { // eslint-disable-line no-unused-vars
485485
}
486486

487487
var publicKeyRequest = {
488-
'encryptionType': Constants.ENCRYPTION_TYPE,
489488
'targetOrigins':[
490489
Constants.PROXY_PREFIX + '://' + request.httpHost
491490
],
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)