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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / Admin / Settings / PaymentsProviders / Stripe.php
woocommerce / src / Internal / Admin / Settings / PaymentsProviders Last commit date
WooPayments 5 months ago Affirm.php 1 year ago AfterpayClearpay.php 1 year ago Airwallex.php 1 year ago AmazonPay.php 1 year ago Antom.php 1 year ago Eway.php 9 months ago GoCardless.php 1 year ago HelioPay.php 1 year ago Klarna.php 1 year ago KlarnaCheckout.php 1 year ago MercadoPago.php 1 year ago Mollie.php 1 year ago Monei.php 1 year ago NexiCheckout.php 9 months ago PayPal.php 1 year ago PayUIndia.php 1 year ago Payfast.php 1 year ago PaymentGateway.php 3 months ago Paymob.php 1 year ago Payoneer.php 1 year ago Paystack.php 1 year ago Paytrail.php 1 year ago PseudoWCPaymentGateway.php 1 year ago Razorpay.php 1 year ago Stripe.php 1 year ago Tilopay.php 1 year ago Visa.php 9 months ago Vivacom.php 1 year ago WCCore.php 7 months ago WooPayments.php 7 months ago
Stripe.php
226 lines
1 <?php
2 declare( strict_types=1 );
3
4 namespace Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders;
5
6 use Automattic\WooCommerce\Internal\Admin\Settings\Payments;
7 use Automattic\WooCommerce\Internal\Admin\Settings\Utils;
8 use Automattic\WooCommerce\Internal\Logging\SafeGlobalFunctionProxy;
9 use Throwable;
10 use WC_Payment_Gateway;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * Stripe payment gateway provider class.
16 *
17 * This class handles all the custom logic for the Stripe payment gateway provider.
18 */
19 class Stripe extends PaymentGateway {
20
21 /**
22 * Try to determine if the payment gateway is in test mode.
23 *
24 * This is a best-effort attempt, as there is no standard way to determine this.
25 * Trust the true value, but don't consider a false value as definitive.
26 *
27 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
28 *
29 * @return bool True if the payment gateway is in test mode, false otherwise.
30 */
31 public function is_in_test_mode( WC_Payment_Gateway $payment_gateway ): bool {
32 try {
33 if ( class_exists( '\WC_Stripe_Mode' ) &&
34 is_callable( '\WC_Stripe_Mode::is_test' ) ) {
35
36 return wc_string_to_bool( \WC_Stripe_Mode::is_test() );
37 }
38 } catch ( Throwable $e ) {
39 // Do nothing but log so we can investigate.
40 SafeGlobalFunctionProxy::wc_get_logger()->debug(
41 'Failed to determine if gateway is in test mode: ' . $e->getMessage(),
42 array(
43 'gateway' => $payment_gateway->id,
44 'source' => 'settings-payments',
45 'exception' => $e,
46 )
47 );
48 }
49
50 return parent::is_in_test_mode( $payment_gateway );
51 }
52
53 /**
54 * Try to determine if the payment gateway is in dev mode.
55 *
56 * This is a best-effort attempt, as there is no standard way to determine this.
57 * Trust the true value, but don't consider a false value as definitive.
58 *
59 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
60 *
61 * @return bool True if the payment gateway is in dev mode, false otherwise.
62 */
63 public function is_in_dev_mode( WC_Payment_Gateway $payment_gateway ): bool {
64 return false;
65 }
66
67 /**
68 * Check if the payment gateway has a payments processor account connected.
69 *
70 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
71 *
72 * @return bool True if the payment gateway account is connected, false otherwise.
73 * If the payment gateway does not provide the information, it will return true.
74 */
75 public function is_account_connected( WC_Payment_Gateway $payment_gateway ): bool {
76 try {
77 if ( class_exists( '\WC_Stripe' ) && is_callable( '\WC_Stripe::get_instance' ) ) {
78 $stripe = \WC_Stripe::get_instance();
79 if ( is_object( $stripe ) && isset( $stripe->account ) &&
80 class_exists( '\WC_Stripe_Account' ) &&
81 defined( '\WC_Stripe_Account::STATUS_NO_ACCOUNT' ) &&
82 $stripe->account instanceof \WC_Stripe_Account &&
83 is_callable( array( $stripe->account, 'get_account_status' ) ) ) {
84
85 return \WC_Stripe_Account::STATUS_NO_ACCOUNT !== $stripe->account->get_account_status();
86 }
87 }
88 } catch ( Throwable $e ) {
89 // Do nothing but log so we can investigate.
90 SafeGlobalFunctionProxy::wc_get_logger()->debug(
91 'Failed to determine if gateway has account connected: ' . $e->getMessage(),
92 array(
93 'gateway' => $payment_gateway->id,
94 'source' => 'settings-payments',
95 'exception' => $e,
96 )
97 );
98 }
99
100 return parent::is_account_connected( $payment_gateway );
101 }
102
103 /**
104 * Check if the payment gateway has started the onboarding process.
105 *
106 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
107 *
108 * @return bool True if the payment gateway has started the onboarding process, false otherwise.
109 * If the payment gateway does not provide the information,
110 * it will infer it from having a connected account.
111 */
112 public function is_onboarding_started( WC_Payment_Gateway $payment_gateway ): bool {
113 // Fall back to inferring this from having a connected account.
114 return $this->is_account_connected( $payment_gateway );
115 }
116
117 /**
118 * Check if the payment gateway has completed the onboarding process.
119 *
120 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
121 *
122 * @return bool True if the payment gateway has completed the onboarding process, false otherwise.
123 * If the payment gateway does not provide the information,
124 * it will infer it from having a connected account.
125 */
126 public function is_onboarding_completed( WC_Payment_Gateway $payment_gateway ): bool {
127 // Sanity check: If the onboarding has not started, it cannot be completed.
128 if ( ! $this->is_onboarding_started( $payment_gateway ) ) {
129 return false;
130 }
131
132 // Fall back to inferring this from having a connected account.
133 return $this->is_account_connected( $payment_gateway );
134 }
135
136 /**
137 * Try to determine if the payment gateway is in test mode onboarding (aka sandbox or test-drive).
138 *
139 * This is a best-effort attempt, as there is no standard way to determine this.
140 * Trust the true value, but don't consider a false value as definitive.
141 *
142 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
143 *
144 * @return bool True if the payment gateway is in test mode onboarding, false otherwise.
145 */
146 public function is_in_test_mode_onboarding( WC_Payment_Gateway $payment_gateway ): bool {
147 try {
148 if ( class_exists( '\WC_Stripe' ) && is_callable( '\WC_Stripe::get_instance' ) ) {
149 $stripe = \WC_Stripe::get_instance();
150 if ( is_object( $stripe ) && isset( $stripe->connect ) &&
151 class_exists( '\WC_Stripe_Connect' ) &&
152 $stripe->connect instanceof \WC_Stripe_Connect &&
153 is_callable( array( $stripe->connect, 'is_connected' ) ) ) {
154
155 return $stripe->connect->is_connected( 'test' )
156 && ! $stripe->connect->is_connected( 'live' );
157 }
158 }
159 } catch ( Throwable $e ) {
160 // Do nothing but log so we can investigate.
161 SafeGlobalFunctionProxy::wc_get_logger()->debug(
162 'Failed to determine if gateway is in test mode onboarding: ' . $e->getMessage(),
163 array(
164 'gateway' => $payment_gateway->id,
165 'source' => 'settings-payments',
166 'exception' => $e,
167 )
168 );
169 }
170
171 return parent::is_in_test_mode_onboarding( $payment_gateway );
172 }
173
174 /**
175 * Get the settings URL for a payment gateway.
176 *
177 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
178 *
179 * @return string The settings URL for the payment gateway.
180 */
181 public function get_settings_url( WC_Payment_Gateway $payment_gateway ): string {
182 return Utils::wc_payments_settings_url(
183 null,
184 array(
185 'section' => strtolower( $payment_gateway->id ),
186 'from' => Payments::FROM_PAYMENTS_SETTINGS,
187 )
188 );
189 }
190
191 /**
192 * Get the onboarding URL for the payment gateway.
193 *
194 * This URL should start or continue the onboarding process.
195 *
196 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
197 * @param string $return_url Optional. The URL to return to after onboarding.
198 * This will likely get attached to the onboarding URL.
199 *
200 * @return string The onboarding URL for the payment gateway.
201 */
202 public function get_onboarding_url( WC_Payment_Gateway $payment_gateway, string $return_url = '' ): string {
203 // Fall back to pointing users to the payment gateway settings page to handle onboarding.
204 return $this->get_settings_url( $payment_gateway );
205 }
206
207 /**
208 * Try and determine a list of recommended payment methods for a payment gateway.
209 *
210 * This data is not always available, and it is up to the payment gateway to provide it.
211 * This is not a definitive list of payment methods that the gateway supports.
212 * The data is aimed at helping the user understand what payment methods are recommended for the gateway
213 * and potentially help them make a decision on which payment methods to enable.
214 *
215 * @param WC_Payment_Gateway $payment_gateway The payment gateway object.
216 * @param string $country_code Optional. The country code for which to get recommended payment methods.
217 * This should be an ISO 3166-1 alpha-2 country code.
218 *
219 * @return array The recommended payment methods list for the payment gateway.
220 * Empty array if there are none.
221 */
222 public function get_recommended_payment_methods( WC_Payment_Gateway $payment_gateway, string $country_code = '' ): array {
223 return array();
224 }
225 }
226