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

[PW-7460] - Support googlepay tx_variant #8

Merged
merged 3 commits into from
Nov 11, 2022
Merged
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
24 changes: 16 additions & 8 deletions view/frontend/web/js/googlepay/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ define([
googlePayToken: null,
googlePayAllowed: null,
isProductView: false,
maskedId: null
maskedId: null,
googlePayTxVariant: null
},

initialize: async function (config, element) {
Expand All @@ -74,9 +75,9 @@ define([
'googlePayAllowed'
]);


this.isProductView = config.isProductView;
let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView);
let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView) ?? await getPaymentMethod('googlepay', this.isProductView);
candemiralp marked this conversation as resolved.
Show resolved Hide resolved
this.googlePayTxVariant = googlePaymentMethod;

// If express methods is not set then set it.
if (this.isProductView) {
Expand Down Expand Up @@ -107,7 +108,8 @@ define([
});
}.bind(this));

googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView);
let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView) ?? await getPaymentMethod('googlepay', this.isProductView);
this.googlePayTxVariant = googlePaymentMethod;

if (!isConfigSet(googlePaymentMethod, ['gatewayMerchantId', 'merchantId'])) {
return;
Expand Down Expand Up @@ -136,7 +138,7 @@ define([
});
const googlePayConfig = this.getGooglePayConfig(googlePaymentMethod, element);

this.googlepay = checkoutComponent.create('paywithgoogle', googlePayConfig);
this.googlepay = checkoutComponent.create(googlePaymentMethod, googlePayConfig);

this.googlepay.isAvailable()
.then(function () {
Expand All @@ -156,7 +158,9 @@ define([
},

reloadGooglePayButton: async function (element) {
const googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView);
let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView) ?? await getPaymentMethod('googlepay', this.isProductView);
this.googlePayTxVariant = googlePaymentMethod;

const pdpResponse = await getExpressMethods().getRequest(element);

setExpressMethods(pdpResponse);
Expand Down Expand Up @@ -300,13 +304,17 @@ define([
},

startPlaceOrder: function (paymentData) {
debugger;

let self = this;

this.setShippingInformation(paymentData)
.done(function () {
const stateData = JSON.stringify({
paymentMethod: {
googlePayCardNetwork: paymentData.paymentMethodData.info.cardNetwork,
googlePayToken: paymentData.paymentMethodData.tokenizationData.token,
type: 'paywithgoogle'
type: self.googlePayTxVariant.type
}
}),
payload = {
Expand All @@ -316,7 +324,7 @@ define([
paymentMethod: {
method: 'adyen_hpp',
additional_data: {
brand_code: 'paywithgoogle',
brand_code: self.googlePayTxVariant.type,
stateData
},
extension_attributes: getExtensionAttributes(paymentData)
Expand Down
8 changes: 6 additions & 2 deletions view/frontend/web/js/helpers/getPaymentMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ define([

const foundMethods = findPaymentMethod(paymentMethods, paymentType);

foundMethods.configuration = convertKeysToCamelCase(foundMethods.configuration);
return foundMethods;
if (!!foundMethods) {
foundMethods.configuration = convertKeysToCamelCase(foundMethods.configuration);
return foundMethods;
}

return null;
});

};
Expand Down