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
Eway.php
114 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 | * Eway payment gateway provider class. |
| 14 | * |
| 15 | * This class handles all the custom logic for the Eway payment gateway provider. |
| 16 | */ |
| 17 | class Eway extends PaymentGateway { |
| 18 | |
| 19 | /** |
| 20 | * Check if the payment gateway has a payments processor account connected. |
| 21 | * |
| 22 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 23 | * |
| 24 | * @return bool True if the payment gateway account is connected, false otherwise. |
| 25 | * If the payment gateway does not provide the information, it will return true. |
| 26 | */ |
| 27 | public function is_account_connected( WC_Payment_Gateway $payment_gateway ): bool { |
| 28 | try { |
| 29 | return ! empty( $payment_gateway->get_option( 'customer_api' ) ) && ! empty( $payment_gateway->get_option( 'customer_password' ) ); |
| 30 | } catch ( Throwable $e ) { |
| 31 | // Do nothing but log so we can investigate. |
| 32 | SafeGlobalFunctionProxy::wc_get_logger()->debug( |
| 33 | 'Failed to determine if gateway has an account connected: ' . $e->getMessage(), |
| 34 | array( |
| 35 | 'gateway' => $payment_gateway->id, |
| 36 | 'source' => 'settings-payments', |
| 37 | 'exception' => $e, |
| 38 | ) |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | return parent::is_account_connected( $payment_gateway ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Try to determine if the payment gateway is in test mode. |
| 47 | * |
| 48 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 49 | * |
| 50 | * @return bool True if the payment gateway is in test mode, false otherwise. |
| 51 | */ |
| 52 | public function is_in_test_mode( WC_Payment_Gateway $payment_gateway ): bool { |
| 53 | return $this->is_eway_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode( $payment_gateway ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Try to determine if the payment gateway is in dev mode. |
| 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 $this->is_eway_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_dev_mode( $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 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 71 | * |
| 72 | * @return bool True if the payment gateway is in test mode onboarding, false otherwise. |
| 73 | */ |
| 74 | public function is_in_test_mode_onboarding( WC_Payment_Gateway $payment_gateway ): bool { |
| 75 | return $this->is_eway_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode_onboarding( $payment_gateway ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Check if the Eway payment gateway is in test/sandbox mode. |
| 80 | * |
| 81 | * There are two different environments: test/sandbox and production. |
| 82 | * |
| 83 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 84 | * |
| 85 | * @return ?bool True if the payment gateway is in sandbox mode, false otherwise. |
| 86 | * Null if the environment could not be determined. |
| 87 | */ |
| 88 | private function is_eway_in_sandbox_mode( WC_Payment_Gateway $payment_gateway ): ?bool { |
| 89 | try { |
| 90 | // Prefer option over property. |
| 91 | $raw_option = $payment_gateway->get_option( 'testmode' ); |
| 92 | if ( '' !== $raw_option && null !== $raw_option ) { |
| 93 | return \wc_string_to_bool( $raw_option ); |
| 94 | } |
| 95 | if ( isset( $payment_gateway->testmode ) ) { |
| 96 | return \wc_string_to_bool( $payment_gateway->testmode ); |
| 97 | } |
| 98 | } catch ( Throwable $e ) { |
| 99 | // Do nothing but log so we can investigate. |
| 100 | SafeGlobalFunctionProxy::wc_get_logger()->debug( |
| 101 | 'Failed to determine if gateway is in sandbox mode: ' . $e->getMessage(), |
| 102 | array( |
| 103 | 'gateway' => $payment_gateway->id, |
| 104 | 'source' => 'settings-payments', |
| 105 | 'exception' => $e, |
| 106 | ) |
| 107 | ); |
| 108 | } |
| 109 | |
| 110 | // Let the caller know that we couldn't determine the environment. |
| 111 | return null; |
| 112 | } |
| 113 | } |
| 114 |