PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
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 / CreatePaymentIntent.php

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

91 lines 3.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\Framework\PaymentGateways\DonationSummary;
9 use Give\PaymentGateways\Exceptions\InvalidPropertyName;
10 use Give\PaymentGateways\Gateways\Stripe\ValueObjects\PaymentIntent;
11 use Give\PaymentGateways\Gateways\Stripe\ValueObjects\PaymentMethod;
12
13 /**
14 * @since 2.19.0
15 */
16 class CreatePaymentIntent
17 {
18 /** @var array */
19 protected $defaultIntentArgs;
20
21 /**
22 * @since 2.19.0
23 */
24 public function __construct(array $paymentIntentArgs = [])
25 {
26 $this->defaultIntentArgs = $paymentIntentArgs;
27 }
28
29 /**
30 * @since 3.5.0 remove descriptor as Stripe automatically adds it, per Stripe API changes (https://support.stripe.com/questions/use-of-the-statement-descriptor-parameter-on-paymentintents-for-card-charges)
31 * @since 2.33.0 no longer store the payment intent secret
32 * @since 2.19.0
33 *
34 * @throws InvalidPropertyName
35 * @throws Exception
36 */
37 public function __invoke(
38 Donation $donation,
39 DonationSummary $donationSummary,
40 \Give_Stripe_Customer $giveStripeCustomer,
41 PaymentMethod $paymentMethod
42 ): PaymentIntent {
43 /**
44 * This filter hook is used to update the payment intent arguments.
45 *
46 * @since 2.5.0
47 */
48 $intent_args = apply_filters(
49 'give_stripe_create_intent_args',
50 array_merge([
51 'amount' => $donation->amount->formatToMinorAmount(),
52 'currency' => $donation->amount->getCurrency(),
53 'payment_method_types' => ['card'],
54 'description' => $donationSummary->getSummaryWithDonor(),
55 'metadata' => give_stripe_prepare_metadata($donation->id),
56 'customer' => $giveStripeCustomer->get_id(),
57 'payment_method' => $paymentMethod->id(),
58 'confirm' => true,
59 'return_url' => give_get_success_page_uri(),
60 ], $this->defaultIntentArgs)
61 );
62
63 // Send Stripe Receipt emails when enabled.
64 if (give_is_setting_enabled(give_get_option('stripe_receipt_emails'))) {
65 $intent_args['receipt_email'] = $donation->email;
66 }
67
68 $intent = give(PaymentIntent::class)->create($intent_args);
69
70 DonationNote::create([
71 'donationId' => $donation->id,
72 'content' => sprintf(__('Stripe Charge/Payment Intent ID: %s', 'give'), $intent->id())
73 ]);
74
75 if ('requires_action' === $intent->status()) {
76 DonationNote::create([
77 'donationId' => $donation->id,
78 'content' => __('Stripe requires additional action to be fulfilled. Check your Stripe account.', 'give')
79 ]);
80
81 give_update_meta(
82 $donation->id,
83 '_give_stripe_payment_intent_require_action_url',
84 $intent->nextActionRedirectUrl()
85 );
86 }
87
88 return $intent;
89 }
90 }
91