Skip to content

Commit

Permalink
AD-321: Implement Configuration for Enabling Express Payments
Browse files Browse the repository at this point in the history
  • Loading branch information
kpieloch committed Nov 22, 2024
1 parent b8a7a93 commit 068e75f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ export interface AdyenConfigData {
countryCode: string;
cardHolderNameRequired: boolean;
sepaDirectDebit: boolean;
expressPaymentConfig: {
googlePayExpressEnabledOnCart: boolean,
applePayExpressEnabledOnCart: boolean,
paypalExpressEnabledOnCart: boolean,
amazonPayExpressEnabledOnCart: boolean,
googlePayExpressEnabledOnProduct: boolean,
applePayExpressEnabledOnProduct: boolean,
paypalExpressEnabledOnProduct: boolean,
amazonPayExpressEnabledOnProduct: boolean
}
}

interface SessionData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,40 @@ export class GoogleExpressPaymentComponent implements OnInit, OnDestroy{
private async setupAdyenCheckout(config: AdyenConfigData) {
const adyenCheckout = await AdyenCheckout(this.getAdyenCheckoutConfig(config));

this.googlePay = new GooglePay(adyenCheckout, {
callbackIntents: ['SHIPPING_ADDRESS'],
shippingAddressRequired: true,
shippingOptionRequired: false,
emailRequired: true,
shippingAddressParameters: {
allowedCountryCodes: [],
phoneNumberRequired: false
},
isExpress: true,
transactionInfo: {
totalPriceStatus: 'FINAL',
totalPriceLabel: 'Total',
totalPrice: this.product?.price?.value ? this.product.price.value.toString() : config.amountDecimal.toString(),
currencyCode: this.product?.price?.currencyIso ? this.product.price.currencyIso : config.amount.currency,
countryCode: 'US'
},
onSubmit: (state: any, element: UIElement, actions) => this.handleOnSubmit(state, actions),
paymentDataCallbacks: {
onPaymentDataChanged: async (intermediatePaymentData) => {
return new Promise(async resolve => {
const paymentDataRequestUpdate: google.payments.api.PaymentDataRequestUpdate = {};
resolve(paymentDataRequestUpdate);
});
if (config.expressPaymentConfig && (this.product && config.expressPaymentConfig.googlePayExpressEnabledOnProduct || config.expressPaymentConfig.amazonPayExpressEnabledOnProduct)){
this.googlePay = new GooglePay(adyenCheckout, {
callbackIntents: ['SHIPPING_ADDRESS'],
shippingAddressRequired: true,
shippingOptionRequired: false,
emailRequired: true,
shippingAddressParameters: {
allowedCountryCodes: [],
phoneNumberRequired: false
},
},
onAuthorized: (paymentData, actions) => {
this.authorizedPaymentData = paymentData;
actions.resolve();
},
onError: (error) => this.handleError(error)
}).mount("#google-pay-button");
isExpress: true,
transactionInfo: {
totalPriceStatus: 'FINAL',
totalPriceLabel: 'Total',
totalPrice: this.product?.price?.value ? this.product.price.value.toString() : config.amountDecimal.toString(),
currencyCode: this.product?.price?.currencyIso ? this.product.price.currencyIso : config.amount.currency,
countryCode: 'US'
},
onSubmit: (state: any, element: UIElement, actions) => this.handleOnSubmit(state, actions),
paymentDataCallbacks: {
onPaymentDataChanged: async (intermediatePaymentData) => {
return new Promise(async resolve => {
const paymentDataRequestUpdate: google.payments.api.PaymentDataRequestUpdate = {};
resolve(paymentDataRequestUpdate);
});
},
},
onAuthorized: (paymentData, actions) => {
this.authorizedPaymentData = paymentData;
actions.resolve();
},
onError: (error) => this.handleError(error)
}).mount("#google-pay-button");
}
}

private handleOnSubmit(state: any, actions: any) {
Expand Down

0 comments on commit 068e75f

Please sign in to comment.