mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
catch exception
This commit is contained in:
parent
85944d392a
commit
3a4b942663
1 changed files with 60 additions and 43 deletions
|
@ -5,6 +5,7 @@ namespace Inpsyde\PayPalCommerce\Onboarding\Render;
|
|||
|
||||
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Endpoint\PartnerReferrals;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
|
||||
class OnboardingRenderer
|
||||
{
|
||||
|
@ -16,48 +17,64 @@ class OnboardingRenderer
|
|||
}
|
||||
|
||||
public function render() {
|
||||
$url = add_query_arg(
|
||||
[
|
||||
'displayMode'=>'minibrowser',
|
||||
],
|
||||
$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"
|
||||
data-paypal-onboard-complete="onboardingCallback"
|
||||
href="<?php echo esc_url($url); ?>"
|
||||
data-paypal-button="true"
|
||||
><?php
|
||||
esc_html_e('Sign up for PayPal', 'woocommerce-paypal-commerce-gateway');
|
||||
?></a>
|
||||
<script
|
||||
id="paypal-js"
|
||||
src="https://www.sandbox.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js"
|
||||
></script>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
try {
|
||||
$url = add_query_arg(
|
||||
[
|
||||
'displayMode' => 'minibrowser',
|
||||
],
|
||||
$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"
|
||||
data-paypal-onboard-complete="onboardingCallback"
|
||||
href="<?php echo esc_url($url); ?>"
|
||||
data-paypal-button="true"
|
||||
><?php
|
||||
esc_html_e('Sign up for PayPal', 'woocommerce-paypal-commerce-gateway');
|
||||
?></a>
|
||||
<script
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue