diff --git a/includes/class-notices.php b/includes/class-notices.php index 9cf611167a..bf5979fb71 100644 --- a/includes/class-notices.php +++ b/includes/class-notices.php @@ -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 * @@ -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; } diff --git a/src/PaymentGateways/PayPalCommerce/ScriptLoader.php b/src/PaymentGateways/PayPalCommerce/ScriptLoader.php index 72f05332ee..0430861564 100644 --- a/src/PaymentGateways/PayPalCommerce/ScriptLoader.php +++ b/src/PaymentGateways/PayPalCommerce/ScriptLoader.php @@ -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() @@ -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 @@ -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'))) {