Skip to content

Commit eabf299

Browse files
committed
implemented Payer Auth for GooglePay
1 parent f18b44f commit eabf299

File tree

9 files changed

+68
-30
lines changed

9 files changed

+68
-30
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ var baseCardPaymentMethod = {
3030
type: 'CARD',
3131
parameters: {
3232
allowedAuthMethods: allowedCardAuthMethods,
33-
allowedCardNetworks: allowedCardNetworks
33+
allowedCardNetworks: allowedCardNetworks,
34+
assuranceDetailsRequired: true
3435
}
3536
};
3637

@@ -153,7 +154,7 @@ function getGoogleTransactionInfo() {
153154
currencyCode: 'USD',
154155
totalPriceStatus: 'FINAL',
155156
totalPrice: $('body').find('.row.grand-total').find('.grand-total-sum').text()
156-
.replace('$', '')
157+
.replace('$', '').replace(',', '')
157158
};
158159
}
159160
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var baseCardPaymentMethod = {
3131
parameters: {
3232
allowedAuthMethods: allowedCardAuthMethods,
3333
allowedCardNetworks: allowedCardNetworks,
34+
assuranceDetailsRequired: true,
3435
billingAddressRequired: true,
3536
billingAddressParameters: {
3637
format: 'FULL',
@@ -53,7 +54,7 @@ function getGoogleTransactionInfo() {
5354
countryCode: 'US',
5455
currencyCode: 'USD',
5556
totalPriceStatus: 'FINAL',
56-
totalPrice: $('.checkout-continue').find('#carttotal').val() != null ? $('.checkout-continue').find('#carttotal').val().replace('$', '') : ''
57+
totalPrice: $('.checkout-continue').find('#carttotal').val() != null ? $('.checkout-continue').find('#carttotal').val().replace('$', '').replace(',', '') : ''
5758
};
5859
}
5960

cartridges/int_cybs_sfra_base/cartridge/apiClient/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
SANDBOX_RUN_ENV: "cybersource.environment.sandbox",
3232
PRODUCTION_RUN_ENV: "cybersource.environment.production",
3333
APPLICATION_NAME: "Salesforce B2C(REST)",
34-
APPLICATION_VERSION: "25.2.0",
34+
APPLICATION_VERSION: "25.3.0",
3535

3636
/* Digest Constants*/
3737
SIGNATURE_ALGORITHAM: "SHA-256=",

cartridges/int_cybs_sfra_base/cartridge/controllers/Checkout.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ server.prepend(
2424
return next();
2525
}
2626
session.custom.Flag3ds = false;
27+
session.custom.scaTokenFlag = false;
2728
// eslint-disable-next-line no-undef
2829
if (session.getCustomer().getProfile() !== null) {
2930
// eslint-disable-next-line no-undef

cartridges/int_cybs_sfra_base/cartridge/controllers/CheckoutServices.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ var currentBasket = BasketMgr.getCurrentBasket();
1212
var paymentMethod = currentBasket && currentBasket.paymentInstrument && currentBasket.paymentInstrument.paymentMethod;
1313
var isVisaSRC = paymentMethod && paymentMethod === 'CLICK_TO_PAY';
1414

15+
var isGPay_PayerAuthEnabled = false;
16+
if(!empty(session.privacy.encryptedDataGP) && session.custom.isGpayCardHolderAuthenticated == false && configObject.payerAuthenticationEnabled) {
17+
isGPay_PayerAuthEnabled = true;
18+
}
1519
// eslint-disable-next-line no-undef
16-
if (configObject.payerAuthenticationEnabled && configObject.cartridgeEnabled && empty(session.privacy.encryptedDataGP)
17-
&& !isVisaSRC
18-
) {
20+
if (((configObject.payerAuthenticationEnabled && empty(session.privacy.encryptedDataGP)) || isGPay_PayerAuthEnabled) && configObject.cartridgeEnabled && !isVisaSRC) {
21+
1922
// eslint-disable-next-line consistent-return
2023
server.prepend('PlaceOrder', server.middleware.https, function (req, res, next) {
2124

@@ -193,10 +196,10 @@ if (configObject.payerAuthenticationEnabled && configObject.cartridgeEnabled &&
193196
jwttoken: billingForm.creditCardFields.flexresponse.value,
194197
securityCode: billingForm.creditCardFields.securityCode.value,
195198
fluidData: paymentInstrument.custom.fluidData,
199+
googlePayFluidData: session.privacy.encryptedDataGP,
196200
callId: paymentInstrument.custom.callID
197201
};
198202

199-
200203
var setupResponse = payerAuthentication.paSetup(billingForm, session.privacy.orderID, card);
201204
var accessToken = setupResponse.consumerAuthenticationInformation.accessToken;
202205
session.privacy.deviceDataCollectionUrl = setupResponse.consumerAuthenticationInformation.deviceDataCollectionUrl;
@@ -299,6 +302,7 @@ server.post('getResponse', server.middleware.https, function (req, res, next) {
299302
jwttoken: billingForm.creditCardFields.flexresponse.value,
300303
securityCode: billingForm.creditCardFields.securityCode.value,
301304
fluidData: paymentInstrument.custom.fluidData,
305+
googlePayFluidData: session.privacy.encryptedDataGP,
302306
callId: paymentInstrument.custom.callID
303307
};
304308
}
@@ -342,6 +346,8 @@ server.post('getResponse', server.middleware.https, function (req, res, next) {
342346
session.privacy.orderID = '';
343347
// eslint-disable-next-line no-undef
344348
session.privacy.orderToken = '';
349+
delete session.privacy.encryptedDataGP;
350+
delete session.custom.isGpayCardHolderAuthenticated;
345351
}
346352
// eslint-disable-next-line
347353
else if (enrollResponse.errorInformation.reason === 'CUSTOMER_AUTHENTICATION_REQUIRED' && session.custom.Flag3ds === false) {
@@ -362,6 +368,8 @@ server.post('getResponse', server.middleware.https, function (req, res, next) {
362368
session.privacy.orderID = '';
363369
// eslint-disable-next-line no-undef
364370
session.privacy.orderToken = '';
371+
delete session.privacy.encryptedDataGP;
372+
delete session.custom.isGpayCardHolderAuthenticated;
365373
}
366374

367375
res.render('payerAuthentication/checkoutRedirect', {
@@ -411,6 +419,7 @@ server.post('handlingConsumerAuthResponse', server.middleware.https, function (r
411419
jwttoken: billingForm.creditCardFields.flexresponse.value,
412420
securityCode: billingForm.creditCardFields.securityCode.value,
413421
fluidData: paymentInstrument.custom.fluidData,
422+
googlePayFluidData: session.privacy.encryptedDataGP,
414423
callId: paymentInstrument.custom.callID
415424
};
416425
}
@@ -436,6 +445,8 @@ server.post('handlingConsumerAuthResponse', server.middleware.https, function (r
436445
session.privacy.orderID = '';
437446
// eslint-disable-next-line no-undef
438447
session.privacy.orderToken = '';
448+
delete session.privacy.encryptedDataGP;
449+
delete session.custom.isGpayCardHolderAuthenticated;
439450
}
440451

441452
// eslint-disable-next-line
@@ -458,6 +469,8 @@ server.post('handlingConsumerAuthResponse', server.middleware.https, function (r
458469
session.privacy.orderID = '';
459470
// eslint-disable-next-line no-undef
460471
session.privacy.orderToken = '';
472+
delete session.privacy.encryptedDataGP;
473+
delete session.custom.isGpayCardHolderAuthenticated;
461474
}
462475
res.render('payerAuthentication/checkoutRedirect', {
463476
redirect: redirect,
@@ -469,6 +482,7 @@ server.post('handlingConsumerAuthResponse', server.middleware.https, function (r
469482
return next();
470483
});
471484

485+
// for Gpay on checkout page
472486
server.post('SubmitPaymentGP', function (req, res, next) {
473487
var COHelpers = require('*/cartridge/scripts/checkout/checkoutHelpers');
474488
var Encoding = require('dw/crypto/Encoding');
@@ -493,6 +507,7 @@ server.post('SubmitPaymentGP', function (req, res, next) {
493507
// eslint-disable-next-line no-undef
494508
var paymentData = JSON.parse(request.httpParameterMap.googletoken);
495509
var GPtoken = paymentData.paymentMethodData.tokenizationData.token;
510+
session.custom.isGpayCardHolderAuthenticated = paymentData.paymentMethodData.info.assuranceDetails.cardHolderAuthenticated;
496511
// eslint-disable-next-line no-undef
497512
session.privacy.encryptedDataGP = Encoding.toBase64(new dw.util.Bytes(GPtoken));
498513

@@ -689,6 +704,7 @@ function shippingUpdate(cart, shippingdetails) {
689704
}
690705
}
691706

707+
//for Gapy on cart and minicart
692708
// eslint-disable-next-line consistent-return
693709
server.post('GetGooglePayToken', function (req, res, next) {
694710
var Encoding = require('dw/crypto/Encoding');
@@ -720,6 +736,7 @@ server.post('GetGooglePayToken', function (req, res, next) {
720736
ShippingHelper.selectShippingMethod(cart.defaultShipment, null);
721737
});
722738
var GPtoken = response.paymentMethodData.tokenizationData.token;
739+
session.custom.isGpayCardHolderAuthenticated = response.paymentMethodData.info.assuranceDetails.cardHolderAuthenticated;
723740
// eslint-disable-next-line no-undef
724741
session.privacy.encryptedDataGP = Encoding.toBase64(new dw.util.Bytes(GPtoken));
725742
} else {

cartridges/int_cybs_sfra_base/cartridge/scripts/hooks/payment/processor/payments_credit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ function Authorize(orderNumber, paymentInstrument, paymentProcessor) {
264264
gPayToken: session.privacy.encryptedDataGP
265265
};
266266
// eslint-disable-next-line no-undef
267-
session.privacy.encryptedDataGP = '';
267+
delete session.privacy.encryptedDataGP;
268+
delete session.custom.isGpayCardHolderAuthenticated;
268269
var customerEmail = order.customerEmail;
269270
var currencyCode = order.currencyCode.toUpperCase();
270271
try {

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

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ function paSetup(billingDetails, referenceInformationCode, cardData) {
7979
fluidData.value = cardData.fluidData;
8080
fluidData.key = configObject.visaSRCKey;
8181
paymentInformation.fluidData = fluidData;
82+
} else if (cardData.googlePayFluidData != null) {
83+
processingInformation.paymentSolution = '012'; //googlepay
84+
var fluidData = new cybersourceRestApi.Ptsv2paymentsPaymentInformationFluidData();
85+
fluidData.value = cardData.googlePayFluidData;
86+
paymentInformation.fluidData = fluidData;
8287
} else {
8388
card = new cybersourceRestApi.Ptsv2paymentsPaymentInformationCard();
8489
card.expirationMonth = billingDetails.creditCardFields.expirationMonth.value;
@@ -153,14 +158,15 @@ function paEnroll(billingDetails, shippingAddress, referenceInformationCode, tot
153158

154159
var billTo = new cybersourceRestApi.Ptsv2paymentsOrderInformationBillTo();
155160
billTo.email = order.getCustomerEmail();
156-
billTo.country = billingDetails.addressFields.country.htmlValue;
157-
billTo.firstName = billingDetails.addressFields.firstName.htmlValue;
158-
billTo.lastName = billingDetails.addressFields.lastName.htmlValue;
159-
billTo.phoneNumber = billingDetails.contactInfoFields.phone.htmlValue;
160-
billTo.address1 = billingDetails.addressFields.address1.htmlValue;
161-
billTo.postalCode = billingDetails.addressFields.postalCode.htmlValue;
162-
billTo.administrativeArea = billingDetails.addressFields.states && billingDetails.addressFields.states.stateCode.htmlValue;
163-
billTo.locality = billingDetails.addressFields.city.htmlValue;
161+
billTo.country = order.billingAddress.countryCode.toString().toUpperCase();
162+
billTo.firstName = order.billingAddress.firstName;
163+
billTo.lastName = order.billingAddress.lastName;
164+
billTo.phoneNumber = order.billingAddress.phone;
165+
billTo.address1 = order.billingAddress.address1;
166+
billTo.address2 = order.billingAddress.address2;
167+
billTo.postalCode = order.billingAddress.postalCode;
168+
billTo.administrativeArea = order.billingAddress.stateCode;
169+
billTo.locality = order.billingAddress.city;
164170

165171
var shipTo = new cybersourceRestApi.Ptsv2paymentsOrderInformationShipTo();
166172
shipTo.email = order.getCustomerEmail();
@@ -242,6 +248,11 @@ function paEnroll(billingDetails, shippingAddress, referenceInformationCode, tot
242248
fluidData.value = cardData.fluidData;
243249
fluidData.key = configObject.visaSRCKey;
244250
paymentInformation.fluidData = fluidData;
251+
} else if (cardData.googlePayFluidData != null) {
252+
processingInformation.paymentSolution = '012'; //googlepay
253+
var fluidData = new cybersourceRestApi.Ptsv2paymentsPaymentInformationFluidData();
254+
fluidData.value = cardData.googlePayFluidData;
255+
paymentInformation.fluidData = fluidData;
245256
} else {
246257
card = new cybersourceRestApi.Ptsv2paymentsPaymentInformationCard();
247258
card.expirationMonth = billingDetails.creditCardFields.expirationMonth.value;
@@ -315,15 +326,15 @@ function paConsumerAuthenticate(billingDetails, referenceInformationCode, total,
315326

316327
var billTo = new cybersourceRestApi.Ptsv2paymentsOrderInformationBillTo();
317328
billTo.email = order.getCustomerEmail();
318-
billTo.country = billingDetails.addressFields.country.htmlValue;
319-
billTo.firstName = billingDetails.addressFields.firstName.htmlValue;
320-
billTo.lastName = billingDetails.addressFields.lastName.htmlValue;
321-
billTo.phoneNumber = billingDetails.contactInfoFields.phone.htmlValue;
322-
billTo.address1 = billingDetails.addressFields.address1.htmlValue;
323-
billTo.postalCode = billingDetails.addressFields.postalCode.htmlValue;
324-
billTo.administrativeArea = billingDetails.addressFields.states
325-
&& billingDetails.addressFields.states.stateCode.htmlValue;
326-
billTo.locality = billingDetails.addressFields.city.htmlValue;
329+
billTo.country = order.billingAddress.countryCode.toString().toUpperCase();
330+
billTo.firstName = order.billingAddress.firstName;
331+
billTo.lastName = order.billingAddress.lastName;
332+
billTo.phoneNumber = order.billingAddress.phone;
333+
billTo.address1 = order.billingAddress.address1;
334+
billTo.address2 = order.billingAddress.address2;
335+
billTo.postalCode = order.billingAddress.postalCode;
336+
billTo.administrativeArea = order.billingAddress.stateCode;
337+
billTo.locality = order.billingAddress.city;
327338

328339
var orderInformation = new cybersourceRestApi.Ptsv2paymentsOrderInformation();
329340
orderInformation.amountDetails = amountDetails;
@@ -363,6 +374,11 @@ function paConsumerAuthenticate(billingDetails, referenceInformationCode, total,
363374
fluidData.value = cardData.fluidData;
364375
fluidData.key = configObject.visaSRCKey;
365376
paymentInformation.fluidData = fluidData;
377+
} else if (cardData.googlePayFluidData != null) {
378+
processingInformation.paymentSolution = '012'; //googlepay
379+
var fluidData = new cybersourceRestApi.Ptsv2paymentsPaymentInformationFluidData();
380+
fluidData.value = cardData.googlePayFluidData;
381+
paymentInformation.fluidData = fluidData;
366382
} else {
367383
var card = new cybersourceRestApi.Ptsv2paymentsPaymentInformationCard(); // eslint-disable-line no-redeclare
368384
card.expirationMonth = billingDetails.creditCardFields.expirationMonth.value;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ function httpZeroDollarAuth(
174174
customerEmail, referenceInformationCode, billingAddress, currency, skipDMFlag
175175
) {
176176
var configObject = require('../../configuration/index');
177-
session.custom.scaTokenFlag = false;
178177
var padNumber = require('../util/pad');
179178
var cybersourceRestApi = require('../../apiClient/index');
180179

@@ -293,7 +292,6 @@ function httpZeroDollarAuthWithTransientToken(
293292
customerEmail, referenceInformationCode, billingAddress, currency
294293
) {
295294
var configObject = require('../../configuration/index');
296-
session.custom.scaTokenFlag = false;
297295
var cybersourceRestApi = require('../../apiClient/index');
298296
var errors = require('~/cartridge/scripts/util/errors');
299297
var instance = new cybersourceRestApi.PaymentsApi(configObject);
@@ -492,7 +490,10 @@ function createFlexKey() { // eslint-disable-line no-unused-vars
492490
Constants.PROXY_PREFIX + '://' + request.httpHost
493491
],
494492
'allowedCardNetworks': list,
495-
'clientVersion': Constants.CLIENT_VERSION
493+
'clientVersion': Constants.CLIENT_VERSION,
494+
'transientTokenResponseOptions':{
495+
'includeCardPrefix':false
496+
}
496497
};
497498
var opts = {};
498499
opts.format = 'JWT';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "int_cybs_sfra",
3-
"version": "25.2.0",
3+
"version": "25.3.0",
44
"description": "New overlay cartridge",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)