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
Paytrail.php
94 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 | * Paytrail payment gateway provider class. |
| 14 | * |
| 15 | * This class handles all the custom logic for the Paytrail payment gateway provider. |
| 16 | */ |
| 17 | class Paytrail 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 | try { |
| 31 | return wc_string_to_bool( $payment_gateway->get_option( 'enable_test_mode', 'no' ) ); |
| 32 | } catch ( Throwable $e ) { |
| 33 | // Do nothing but log so we can investigate. |
| 34 | SafeGlobalFunctionProxy::wc_get_logger()->debug( |
| 35 | 'Failed to determine if gateway is in test mode: ' . $e->getMessage(), |
| 36 | array( |
| 37 | 'gateway' => $payment_gateway->id, |
| 38 | 'source' => 'settings-payments', |
| 39 | 'exception' => $e, |
| 40 | ) |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | return parent::is_in_test_mode( $payment_gateway ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Check if the payment gateway has a payments processor account connected. |
| 49 | * |
| 50 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 51 | * |
| 52 | * @return bool True if the payment gateway account is connected, false otherwise. |
| 53 | * If the payment gateway does not provide the information, it will return true. |
| 54 | */ |
| 55 | public function is_account_connected( WC_Payment_Gateway $payment_gateway ): bool { |
| 56 | try { |
| 57 | // When in test mode onboarding, hard coded credentials are used, so we consider it connected. |
| 58 | if ( $this->is_in_test_mode_onboarding( $payment_gateway ) ) { |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | return ! empty( $payment_gateway->get_option( 'merchant_id' ) ) && |
| 63 | ! empty( $payment_gateway->get_option( 'secret_key' ) ); |
| 64 | } catch ( Throwable $e ) { |
| 65 | // Do nothing but log so we can investigate. |
| 66 | SafeGlobalFunctionProxy::wc_get_logger()->debug( |
| 67 | 'Failed to determine if gateway has an account connected: ' . $e->getMessage(), |
| 68 | array( |
| 69 | 'gateway' => $payment_gateway->id, |
| 70 | 'source' => 'settings-payments', |
| 71 | 'exception' => $e, |
| 72 | ) |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | return parent::is_account_connected( $payment_gateway ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Try to determine if the payment gateway is in test mode onboarding (aka sandbox or test-drive). |
| 81 | * |
| 82 | * This is a best-effort attempt, as there is no standard way to determine this. |
| 83 | * Trust the true value, but don't consider a false value as definitive. |
| 84 | * |
| 85 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 86 | * |
| 87 | * @return bool True if the payment gateway is in test mode onboarding, false otherwise. |
| 88 | */ |
| 89 | public function is_in_test_mode_onboarding( WC_Payment_Gateway $payment_gateway ): bool { |
| 90 | // Test mode is actually sandbox mode for Paytrail, affecting the API keys used. |
| 91 | return $this->is_in_test_mode( $payment_gateway ); |
| 92 | } |
| 93 | } |
| 94 |