mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
♻️ Remove “append-token” method
We want to build the full payload, including the token, in the `::data()` method.
This commit is contained in:
parent
d1ee75b659
commit
f014539a95
3 changed files with 27 additions and 31 deletions
|
@ -45,15 +45,35 @@ class PartnerReferralsData {
|
|||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue