-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathAlipayDefinition.php
More file actions
274 lines (243 loc) · 7.52 KB
/
AlipayDefinition.php
File metadata and controls
274 lines (243 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
/**
* Alipay Payment Method Definition
*
* @package WCPay\PaymentMethods\Configs\Definitions
*/
namespace WCPay\PaymentMethods\Configs\Definitions;
use WCPay\PaymentMethods\Configs\Interfaces\PaymentMethodDefinitionInterface;
use WCPay\PaymentMethods\Configs\Constants\PaymentMethodCapability;
use WCPay\Constants\Country_Code;
use WCPay\Constants\Currency_Code;
use WCPay\PaymentMethods\Configs\Utils\PaymentMethodUtils;
/**
* Class implementing the Alipay payment method definition.
*/
class AlipayDefinition implements PaymentMethodDefinitionInterface {
/**
* Get the internal ID for the payment method
*
* @return string
*/
public static function get_id(): string {
return 'alipay';
}
/**
* Get the keywords for the payment method. These are used by the duplicate detection service.
*
* @return string[]
*/
public static function get_keywords(): array {
return [ 'alipay' ];
}
/**
* Get the Stripe payment method ID
*
* @return string
*/
public static function get_stripe_id(): string {
return PaymentMethodUtils::get_stripe_id( self::get_id() );
}
/**
* Get the customer-facing title of the payment method
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_title( ?string $account_country = null ): string {
return __( 'Alipay', 'woocommerce-payments' );
}
/**
* Get the title of the payment method for the settings page.
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_settings_label( ?string $account_country = null ): string {
return self::get_title( $account_country );
}
/**
* Get the customer-facing description of the payment method
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string
*/
public static function get_description( ?string $account_country = null ): string {
return __( 'Alipay is a popular wallet in China, operated by Ant Financial Services Group, a financial services provider affiliated with Alibaba.', 'woocommerce-payments' );
}
/**
* Get the list of supported currencies
*
* @return string[] Array of currency codes
*/
public static function get_supported_currencies(): array {
$account = \WC_Payments::get_account_service()->get_cached_account_data();
$account_country = isset( $account['country'] ) ? strtoupper( $account['country'] ) : '';
if ( Country_Code::AUSTRALIA === $account_country ) {
return [ Currency_Code::AUSTRALIAN_DOLLAR ];
}
if ( Country_Code::CANADA === $account_country ) {
return [ Currency_Code::CANADIAN_DOLLAR ];
}
if ( Country_Code::UNITED_KINGDOM === $account_country ) {
return [ Currency_Code::POUND_STERLING ];
}
if ( Country_Code::HONG_KONG === $account_country ) {
return [ Currency_Code::HONG_KONG_DOLLAR ];
}
if ( Country_Code::JAPAN === $account_country ) {
return [ Currency_Code::JAPANESE_YEN ];
}
if ( Country_Code::NEW_ZEALAND === $account_country ) {
return [ Currency_Code::NEW_ZEALAND_DOLLAR ];
}
if ( Country_Code::SINGAPORE === $account_country ) {
return [ Currency_Code::SINGAPORE_DOLLAR ];
}
if ( Country_Code::UNITED_STATES === $account_country ) {
return [ Currency_Code::UNITED_STATES_DOLLAR ];
}
if ( Country_Code::HUNGARY === $account_country ) {
return [ Currency_Code::HUNGARIAN_FORINT ];
}
if ( in_array(
$account_country,
[
Country_Code::AUSTRIA,
Country_Code::BELGIUM,
Country_Code::BULGARIA,
Country_Code::CYPRUS,
Country_Code::CZECHIA,
Country_Code::DENMARK,
Country_Code::ESTONIA,
Country_Code::FINLAND,
Country_Code::FRANCE,
Country_Code::GERMANY,
Country_Code::GREECE,
Country_Code::IRELAND,
Country_Code::ITALY,
Country_Code::LATVIA,
Country_Code::LITHUANIA,
Country_Code::LUXEMBOURG,
Country_Code::MALTA,
Country_Code::NETHERLANDS,
Country_Code::NORWAY,
Country_Code::PORTUGAL,
Country_Code::ROMANIA,
Country_Code::SLOVAKIA,
Country_Code::SLOVENIA,
Country_Code::SPAIN,
Country_Code::SWEDEN,
Country_Code::SWITZERLAND,
Country_Code::CROATIA,
],
true
) ) {
return [ Currency_Code::EURO ];
}
// fallback currency code, just in case.
return [ Currency_Code::CHINESE_YUAN ];
}
/**
* Get the list of supported countries
*
* @param string|null $account_country Optional. The merchant's account country.
* @return string[] Array of country codes
*/
public static function get_supported_countries( ?string $account_country = null ): array {
return [];
}
/**
* Get the payment method capabilities
*
* @return string[]
*/
public static function get_capabilities(): array {
return [
PaymentMethodCapability::REFUNDS,
PaymentMethodCapability::MULTI_CURRENCY,
];
}
/**
* Get the URL for the payment method's icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_icon_url( ?string $account_country = null ): string {
return plugins_url( 'assets/images/payment-methods/alipay-logo.svg', WCPAY_PLUGIN_FILE );
}
/**
* Get the URL for the payment method's dark mode icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string Returns regular icon URL if no dark mode icon exists
*/
public static function get_dark_icon_url( ?string $account_country = null ): string {
return self::get_icon_url( $account_country );
}
/**
* Get the URL for the payment method's settings icon
*
* @param string|null $account_country Optional. The merchant's account country.
*
* @return string
*/
public static function get_settings_icon_url( ?string $account_country = null ): string {
return self::get_icon_url( $account_country );
}
/**
* Get the testing instructions for the payment method
*
* @param string $account_country The merchant's account country.
* @return string HTML string containing testing instructions
*/
public static function get_testing_instructions( string $account_country ): string {
return '';
}
/**
* Get the currency limits for the payment method
*
* @return array<string,array<string,array{min:int,max:int}>>
*/
public static function get_limits_per_currency(): array {
return [];
}
/**
* Whether this payment method is available for the given currency and country
*
* @param string $currency The currency code to check.
* @param string $account_country The merchant's account country.
*
* @return bool
*/
public static function is_available_for( string $currency, string $account_country ): bool {
return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country );
}
/**
* Get the minimum amount for this payment method for a given currency and country
*
* @param string $currency The currency code.
* @param string $country The country code.
*
* @return int|null The minimum amount or null if no minimum.
*/
public static function get_minimum_amount( string $currency, string $country ): ?int {
return null;
}
/**
* Get the maximum amount for this payment method for a given currency and country
*
* @param string $currency The currency code.
* @param string $country The country code.
*
* @return int|null The maximum amount or null if no maximum.
*/
public static function get_maximum_amount( string $currency, string $country ): ?int {
return null;
}
}