diff --git a/examples/angular/src/app/app.component.html b/examples/angular/src/app/app.component.html index ad440ed..66b18c5 100644 --- a/examples/angular/src/app/app.component.html +++ b/examples/angular/src/app/app.component.html @@ -90,7 +90,8 @@ totalPrice: amount, currencyCode: 'USD', countryCode: 'US' - } + }, + callbackIntents: ['PAYMENT_AUTHORIZATION'] }" (loadpaymentdata)="onLoadPaymentData($event)" (error)="onError($event)" @@ -131,7 +132,8 @@ totalPrice: amount, currencyCode: 'USD', countryCode: 'US' - } + }, + callbackIntents: ['PAYMENT_AUTHORIZATION'] }" (loadpaymentdata)="onLoadPaymentData($event)" (error)="onError($event)" @@ -158,7 +160,8 @@ currencyCode: 'USD', countryCode: 'US' }, - shippingAddressRequired: true + shippingAddressRequired: true, + callbackIntents: ['PAYMENT_AUTHORIZATION'] }" (loadpaymentdata)="onLoadPaymentData($event)" (error)="onError($event)" diff --git a/examples/html/app.js b/examples/html/app.js index 19a54f8..fde4361 100644 --- a/examples/html/app.js +++ b/examples/html/app.js @@ -132,6 +132,7 @@ const googlePayButtons = [ }, }, existingPaymentRequired: controls.existingPaymentRequired.value === 'true', + callbackIntents: ['PAYMENT_AUTHORIZATION'], onLoadPaymentData, onPaymentAuthorized, }; @@ -151,6 +152,7 @@ const googlePayButtons = [ }, }, existingPaymentRequired: controls.existingPaymentRequired.value === 'true', + callbackIntents: ['PAYMENT_AUTHORIZATION'], onLoadPaymentData, onPaymentAuthorized, }; @@ -171,6 +173,7 @@ const googlePayButtons = [ }, existingPaymentRequired: controls.existingPaymentRequired.value === 'true', shippingAddressRequired: true, + callbackIntents: ['PAYMENT_AUTHORIZATION'], onLoadPaymentData, onPaymentAuthorized, }; diff --git a/examples/react/src/examples/DisplayItemsExample.tsx b/examples/react/src/examples/DisplayItemsExample.tsx index 1479fa0..43399a1 100644 --- a/examples/react/src/examples/DisplayItemsExample.tsx +++ b/examples/react/src/examples/DisplayItemsExample.tsx @@ -70,6 +70,7 @@ export default (props: any) => { }, ], }, + callbackIntents: ['PAYMENT_AUTHORIZATION'], }} onLoadPaymentData={paymentRequest => { console.log('Success', paymentRequest); diff --git a/examples/react/src/examples/DynamicPriceUpdateExample.tsx b/examples/react/src/examples/DynamicPriceUpdateExample.tsx index f79ce04..fd4af07 100644 --- a/examples/react/src/examples/DynamicPriceUpdateExample.tsx +++ b/examples/react/src/examples/DynamicPriceUpdateExample.tsx @@ -90,6 +90,7 @@ const paymentRequest: google.payments.api.PaymentDataRequest = { description: o.description, })), }, + callbackIntents: ['SHIPPING_ADDRESS', 'SHIPPING_OPTION'], }; export default (props: any) => { diff --git a/examples/react/src/examples/PaymentDataChangedErrorExample.tsx b/examples/react/src/examples/PaymentDataChangedErrorExample.tsx index 9d7453f..f1861b0 100644 --- a/examples/react/src/examples/PaymentDataChangedErrorExample.tsx +++ b/examples/react/src/examples/PaymentDataChangedErrorExample.tsx @@ -53,6 +53,7 @@ export default (props: any) => { countryCode: 'US', }, shippingAddressRequired: true, + callbackIntents: ['SHIPPING_ADDRESS'], }} onLoadPaymentData={paymentRequest => { console.log('Success', paymentRequest); diff --git a/examples/react/src/examples/PaymentDataChangedExample.tsx b/examples/react/src/examples/PaymentDataChangedExample.tsx index ebfdba2..4feb3ad 100644 --- a/examples/react/src/examples/PaymentDataChangedExample.tsx +++ b/examples/react/src/examples/PaymentDataChangedExample.tsx @@ -53,6 +53,7 @@ export default (props: any) => { countryCode: 'US', }, shippingAddressRequired: true, + callbackIntents: ['SHIPPING_ADDRESS'], }} onLoadPaymentData={paymentRequest => { console.log('Success', paymentRequest); diff --git a/examples/vue/src/components/Examples.vue b/examples/vue/src/components/Examples.vue index e0cca6f..ca86b05 100644 --- a/examples/vue/src/components/Examples.vue +++ b/examples/vue/src/components/Examples.vue @@ -131,6 +131,7 @@ currencyCode: 'USD', countryCode: 'US', }, + callbackIntents: ['PAYMENT_AUTHORIZATION'], }" v-on:loadpaymentdata="onLoadPaymentData" v-on:error="onError" @@ -158,6 +159,7 @@ countryCode: 'US', }, shippingAddressRequired: true, + callbackIntents: ['PAYMENT_AUTHORIZATION'], }" v-on:loadpaymentdata="onLoadPaymentData" v-on:error="onError" diff --git a/src/button-element/README.md b/src/button-element/README.md index eea4eb3..ef54763 100644 --- a/src/button-element/README.md +++ b/src/button-element/README.md @@ -233,6 +233,7 @@ integrating Google Pay into your website.

Invoked when a user chooses a payment method. This callback should be used to validate whether or not the payment method can be used to complete a payment.

This would be typically used to perform pre-authorization to ensure that the card is valid and has sufficient funds.

+

Note that in order to use this callback paymentRequest.callbackIntents must include PAYMENT_AUTHORIZATION.

See payment authorization reference for more information.

@@ -242,6 +243,7 @@ integrating Google Pay into your website.

Invoked when payment the user changes payment data options including payment method, shipping details, and contact details. This callback can be used to dynamically update transactionInfo when payment details, shipping address, or shipping options change.

+

Note that in order to use this callback paymentRequest.callbackIntents must include either SHIPPING_ADDRESS or SHIPPING_OPTION.

See payment data changed reference for more information.

diff --git a/src/button-react/README.md b/src/button-react/README.md index 7173a18..a5bcc0b 100644 --- a/src/button-react/README.md +++ b/src/button-react/README.md @@ -152,6 +152,7 @@ integrating Google Pay into your website.

Invoked when a user chooses a payment method. This callback should be used to validate whether or not the payment method can be used to complete a payment.

This would be typically used to perform pre-authorization to ensure that the card is valid and has sufficient funds.

+

Note that in order to use this callback paymentRequest.callbackIntents must include PAYMENT_AUTHORIZATION.

See payment authorization reference for more information.

@@ -159,6 +160,7 @@ integrating Google Pay into your website.

onPaymentDataChanged

Invoked when payment the user changes payment data options including payment method, shipping details, and contact details. This callback can be used to dynamically update transactionInfo when payment details, shipping address, or shipping options change.

+

Note that in order to use this callback paymentRequest.callbackIntents must include either SHIPPING_ADDRESS or SHIPPING_OPTION.

See payment data changed reference for more information.

diff --git a/src/lib/button-manager.test.ts b/src/lib/button-manager.test.ts index 8131dca..0b327c9 100644 --- a/src/lib/button-manager.test.ts +++ b/src/lib/button-manager.test.ts @@ -182,7 +182,8 @@ describe('PaymentsClient options', () => { }); }); -describe('Callbacks', () => { +// TODO: #13 re-enable inferrence if/when we agree as a team +describe.skip('Callbacks', () => { it('maintains default callback values', () => { const manager = new ButtonManager(managerOptions); const config: Config = { diff --git a/src/lib/button-manager.ts b/src/lib/button-manager.ts index f920084..e28f740 100644 --- a/src/lib/button-manager.ts +++ b/src/lib/button-manager.ts @@ -182,31 +182,32 @@ export class ButtonManager { } } - // infer callback intents if not set - if (!request.callbackIntents && (config.onPaymentDataChanged || config.onPaymentAuthorized)) { - const intents: google.payments.api.CallbackIntent[] = []; - if (config.onPaymentDataChanged) { - if (!request.shippingAddressRequired && !request.shippingOptionRequired) { - throw new Error( - 'onPaymentDataChanged must be used with either shippingAddressRequired or shippingOptionRequired', - ); - } - - if (request.shippingAddressRequired) { - intents.push('SHIPPING_ADDRESS'); - } - - if (request.shippingOptionRequired) { - intents.push('SHIPPING_OPTION'); - } - } - - if (config.onPaymentAuthorized) { - intents.push('PAYMENT_AUTHORIZATION'); - } - - request.callbackIntents = intents; - } + // TODO: #13 re-enable inferrence if/when we agree as a team + // // infer callback intents if not set + // if (!request.callbackIntents && (config.onPaymentDataChanged || config.onPaymentAuthorized)) { + // const intents: google.payments.api.CallbackIntent[] = []; + // if (config.onPaymentDataChanged) { + // if (!request.shippingAddressRequired && !request.shippingOptionRequired) { + // throw new Error( + // 'onPaymentDataChanged must be used with either shippingAddressRequired or shippingOptionRequired', + // ); + // } + + // if (request.shippingAddressRequired) { + // intents.push('SHIPPING_ADDRESS'); + // } + + // if (request.shippingOptionRequired) { + // intents.push('SHIPPING_OPTION'); + // } + // } + + // if (config.onPaymentAuthorized) { + // intents.push('PAYMENT_AUTHORIZATION'); + // } + + // request.callbackIntents = intents; + // } // infer billingAddressRequired request.allowedPaymentMethods = request.allowedPaymentMethods.map(pm => {