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 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / classes / multi-currency / payment-gateways / class-wcml-payment-gateway-stripe.php
woocommerce-multilingual / classes / multi-currency / payment-gateways Last commit date
class-wcml-currencies-payment-gateways.php 1 month ago class-wcml-not-supported-payment-gateway.php 1 month ago class-wcml-payment-gateway-bacs.php 1 month ago class-wcml-payment-gateway-paypal-v2.php 1 month ago class-wcml-payment-gateway-paypal.php 1 month ago class-wcml-payment-gateway-stripe.php 1 month ago class-wcml-payment-gateway.php 1 month ago
class-wcml-payment-gateway-stripe.php
136 lines
1 <?php
2
3 class WCML_Payment_Gateway_Stripe extends WCML_Payment_Gateway {
4
5 const ID = 'stripe';
6
7 public function get_output_model() {
8 return [
9 'id' => $this->get_id(),
10 'title' => $this->get_title(),
11 'isSupported' => true,
12 'settings' => $this->get_currencies_details(),
13 'tooltip' => '',
14 'strings' => [
15 'labelCurrency' => __( 'Currency', 'woocommerce-multilingual' ),
16 'labelLivePublishableKey' => __( 'Live Publishable Key', 'woocommerce-multilingual' ),
17 'labelLiveSecretKey' => __( 'Live Secret Key', 'woocommerce-multilingual' ),
18 'labelTestPublishableKey' => __( 'Test Publishable Key', 'woocommerce-multilingual' ),
19 'labelTestSecretKey' => __( 'Test Secret Key', 'woocommerce-multilingual' ),
20 ],
21 ];
22 }
23
24 public function add_hooks() {
25 $client_currency = $this->woocommerce_wpml->multi_currency->get_client_currency();
26
27 if ( $this->is_client_currency_supported( $client_currency ) ) {
28 add_filter( 'wc_stripe_generate_create_intent_request', [
29 $this,
30 'convert_stripe_payment_request'
31 ], 10, 3 );
32 }
33 }
34
35 public function convert_stripe_payment_request( $request, $order, $source ) {
36 $client_currency = $request ['currency'] ?? null;
37 $client_currency = strtoupper( $client_currency );
38
39 $convert_to_currency = $this->maybe_convert_currency( $client_currency );
40 if ( null === $convert_to_currency ) {
41 return $request;
42 }
43
44 if ( $client_currency !== $convert_to_currency ) {
45 $convert_price = $this->get_convert_price_callable( $convert_to_currency );
46
47 $request = $convert_price( $request );
48 }
49
50 return $request;
51 }
52
53 public function get_currencies_details() {
54 $currencies_details = [];
55 $default_currency = wcml_get_woocommerce_currency_option();
56 $active_currencies = get_woocommerce_currencies();
57
58 foreach ( $active_currencies as $code => $currency ) {
59
60 if ( $default_currency === $code ) {
61 $currencies_details[ $code ]['currency'] = $code;
62 $currencies_details[ $code ]['publishable_key'] = $this->get_gateway()->settings['publishable_key'];
63 $currencies_details[ $code ]['secret_key'] = $this->get_gateway()->settings['secret_key'];
64 $currencies_details[ $code ]['test_publishable_key'] = $this->get_gateway()->settings['test_publishable_key'];
65 $currencies_details[ $code ]['test_secret_key'] = $this->get_gateway()->settings['test_secret_key'];
66 } else {
67 $currency_gateway_setting = $this->get_setting( $code );
68 $currencies_details[ $code ]['currency'] = $currency_gateway_setting['currency'] ?? '';
69 $currencies_details[ $code ]['publishable_key'] = $currency_gateway_setting['publishable_key'] ?? '';
70 $currencies_details[ $code ]['secret_key'] = $currency_gateway_setting['secret_key'] ?? '';
71 $currencies_details[ $code ]['test_publishable_key'] = $currency_gateway_setting['test_publishable_key'] ?? '';
72 $currencies_details[ $code ]['test_secret_key'] = $currency_gateway_setting['test_secret_key'] ?? '';
73 }
74 }
75
76 return $currencies_details;
77
78 }
79
80 public static function filter_stripe_settings( $settings ) {
81 if ( is_admin() ) {
82 return $settings;
83 }
84
85 global $woocommerce_wpml;
86
87 $client_currency = $woocommerce_wpml->multi_currency->get_client_currency();
88 $gateway_settings = get_option( self::OPTION_KEY . self::ID, [] );
89
90 if ( $gateway_settings && isset( $gateway_settings[ $client_currency ] ) ) {
91 $gateway_setting = $gateway_settings[ $client_currency ];
92 if ( ! empty( $gateway_setting['publishable_key'] ) && ! empty( $gateway_setting['secret_key'] ) ) {
93 $settings['publishable_key'] = $gateway_setting['publishable_key'];
94 $settings['secret_key'] = $gateway_setting['secret_key'];
95 }
96 if ( ! empty( $gateway_setting['test_publishable_key'] ) && ! empty( $gateway_setting['test_secret_key'] ) ) {
97 $settings['test_publishable_key'] = $gateway_setting['test_publishable_key'];
98 $settings['test_secret_key'] = $gateway_setting['test_secret_key'];
99 }
100 }
101
102 return $settings;
103 }
104
105 private function get_convert_price_callable( $convert_to_currency ): callable {
106 return function ( array $price_params ) use ( $convert_to_currency ): array {
107 $value = $price_params['amount'];
108 $currency = strtoupper( $price_params['currency'] );
109
110 $price_default = $this->woocommerce_wpml->multi_currency->prices->unconvert_price_amount( $value, $currency );
111 $price_converted = $this->woocommerce_wpml->multi_currency->prices->convert_price_amount( $price_default, $convert_to_currency );
112
113 $price_params['amount'] = (int) $price_converted;
114 $price_params['currency'] = strtolower( $convert_to_currency );
115
116 return $price_params;
117 };
118 }
119
120 private function maybe_convert_currency( string $client_currency ) {
121 $gateway_setting = $this->get_setting( $client_currency );
122
123 return $gateway_setting['currency'] ?? null;
124 }
125
126 private function is_client_currency_supported( string $client_currency ): bool {
127 $newCurrency = $this->maybe_convert_currency( $client_currency );
128
129 if ( null === $newCurrency ) {
130 return false;
131 }
132
133 return true;
134 }
135 }
136