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 / SEPAGateway.php

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

139 lines 3.9 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;
4
5 use Give\Donations\Models\Donation;
6 use Give\Framework\Exceptions\Primitives\Exception;
7 use Give\Framework\PaymentGateways\Commands\GatewayCommand;
8 use Give\Framework\PaymentGateways\Exceptions\PaymentGatewayException;
9 use Give\Framework\PaymentGateways\PaymentGateway;
10 use Give\Framework\PaymentGateways\SubscriptionModule;
11 use Give\Helpers\Call;
12 use Give\PaymentGateways\Gateways\Stripe\Traits\HandlePaymentIntentStatus;
13 use Give\PaymentGateways\Gateways\Stripe\Traits\SEPAMandateForm;
14 use Give\PaymentGateways\Gateways\Stripe\ValueObjects\PaymentMethod;
15
16 /**
17 * @since 2.19.0
18 */
19 class SEPAGateway extends PaymentGateway
20 {
21 use SEPAMandateForm;
22 use HandlePaymentIntentStatus;
23
24 /** @var array */
25 protected $errorMessages = [];
26
27 /**
28 * @param SubscriptionModule|null $subscriptionModule
29 */
30 public function __construct(SubscriptionModule $subscriptionModule = null)
31 {
32 parent::__construct($subscriptionModule);
33
34 $this->errorMessages['accountConfiguredNoSsl'] = esc_html__(
35 'IBAN fields are disabled because your site is not running securely over HTTPS.',
36 'give'
37 );
38 $this->errorMessages['accountNotConfiguredNoSsl'] = esc_html__(
39 'IBAN fields are disabled because Stripe is not connected and your site is not running securely over HTTPS.',
40 'give'
41 );
42 $this->errorMessages['accountNotConfigured'] = esc_html__(
43 'IBAN fields are disabled. Please connect and configure your Stripe account to accept donations.',
44 'give'
45 );
46 }
47
48 /**
49 * @inheritDoc
50 * @since 2.19.7 fix handlePaymentIntentStatus not receiving extra param
51 * @since 2.19.0
52 *
53 * @param array{stripePaymentMethod: PaymentMethod} $gatewayData
54 *
55 * @return GatewayCommand
56 * @throws PaymentGatewayException
57 */
58 public function createPayment(Donation $donation, $gatewayData): GatewayCommand
59 {
60
61 $donationSummary = Call::invoke(Actions\SaveDonationSummary::class, $donation);
62 $stripeCustomer = Call::invoke(Actions\GetOrCreateStripeCustomer::class, $donation);
63
64 $createIntentAction = new Actions\CreatePaymentIntent($this->getPaymentIntentArgs());
65
66 return $this->handlePaymentIntentStatus(
67 $createIntentAction(
68 $donation,
69 $donationSummary,
70 $stripeCustomer,
71 $gatewayData['stripePaymentMethod']
72 ),
73 $donation
74 );
75 }
76
77 /**
78 * @inheritDoc
79 */
80 public static function id(): string
81 {
82 return 'stripe_sepa';
83 }
84
85 /**
86 * @inheritDoc
87 */
88 public function getId(): string
89 {
90 return self::id();
91 }
92
93 /**
94 * @inheritDoc
95 */
96 public function getName(): string
97 {
98 return __('Stripe - SEPA Direct Debit', 'give');
99 }
100
101 /**
102 * @inheritDoc
103 */
104 public function getPaymentMethodLabel(): string
105 {
106 return __('Stripe - SEPA Direct Debit', 'give');
107 }
108
109 /**
110 * @inheritDoc
111 */
112 public function getLegacyFormFieldMarkup(int $formId, array $args): string
113 {
114 return $this->getMandateFormHTML($formId, $args);
115 }
116
117 /**
118 * @since 2.33.5 Use give_get_ip() instead of give_stripe_get_ip_address()
119 * @since 2.19.0
120 * @return array
121 */
122 protected function getPaymentIntentArgs(): array
123 {
124 return [
125 'payment_method_types' => ['sepa_debit'],
126 'setup_future_usage' => 'on_session',
127 'mandate_data' => [
128 'customer_acceptance' => [
129 'type' => 'online',
130 'online' => [
131 'ip_address' => give_get_ip(),
132 'user_agent' => give_get_user_agent(),
133 ],
134 ],
135 ],
136 ];
137 }
138 }
139