PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8
GiveWP – Donation Plugin and Fundraising Platform v4.16.8
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 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / PaymentGateways / Gateways / Stripe / BECSGateway.php
BECSGateway.php
137 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 */
30 public function __construct(SubscriptionModule $subscriptionModule = null)
31 {
32 parent::__construct($subscriptionModule);
33
34 $this->errorMessages['accountConfiguredNoSsl'] = esc_html__(
35 'Mandate form fields are disabled because your site is not running securely over HTTPS.',
36 'give'
37 );
38 $this->errorMessages['accountNotConfiguredNoSsl'] = esc_html__(
39 'Mandate form 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 'Mandate form 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 * @throws PaymentGatewayException
56 */
57 public function createPayment(Donation $donation, $gatewayData): GatewayCommand
58 {
59 $donationSummary = Call::invoke(Actions\SaveDonationSummary::class, $donation);
60 $stripeCustomer = Call::invoke(Actions\GetOrCreateStripeCustomer::class, $donation);
61
62 $createIntentAction = new Actions\CreatePaymentIntent($this->getPaymentIntentArgs());
63
64 return $this->handlePaymentIntentStatus(
65 $createIntentAction(
66 $donation,
67 $donationSummary,
68 $stripeCustomer,
69 $gatewayData['stripePaymentMethod']
70 ),
71 $donation
72 );
73 }
74
75 /**
76 * @inheritDoc
77 */
78 public static function id(): string
79 {
80 return 'stripe_becs';
81 }
82
83 /**
84 * @inheritDoc
85 */
86 public function getId(): string
87 {
88 return self::id();
89 }
90
91 /**
92 * @inheritDoc
93 */
94 public function getName(): string
95 {
96 return __('Stripe - BECS Direct Debit', 'give');
97 }
98
99 /**
100 * @inheritDoc
101 */
102 public function getPaymentMethodLabel(): string
103 {
104 return __('Stripe - BECS Direct Debit', 'give');
105 }
106
107 /**
108 * @inheritDoc
109 */
110 public function getLegacyFormFieldMarkup(int $formId, array $args): string
111 {
112 return $this->getMandateFormHTML($formId, $args);
113 }
114
115 /**
116 * @since 2.33.5 Use give_get_ip() instead of give_stripe_get_ip_address()
117 * @since 2.19.0
118 * @return array
119 */
120 protected function getPaymentIntentArgs(): array
121 {
122 return [
123 'payment_method_types' => ['au_becs_debit'],
124 'setup_future_usage' => 'on_session',
125 'mandate_data' => [
126 'customer_acceptance' => [
127 'type' => 'online',
128 'online' => [
129 'ip_address' => give_get_ip(),
130 'user_agent' => give_get_user_agent(),
131 ],
132 ],
133 ],
134 ];
135 }
136 }
137