mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Get signup links without reloading the page (WIP)
This commit is contained in:
parent
aa156a17b2
commit
f1e54ced4f
5 changed files with 102 additions and 18 deletions
|
@ -87,7 +87,14 @@ const ppcp_onboarding = {
|
|||
}).then((res)=>{
|
||||
return res.json();
|
||||
}).then((data)=>{
|
||||
location.reload();
|
||||
buttons.forEach((element) => {
|
||||
for (let [key, value] of Object.entries(data.data.signup_links)) {
|
||||
key = 'connect-to' + key.replace(/-/g, '');
|
||||
if(key === element.id) {
|
||||
element.setAttribute('href', value);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
},
|
||||
|
|
|
@ -191,6 +191,9 @@ return array(
|
|||
return new PayUponInvoiceEndpoint(
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'button.request-data' ),
|
||||
$container->get( 'onboarding.signup-link-cache' ),
|
||||
$container->get( 'onboarding.render' ),
|
||||
$container->get( 'onboarding.signup-link-ids' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
},
|
||||
|
@ -213,6 +216,14 @@ return array(
|
|||
'onboarding.signup-link-cache' => static function( ContainerInterface $container ): Cache {
|
||||
return new Cache( 'ppcp-paypal-signup-link' );
|
||||
},
|
||||
'onboarding.signup-link-ids' => static function ( ContainerInterface $container ): array {
|
||||
return array(
|
||||
'production-ppcp',
|
||||
'production-express_checkout',
|
||||
'sandbox-ppcp',
|
||||
'sandbox-express_checkout',
|
||||
);
|
||||
},
|
||||
'onboarding.render' => static function ( ContainerInterface $container ) : OnboardingRenderer {
|
||||
$partner_referrals = $container->get( 'api.endpoint.partner-referrals-production' );
|
||||
$partner_referrals_sandbox = $container->get( 'api.endpoint.partner-referrals-sandbox' );
|
||||
|
|
|
@ -11,8 +11,10 @@ namespace WooCommerce\PayPalCommerce\Onboarding\Endpoint;
|
|||
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\Button\Endpoint\EndpointInterface;
|
||||
use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
|
||||
|
@ -35,6 +37,27 @@ class PayUponInvoiceEndpoint implements EndpointInterface {
|
|||
*/
|
||||
protected $request_data;
|
||||
|
||||
/**
|
||||
* The signup link cache.
|
||||
*
|
||||
* @var Cache
|
||||
*/
|
||||
protected $signup_link_cache;
|
||||
|
||||
/**
|
||||
* The onboarding renderer.
|
||||
*
|
||||
* @var OnboardingRenderer
|
||||
*/
|
||||
protected $onboarding_renderer;
|
||||
|
||||
/**
|
||||
* Signup link ids.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $signup_link_ids;
|
||||
|
||||
/**
|
||||
* The logger.
|
||||
*
|
||||
|
@ -45,14 +68,27 @@ class PayUponInvoiceEndpoint implements EndpointInterface {
|
|||
/**
|
||||
* PayUponInvoiceEndpoint constructor.
|
||||
*
|
||||
* @param Settings $settings The settings.
|
||||
* @param RequestData $request_data The request data.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param Settings $settings The settings.
|
||||
* @param RequestData $request_data The request data.
|
||||
* @param Cache $signup_link_cache The signup link cache.
|
||||
* @param OnboardingRenderer $onboarding_renderer The onboarding renderer.
|
||||
* @param array $signup_link_ids Signup link ids.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
*/
|
||||
public function __construct( Settings $settings, RequestData $request_data, LoggerInterface $logger ) {
|
||||
$this->settings = $settings;
|
||||
$this->request_data = $request_data;
|
||||
$this->logger = $logger;
|
||||
public function __construct(
|
||||
Settings $settings,
|
||||
RequestData $request_data,
|
||||
Cache $signup_link_cache,
|
||||
OnboardingRenderer $onboarding_renderer,
|
||||
array $signup_link_ids,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$this->settings = $settings;
|
||||
$this->request_data = $request_data;
|
||||
$this->signup_link_cache = $signup_link_cache;
|
||||
$this->onboarding_renderer = $onboarding_renderer;
|
||||
$this->logger = $logger;
|
||||
$this->signup_link_ids = $signup_link_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,18 +107,33 @@ class PayUponInvoiceEndpoint implements EndpointInterface {
|
|||
* @throws NotFoundException When order not found or handling failed.
|
||||
*/
|
||||
public function handle_request(): bool {
|
||||
$signup_links = array();
|
||||
|
||||
try {
|
||||
$data = $this->request_data->read_request( $this->nonce() );
|
||||
$this->settings->set( 'ppcp-onboarding-pui', $data['checked'] );
|
||||
$this->settings->persist();
|
||||
|
||||
foreach ( $this->signup_link_ids as $key ) {
|
||||
if ( $this->signup_link_cache->has( $key ) ) {
|
||||
$this->signup_link_cache->delete( $key );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $this->signup_link_ids as $key ) {
|
||||
$parts = explode( '-', $key );
|
||||
$is_production = 'production' === $parts[0];
|
||||
$products = 'ppcp' === $parts[1] ? array( 'PPCP' ) : array( 'EXPRESS_CHECKOUT' );
|
||||
$signup_links[ $key ] = $this->onboarding_renderer->get_signup_link( $is_production, $products );
|
||||
}
|
||||
} catch ( Exception $exception ) {
|
||||
$this->logger->error( $exception->getMessage() );
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
$this->settings->get( 'ppcp-onboarding-pui' ),
|
||||
'onboarding_pui' => $this->settings->get( 'ppcp-onboarding-pui' ),
|
||||
'signup_links' => $signup_links,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue