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
WCCore.php
112 lines
| 1 | <?php |
| 2 | declare( strict_types=1 ); |
| 3 | |
| 4 | namespace Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders; |
| 5 | |
| 6 | use WC_Payment_Gateway; |
| 7 | use WC_Gateway_BACS; |
| 8 | use WC_Gateway_Cheque; |
| 9 | use WC_Gateway_COD; |
| 10 | use WC_Gateway_Paypal; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | /** |
| 15 | * WooCommerce core payment gateways provider class. |
| 16 | * |
| 17 | * This class handles all the custom logic for the payment gateways built into the WC core. |
| 18 | */ |
| 19 | class WCCore extends PaymentGateway { |
| 20 | |
| 21 | /** |
| 22 | * Get the provider icon URL of the payment gateway. |
| 23 | * |
| 24 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 25 | * |
| 26 | * @return string The provider icon URL of the payment gateway. |
| 27 | */ |
| 28 | public function get_icon( WC_Payment_Gateway $payment_gateway ): string { |
| 29 | // Provide custom icons for core payment gateways. |
| 30 | switch ( $payment_gateway->id ) { |
| 31 | case WC_Gateway_BACS::ID: |
| 32 | return plugins_url( 'assets/images/payment_methods/bacs.svg', WC_PLUGIN_FILE ); |
| 33 | case WC_Gateway_Cheque::ID: |
| 34 | return plugins_url( 'assets/images/payment_methods/cheque.svg', WC_PLUGIN_FILE ); |
| 35 | case WC_Gateway_COD::ID: |
| 36 | return plugins_url( 'assets/images/payment_methods/cod.svg', WC_PLUGIN_FILE ); |
| 37 | case WC_Gateway_Paypal::ID: |
| 38 | return plugins_url( 'assets/images/payment_methods/72x72/paypal.png', WC_PLUGIN_FILE ); |
| 39 | } |
| 40 | |
| 41 | return parent::get_icon( $payment_gateway ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Check if the payment gateway has a payments processor account connected. |
| 46 | * |
| 47 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 48 | * |
| 49 | * @return bool True if the payment gateway account is connected, false otherwise. |
| 50 | * If the payment gateway does not provide the information, it will return true. |
| 51 | */ |
| 52 | public function is_account_connected( WC_Payment_Gateway $payment_gateway ): bool { |
| 53 | // Provide custom account connected logic for core payment gateways. |
| 54 | switch ( $payment_gateway->id ) { |
| 55 | case WC_Gateway_BACS::ID: |
| 56 | // BACS requires bank account details to be set up. |
| 57 | return property_exists( $payment_gateway, 'account_details' ) && ! empty( $payment_gateway->account_details ); |
| 58 | case WC_Gateway_Cheque::ID: |
| 59 | case WC_Gateway_COD::ID: |
| 60 | // There is no account setup for these gateways, so we return true. |
| 61 | return true; |
| 62 | case WC_Gateway_Paypal::ID: |
| 63 | // PayPal requires just an account email address to be set up. |
| 64 | return property_exists( $payment_gateway, 'email' ) && is_email( $payment_gateway->email ); |
| 65 | } |
| 66 | |
| 67 | return parent::is_account_connected( $payment_gateway ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Try to determine if the payment gateway is in test mode onboarding (aka sandbox or test-drive). |
| 72 | * |
| 73 | * This is a best-effort attempt, as there is no standard way to determine this. |
| 74 | * Trust the true value, but don't consider a false value as definitive. |
| 75 | * |
| 76 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 77 | * |
| 78 | * @return bool True if the payment gateway is in test mode onboarding, false otherwise. |
| 79 | */ |
| 80 | public function is_in_test_mode_onboarding( WC_Payment_Gateway $payment_gateway ): bool { |
| 81 | // Provide custom test mode onboarding logic for core payment gateways. |
| 82 | switch ( $payment_gateway->id ) { |
| 83 | case WC_Gateway_BACS::ID: |
| 84 | case WC_Gateway_Cheque::ID: |
| 85 | case WC_Gateway_COD::ID: |
| 86 | return false; // These gateways do not have a test mode onboarding. |
| 87 | case WC_Gateway_Paypal::ID: |
| 88 | // Test mode is actually sandbox mode for PayPal, affecting the API keys used. |
| 89 | return $this->is_in_test_mode( $payment_gateway ); |
| 90 | } |
| 91 | |
| 92 | return parent::is_in_test_mode_onboarding( $payment_gateway ); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Get the plugin details for a WC core-provided payment gateway. |
| 97 | * |
| 98 | * @param WC_Payment_Gateway $payment_gateway The payment gateway object. |
| 99 | * |
| 100 | * @return array The plugin details for the payment gateway. |
| 101 | */ |
| 102 | public function get_plugin_details( WC_Payment_Gateway $payment_gateway ): array { |
| 103 | $plugin_details = parent::get_plugin_details( $payment_gateway ); |
| 104 | |
| 105 | // Since these are core-provided gateways, we need to make sure that the provider (WC) can't be deactivated. |
| 106 | // The way to do this is to NOT provide a plugin file path. |
| 107 | $plugin_details['file'] = ''; |
| 108 | |
| 109 | return $plugin_details; |
| 110 | } |
| 111 | } |
| 112 |