From 34ee247a50c78d5fc7d85a0f6fa4d17e922b7f40 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 6 Jul 2023 20:46:23 +0530 Subject: [PATCH 1/3] feat: display error on donation form --- includes/class-notices.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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; } From 406ce0ed0fa7e084ff9b54f6f69ba4918309f5f4 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 6 Jul 2023 20:47:15 +0530 Subject: [PATCH 2/3] fix: display error if client token is not generated successfully --- .../PayPalCommerce/ScriptLoader.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/PaymentGateways/PayPalCommerce/ScriptLoader.php b/src/PaymentGateways/PayPalCommerce/ScriptLoader.php index 1807405297..1ce67da85c 100644 --- a/src/PaymentGateways/PayPalCommerce/ScriptLoader.php +++ b/src/PaymentGateways/PayPalCommerce/ScriptLoader.php @@ -144,6 +144,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 +172,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'))) { From 8d4cd8b0097a9475d1101755496709121afd8b7a Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Thu, 6 Jul 2023 20:52:53 +0530 Subject: [PATCH 3/3] doc: log changes --- src/PaymentGateways/PayPalCommerce/ScriptLoader.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PaymentGateways/PayPalCommerce/ScriptLoader.php b/src/PaymentGateways/PayPalCommerce/ScriptLoader.php index 1ce67da85c..1c4f974470 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()