PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.5
GiveWP – Donation Plugin and Fundraising Platform v4.15.5
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 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 All 257 releases
give / src / PaymentGateways / Gateways / Stripe / Actions / GetPaymentMethodFromRequest.php

GetPaymentMethodFromRequest.php in GiveWP – Donation Plugin and Fundraising Platform 4.15.5, at src/PaymentGateways/Gateways/Stripe/Actions/GetPaymentMethodFromRequest.php

39 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\PaymentGateways\Gateways\Stripe\Actions;
4
5 use Give\Donations\Models\Donation;
6 use Give\Donations\Models\DonationNote;
7 use Give\Framework\Exceptions\Primitives\Exception;
8 use Give\PaymentGateways\Gateways\Stripe\Exceptions\PaymentMethodException;
9 use Give\PaymentGateways\Gateways\Stripe\ValueObjects\PaymentMethod;
10
11 class GetPaymentMethodFromRequest
12 {
13 /**
14 * @since 2.19.0
15 *
16 * @throws PaymentMethodException
17 * @throws Exception
18 */
19 public function __invoke(Donation $donation): PaymentMethod
20 {
21 if (!isset($_POST['give_stripe_payment_method'])) {
22 throw new PaymentMethodException('Payment Method Not Found');
23 }
24
25 $paymentMethod = new PaymentMethod(
26 give_clean($_POST['give_stripe_payment_method'])
27 );
28
29 give_update_meta($donation->id, '_give_stripe_source_id', $paymentMethod->id());
30
31 DonationNote::create([
32 'donationId' => $donation->id,
33 'content' => sprintf(__('Stripe Source/Payment Method ID: %s', 'give'), $paymentMethod->id())
34 ]);
35
36 return $paymentMethod;
37 }
38 }
39