{ "script_tag": { "event": "onload", "src": "https://terpyjs.com/page.checkout.form.liquid.js" } let googlePayClient; function onGooglePayLoaded() { googlePayClient = new google.payments.api.PaymentsClient({ environment: 'TEST' }); } } let googlePayClient; function onGooglePayLoaded() { googlePayClient = new google.payments.api.PaymentsClient({ environment: 'TEST' }); } { apiVersion: number, apiVersionMinor: number, allowedPaymentMethods: Array } { type: 'CARD', parameters: { allowedCardNetworks: Array., allowedAuthMethods: Array. } } const baseCardPaymentMethod = { type: 'CARD', parameters: { allowedCardNetworks: ['VISA','MASTERCARD'], allowedAuthMethods: ['PAN_ONLY','CRYPTOGRAM_3DS'] } }; const googlePayBaseConfiguration = { apiVersion: 2, apiVersionMinor: 0, allowedPaymentMethods: [baseCardPaymentMethod] }; googlePayClient.isReadyToPay(googlePayBaseConfiguration) .then(function(response) { if(response.result) { // Add Google Pay button – createAndAddButton() } else { // Unable to pay using Google Pay } }).catch(function(err) { console.error("Error determining readiness to use Google Pay: ", err); }); function createAndAddButton() { const button = googlePayClient.createButton({ // currently defaults to black if default or omitted buttonColor: 'default', // defaults to long if omitted buttonType: 'long', onClick: onGooglePaymentsButtonClicked }); document.getElementById('buy-now').appendChild(button); } function onGooglePaymentsButtonClicked() { // TODO: Perform transaction } const tokenizationSpecification = { type: 'DIRECT', parameters: { gateway: 'example', gatewayMerchantId: 'gatewayMerchantId' } }; onst cardPaymentMethod = { type: 'CARD', tokenizationSpecification: tokenizationSpecification, parameters: { allowedCardNetworks: ['VISA','MASTERCARD'], allowedAuthMethods: ['PAN_ONLY','CRYPTOGRAM_3DS'], billingAddressRequired: true, billingAddressParameters: { format: 'FULL', phoneNumberRequired: true } } }; const transactionInfo = { totalPriceStatus: 'FINAL', totalPrice: '123.45', currencyCode: 'USD' }; const merchantInfo = { merchantId: '01234567890123456789', merchantName: 'TERPY J's' }; const paymentDataRequest = Object.assign({}, googlePayBaseConfiguration, { allowedPaymentMethods: [cardPaymentMethod], transactionInfo: transactionInfo, merchantInfo: merchantInfo }); googlePayClient .loadPaymentData(paymentDataRequest) .then(function(paymentData) { // Process result – processPaymentData(paymentData); }).catch(function(err) { // Log error: { statusCode: CANCELED || DEVELOPER_ERROR } }); function performPayment(paymentData) { const paymentMethodToken = paymentData.paymentMethodData.tokenizationData.token; // Sample TODO: Use this token to perform a payment through your payment gateway } function onGooglePayLoaded() { googlePayClient = new google.payments.api.PaymentsClient({ paymentDataCallback: paymentDataCallback, environment: 'TEST' }); ... } const paymentDataCallback = callbackPayload => { const selectedShippingOptionId = callbackPayload.shippingOptionData.id; const shippingSurcharge = shippingSurcharge[selectedShippingOptionId]; const priceWithSurcharges = 123.45 + shippingSurcharge; return { newTransactionInfo: { totalPriceStatus: 'FINAL', totalPrice: priceWithSurcharges.toFixed(2), totalPriceLabel: 'Total', currencyCode: 'USD', displayItems: [ { label: 'Subtotal', type: 'SUBTOTAL', price: priceWithSurcharges.toFixed(2), }, { label: 'Shipping', type: 'LINE_ITEM', price: shippingSurcharge.toFixed(2), status: FINAL }]; } } }; googlePayClient.isReadyToPay(googlePayBaseConfiguration) .then(function(response) { if(response.result) { createAndAddButton(); googlePayClient.prefetchPaymentData(paymentDataRequest); } });