Skip to content

Commit

Permalink
refactor: reuse paypal sdk options
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinderk committed Aug 18, 2023
1 parent 22989ce commit 8c15c9f
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions src/PaymentGateways/PayPalCommerce/ScriptLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public function loadPublicAssets()
try {
$formSettings = $this->payPalCommerceGateway->formSettings(FrontendFormTemplateUtils::getFormId());
$paypalSDKOptions = $formSettings['sdkOptions'];

// Remove v3 donation form related param.
unset($paypalSDKOptions['data-namespace']);
} catch (\Exception $e) {
give_set_error(
'give-paypal-commerce-client-token-error',
Expand All @@ -165,23 +168,6 @@ public function loadPublicAssets()
/* @var MerchantDetail $merchant */
$merchant = give(MerchantDetail::class);

/**
* @since 2.27.1 Removed locale query parameter.
*/
$payPalSdkQueryParameters = [
'client-id' => $paypalSDKOptions['client-id'],
'merchant-id' => $paypalSDKOptions['merchant-id'],
'components' => $paypalSDKOptions['components'],
'disable-funding' => 'credit',
'vault' => true,
'data-partner-attribution-id' => give('PAYPAL_COMMERCE_ATTRIBUTION_ID'),
'data-client-token' => $paypalSDKOptions['data-client-token'],
];

if (array_key_exists('enable-funding', $paypalSDKOptions) && $paypalSDKOptions['enable-funding']) {
$payPalSdkQueryParameters['enable-funding'] = $paypalSDKOptions['enable-funding'];
}

$scriptId = 'give-paypal-commerce-js';

wp_enqueue_script(
Expand Down Expand Up @@ -219,7 +205,7 @@ public function loadPublicAssets()
'hostedCardFieldStyles' => apply_filters('give_paypal_commerce_hosted_field_style', []),
'supportsCustomPayments' => $merchant->supportsCustomPayments ? 1 : '',
'separatorLabel' => esc_html__('Or pay with card', 'give'),
'payPalSdkQueryParameters' => $payPalSdkQueryParameters,
'payPalSdkQueryParameters' => $paypalSDKOptions,
'textForOverlayScreen' => sprintf(
'<h3>%1$s</h3><p>%2$s</p><p>%3$s</p>',
esc_html__('Donation Processing...', 'give'),
Expand Down

0 comments on commit 8c15c9f

Please sign in to comment.