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
Paystack.php
91 lines
| 1 | <?php |
| 2 | declare( strict_types=1 ); |
| 3 | |
| 4 | namespace Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders; |
| 5 | |
| 6 | use Automattic\WooCommerce\Internal\Logging\SafeGlobalFunctionProxy; |
| 7 | use Throwable; |
| 8 | use WC_Payment_Gateway; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | /** |
| 13 | * Paystack payment gateway provider class. |
| 14 | * |
| 15 | * This class handles all the custom logic for the Paystack payment gateway provider. |
| 16 | */ |
| 17 | class Paystack extends PaymentGateway { |
| 18 | |
| 19 | /** |
| 20 | * Check if the payment gateway needs setup. |
| 21 | * |
| 22 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 23 | * |
| 24 | * @return bool True if the payment gateway needs setup, false otherwise. |
| 25 | */ |
| 26 | public function needs_setup( WC_Payment_Gateway $payment_gateway ): bool { |
| 27 | try { |
| 28 | $is_valid_for_use = true; |
| 29 | if ( is_callable( array( $payment_gateway, 'is_valid_for_use' ) ) ) { |
| 30 | $is_valid_for_use = wc_string_to_bool( $payment_gateway->is_valid_for_use() ); |
| 31 | } |
| 32 | |
| 33 | return ! $is_valid_for_use || ! $this->is_account_connected( $payment_gateway ); |
| 34 | } catch ( Throwable $e ) { |
| 35 | // Do nothing but log so we can investigate. |
| 36 | SafeGlobalFunctionProxy::wc_get_logger()->debug( |
| 37 | 'Failed to determine if gateway needs setup: ' . $e->getMessage(), |
| 38 | array( |
| 39 | 'gateway' => $payment_gateway->id, |
| 40 | 'source' => 'settings-payments', |
| 41 | 'exception' => $e, |
| 42 | ) |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | return parent::needs_setup( $payment_gateway ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Check if the payment gateway has a payments processor account connected. |
| 51 | * |
| 52 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 53 | * |
| 54 | * @return bool True if the payment gateway account is connected, false otherwise. |
| 55 | * If the payment gateway does not provide the information, it will return true. |
| 56 | */ |
| 57 | public function is_account_connected( WC_Payment_Gateway $payment_gateway ): bool { |
| 58 | try { |
| 59 | return property_exists( $payment_gateway, 'public_key' ) && ! empty( $payment_gateway->public_key ) && |
| 60 | property_exists( $payment_gateway, 'secret_key' ) && ! empty( $payment_gateway->secret_key ); |
| 61 | } catch ( Throwable $e ) { |
| 62 | // Do nothing but log so we can investigate. |
| 63 | SafeGlobalFunctionProxy::wc_get_logger()->debug( |
| 64 | 'Failed to determine if gateway has an account connected: ' . $e->getMessage(), |
| 65 | array( |
| 66 | 'gateway' => $payment_gateway->id, |
| 67 | 'source' => 'settings-payments', |
| 68 | 'exception' => $e, |
| 69 | ) |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | return parent::is_account_connected( $payment_gateway ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Try to determine if the payment gateway is in test mode onboarding (aka sandbox or test-drive). |
| 78 | * |
| 79 | * This is a best-effort attempt, as there is no standard way to determine this. |
| 80 | * Trust the true value, but don't consider a false value as definitive. |
| 81 | * |
| 82 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 83 | * |
| 84 | * @return bool True if the payment gateway is in test mode onboarding, false otherwise. |
| 85 | */ |
| 86 | public function is_in_test_mode_onboarding( WC_Payment_Gateway $payment_gateway ): bool { |
| 87 | // Test mode is actually sandbox mode for Paystack, affecting the used API keys. |
| 88 | return $this->is_in_test_mode( $payment_gateway ); |
| 89 | } |
| 90 | } |
| 91 |