mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
adjust onboarding process to new settings mechanism
This commit is contained in:
parent
f09d71e888
commit
f74773952c
5 changed files with 49 additions and 42 deletions
13
modules.local/ppcp-onboarding/assets/js/onboarding.js
Normal file
13
modules.local/ppcp-onboarding/assets/js/onboarding.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
function onboardingCallback(authCode, sharedId) {
|
||||
fetch(PayPalCommerceGatewayOnboarding.endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
authCode: authCode,
|
||||
sharedId: sharedId,
|
||||
nonce: PayPalCommerceGatewayOnboarding.nonce
|
||||
})
|
||||
});
|
||||
}
|
|
@ -115,12 +115,12 @@ return [
|
|||
$requestData = $container->get('button.request-data');
|
||||
$loginSellerEndpoint = $container->get('api.endpoint.login-seller');
|
||||
$partnerReferralsData = $container->get('api.repository.partner-referrals-data');
|
||||
$gateway = $container->get('wcgateway.gateway.base');
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
return new LoginSellerEndpoint(
|
||||
$requestData,
|
||||
$loginSellerEndpoint,
|
||||
$partnerReferralsData,
|
||||
$gateway
|
||||
$settings
|
||||
);
|
||||
},
|
||||
'onboarding.render' => static function (ContainerInterface $container) : OnboardingRenderer {
|
||||
|
|
|
@ -9,6 +9,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
|
|||
use Inpsyde\PayPalCommerce\Button\Endpoint\EndpointInterface;
|
||||
use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGatewayInterface;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
class LoginSellerEndpoint implements EndpointInterface
|
||||
{
|
||||
|
@ -17,18 +18,18 @@ class LoginSellerEndpoint implements EndpointInterface
|
|||
private $requestData;
|
||||
private $loginSellerEndpoint;
|
||||
private $partnerReferralsData;
|
||||
private $gateway;
|
||||
private $settings;
|
||||
public function __construct(
|
||||
RequestData $requestData,
|
||||
LoginSeller $loginSellerEndpoint,
|
||||
PartnerReferralsData $partnerReferralsData,
|
||||
\WC_Payment_Gateway $gateway
|
||||
Settings $settings
|
||||
) {
|
||||
|
||||
$this->requestData = $requestData;
|
||||
$this->loginSellerEndpoint = $loginSellerEndpoint;
|
||||
$this->partnerReferralsData = $partnerReferralsData;
|
||||
$this->gateway = $gateway;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
public static function nonce(): string
|
||||
|
@ -46,8 +47,9 @@ class LoginSellerEndpoint implements EndpointInterface
|
|||
$data['authCode'],
|
||||
$this->partnerReferralsData->nonce()
|
||||
);
|
||||
$this->gateway->update_option('client_secret', $credentials->client_secret);
|
||||
$this->gateway->update_option('client_id', $credentials->client_id);
|
||||
$this->settings->set('client_secret', $credentials->client_secret);
|
||||
$this->settings->set('client_id', $credentials->client_id);
|
||||
$this->settings->persist();
|
||||
wp_send_json_success();
|
||||
return true;
|
||||
} catch (\RuntimeException $error) {
|
||||
|
|
|
@ -8,6 +8,7 @@ use Dhii\Container\ServiceProvider;
|
|||
use Dhii\Modular\Module\ModuleInterface;
|
||||
use Inpsyde\PayPalCommerce\Onboarding\Assets\OnboardingAssets;
|
||||
use Inpsyde\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
|
||||
use Inpsyde\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
|
||||
use Interop\Container\ServiceProviderInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
|
@ -43,6 +44,28 @@ class OnboardingModule implements ModuleInterface
|
|||
]
|
||||
);
|
||||
|
||||
|
||||
|
||||
add_filter(
|
||||
'woocommerce_form_field',
|
||||
static function ($field, $key, $config) use ($container) {
|
||||
if ($config['type'] !== 'ppcp_onboarding') {
|
||||
return $field;
|
||||
}
|
||||
$renderer = $container->get('onboarding.render');
|
||||
/**
|
||||
* @var OnboardingRenderer $renderer
|
||||
*/
|
||||
ob_start();
|
||||
$renderer->render();
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $content;
|
||||
},
|
||||
10,
|
||||
3
|
||||
);
|
||||
|
||||
add_action(
|
||||
'wc_ajax_' . LoginSellerEndpoint::ENDPOINT,
|
||||
static function () use ($container) {
|
||||
|
|
|
@ -25,26 +25,6 @@ class OnboardingRenderer
|
|||
$this->partnerReferrals->signupLink()
|
||||
);
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc">
|
||||
<?php echo esc_html_e('Connect to PayPal', 'woocommerce-paypal-commerce-gateway'); ?>
|
||||
</th>
|
||||
<td class="forminp">
|
||||
<script>
|
||||
function onboardingCallback(authCode, sharedId) {
|
||||
fetch(PayPalCommerceGatewayOnboarding.endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
authCode: authCode,
|
||||
sharedId: sharedId,
|
||||
nonce: PayPalCommerceGatewayOnboarding.nonce
|
||||
})
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<a
|
||||
target="_blank"
|
||||
class="button-primary"
|
||||
|
@ -58,23 +38,12 @@ class OnboardingRenderer
|
|||
id="paypal-js"
|
||||
src="https://www.sandbox.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js"
|
||||
></script>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
} catch(RuntimeException $exception) {
|
||||
?>
|
||||
<tr valign="top">
|
||||
<th scope="row" class="titledesc">
|
||||
<?php echo esc_html_e('Connect to PayPal', 'woocommerce-paypal-commerce-gateway'); ?>
|
||||
</th>
|
||||
<td>
|
||||
<?php echo esc_html_e(
|
||||
'We could not properly connect to PayPal. Please reload the page to continue',
|
||||
'woocommerce-paypal-commerce-gateway'
|
||||
); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
esc_html_e(
|
||||
'We could not properly connect to PayPal. Please reload the page to continue',
|
||||
'woocommerce-paypal-commerce-gateway'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue