CreateCheckoutSession.php
4 years ago
CreatePaymentIntent.php
4 years ago
GetOrCreateStripeCustomer.php
4 years ago
GetPaymentMethodFromRequest.php
4 years ago
SaveDonationSummary.php
4 years ago
UpdateStripeAccountStatementDescriptor.php
4 years ago
ValidatePaymentMethod.php
4 years ago
GetPaymentMethodFromRequest.php
39 lines
| 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 |