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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-paypal.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-paypal.php
150 lines
1 <?php
2
3 class WCML_Payment_Gateway_PayPal extends WCML_Payment_Gateway {
4
5 const ID = 'paypal';
6 const SUPPORTED_CURRENCIES = [
7 'AUD',
8 'BRL',
9 'CAD',
10 'MXN',
11 'NZD',
12 'HKD',
13 'SGD',
14 'USD',
15 'EUR',
16 'JPY',
17 'TRY',
18 'NOK',
19 'CZK',
20 'DKK',
21 'HUF',
22 'ILS',
23 'MYR',
24 'PHP',
25 'PLN',
26 'SEK',
27 'CHF',
28 'TWD',
29 'THB',
30 'GBP',
31 'RMB',
32 'RUB',
33 'INR',
34 ];
35
36 public function get_output_model() {
37 return [
38 'id' => $this->get_id(),
39 'title' => $this->get_title(),
40 'isSupported' => true,
41 'settings' => $this->get_currencies_details(),
42 'tooltip' => '',
43 'strings' => [
44 'labelCurrency' => __( 'Currency', 'woocommerce-multilingual' ),
45 'labelPayPalEmail' => __( 'PayPal Email', 'woocommerce-multilingual' ),
46 // translators: %s is currency code.
47 'tooltipNotSupported' => __( 'This gateway does not support %s. To show this gateway please select another currency.', 'woocommerce-multilingual' ),
48 ],
49 ];
50 }
51
52 public function is_valid_for_use( $currency ) {
53
54 $filter_removed = remove_filter( 'woocommerce_paypal_supported_currencies', [ 'WCML_Payment_Gateway_PayPal', 'filter_supported_currencies' ] );
55
56 $is_valid = in_array(
57 $currency,
58 apply_filters(
59 'woocommerce_paypal_supported_currencies',
60 self::SUPPORTED_CURRENCIES
61 ),
62 true
63 );
64
65 if ( $filter_removed ) {
66 add_filter( 'woocommerce_paypal_supported_currencies', [ 'WCML_Payment_Gateway_PayPal', 'filter_supported_currencies' ] );
67 }
68
69 return $is_valid;
70 }
71
72 public function get_currencies_details() {
73
74 $currencies_details = [];
75 $default_currency = wcml_get_woocommerce_currency_option();
76 $woocommerce_currencies = get_woocommerce_currencies();
77
78 foreach ( $woocommerce_currencies as $code => $currency ) {
79
80 if ( $default_currency === $code ) {
81 $currencies_details[ $code ]['value'] = $this->get_gateway()->settings['email'] ?? '';
82 $currencies_details[ $code ]['currency'] = $code;
83 $currencies_details[ $code ]['isValid'] = $this->is_valid_for_use( $default_currency );
84 } else {
85 $currency_gateway_setting = $this->get_setting( $code );
86 $currencies_details[ $code ]['value'] = $currency_gateway_setting ? $currency_gateway_setting['value'] : '';
87 $currencies_details[ $code ]['currency'] = $currency_gateway_setting ? $currency_gateway_setting['currency'] : $code;
88 $currencies_details[ $code ]['isValid'] = $this->is_valid_for_use( $code );
89 }
90 }
91
92 return $currencies_details;
93
94 }
95
96 public function add_hooks() {
97 add_filter( 'woocommerce_paypal_args', [ $this, 'filter_paypal_args' ], 10, 2 );
98 }
99
100 public function filter_paypal_args( $args, $order ) {
101
102 $order_data = $order->get_data();
103 $client_currency = $order_data['currency'];
104 $gateway_setting = $this->get_setting( $client_currency );
105
106 if ( $gateway_setting ) {
107
108 if ( $gateway_setting['value'] ) {
109 $args['business'] = $gateway_setting['value'];
110 }
111
112 if ( $client_currency !== $gateway_setting['currency'] ) {
113 $args['currency_code'] = $gateway_setting['currency'];
114 $cart_items = WC()->cart->get_cart_contents();
115 $item_id = 1;
116
117 foreach ( $cart_items as $item ) {
118 $item_product_id = $item['variation_id'] ?: $item['product_id'];
119 $args[ 'amount_' . $item_id ] = $this->woocommerce_wpml->multi_currency->prices->get_product_price_in_currency( $item_product_id, $gateway_setting['currency'] );
120 $item_id ++;
121 }
122
123 $args['shipping_1'] = $this->woocommerce_wpml->cart->convert_cart_shipping_to_currency( $gateway_setting['currency'] );
124 }
125 }
126
127 return $args;
128 }
129
130 public static function filter_supported_currencies( $supported_currencies ) {
131 global $woocommerce_wpml;
132
133 $client_currency = $woocommerce_wpml->multi_currency->get_client_currency();
134
135 if ( ! in_array( $client_currency, self::SUPPORTED_CURRENCIES, true ) ) {
136 $gateway_settings = get_option( self::OPTION_KEY . self::ID, [] );
137
138 if ( $gateway_settings && isset( $gateway_settings[ $client_currency ] ) ) {
139
140 if ( in_array( $gateway_settings[ $client_currency ]['currency'], self::SUPPORTED_CURRENCIES, true ) ) {
141 $supported_currencies[] = $client_currency;
142 }
143 }
144 }
145
146 return $supported_currencies;
147 }
148
149 }
150