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
Airwallex.php
112 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 | * Airwallex payment gateway provider class. |
| 14 | * |
| 15 | * This class handles all the custom logic for the Airwallex payment gateway provider. |
| 16 | */ |
| 17 | class Airwallex extends PaymentGateway { |
| 18 | |
| 19 | /** |
| 20 | * Try to determine if the payment gateway is in test mode. |
| 21 | * |
| 22 | * This is a best-effort attempt, as there is no standard way to determine this. |
| 23 | * Trust the true value, but don't consider a false value as definitive. |
| 24 | * |
| 25 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 26 | * |
| 27 | * @return bool True if the payment gateway is in test mode, false otherwise. |
| 28 | */ |
| 29 | public function is_in_test_mode( WC_Payment_Gateway $payment_gateway ): bool { |
| 30 | return $this->is_airwallex_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode( $payment_gateway ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Check if the payment gateway has a payments processor account connected. |
| 35 | * |
| 36 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 37 | * |
| 38 | * @return bool True if the payment gateway account is connected, false otherwise. |
| 39 | * If the payment gateway does not provide the information, it will return true. |
| 40 | */ |
| 41 | public function is_account_connected( WC_Payment_Gateway $payment_gateway ): bool { |
| 42 | try { |
| 43 | if ( class_exists( '\Airwallex\Services\Util' ) && |
| 44 | is_callable( '\Airwallex\Services\Util::getClientId' ) && |
| 45 | is_callable( '\Airwallex\Services\Util::getApiKey' ) && |
| 46 | is_callable( '\Airwallex\Services\Util::getWebhookSecret' ) ) { |
| 47 | |
| 48 | return ! empty( \Airwallex\Services\Util::getClientId() ) && |
| 49 | ! empty( \Airwallex\Services\Util::getApiKey() ) && |
| 50 | ! empty( \Airwallex\Services\Util::getWebhookSecret() ); |
| 51 | } |
| 52 | } catch ( Throwable $e ) { |
| 53 | // Do nothing but log so we can investigate. |
| 54 | SafeGlobalFunctionProxy::wc_get_logger()->debug( |
| 55 | 'Failed to determine if gateway has an account connected: ' . $e->getMessage(), |
| 56 | array( |
| 57 | 'gateway' => $payment_gateway->id, |
| 58 | 'source' => 'settings-payments', |
| 59 | 'exception' => $e, |
| 60 | ) |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | return parent::is_account_connected( $payment_gateway ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Try to determine if the payment gateway is in test mode onboarding (aka sandbox or test-drive). |
| 69 | * |
| 70 | * This is a best-effort attempt, as there is no standard way to determine this. |
| 71 | * Trust the true value, but don't consider a false value as definitive. |
| 72 | * |
| 73 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 74 | * |
| 75 | * @return bool True if the payment gateway is in test mode onboarding, false otherwise. |
| 76 | */ |
| 77 | public function is_in_test_mode_onboarding( WC_Payment_Gateway $payment_gateway ): bool { |
| 78 | return $this->is_airwallex_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode_onboarding( $payment_gateway ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Check if the Airwallex payment gateway is in sandbox mode. |
| 83 | * |
| 84 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 85 | * |
| 86 | * @return ?bool True if the payment gateway is in sandbox mode, false otherwise. |
| 87 | * Null if the environment could not be determined. |
| 88 | */ |
| 89 | private function is_airwallex_in_sandbox_mode( WC_Payment_Gateway $payment_gateway ): ?bool { |
| 90 | try { |
| 91 | if ( class_exists( '\Airwallex\Services\Util' ) && |
| 92 | is_callable( '\Airwallex\Services\Util::getEnvironment' ) ) { |
| 93 | |
| 94 | return 'demo' === \Airwallex\Services\Util::getEnvironment(); |
| 95 | } |
| 96 | } catch ( \Throwable $e ) { |
| 97 | // Do nothing but log so we can investigate. |
| 98 | SafeGlobalFunctionProxy::wc_get_logger()->debug( |
| 99 | 'Failed to determine if gateway is in sandbox mode: ' . $e->getMessage(), |
| 100 | array( |
| 101 | 'gateway' => $payment_gateway->id, |
| 102 | 'source' => 'settings-payments', |
| 103 | 'exception' => $e, |
| 104 | ) |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | // Let the caller know that we couldn't determine the environment. |
| 109 | return null; |
| 110 | } |
| 111 | } |
| 112 |