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

Feature/ad 332 #472

Merged
merged 7 commits into from
Nov 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
amountDecimal: '${amountDecimal}',
merchantAccount: '${merchantAccount}',
label: ['visible-xs', 'hidden-xs'],
applePayMerchantIdentifier: '${applePayMerchantIdentifier}',
applePayMerchantName: '${applePayMerchantName}',
pageType: '${pageType}',
productCode: '${product.code}'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
<div class="adyen-google-pay-button">
</div>
</div>
<div class="col-sm-4 col-md-3 pull-right">
<div class="adyen-apple-pay-button">
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@

<div class="adyen-google-pay-button">
</div>
<div class="adyen-apple-pay-button">
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var AdyenExpressCheckoutHybris = (function() {
var AdyenExpressCheckoutHybris = (function () {
'use strict';

var ErrorMessages = {
Expand All @@ -11,13 +11,11 @@ var AdyenExpressCheckoutHybris = (function() {
return {

adyenConfig: {
merchantName: null,
merchantId: null,
pageType: null,
productCode: null
},

initiateCheckout: async function(initConfig) {
initiateCheckout: async function (initConfig) {
const configuration = {
...initConfig,
analytics: {
Expand All @@ -30,49 +28,34 @@ var AdyenExpressCheckoutHybris = (function() {
console.error("Checkout error occured");
},
};

return await AdyenWeb.AdyenCheckout(configuration);
},
initExpressCheckout: async function (params, config) {
var checkoutPromise = this.initiateCheckout(config);
checkoutPromise.then((checkout) => {
this.initiateGooglePayExpress(checkout, params)
this.initiateApplePayExpress(checkout, params)
});
},
initiateApplePayExpress: async function(params, config) {
var checkoutPromise = this.initiateCheckout(config);
initiateApplePayExpress: async function (checkout, params) {
const {
amount,
countryCode,
applePayMerchantIdentifier,
applePayMerchantName,
pageType,
productCode
} = params;

const applePayNode = document.getElementById('adyen-component-button-container');
const applePayNodes = document.getElementsByClassName('adyen-apple-pay-button');

this.adyenConfig.merchantName = applePayMerchantName;
this.adyenConfig.merchantId = applePayMerchantIdentifier;
this.adyenConfig.pageType = pageType;
this.adyenConfig.productCode = productCode;

const applePayConfiguration = {
//onValidateMerchant is required if you're using your own Apple Pay certificate
onValidateMerchant: (resolve, reject, validationURL) => {
resolve();
}
};
checkoutPromise.then((checkout) => {
var applePayComponent = checkout.create("applepay", {

for (let applePayNode of applePayNodes) {
let applePayComponent = new AdyenWeb.ApplePay(checkout, {
amount: {
currency: amount.currency,
value: amount.value
},
configuration: {
merchantName: applePayMerchantName,
merchantId: applePayMerchantIdentifier
},
// Button config
buttonType: "check-out",
buttonColor: "black",
Expand All @@ -91,10 +74,14 @@ var AdyenExpressCheckoutHybris = (function() {
// }
// resolve(shippingMethodUpdate);
// },
onClick: function(resolve, reject) {
//onValidateMerchant is required if you're using your own Apple Pay certificate
onValidateMerchant: (resolve, reject, validationURL) => {
resolve();
},
onClick: function (resolve, reject) {
resolve();
},
onSubmit: function(state, component) {
onSubmit: function (state, component) {
// empty to block session flow, submit logic done in onAuthorized
},
onAuthorized: (resolve, reject, event) => {
Expand All @@ -103,14 +90,13 @@ var AdyenExpressCheckoutHybris = (function() {
}
});
applePayComponent.isAvailable()
.then(function() {
.then(function () {
applePayComponent.mount(applePayNode);
})
.catch(function(e) {
.catch(function (e) {
// Apple Pay is not available
console.log('Something went wrong trying to mount the Apple Pay component');
});
})
}
},
initiateGooglePayExpress: function (checkout, params) {
const {
Expand Down Expand Up @@ -235,7 +221,7 @@ var AdyenExpressCheckoutHybris = (function() {
type: "POST",
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
success: function(response) {
success: function (response) {
try {
if (response.resultCode && (response.resultCode === 'Authorised' || response.resultCode === 'RedirectShopper')) {
resolve();
Expand All @@ -249,7 +235,7 @@ var AdyenExpressCheckoutHybris = (function() {
AdyenExpressCheckoutHybris.handleResult(ErrorMessages.PaymentError, true);
}
},
error: function(xmlHttpResponse, exception) {
error: function (xmlHttpResponse, exception) {
reject();
var responseMessage = xmlHttpResponse.responseJSON;
if (xmlHttpResponse.status === 400) {
Expand All @@ -261,7 +247,7 @@ var AdyenExpressCheckoutHybris = (function() {
}
})
},
handleResult: function(data, error) {
handleResult: function (data, error) {
if (error) {
if (data) {
document.querySelector("#resultCode").value = data.resultCode;
Expand All @@ -274,48 +260,34 @@ var AdyenExpressCheckoutHybris = (function() {
}
document.querySelector("#handleComponentResultForm").submit();
},
prepareDataApple: function(event) {
//TODO: Refactor as google data
prepareDataApple: function (event) {
const baseData = {
applePayDetails: {
applePayToken: btoa(JSON.stringify(event.payment.token.paymentData))
},
addressData: {
email: event.payment.shippingContact.emailAddress,
firstName: event.payment.shippingContact.givenName,
lastName: event.payment.shippingContact.familyName,
line1: event.payment.shippingContact.addressLines[0],
line2: event.payment.shippingContact.addressLines[1],
postalCode: event.payment.shippingContact.postalCode,
town: event.payment.shippingContact.locality,
country: {
isocode: event.payment.shippingContact.countryCode,
name: event.payment.shippingContact.country
}
}
}

if (this.adyenConfig.pageType === 'PDP') {
return {
productCode: this.adyenConfig.productCode,
adyenApplePayMerchantName: this.adyenConfig.merchantName,
adyenApplePayMerchantIdentifier: this.adyenConfig.merchantId,
applePayToken: btoa(JSON.stringify(event.payment.token.paymentData)),
addressData: {
email: event.payment.shippingContact.emailAddress,
firstName: event.payment.shippingContact.givenName,
lastName: event.payment.shippingContact.familyName,
line1: event.payment.shippingContact.addressLines[0],
line2: event.payment.shippingContact.addressLines[1],
postalCode: event.payment.shippingContact.postalCode,
town: event.payment.shippingContact.locality,
country: {
isocode: event.payment.shippingContact.countryCode,
name: event.payment.shippingContact.country
}
}
...baseData
}
}
if (this.adyenConfig.pageType === 'cart') {
return {
adyenApplePayMerchantName: this.adyenConfig.merchantName,
adyenApplePayMerchantIdentifier: this.adyenConfig.merchantId,
applePayToken: btoa(JSON.stringify(event.payment.token.paymentData)),
addressData: {
email: event.payment.shippingContact.emailAddress,
firstName: event.payment.shippingContact.givenName,
lastName: event.payment.shippingContact.familyName,
line1: event.payment.shippingContact.addressLines[0],
line2: event.payment.shippingContact.addressLines[1],
postalCode: event.payment.shippingContact.postalCode,
town: event.payment.shippingContact.locality,
country: {
isocode: event.payment.shippingContact.countryCode,
name: event.payment.shippingContact.country
}
}
}
return baseData
}
console.error('unknown page type')
return {};
Expand Down Expand Up @@ -355,17 +327,17 @@ var AdyenExpressCheckoutHybris = (function() {
console.error('unknown page type')
return {};
},
getAppleUrl: function() {
getAppleUrl: function () {
if (this.adyenConfig.pageType === 'PDP') {
return ACC.config.encodedContextPath + '/expressCheckout/applePayPDP'
return ACC.config.encodedContextPath + '/express-checkout/apple/PDP'
}
if (this.adyenConfig.pageType === 'cart') {
return ACC.config.encodedContextPath + '/expressCheckout/cart'
return ACC.config.encodedContextPath + '/express-checkout/apple/cart'
}
console.error('unknown page type')
return null;
},
getGoogleUrl: function() {
getGoogleUrl: function () {
if (this.adyenConfig.pageType === 'PDP') {
return ACC.config.encodedContextPath + '/express-checkout/google/PDP'
}
Expand Down