From ad08480b67235b3d50902deb727e14ff22ff617d Mon Sep 17 00:00:00 2001
From: Pedro Silva
Date: Thu, 28 Sep 2023 09:32:09 +0100
Subject: [PATCH] Add GooglePay shipping support POC
---
.../src/Assets/ApplePayButton.php | 2 --
.../resources/js/GooglepayButton.js | 23 +++++++++++++++++--
modules/ppcp-googlepay/src/Assets/Button.php | 4 ----
3 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/modules/ppcp-applepay/src/Assets/ApplePayButton.php b/modules/ppcp-applepay/src/Assets/ApplePayButton.php
index 98a9e86ed..9a3934080 100644
--- a/modules/ppcp-applepay/src/Assets/ApplePayButton.php
+++ b/modules/ppcp-applepay/src/Assets/ApplePayButton.php
@@ -178,7 +178,6 @@ class ApplePayButton implements ButtonInterface {
$data['products'][0] = 'PAYMENT_METHODS';
}
$data['capabilities'][] = 'APPLE_PAY';
- $nonce = $data['operations'][0]['api_integration_preference']['rest_api_integration']['first_party_details']['seller_nonce'];
$data['operations'][] = array(
'operation' => 'API_INTEGRATION',
'api_integration_preference' => array(
@@ -190,7 +189,6 @@ class ApplePayButton implements ButtonInterface {
'PAYMENT',
'REFUND',
),
- 'seller_nonce' => $nonce,
),
),
),
diff --git a/modules/ppcp-googlepay/resources/js/GooglepayButton.js b/modules/ppcp-googlepay/resources/js/GooglepayButton.js
index ef601d82d..202fb7d89 100644
--- a/modules/ppcp-googlepay/resources/js/GooglepayButton.js
+++ b/modules/ppcp-googlepay/resources/js/GooglepayButton.js
@@ -104,7 +104,7 @@ class GooglepayButton {
environment: this.buttonConfig.environment,
// add merchant info maybe
paymentDataCallbacks: {
- //onPaymentDataChanged: onPaymentDataChanged,
+ onPaymentDataChanged: this.onPaymentDataChanged.bind(this),
onPaymentAuthorized: this.onPaymentAuthorized.bind(this),
}
});
@@ -186,15 +186,34 @@ class GooglepayButton {
paymentDataRequest.allowedPaymentMethods = googlePayConfig.allowedPaymentMethods;
paymentDataRequest.transactionInfo = await this.contextHandler.transactionInfo();
paymentDataRequest.merchantInfo = googlePayConfig.merchantInfo;
- paymentDataRequest.callbackIntents = ['PAYMENT_AUTHORIZATION'];
+ //paymentDataRequest.callbackIntents = ['PAYMENT_AUTHORIZATION'];
+
+ paymentDataRequest.callbackIntents = ["SHIPPING_ADDRESS", "SHIPPING_OPTION", "PAYMENT_AUTHORIZATION"];
+
+
+ paymentDataRequest.shippingAddressRequired = true;
+ paymentDataRequest.shippingAddressParameters = this.getGoogleShippingAddressParameters();
+ paymentDataRequest.shippingOptionRequired = true;
+
return paymentDataRequest;
}
+ getGoogleShippingAddressParameters() {
+ return {
+ allowedCountryCodes: ['US'],
+ phoneNumberRequired: true
+ };
+ }
//------------------------
// Payment process
//------------------------
+ onPaymentDataChanged(paymentData) {
+ console.log('[GooglePayButton] onPaymentDataChanged', this.context);
+ console.log('[GooglePayButton] paymentData', paymentData);
+ }
+
onPaymentAuthorized(paymentData) {
console.log('[GooglePayButton] onPaymentAuthorized', this.context);
return this.processPayment(paymentData);
diff --git a/modules/ppcp-googlepay/src/Assets/Button.php b/modules/ppcp-googlepay/src/Assets/Button.php
index f8edf694f..eb7de8360 100644
--- a/modules/ppcp-googlepay/src/Assets/Button.php
+++ b/modules/ppcp-googlepay/src/Assets/Button.php
@@ -198,9 +198,6 @@ class Button implements ButtonInterface {
}
$data['capabilities'][] = 'GOOGLE_PAY';
-
- $nonce = $data['operations'][0]['api_integration_preference']['rest_api_integration']['first_party_details']['seller_nonce'];
-
$data['operations'][] = array(
'operation' => 'API_INTEGRATION',
'api_integration_preference' => array(
@@ -212,7 +209,6 @@ class Button implements ButtonInterface {
'PAYMENT',
'REFUND',
),
- 'seller_nonce' => $nonce,
),
),
),