PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.19.4
GiveWP – Donation Plugin and Fundraising Platform v3.19.4
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 / Gateways / PayPalStandard / PayPalStandard.php
give / src / PaymentGateways / Gateways / PayPalStandard Last commit date
Actions 3 years ago Controllers 3 years ago Migrations 2 years ago Views 3 years ago Webhooks 4 years ago resources 2 years ago PayPalStandard.php 2 years ago
PayPalStandard.php
285 lines
1 <?php
2
3 namespace Give\PaymentGateways\Gateways\PayPalStandard;
4
5 use Give\Donations\Models\Donation;
6 use Give\Donations\ValueObjects\DonationStatus;
7 use Give\Framework\Exceptions\Primitives\Exception;
8 use Give\Framework\Http\Response\Types\RedirectResponse;
9 use Give\Framework\PaymentGateways\Commands\RedirectOffsite;
10 use Give\Framework\PaymentGateways\PaymentGateway;
11 use Give\Framework\PaymentGateways\Traits\HandleHttpResponses;
12 use Give\Framework\Support\Scripts\Concerns\HasScriptAssetFile;
13 use Give\Helpers\Language;
14 use Give\PaymentGateways\Gateways\PayPalStandard\Actions\CreatePayPalStandardPaymentURL;
15 use Give\PaymentGateways\Gateways\PayPalStandard\Controllers\PayPalStandardWebhook;
16 use Give\PaymentGateways\Gateways\PayPalStandard\Views\PayPalStandardBillingFields;
17
18 /**
19 * @since 3.0.0 added support for Give 3.0 forms
20 * @since 2.19.0
21 */
22 class PayPalStandard extends PaymentGateway
23 {
24 use HandleHttpResponses;
25 use HasScriptAssetFile;
26
27 public $routeMethods = [
28 'handleIpnNotification',
29 ];
30
31 public $secureRouteMethods = [
32 'handleSuccessPaymentReturn',
33 'handleCancelledPaymentReturn',
34 ];
35
36 /**
37 * @since 2.19.0
38 */
39 public function getLegacyFormFieldMarkup(int $formId, array $args): string
40 {
41 return (new PayPalStandardBillingFields())($formId);
42 }
43
44 /**
45 * @since 2.19.0
46 */
47 public static function id(): string
48 {
49 return 'paypal';
50 }
51
52 /**
53 * @since 2.19.0
54 */
55 public function getId(): string
56 {
57 return self::id();
58 }
59
60 /**
61 * @since 2.19.0
62 */
63 public function getName(): string
64 {
65 return __('PayPal Standard', 'give');
66 }
67
68 /**
69 * @since 2.19.0
70 */
71 public function getPaymentMethodLabel(): string
72 {
73 return esc_html__('PayPal', 'give');
74 }
75
76 /**
77 * @since 3.0.0
78 */
79 public function formSettings(int $formId): array
80 {
81 return [
82 'fields' => [
83 'heading' => __('Make your donation quickly and securely with PayPal', 'give'),
84 'subheading' => __('How it works', 'give'),
85 'body' => __(
86 'You will be redirected to PayPal to complete your donation with your debit card, credit card, or with your PayPal account. Once complete, you will be redirected back to this site to view your receipt.',
87 'give'
88 ),
89 ]
90 ];
91 }
92
93 /**
94 * @since 3.1.0 set translations for script
95 * @since 3.0.0
96 */
97 public function enqueueScript(int $formId)
98 {
99 $assets = $this->getScriptAsset(GIVE_PLUGIN_DIR . 'build/payPalStandardGateway.asset.php');
100 $handle = $this::id();
101
102 wp_enqueue_script(
103 $handle,
104 GIVE_PLUGIN_URL . 'build/payPalStandardGateway.js',
105 $assets['dependencies'],
106 $assets['version'],
107 true
108 );
109
110 Language::setScriptTranslations($handle);
111 }
112
113 /**
114 * @since 3.0.0 update to add `givewp-return-url` to the query params
115 * @since 2.19.0
116 */
117 public function createPayment(Donation $donation, $gatewayData = []): RedirectOffsite
118 {
119 return new RedirectOffsite(
120 (new CreatePayPalStandardPaymentURL())(
121 $donation,
122 $this->generateSecureGatewayRouteUrl(
123 'handleSuccessPaymentReturn',
124 $donation->id,
125 [
126 'donation-id' => $donation->id,
127 'givewp-return-url' => $gatewayData['successUrl']
128 ]
129 ),
130 $this->generateSecureGatewayRouteUrl(
131 'handleCancelledPaymentReturn',
132 $donation->id,
133 [
134 'donation-id' => $donation->id,
135 'givewp-return-url' => $gatewayData['cancelUrl']
136 ]
137 ),
138 $this->generateGatewayRouteUrl(
139 'handleIpnNotification'
140 )
141 )
142 );
143 }
144
145 /**
146 * Handle payment redirect after successful payment on PayPal standard.
147 *
148 * @since 3.0.0 update to use the $gatewayParams return url
149 * @since 2.19.0
150 * @since 2.19.4 Only pending PayPal Standard donation set to processing.
151 * @since 2.19.6 1. Do not set donation to "processing" 2. Add "payment-confirmation" param to receipt page url
152 */
153 protected function handleSuccessPaymentReturn(array $queryParams): RedirectResponse
154 {
155 return new RedirectResponse(esc_url_raw($queryParams['givewp-return-url']));
156 }
157
158 /**
159 * This method is called when the user cancels the payment on PayPal.
160 *
161 * @since 3.0.0
162 */
163 protected function handleCancelledPaymentReturn(array $queryParams): RedirectResponse
164 {
165 $donationId = (int)$queryParams['donation-id'];
166
167 /** @var Donation $donation */
168 $donation = Donation::find($donationId);
169 $donation->status = DonationStatus::CANCELLED();
170 $donation->save();
171
172 return new RedirectResponse(esc_url_raw($queryParams['givewp-return-url']));
173 }
174
175 /**
176 * Handle PayPal IPN notification.
177 *
178 * @since 2.19.0
179 */
180 public function handleIpnNotification()
181 {
182 give(PayPalStandardWebhook::class)->handle();
183 }
184
185 /**
186 * This function returns payment gateway settings.
187 *
188 * @since 2.19.0
189 */
190 public function getOptions(): array
191 {
192 $setting = [
193 // Section 2: PayPal Standard.
194 [
195 'type' => 'title',
196 'id' => 'give_title_gateway_settings_2',
197 ],
198 [
199 'name' => esc_html__('PayPal Email', 'give'),
200 'desc' => esc_html__(
201 'Enter the email address associated with your PayPal account to connect with the gateway.',
202 'give'
203 ),
204 'id' => 'paypal_email',
205 'type' => 'email',
206 ],
207 [
208 'name' => esc_html__('PayPal Page Style', 'give'),
209 'desc' => esc_html__(
210 'Enter the name of the PayPal page style to use, or leave blank to use the default.',
211 'give'
212 ),
213 'id' => 'paypal_page_style',
214 'type' => 'text',
215 ],
216 [
217 'name' => esc_html__('PayPal Transaction Type', 'give'),
218 'desc' => esc_html__(
219 'Nonprofits must verify their status to withdraw donations they receive via PayPal. PayPal users that are not verified nonprofits must demonstrate how their donations will be used, once they raise more than $10,000. By default, GiveWP transactions are sent to PayPal as donations. You may change the transaction type using this option if you feel you may not meet PayPal\'s donation requirements.',
220 'give'
221 ),
222 'id' => 'paypal_button_type',
223 'type' => 'radio_inline',
224 'options' => [
225 'donation' => esc_html__('Donation', 'give'),
226 'standard' => esc_html__('Standard Transaction', 'give'),
227 ],
228 'default' => 'donation',
229 ],
230 [
231 'name' => esc_html__('Billing Details', 'give'),
232 'desc' => esc_html__(
233 'If enabled, required billing address fields are added to PayPal Standard forms. These fields are not required by PayPal to process the transaction, but you may have a need to collect the data. Billing address details are added to both the donation and donor record in GiveWP.',
234 'give'
235 ),
236 'id' => 'paypal_standard_billing_details',
237 'type' => 'radio_inline',
238 'default' => 'disabled',
239 'options' => [
240 'enabled' => esc_html__('Enabled', 'give'),
241 'disabled' => esc_html__('Disabled', 'give'),
242 ],
243 ],
244 [
245 'id' => 'paypal_invoice_prefix',
246 'name' => esc_html__('Invoice ID Prefix', 'give'),
247 'desc' => esc_html__(
248 'Enter a prefix for your invoice numbers. If you use your PayPal account for multiple fundraising platforms or ecommerce stores, ensure this prefix is unique. PayPal will not allow orders or donations with the same invoice number.',
249 'give'
250 ),
251 'type' => 'text',
252 'default' => 'GIVE-',
253 ],
254 [
255 'name' => esc_html__('PayPal Standard Gateway Settings Docs Link', 'give'),
256 'id' => 'paypal_standard_gateway_settings_docs_link',
257 'url' => esc_url('http://docs.givewp.com/settings-gateway-paypal-standard'),
258 'title' => esc_html__('PayPal Standard Gateway Settings', 'give'),
259 'type' => 'give_docs_link',
260 ],
261 [
262 'type' => 'sectionend',
263 'id' => 'give_title_gateway_settings_2',
264 ],
265 ];
266
267 /**
268 * filter the settings.
269 *
270 * @since 2.9.6
271 */
272 return apply_filters('give_get_settings_paypal_standard', $setting);
273 }
274
275 /**
276 * @since 2.20.0
277 * @inerhitDoc
278 * @throws Exception
279 */
280 public function refundDonation(Donation $donation)
281 {
282 throw new Exception('Method has not been implemented yet. Please use the legacy method in the meantime.');
283 }
284 }
285