|
| 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