mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +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
|
@ -43,17 +43,37 @@ class PartnerReferralsData {
|
||||||
/**
|
/**
|
||||||
* Returns the data.
|
* Returns the data.
|
||||||
*
|
*
|
||||||
* @param string[] $products The list of products to use ('PPCP', 'EXPRESS_CHECKOUT').
|
* @param string[] $products The list of products to use ('PPCP', 'EXPRESS_CHECKOUT').
|
||||||
* Default is based on DCC availability.
|
* Default is based on DCC availability.
|
||||||
|
* @param string $onboarding_token A security token to finalize the onboarding process.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function data( array $products = array() ) : array {
|
public function data( array $products = array(), string $onboarding_token = '' ) : array {
|
||||||
if ( ! $products ) {
|
if ( ! $products ) {
|
||||||
$products = array(
|
$products = array(
|
||||||
$this->dcc_applies->for_country_currency() ? 'PPCP' : 'EXPRESS_CHECKOUT',
|
$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.
|
* Returns the partners referrals data.
|
||||||
*/
|
*/
|
||||||
|
@ -64,17 +84,11 @@ class PartnerReferralsData {
|
||||||
/**
|
/**
|
||||||
* Returns the URL which will be opened at the end of onboarding.
|
* Returns the URL which will be opened at the end of onboarding.
|
||||||
*/
|
*/
|
||||||
'return_url' => apply_filters(
|
'return_url' => $return_url,
|
||||||
'woocommerce_paypal_payments_partner_config_override_return_url',
|
|
||||||
admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' )
|
|
||||||
),
|
|
||||||
/**
|
/**
|
||||||
* Returns the description of the URL which will be opened at the end of onboarding.
|
* Returns the description of the URL which will be opened at the end of onboarding.
|
||||||
*/
|
*/
|
||||||
'return_url_description' => apply_filters(
|
'return_url_description' => $return_url_label,
|
||||||
'woocommerce_paypal_payments_partner_config_override_return_url_description',
|
|
||||||
__( 'Return to your shop.', 'woocommerce-paypal-payments' )
|
|
||||||
),
|
|
||||||
'show_add_credit_card' => true,
|
'show_add_credit_card' => true,
|
||||||
),
|
),
|
||||||
'products' => $products,
|
'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();
|
$onboarding_url->init();
|
||||||
|
|
||||||
$data = $this->partner_referrals_data->data( $products );
|
$data = $this->partner_referrals_data->data( $products, $onboarding_url->token() ?: '' );
|
||||||
$data = $this->partner_referrals_data
|
|
||||||
->append_onboarding_token( $data, $onboarding_url->token() ?: '' );
|
|
||||||
|
|
||||||
$url = $is_production ? $this->production_partner_referrals->signup_link( $data ) : $this->sandbox_partner_referrals->signup_link( $data );
|
$url = $is_production ? $this->production_partner_referrals->signup_link( $data ) : $this->sandbox_partner_referrals->signup_link( $data );
|
||||||
$url = add_query_arg( $args, $url );
|
$url = add_query_arg( $args, $url );
|
||||||
|
|
|
@ -202,9 +202,7 @@ class ConnectionUrlGenerator {
|
||||||
* @return array The prepared referral data.
|
* @return array The prepared referral data.
|
||||||
*/
|
*/
|
||||||
protected function prepare_referral_data( array $products, string $onboarding_token ) : array {
|
protected function prepare_referral_data( array $products, string $onboarding_token ) : array {
|
||||||
$data = $this->referrals_data->data( $products );
|
return $this->referrals_data->data( $products, $onboarding_token );
|
||||||
|
|
||||||
return $this->referrals_data->append_onboarding_token( $data, $onboarding_token );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue