Skip to content

Commit 24b00e1

Browse files
committed
Wip
wip
1 parent 1737c51 commit 24b00e1

10 files changed

+232
-0
lines changed

.phpactor.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "/phpactor.schema.json",
3+
"php_code_sniffer.enabled": false
4+
}

includes/abstracts/abstract-wc-stripe-payment-gateway.php

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function get_upe_enabled_payment_method_ids() {
3939
* @return string[]
4040
*/
4141
public function get_upe_available_payment_methods() {
42+
error_log('get_upe_available_payment_methods aqui?');
4243
return [ WC_Stripe_Payment_Methods::CARD ];
4344
}
4445

includes/admin/class-wc-rest-stripe-settings-controller.php

+2
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ public function register_routes() {
238238
* @return WP_REST_Response
239239
*/
240240
public function get_settings() {
241+
error_log('get_settings method');
241242
$is_upe_enabled = WC_Stripe_Feature_Flags::is_upe_checkout_enabled();
243+
error_log('$is_upe_enabled: ' . print_r($is_upe_enabled, true));
242244
$available_payment_method_ids = $is_upe_enabled ? $this->gateway->get_upe_available_payment_methods() : WC_Stripe_Helper::get_legacy_available_payment_method_ids();
243245
$ordered_payment_method_ids = $is_upe_enabled ? WC_Stripe_Helper::get_upe_ordered_payment_method_ids( $this->gateway ) : $available_payment_method_ids;
244246
$enabled_payment_method_ids = $is_upe_enabled ? WC_Stripe_Helper::get_upe_settings_enabled_payment_method_ids( $this->gateway ) : WC_Stripe_Helper::get_legacy_enabled_payment_method_ids();

includes/payment-methods/class-wc-stripe-upe-payment-gateway.php

+1
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ public function get_upe_enabled_at_checkout_payment_method_ids( $order_id = null
596596
* @return string[]
597597
*/
598598
public function get_upe_available_payment_methods() {
599+
error_log('upe gateway get_upe_available_payment_methods');
599600
$available_payment_methods = [];
600601

601602
foreach ( $this->payment_methods as $payment_method ) {

includes/payment-methods/class-wc-stripe-upe-payment-method-ach.php

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function __construct() {
3737
* @return bool True if US-based account; false otherwise.
3838
*/
3939
public function is_available_for_account_country() {
40+
error_log('ACH is_available_for_account_country');
4041
return in_array( WC_Stripe::get_instance()->account->get_account_country(), $this->supported_countries, true );
4142
}
4243

includes/payment-methods/class-wc-stripe-upe-payment-method-acss.php

+10
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@ public function __construct() {
3535
public function get_retrievable_type() {
3636
return $this->get_id();
3737
}
38+
39+
/**
40+
* Checks if ACH is available for the Stripe account's country.
41+
*
42+
* @return bool True if US-based account; false otherwise.
43+
*/
44+
public function is_available_for_account_country() {
45+
error_log('ACSS is_available_for_account_country');
46+
return in_array( WC_Stripe::get_instance()->account->get_account_country(), $this->supported_countries, true );
47+
}
3848
}

includes/payment-methods/class-wc-stripe-upe-payment-method-bacs-debit.php

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public function __construct() {
3636
* @return bool
3737
*/
3838
public function is_available_for_account_country() {
39+
error_log('Bacs is_available_for_account_country');
40+
error_log('Country:' . WC_Stripe::get_instance()->account->get_account_country() );
3941
return in_array( WC_Stripe::get_instance()->account->get_account_country(), $this->supported_countries, true );
4042
}
4143

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Class WC_REST_Stripe_Settings_Controller_Test_GB
4+
*/
5+
6+
use Automattic\WooCommerce\Blocks\Package;
7+
use Automattic\WooCommerce\Blocks\RestApi;
8+
9+
/**
10+
* WC_REST_Stripe_Settings_Controller_Test_Multiple_Countries unit tests.
11+
*/
12+
class WC_REST_Stripe_Settings_Controller_Test_Multiple_Countries extends WP_UnitTestCase {
13+
14+
/**
15+
* Tested REST route.
16+
*/
17+
const SETTINGS_ROUTE = '/wc/v3/wc_stripe/settings';
18+
19+
/**
20+
* Gateway instance that the controller uses.
21+
*
22+
* @var WC_Gateway_Stripe
23+
*/
24+
private static $gateway;
25+
26+
/**
27+
* Pre-test setup
28+
*/
29+
public function set_up() {
30+
parent::set_up();
31+
32+
// Enable LPMs
33+
update_option( WC_Stripe_Feature_Flags::LPM_BACS_FEATURE_FLAG_NAME, 'yes' );
34+
update_option( WC_Stripe_Feature_Flags::LPM_ACH_FEATURE_FLAG_NAME, 'yes' );
35+
update_option( WC_Stripe_Feature_Flags::LPM_ACSS_FEATURE_FLAG_NAME, 'yes' );
36+
37+
// All tests assume UPE feature is enabled.
38+
update_option( '_wcstripe_feature_upe', 'yes' );
39+
40+
// Set the user so that we can pass the authentication.
41+
wp_set_current_user( 1 );
42+
}
43+
44+
public function test_get_settings() {
45+
// test getting payment methods from Canada
46+
self::$gateway = WC_Helper_Rest_Server::reset_rest_server('CA');
47+
$response = $this->rest_get_settings();
48+
error_log('$response: ' . print_r($response->get_data()['available_payment_method_ids'], true));
49+
50+
// test getting payments methos from UK
51+
self::$gateway = WC_Helper_Rest_Server::reset_rest_server('GB');
52+
$response = $this->rest_get_settings();
53+
error_log('$response: ' . print_r($response->get_data()['available_payment_method_ids'], true));
54+
55+
// test getting payment methods from USA
56+
self::$gateway = WC_Helper_Rest_Server::reset_rest_server('US');
57+
$response = $this->rest_get_settings();
58+
error_log('$response: ' . print_r($response->get_data()['available_payment_method_ids'], true));
59+
}
60+
61+
62+
/**
63+
* @return WP_REST_Response
64+
*/
65+
private function rest_get_settings() {
66+
$request = new WP_REST_Request( 'GET', self::SETTINGS_ROUTE );
67+
68+
return rest_do_request( $request );
69+
}
70+
71+
/**
72+
* @return WC_Gateway_Stripe
73+
*/
74+
private function get_gateway() {
75+
return self::$gateway;
76+
}
77+
78+
}

tests/phpunit/bootstrap.php

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function _manually_load_plugin() {
5555
# To keep the plugin self-contained, copy any needed helper to the `helpers/` sub-folder.
5656
require_once __DIR__ . '/helpers/class-upe-test-helper.php';
5757
require_once __DIR__ . '/helpers/class-wc-helper-product.php';
58+
require_once __DIR__ . '/helpers/class-wc-helper-rest-server.php';
5859
require_once __DIR__ . '/helpers/class-wc-helper-shipping.php';
5960
require_once __DIR__ . '/helpers/class-wc-helper-order.php';
6061
require_once __DIR__ . '/helpers/class-wc-helper-subscription.php';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
3+
class WC_Helper_Rest_Server {
4+
public static function reset_rest_server($country = 'US') {
5+
// Aqui se deberia quizás primero habilitar UPE?
6+
// Aunque ya está habilitado por defecto?
7+
// $settings = WC_Stripe_Helper::get_stripe_settings();
8+
// $settings[ WC_Stripe_Feature_Flags::UPE_CHECKOUT_FEATURE_ATTRIBUTE_NAME ] = 'yes';
9+
// WC_Stripe_Helper::update_main_stripe_settings( $settings );
10+
// TODO: Explicar esto
11+
$upe_helper = new UPE_Test_Helper();
12+
update_option( '_wcstripe_feature_upe', 'yes' );
13+
$upe_helper->enable_upe();
14+
15+
// Reemplazamos la instancia interna de WC_Stripe_UPE_Payment_Gateway
16+
// almacenado en la propiedad $stripe_gateway de la clase WC_Stripe
17+
$closure = Closure::bind(
18+
function () {
19+
$this->stripe_gateway = null;
20+
},
21+
woocommerce_gateway_stripe(),
22+
WC_Stripe::class
23+
);
24+
$closure();
25+
26+
// TODO: Ver si esto es realmente necesario
27+
WC()->payment_gateways()->payment_gateways = [];
28+
WC()->payment_gateways()->init();
29+
WC_Stripe_Helper::$stripe_legacy_gateways = [];
30+
31+
// Actualiza la configuracion del plugin de Stripe,
32+
// Esto comprende los campos de formulario de admin includes/admin/stripe-settings.php
33+
// y algunos otros
34+
35+
// array (
36+
// 'enabled' => 'yes',
37+
// 'title' => 'Credit Card (Stripe)',
38+
// 'description' => 'Pay with your credit card via Stripe.',
39+
// 'api_credentials' => '',
40+
// 'testmode' => 'yes',
41+
// 'test_publishable_key' => 'pk_test_51Ja916HJAl4h87JObUIt4zkPVW0UU4tUbJHfoBI1t0rpWdugrxxV9WUwAy8MxcTD5MXb8yYr43Bhdh0KB03PiTpk006b5juGeu',
42+
// 'test_secret_key' => 'sk_test_51Ja916HJAl4h87JODCpwTxpNk41LB3sLU2TSwUhrkEy7cqyQ9uarAFiGPTp3Cl1At3qgyPWYrudsdlv0XcmZs2bH000NgEGVow',
43+
// 'publishable_key' => '',
44+
// 'secret_key' => '',
45+
// 'webhook' => '',
46+
// 'test_webhook_secret' => 'whsec_b83d6b8a2c8d51a0075b2f233156922e4848b52bbae97d484ddc8543d4639724',
47+
// 'webhook_secret' => '',
48+
// 'inline_cc_form' => 'no',
49+
// 'statement_descriptor' => '',
50+
// 'short_statement_descriptor' => '',
51+
// 'capture' => 'yes',
52+
// 'payment_request' => 'no',
53+
// 'payment_request_button_type' => 'default',
54+
// 'payment_request_button_theme' => 'dark',
55+
// 'payment_request_button_locations' =>
56+
// array (
57+
// 0 => 'product',
58+
// 1 => 'cart',
59+
// 2 => 'checkout',
60+
// ),
61+
// 'payment_request_button_size' => 'default',
62+
// 'saved_cards' => 'yes',
63+
// 'logging' => 'yes',
64+
// 'upe_checkout_experience_enabled' => 'yes',
65+
// 'upe_checkout_experience_accepted_payments' =>
66+
// array (
67+
// 0 => 'card',
68+
// 1 => 'wechat_pay',
69+
// 2 => 'cashapp',
70+
// ),
71+
// 'test_connection_type' => 'connect',
72+
// 'apple_pay_verified_domain' => 'wcstripe.test',
73+
// 'apple_pay_domain_set' => 'no',
74+
// 'test_webhook_data' =>
75+
// array (
76+
// 'id' => 'we_1QhkMZHJAl4h87JOZ8KtlV4f',
77+
// 'url' => 'https://wcstripe.test/?wc-api=wc_stripe',
78+
// 'secret' => 'sk_test_51Ja916HJAl4h87JODCpwTxpNk41LB3sLU2TSwUhrkEy7cqyQ9uarAFiGPTp3Cl1At3qgyPWYrudsdlv0XcmZs2bH000NgEGVow',
79+
// ),
80+
// 'stripe_upe_payment_method_order' =>
81+
// array (
82+
// 0 => 'card',
83+
// 1 => 'alipay',
84+
// 2 => 'klarna',
85+
// 3 => 'afterpay_clearpay',
86+
// 4 => 'eps',
87+
// 5 => 'bancontact',
88+
// 6 => 'boleto',
89+
// 7 => 'ideal',
90+
// 8 => 'oxxo',
91+
// 9 => 'sepa_debit',
92+
// 10 => 'p24',
93+
// 11 => 'multibanco',
94+
// 12 => 'link',
95+
// 13 => 'wechat_pay',
96+
// 14 => 'us_bank_account',
97+
// 15 => 'affirm',
98+
// 16 => 'cashapp',
99+
// ),
100+
// 'is_short_statement_descriptor_enabled' => 'no',
101+
// 'sepa_tokens_for_other_methods' => 'yes',
102+
// 'amazon_pay' => 'no',
103+
// 'amazon_pay_button_size' => 'default',
104+
// 'amazon_pay_button_locations' =>
105+
// array (
106+
// 0 => 'product',
107+
// 1 => 'cart',
108+
// ),
109+
// )
110+
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
111+
$stripe_settings['enabled'] = 'yes';
112+
$stripe_settings['testmode'] = 'yes';
113+
$stripe_settings['test_publishable_key'] = 'pk_test_key';
114+
$stripe_settings['test_secret_key'] = 'sk_test_key';
115+
// $stripe_settings['country'] = 'GB'; // parece error,
116+
117+
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
118+
119+
// actualizamos el trasient wcstripe_account_data_test el cual es usado por WC_Stripe_Account
120+
// TODO: Especificar por qué es necesrio hacer esto.
121+
$account = [
122+
'country' => $country,
123+
'capabilities' => [],
124+
];
125+
set_transient( 'wcstripe_account_data_test', $account );
126+
127+
// TODO: quiza lo de arriba sirva para el gateway?
128+
$new_gateway = WC()->payment_gateways()->payment_gateways()[ WC_Gateway_Stripe::ID ];
129+
130+
return $new_gateway;
131+
}
132+
}

0 commit comments

Comments
 (0)