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

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

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