Skip to content

Commit

Permalink
Merge branch 'hotfix/handle-exception-gracefully'
Browse files Browse the repository at this point in the history
  • Loading branch information
angelablake committed Aug 1, 2023
2 parents 159bdfd + 8d4cd8b commit 23ac57c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
10 changes: 8 additions & 2 deletions includes/class-notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public function render_admin_notices() {
/**
* Render give frontend notices.
*
* @unreleased Display registered error on donation form.
* @since 1.8.9
* @access public
*
Expand All @@ -295,8 +296,13 @@ public function render_frontend_notices( $form_id = 0 ) {

$request_form_id = isset( $_REQUEST['form-id'] ) ? absint( $_REQUEST['form-id'] ) : 0;

// Sanity checks first: Ensure that gateway returned errors display on the appropriate form.
if ( ! isset( $_POST['give_ajax'] ) && $request_form_id !== $form_id ) {
// Sanity checks first:
// - Ensure that gateway returned errors display on the appropriate form.
// - Error should not display on AJAX request.
if (
isset( $_POST['give_ajax'] )
|| ( $request_form_id && $request_form_id !== $form_id )
) {
return;
}

Expand Down
19 changes: 18 additions & 1 deletion src/PaymentGateways/PayPalCommerce/ScriptLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function givePayPalOnBoardedCallback(mode, authCode, sharedId) {
/**
* Load public assets.
*
* @unreleased Handle exception if client token is not generated.
* @since 2.9.0
*/
public function loadPublicAssets()
Expand All @@ -144,6 +145,22 @@ public function loadPublicAssets()
/* @var MerchantDetail $merchant */
$merchant = give(MerchantDetail::class);
$scriptId = 'give-paypal-commerce-js';
$clientToken = '';

try{
$clientToken = $this->merchantRepository->getClientToken();
} catch ( \Exception $exception ) {
give_set_error(
'give-paypal-commerce-client-token-error',
sprintf(
esc_html__(
'Unable to load PayPal Commerce client token. Please try again later. Error: %1$s',
'give'
),
$exception->getMessage()
)
);
}

/**
* List of PayPal query parameters: https://developer.paypal.com/docs/checkout/reference/customize-sdk/#query-parameters
Expand All @@ -156,7 +173,7 @@ public function loadPublicAssets()
'disable-funding' => 'credit',
'vault' => true,
'data-partner-attribution-id' => give('PAYPAL_COMMERCE_ATTRIBUTION_ID'),
'data-client-token' => $this->merchantRepository->getClientToken(),
'data-client-token' => $clientToken,
];

if (give_is_setting_enabled(give_get_option('paypal_commerce_accept_venmo', 'disabled'))) {
Expand Down

0 comments on commit 23ac57c

Please sign in to comment.