From f014539a95a23197f50f2649b3ba363eadfacfed Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Wed, 5 Mar 2025 15:14:52 +0100
Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Remove=20=E2=80=9Cappend-t?=
=?UTF-8?q?oken=E2=80=9D=20method?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We want to build the full payload, including the token, in the `::data()` method.
---
.../src/Repository/PartnerReferralsData.php | 50 +++++++++----------
.../src/Render/OnboardingRenderer.php | 4 +-
.../src/Service/ConnectionUrlGenerator.php | 4 +-
3 files changed, 27 insertions(+), 31 deletions(-)
diff --git a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
index d5a705b95..527fb6fd0 100644
--- a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
+++ b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php
@@ -43,17 +43,37 @@ class PartnerReferralsData {
/**
* Returns the data.
*
- * @param string[] $products The list of products to use ('PPCP', 'EXPRESS_CHECKOUT').
- * Default is based on DCC availability.
+ * @param string[] $products The list of products to use ('PPCP', 'EXPRESS_CHECKOUT').
+ * Default is based on DCC availability.
+ * @param string $onboarding_token A security token to finalize the onboarding process.
* @return array
*/
- public function data( array $products = array() ) : array {
+ public function data( array $products = array(), string $onboarding_token = '' ) : array {
if ( ! $products ) {
$products = array(
$this->dcc_applies->for_country_currency() ? 'PPCP' : 'EXPRESS_CHECKOUT',
);
}
+ /**
+ * Filter the return-URL, which is called at the end of the OAuth onboarding
+ * process, when the merchant clicks the "Return to your shop" button.
+ */
+ $return_url = apply_filters(
+ 'woocommerce_paypal_payments_partner_config_override_return_url',
+ admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' )
+ );
+ $return_url = add_query_arg( array( 'ppcpToken' => $onboarding_token ), $return_url );
+
+ /**
+ * Filter the label of the "Return to your shop" button.
+ * It's displayed on the very last page of the onboarding popup.
+ */
+ $return_url_label = apply_filters(
+ 'woocommerce_paypal_payments_partner_config_override_return_url_description',
+ __( 'Return to your shop.', 'woocommerce-paypal-payments' )
+ );
+
/**
* Returns the partners referrals data.
*/
@@ -64,17 +84,11 @@ class PartnerReferralsData {
/**
* Returns the URL which will be opened at the end of onboarding.
*/
- 'return_url' => apply_filters(
- 'woocommerce_paypal_payments_partner_config_override_return_url',
- admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' )
- ),
+ 'return_url' => $return_url,
/**
* Returns the description of the URL which will be opened at the end of onboarding.
*/
- 'return_url_description' => apply_filters(
- 'woocommerce_paypal_payments_partner_config_override_return_url_description',
- __( 'Return to your shop.', 'woocommerce-paypal-payments' )
- ),
+ 'return_url_description' => $return_url_label,
'show_add_credit_card' => true,
),
'products' => $products,
@@ -109,18 +123,4 @@ class PartnerReferralsData {
)
);
}
-
- /**
- * Append the validation token to the return_url
- *
- * @param array $data The referral data.
- * @param string $token The token to be appended.
- * @return array
- */
- public function append_onboarding_token( array $data, string $token ) : array {
- $data['partner_config_override']['return_url'] =
- add_query_arg( 'ppcpToken', $token, $data['partner_config_override']['return_url'] );
-
- return $data;
- }
}
diff --git a/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php b/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
index 2659e7dbb..13189fd77 100644
--- a/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
+++ b/modules/ppcp-onboarding/src/Render/OnboardingRenderer.php
@@ -118,9 +118,7 @@ class OnboardingRenderer {
$onboarding_url->init();
- $data = $this->partner_referrals_data->data( $products );
- $data = $this->partner_referrals_data
- ->append_onboarding_token( $data, $onboarding_url->token() ?: '' );
+ $data = $this->partner_referrals_data->data( $products, $onboarding_url->token() ?: '' );
$url = $is_production ? $this->production_partner_referrals->signup_link( $data ) : $this->sandbox_partner_referrals->signup_link( $data );
$url = add_query_arg( $args, $url );
diff --git a/modules/ppcp-settings/src/Service/ConnectionUrlGenerator.php b/modules/ppcp-settings/src/Service/ConnectionUrlGenerator.php
index 66dc1415e..1d9084912 100644
--- a/modules/ppcp-settings/src/Service/ConnectionUrlGenerator.php
+++ b/modules/ppcp-settings/src/Service/ConnectionUrlGenerator.php
@@ -202,9 +202,7 @@ class ConnectionUrlGenerator {
* @return array The prepared referral data.
*/
protected function prepare_referral_data( array $products, string $onboarding_token ) : array {
- $data = $this->referrals_data->data( $products );
-
- return $this->referrals_data->append_onboarding_token( $data, $onboarding_token );
+ return $this->referrals_data->data( $products, $onboarding_token );
}
/**