PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.1.2
GiveWP – Donation Plugin and Fundraising Platform v3.1.2
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / PaymentGateways / PayPalCommerce / ScriptLoader.php
give / src / PaymentGateways / PayPalCommerce Last commit date
Banners 2 years ago DataTransferObjects 4 years ago Exceptions 3 years ago Migrations 2 years ago Models 2 years ago PayPalCheckoutSdk 2 years ago Repositories 2 years ago Webhooks 2 years ago AccountAdminNotices.php 4 years ago AdminSettingFields.php 2 years ago AdvancedCardFields.php 4 years ago AjaxRequestHandler.php 2 years ago DonationDetailsPage.php 4 years ago DonationFormPaymentMethod.php 2 years ago PayPalClient.php 2 years ago PayPalCommerce.php 2 years ago RefreshToken.php 2 years ago RefundPaymentHandler.php 4 years ago ScriptLoader.php 2 years ago Utils.php 2 years ago onBoardingRedirectHandler.php 2 years ago
ScriptLoader.php
286 lines
1 <?php
2
3 namespace Give\PaymentGateways\PayPalCommerce;
4
5 use Give\Helpers\EnqueueScript;
6 use Give\PaymentGateways\Gateways\PayPalCommerce\PayPalCommerceGateway;
7 use Give\PaymentGateways\PayPalCommerce\Models\MerchantDetail;
8 use Give\Helpers\Form\Template\Utils\Frontend as FrontendFormTemplateUtils;
9 use Give_Admin_Settings;
10
11 /**
12 * Class ScriptLoader
13 * @package Give\PaymentGateways\PayPalCommerce
14 *
15 * @since 3.0.0 Implement on-demand PayPal connection. Admin can select Advance or standard card processing.
16 * @since 2.9.0
17 */
18 class ScriptLoader
19 {
20 /**
21 * List of connection account type.
22 *
23 * @since 3.0.0
24 * @var string[]
25 */
26 public static $accountTypes = [
27 'PPCP',
28 'EXPRESS_CHECKOUT'
29 ];
30
31 /**
32 * List of countries that support custom payment accounts
33 *
34 * @since 3.0.0
35 * @var string[]
36 */
37 private $countriesAvailableForAdvanceConnection = [
38 'AU',
39 'AT',
40 'BE',
41 'BG',
42 'CY',
43 'CZ',
44 'DK',
45 'EE',
46 'FI',
47 'FR',
48 'GR',
49 'HU',
50 'IT',
51 'LV',
52 'LI',
53 'LT',
54 'LU',
55 'MT',
56 'NL',
57 'NO',
58 'PL',
59 'PT',
60 'RO',
61 'SK',
62 'SI',
63 'ES',
64 'SE',
65 'GB',
66 'US',
67 ];
68
69 /**
70 * @since 2.9.0
71 *
72 * @var PayPalCommerceGateway
73 */
74 private $payPalCommerceGateway;
75
76 /**
77 * ScriptLoader constructor.
78 *
79 * @since 3.0.0 Remove $merchantRepository parameter and add $payPalCommerceGateway parameter.
80 * @since 2.9.0
81 *
82 * @param PayPalCommerceGateway $payPalCommerceGateway
83 */
84 public function __construct(PayPalCommerceGateway $payPalCommerceGateway)
85 {
86 $this->payPalCommerceGateway = $payPalCommerceGateway;
87 }
88
89 /**
90 * Load admin scripts
91 *
92 * @since 2.9.0
93 */
94 public function loadAdminScripts()
95 {
96 if (!Give_Admin_Settings::is_setting_page('gateway', 'paypal')) {
97 return;
98 }
99
100 wp_enqueue_script(
101 'give-paypal-partner-js',
102 $this->getPartnerJsUrl(),
103 [],
104 null,
105 true
106 );
107
108 wp_enqueue_style(
109 'give-admin-paypal-commerce-css',
110 GIVE_PLUGIN_URL . 'assets/dist/css/admin-paypal-commerce.css',
111 [],
112 GIVE_VERSION
113 );
114
115 wp_localize_script(
116 'give-paypal-partner-js',
117 'givePayPalCommerce',
118 [
119 'countriesAvailableForAdvanceConnection' => $this->countriesAvailableForAdvanceConnection,
120 'accountTypes' => self::$accountTypes,
121 'translations' => [
122 'confirmPaypalAccountDisconnection' => esc_html__('Disconnect PayPal Account', 'give'),
123 'disconnectPayPalAccount' => esc_html__(
124 'Are you sure you want to disconnect your PayPal account?',
125 'give'
126 ),
127 'connectSuccessTitle' => esc_html__('You’re connected to PayPal! Here’s what’s next...', 'give'),
128 'pciWarning' => sprintf(
129 __(
130 'PayPal allows you to accept credit or debit cards directly on your website. Because of
131 this, your site needs to maintain <a href="%1$s" target="_blank">PCI-DDS compliance</a>.
132 GiveWP never stores sensitive information like card details to your server and works
133 seamlessly with SSL certificates. Compliance is comprised of, but not limited to:',
134 'give'
135 ),
136 'https://givewp.com/documentation/resources/pci-compliance/'
137 ),
138 'pciComplianceInstructions' => [
139 esc_html__(
140 'Using a trusted, secure hosting provider – preferably one which claims and actively promotes PCI compliance.',
141 'give'
142 ),
143 esc_html__(
144 'Maintain security best practices when setting passwords and limit access to your server.',
145 'give'
146 ),
147 esc_html__('Implement an SSL certificate to keep your donations secure.', 'give'),
148 esc_html__('Keep plugins up to date to ensure latest security fixes are present.', 'give'),
149 ],
150 ],
151 ]
152 );
153
154 $script = <<<EOT
155 function giveSandboxPayPalOnBoardedCallback(authCode, sharedId){
156 givePayPalOnBoardedCallback('sandbox', authCode, sharedId);
157 }
158
159 function giveLivePayPalOnBoardedCallback(authCode, sharedId){
160 givePayPalOnBoardedCallback('live', authCode, sharedId);
161 }
162
163 function givePayPalOnBoardedCallback(mode, authCode, sharedId) {
164 const query = '&mode=' + mode + '&authCode=' + authCode + '&sharedId=' + sharedId;
165
166 fetch( ajaxurl + '?action=give_paypal_commerce_user_on_boarded' + query )
167 .then(function(res){ return res.json() })
168 .then(function(res) {
169 if ( true !== res.success ) {
170 console.log(res);
171 alert('Something went wrong!');
172 return;
173 }
174
175 // Remove PayPal quick help container.
176 const paypalErrorQuickHelp = document.getElementById('give-paypal-onboarding-trouble-notice');
177 paypalErrorQuickHelp && paypalErrorQuickHelp.remove();
178 });
179 }
180 EOT;
181
182 wp_add_inline_script(
183 'give-paypal-partner-js',
184 $script
185 );
186 }
187
188 /**
189 * Load public assets.
190 *
191 * @unreleased Use EnqueueScript to register and enqueue script.
192 * @since 2.32.0 Handle exception if client token is not generated.
193 * @since 2.9.0
194 */
195 public function loadPublicAssets()
196 {
197 $formId = FrontendFormTemplateUtils::getFormId();
198
199 if (
200 ! $formId
201 || \Give\Helpers\Form\Utils::isV3Form($formId)
202 || ! Utils::gatewayIsActive()
203 || ! Utils::isAccountReadyToAcceptPayment()
204 ) {
205 return;
206 }
207
208 try {
209 $formSettings = $this->payPalCommerceGateway->formSettings($formId);
210 $paypalSDKOptions = $formSettings['sdkOptions'];
211
212 // Remove v3 donation form related param.
213 unset($paypalSDKOptions['data-namespace']);
214 } catch (\Exception $e) {
215 give_set_error(
216 'give-paypal-commerce-client-token-error',
217 sprintf(
218 esc_html__(
219 'Unable to load PayPal Commerce client token. Please try again later. Error: %1$s',
220 'give'
221 ),
222 $e->getMessage()
223 )
224 );
225
226 return;
227 }
228
229 /* @var MerchantDetail $merchant */
230 $merchant = give(MerchantDetail::class);
231
232 $scriptId = 'give-paypal-commerce-js';
233 $data = [
234 'paypalCardInfoErrorPrefixes' => [
235 'expirationDateField' => esc_html__('Card Expiration Date:', 'give'),
236 'cardNumberField' => esc_html__('Card Number:', 'give'),
237 'cardCvcField' => esc_html__('Card CVC:', 'give'),
238 ],
239 'cardFieldPlaceholders' => [
240 'cardNumber' => esc_html__('Card Number', 'give'),
241 'cardCvc' => esc_html__('CVC', 'give'),
242 'expirationDate' => esc_html__('MM/YY', 'give'),
243 ],
244 'threeDsCardAuthenticationFailedNotice' => esc_html__(
245 'There was a problem authenticating your payment method. Please try again. If the problem persists, please try another payment method.',
246 'give'
247 ),
248 'errorCodeLabel' => esc_html__('Error Code', 'give'),
249 'genericDonorErrorMessage' => __(
250 'There was an error processing your donation. Please contact the administrator.',
251 'give'
252 ),
253 // List of style properties support by PayPal for advanced card fields: https://developer.paypal.com/docs/business/checkout/reference/style-guide/#style-the-card-payments-fields
254 'hostedCardFieldStyles' => apply_filters('give_paypal_commerce_hosted_field_style', []),
255 'supportsCustomPayments' => $merchant->supportsCustomPayments ? 1 : '',
256 'separatorLabel' => esc_html__('Or pay with card', 'give'),
257 'payPalSdkQueryParameters' => $paypalSDKOptions,
258 'textForOverlayScreen' => sprintf(
259 '<h3>%1$s</h3><p>%2$s</p><p>%3$s</p>',
260 esc_html__('Donation Processing...', 'give'),
261 esc_html__('Checking donation status with PayPal.', 'give'),
262 esc_html__('This will only take a second!', 'give')
263 )
264 ];
265
266 EnqueueScript::make($scriptId, 'assets/dist/js/paypal-commerce.js')
267 ->registerTranslations()
268 ->loadInFooter()
269 ->registerLocalizeData('givePayPalCommerce', $data)
270 ->enqueue();
271 }
272
273 /**
274 * Get PayPal partner js url.
275 *
276 * @since 2.30.0 sandbox PayPal partner js loads slow. So we are using live url for now.
277 * @since 2.9.0
278 *
279 * @return string
280 */
281 private function getPartnerJsUrl()
282 {
283 return 'https://www.paypal.com/webapps/merchantboarding/js/lib/lightbox/partner.js';
284 }
285 }
286