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
Visa.php
134 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 | * Visa payment gateway provider class. |
| 14 | * |
| 15 | * This class handles all the custom logic for the Visa payment gateway provider. |
| 16 | */ |
| 17 | class Visa 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 | if ( is_callable( array( $payment_gateway, 'get_config_settings' ) ) && |
| 30 | defined( 'VISA_ACCEPTANCE_ENVIRONMENT_TEST' ) && |
| 31 | defined( 'VISA_ACCEPTANCE_ENVIRONMENT_PRODUCTION' ) ) { |
| 32 | $settings = $payment_gateway->get_config_settings(); |
| 33 | |
| 34 | return is_array( $settings ) && isset( $settings['environment'] ) && |
| 35 | ( ( \VISA_ACCEPTANCE_ENVIRONMENT_TEST === $settings['environment'] && |
| 36 | ! empty( $settings['test_merchant_id'] ) && |
| 37 | ! empty( $settings['test_api_key'] ) && |
| 38 | ! empty( $settings['test_api_shared_secret'] ) ) || |
| 39 | ( \VISA_ACCEPTANCE_ENVIRONMENT_PRODUCTION === $settings['environment'] && |
| 40 | ! empty( $settings['merchant_id'] ) && |
| 41 | ! empty( $settings['api_key'] ) && |
| 42 | ! empty( $settings['api_shared_secret'] ) ) ); |
| 43 | } |
| 44 | } catch ( Throwable $e ) { |
| 45 | // Do nothing but log so we can investigate. |
| 46 | SafeGlobalFunctionProxy::wc_get_logger()->debug( |
| 47 | 'Failed to determine if gateway has an account connected: ' . $e->getMessage(), |
| 48 | array( |
| 49 | 'gateway' => $payment_gateway->id, |
| 50 | 'source' => 'settings-payments', |
| 51 | 'exception' => $e, |
| 52 | ) |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | return parent::is_account_connected( $payment_gateway ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Try to determine if the payment gateway is in test mode. |
| 61 | * |
| 62 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 63 | * |
| 64 | * @return bool True if the payment gateway is in test mode, false otherwise. |
| 65 | */ |
| 66 | public function is_in_test_mode( WC_Payment_Gateway $payment_gateway ): bool { |
| 67 | return $this->is_visa_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode( $payment_gateway ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Try to determine if the payment gateway is in dev mode. |
| 72 | * |
| 73 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 74 | * |
| 75 | * @return bool True if the payment gateway is in dev mode, false otherwise. |
| 76 | */ |
| 77 | public function is_in_dev_mode( WC_Payment_Gateway $payment_gateway ): bool { |
| 78 | return $this->is_visa_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_dev_mode( $payment_gateway ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Try to determine if the payment gateway is in test mode onboarding (aka sandbox or test-drive). |
| 83 | * |
| 84 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 85 | * |
| 86 | * @return bool True if the payment gateway is in test mode onboarding, false otherwise. |
| 87 | */ |
| 88 | public function is_in_test_mode_onboarding( WC_Payment_Gateway $payment_gateway ): bool { |
| 89 | return $this->is_visa_in_sandbox_mode( $payment_gateway ) ?? parent::is_in_test_mode_onboarding( $payment_gateway ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Check if the Visa payment gateway is in test/sandbox mode. |
| 94 | * |
| 95 | * There are two different environments: test/sandbox and production. |
| 96 | * |
| 97 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 98 | * |
| 99 | * @return ?bool True if the payment gateway is in sandbox mode, false otherwise. |
| 100 | * Null if the environment could not be determined. |
| 101 | */ |
| 102 | private function is_visa_in_sandbox_mode( WC_Payment_Gateway $payment_gateway ): ?bool { |
| 103 | try { |
| 104 | if ( is_callable( array( $payment_gateway, 'get_config_settings' ) ) && |
| 105 | defined( 'VISA_ACCEPTANCE_ENVIRONMENT_TEST' ) && |
| 106 | defined( 'VISA_ACCEPTANCE_ENVIRONMENT_PRODUCTION' ) ) { |
| 107 | $settings = $payment_gateway->get_config_settings(); |
| 108 | |
| 109 | if ( is_array( $settings ) && isset( $settings['environment'] ) ) { |
| 110 | if ( \VISA_ACCEPTANCE_ENVIRONMENT_TEST === $settings['environment'] ) { |
| 111 | return true; |
| 112 | } |
| 113 | if ( \VISA_ACCEPTANCE_ENVIRONMENT_PRODUCTION === $settings['environment'] ) { |
| 114 | return false; |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } catch ( Throwable $e ) { |
| 119 | // Do nothing but log so we can investigate. |
| 120 | SafeGlobalFunctionProxy::wc_get_logger()->debug( |
| 121 | 'Failed to determine if gateway is in sandbox mode: ' . $e->getMessage(), |
| 122 | array( |
| 123 | 'gateway' => $payment_gateway->id, |
| 124 | 'source' => 'settings-payments', |
| 125 | 'exception' => $e, |
| 126 | ) |
| 127 | ); |
| 128 | } |
| 129 | |
| 130 | // Let the caller know that we couldn't determine the environment. |
| 131 | return null; |
| 132 | } |
| 133 | } |
| 134 |