Completed
Push — update/use-wordpress-api-fetch... ( 2f6fe4...cd05e3 )
by
unknown
124:11 queued 116:32
created

Jetpack_Simple_Payments::get_currency()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 129

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 129
rs 8
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * Simple Payments lets users embed a PayPal button fully integrated with wpcom to sell products on the site.
4
 * This is not a proper module yet, because not all the pieces are in place. Until everything is shipped, it can be turned
5
 * into module that can be enabled/disabled.
6
*/
7
class Jetpack_Simple_Payments {
8
	// These have to be under 20 chars because that is CPT limit.
9
	static $post_type_order = 'jp_pay_order';
10
	static $post_type_product = 'jp_pay_product';
11
12
	static $shortcode = 'simple-payment';
13
14
	static $css_classname_prefix = 'jetpack-simple-payments';
15
16
	// Increase this number each time there's a change in CSS or JS to bust cache.
17
	static $version = '0.25';
18
19
	// Classic singleton pattern:
20
	private static $instance;
21
	private function __construct() {}
22
	static function getInstance() {
23
		if ( ! self::$instance ) {
24
			self::$instance = new self();
25
			self::$instance->register_init_hooks();
26
		}
27
		return self::$instance;
28
	}
29
30
	private function register_scripts_and_styles() {
31
		/**
32
		 * Paypal heavily discourages putting that script in your own server:
33
		 * @see https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/add-paypal-button/
34
		 */
35
		wp_register_script( 'paypal-checkout-js', 'https://www.paypalobjects.com/api/checkout.js', array(), null, true );
36
		wp_register_script( 'paypal-express-checkout', plugins_url( '/paypal-express-checkout.js', __FILE__ ),
37
			array( 'jquery', 'paypal-checkout-js' ), self::$version );
38
		wp_register_style( 'jetpack-simple-payments', plugins_url( '/simple-payments.css', __FILE__ ), array( 'dashicons' ) );
39
	}
40
41
	private function register_init_hooks() {
42
		add_action( 'init', array( $this, 'init_hook_action' ) );
43
		add_action( 'rest_api_init', array( $this, 'register_meta_fields_in_rest_api' ) );
44
	}
45
46
	private function register_shortcode() {
47
		add_shortcode( self::$shortcode, array( $this, 'parse_shortcode' ) );
48
	}
49
50
	public function init_hook_action() {
51
		add_filter( 'rest_api_allowed_post_types', array( $this, 'allow_rest_api_types' ) );
52
		add_filter( 'jetpack_sync_post_meta_whitelist', array( $this, 'allow_sync_post_meta' ) );
53
		if ( ! is_admin() ) {
54
			$this->register_scripts_and_styles();
55
		}
56
		$this->register_shortcode();
57
		$this->setup_cpts();
58
59
		add_filter( 'the_content', array( $this, 'remove_auto_paragraph_from_product_description' ), 0 );
60
61
		if ( $this->is_enabled_jetpack_simple_payments() ) {
62
			jetpack_register_block( 'simple-payments' );
63
		} else {
64
			jetpack_register_block( 'simple-payments', array(), array( 'available' => false, 'unavailable_reason' => 'missing_plan' ) );
65
		}
66
	}
67
68
	function remove_auto_paragraph_from_product_description( $content ) {
69
		if ( get_post_type() === self::$post_type_product ) {
70
			remove_filter( 'the_content', 'wpautop' );
71
		}
72
73
		return $content;
74
	}
75
76
	function get_blog_id() {
77
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
78
			return get_current_blog_id();
79
		}
80
81
		return Jetpack_Options::get_option( 'id' );
82
	}
83
84
	/**
85
	 * Used to check whether Simple Payments are enabled for given site.
86
	 *
87
	 * @return bool True if Simple Payments are enabled, false otherwise.
88
	 */
89
	function is_enabled_jetpack_simple_payments() {
90
		/**
91
		 * Can be used by plugin authors to disable the conflicting output of Simple Payments.
92
		 *
93
		 * @since 6.3.0
94
		 *
95
		 * @param bool True if Simple Payments should be disabled, false otherwise.
96
		 */
97
		if ( apply_filters( 'jetpack_disable_simple_payments', false ) ) {
98
			return false;
99
		}
100
101
		// For WPCOM sites
102
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'has_any_blog_stickers' ) ) {
103
			$site_id = $this->get_blog_id();
104
			return has_any_blog_stickers( array( 'premium-plan', 'business-plan', 'ecommerce-plan' ), $site_id );
105
		}
106
107
		// For all Jetpack sites
108
		return Jetpack::is_active() && Jetpack::active_plan_supports( 'simple-payments');
109
	}
110
111
	function parse_shortcode( $attrs, $content = false ) {
112
		if ( empty( $attrs['id'] ) ) {
113
			return;
114
		}
115
		$product = get_post( $attrs['id'] );
116
		if ( ! $product || is_wp_error( $product ) ) {
117
			return;
118
		}
119
		if ( $product->post_type !== self::$post_type_product || 'publish' !== $product->post_status ) {
120
			return;
121
		}
122
123
		// We allow for overriding the presentation labels
124
		$data = shortcode_atts( array(
125
			'blog_id'     => $this->get_blog_id(),
126
			'dom_id'      => uniqid( self::$css_classname_prefix . '-' . $product->ID . '_', true ),
127
			'class'       => self::$css_classname_prefix . '-' . $product->ID,
128
			'title'       => get_the_title( $product ),
129
			'description' => $product->post_content,
130
			'cta'         => get_post_meta( $product->ID, 'spay_cta', true ),
131
			'multiple'    => get_post_meta( $product->ID, 'spay_multiple', true ) || '0'
132
		), $attrs );
133
134
		$data['price'] = $this->format_price(
135
			get_post_meta( $product->ID, 'spay_price', true ),
136
			get_post_meta( $product->ID, 'spay_currency', true )
137
		);
138
139
		$data['id'] = $attrs['id'];
140
141
		if( ! wp_style_is( 'jetpack-simple-payments', 'enqueue' ) ) {
142
			wp_enqueue_style( 'jetpack-simple-payments' );
143
		}
144
145
		if ( ! $this->is_enabled_jetpack_simple_payments() ) {
146
			return $this->output_admin_warning( $data );
147
		}
148
149
		if ( ! wp_script_is( 'paypal-express-checkout', 'enqueued' ) ) {
150
			wp_enqueue_script( 'paypal-express-checkout' );
151
		}
152
153
		wp_add_inline_script( 'paypal-express-checkout', sprintf(
154
			"try{PaypalExpressCheckout.renderButton( '%d', '%d', '%s', '%d' );}catch(e){}",
155
			esc_js( $data['blog_id'] ),
156
			esc_js( $attrs['id'] ),
157
			esc_js( $data['dom_id'] ),
158
			esc_js( $data['multiple'] )
159
		) );
160
161
		return $this->output_shortcode( $data );
162
	}
163
164
	function output_admin_warning( $data ) {
165
		if ( ! current_user_can( 'manage_options' ) ) {
166
			return;
167
		}
168
		$css_prefix = self::$css_classname_prefix;
169
170
		$support_url = ( defined( 'IS_WPCOM' ) && IS_WPCOM )
171
			? 'https://support.wordpress.com/simple-payments/'
172
			: 'https://jetpack.com/support/simple-payment-button/';
173
174
		return sprintf( '
175
<div class="%1$s">
176
	<div class="%2$s">
177
		<div class="%3$s">
178
			<div class="%4$s" id="%5$s">
179
				<p>%6$s</p>
180
				<p>%7$s</p>
181
			</div>
182
		</div>
183
	</div>
184
</div>
185
',
186
			esc_attr( "{$data['class']} ${css_prefix}-wrapper" ),
187
			esc_attr( "${css_prefix}-product" ),
188
			esc_attr( "${css_prefix}-details" ),
189
			esc_attr( "${css_prefix}-purchase-message show error" ),
190
			esc_attr( "{$data['dom_id']}-message-container" ),
191
			sprintf(
192
				wp_kses(
193
					__( 'Your plan doesn\'t include Simple Payments. <a href="%s" rel="noopener noreferrer" target="_blank">Learn more and upgrade</a>.', 'jetpack' ),
194
					array( 'a' => array( 'href' => array(), 'rel' => array(), 'target' => array() ) )
195
				),
196
				esc_url( $support_url )
197
			),
198
			esc_html__( '(Only administrators will see this message.)', 'jetpack' )
199
		);
200
	}
201
202
	function output_shortcode( $data ) {
203
		$items = '';
204
		$css_prefix = self::$css_classname_prefix;
205
206
		if ( $data['multiple'] ) {
207
			$items = sprintf( '
208
				<div class="%1$s">
209
					<input class="%2$s" type="number" value="1" min="1" id="%3$s" />
210
				</div>
211
				',
212
				esc_attr( "${css_prefix}-items" ),
213
				esc_attr( "${css_prefix}-items-number" ),
214
				esc_attr( "{$data['dom_id']}_number" )
215
			);
216
		}
217
		$image = "";
218
		if( has_post_thumbnail( $data['id'] ) ) {
219
			$image = sprintf( '<div class="%1$s"><div class="%2$s">%3$s</div></div>',
220
				esc_attr( "${css_prefix}-product-image" ),
221
				esc_attr( "${css_prefix}-image" ),
222
				get_the_post_thumbnail( $data['id'], 'full' )
223
			);
224
		}
225
		return sprintf( '
226
<div class="%1$s">
227
	<div class="%2$s">
228
		%3$s
229
		<div class="%4$s">
230
			<div class="%5$s"><p>%6$s</p></div>
231
			<div class="%7$s"><p>%8$s</p></div>
232
			<div class="%9$s"><p>%10$s</p></div>
233
			<div class="%11$s" id="%12$s"></div>
234
			<div class="%13$s">
235
				%14$s
236
				<div class="%15$s" id="%16$s"></div>
237
			</div>
238
		</div>
239
	</div>
240
</div>
241
',
242
			esc_attr( "{$data['class']} ${css_prefix}-wrapper" ),
243
			esc_attr( "${css_prefix}-product" ),
244
			$image,
245
			esc_attr( "${css_prefix}-details" ),
246
			esc_attr( "${css_prefix}-title" ),
247
			$data['title'],
248
			esc_attr( "${css_prefix}-description" ),
249
			$data['description'],
250
			esc_attr( "${css_prefix}-price" ),
251
			esc_html( $data['price'] ),
252
			esc_attr( "${css_prefix}-purchase-message" ),
253
			esc_attr( "{$data['dom_id']}-message-container" ),
254
			esc_attr( "${css_prefix}-purchase-box" ),
255
			$items,
256
			esc_attr( "${css_prefix}-button" ),
257
			esc_attr( "{$data['dom_id']}_button" )
258
		);
259
	}
260
261
	/**
262
	 * Format a price with currency
263
	 *
264
	 * Uses currency-aware formatting to output a formatted price with a simple fallback.
265
	 *
266
	 * Largely inspired by WordPress.com's Store_Price::display_currency
267
	 *
268
	 * @param  string $price    Price.
269
	 * @param  string $currency Currency.
270
	 * @return string           Formatted price.
271
	 */
272
	private function format_price( $price, $currency ) {
273
		$currency_details = self::get_currency( $currency );
274
275
		if ( $currency_details ) {
276
			// Ensure USD displays as 1234.56 even in non-US locales.
277
			$amount = 'USD' === $currency
278
				? number_format( $price, $currency_details['decimal'], '.', ',' )
279
				: number_format_i18n( $price, $currency_details['decimal'] );
280
281
			return sprintf(
282
				$currency_details['format'],
283
				$currency_details['symbol'],
284
				$amount
285
			);
286
		}
287
288
		return "$price $currency";
289
	}
290
291
	/**
292
	 * Allows custom post types to be used by REST API.
293
	 * @param $post_types
294
	 * @see hook 'rest_api_allowed_post_types'
295
	 * @return array
296
	 */
297
	function allow_rest_api_types( $post_types ) {
298
		$post_types[] = self::$post_type_order;
299
		$post_types[] = self::$post_type_product;
300
		return $post_types;
301
	}
302
303
	function allow_sync_post_meta( $post_meta ) {
304
		return array_merge( $post_meta, array(
305
			'spay_paypal_id',
306
			'spay_status',
307
			'spay_product_id',
308
			'spay_quantity',
309
			'spay_price',
310
			'spay_customer_email',
311
			'spay_currency',
312
			'spay_cta',
313
			'spay_email',
314
			'spay_multiple',
315
			'spay_formatted_price',
316
		) );
317
	}
318
319
	/**
320
	 * Enable Simple payments custom meta values for access through the REST API.
321
	 * Field’s value will be exposed on a .meta key in the endpoint response,
322
	 * and WordPress will handle setting up the callbacks for reading and writing
323
	 * to that meta key.
324
	 *
325
	 * @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
326
	 */
327
	public function register_meta_fields_in_rest_api() {
328
		register_meta( 'post', 'spay_price', array(
329
			'description'       => esc_html__( 'Simple payments; price.', 'jetpack' ),
330
			'object_subtype'    => self::$post_type_product,
331
			'sanitize_callback' => array( $this, 'sanitize_price' ),
332
			'show_in_rest'      => true,
333
			'single'            => true,
334
			'type'              => 'number',
335
		) );
336
337
		register_meta( 'post', 'spay_currency', array(
338
			'description'       => esc_html__( 'Simple payments; currency code.', 'jetpack' ),
339
			'object_subtype'    => self::$post_type_product,
340
			'sanitize_callback' => array( $this, 'sanitize_currency' ),
341
			'show_in_rest'      => true,
342
			'single'            => true,
343
			'type'              => 'string',
344
		) );
345
346
		register_meta( 'post', 'spay_cta', array(
347
			'description'       => esc_html__( 'Simple payments; text with "Buy" or other CTA', 'jetpack' ),
348
			'object_subtype'    => self::$post_type_product,
349
			'sanitize_callback' => 'sanitize_text_field',
350
			'show_in_rest'      => true,
351
			'single'            => true,
352
			'type'              => 'string',
353
		) );
354
355
		register_meta( 'post', 'spay_multiple', array(
356
			'description'       => esc_html__( 'Simple payments; allow multiple items', 'jetpack' ),
357
			'object_subtype'    => self::$post_type_product,
358
			'sanitize_callback' => 'rest_sanitize_boolean',
359
			'show_in_rest'      => true,
360
			'single'            => true,
361
			'type'              => 'boolean',
362
		) );
363
364
		register_meta( 'post', 'spay_email', array(
365
			'description'       => esc_html__( 'Simple payments button; paypal email.', 'jetpack' ),
366
			'sanitize_callback' => 'sanitize_email',
367
			'show_in_rest'      => true,
368
			'single'            => true,
369
			'type'              => 'string',
370
		) );
371
372
		register_meta( 'post', 'spay_status', array(
373
			'description'       => esc_html__( 'Simple payments; status.', 'jetpack' ),
374
			'object_subtype'    => self::$post_type_product,
375
			'sanitize_callback' => 'sanitize_text_field',
376
			'show_in_rest'      => true,
377
			'single'            => true,
378
			'type'              => 'string',
379
		) );
380
	}
381
382
	/**
383
	 * Sanitize three-character ISO-4217 Simple payments currency
384
	 *
385
	 * List has to be in sync with list at the client side:
386
	 * @link https://github.com/Automattic/wp-calypso/blob/6d02ffe73cc073dea7270a22dc30881bff17d8fb/client/lib/simple-payments/constants.js
387
	 *
388
	 * Currencies should be supported by PayPal:
389
	 * @link https://developer.paypal.com/docs/integration/direct/rest/currency-codes/
390
	 */
391
	public static function sanitize_currency( $currency ) {
392
		$valid_currencies = array(
393
			'USD',
394
			'EUR',
395
			'AUD',
396
			'BRL',
397
			'CAD',
398
			'CZK',
399
			'DKK',
400
			'HKD',
401
			'HUF',
402
			'ILS',
403
			'JPY',
404
			'MYR',
405
			'MXN',
406
			'TWD',
407
			'NZD',
408
			'NOK',
409
			'PHP',
410
			'PLN',
411
			'GBP',
412
			'RUB',
413
			'SGD',
414
			'SEK',
415
			'CHF',
416
			'THB',
417
		);
418
419
		return in_array( $currency, $valid_currencies ) ? $currency : false;
420
	}
421
422
	/**
423
	 * Sanitize price:
424
	 *
425
	 * Positive integers and floats
426
	 * Supports two decimal places.
427
	 * Maximum length: 10.
428
	 *
429
	 * See `price` from PayPal docs:
430
	 * @link https://developer.paypal.com/docs/api/orders/v1/#definition-item
431
	 *
432
	 * @param      $value
433
	 * @return null|string
434
	 */
435
	public static function sanitize_price( $price ) {
436
		return preg_match( '/^[0-9]{0,10}(\.[0-9]{0,2})?$/', $price ) ? $price : false;
437
	}
438
439
	/**
440
	 * Sets up the custom post types for the module.
441
	 */
442
	function setup_cpts() {
443
444
		/*
445
		 * ORDER data structure. holds:
446
		 * title = customer_name | 4xproduct_name
447
		 * excerpt = customer_name + customer contact info + customer notes from paypal form
448
		 * metadata:
449
		 * spay_paypal_id - paypal id of transaction
450
		 * spay_status
451
		 * spay_product_id - post_id of bought product
452
		 * spay_quantity - quantity of product
453
		 * spay_price - item price at the time of purchase
454
		 * spay_customer_email - customer email
455
		 * ... (WIP)
456
		 */
457
		$order_capabilities = array(
458
			'edit_post'             => 'edit_posts',
459
			'read_post'             => 'read_private_posts',
460
			'delete_post'           => 'delete_posts',
461
			'edit_posts'            => 'edit_posts',
462
			'edit_others_posts'     => 'edit_others_posts',
463
			'publish_posts'         => 'publish_posts',
464
			'read_private_posts'    => 'read_private_posts',
465
		);
466
		$order_args = array(
467
			'label'                 => esc_html_x( 'Order', 'noun: a quantity of goods or items purchased or sold', 'jetpack' ),
468
			'description'           => esc_html__( 'Simple Payments orders', 'jetpack' ),
469
			'supports'              => array( 'custom-fields', 'excerpt' ),
470
			'hierarchical'          => false,
471
			'public'                => false,
472
			'show_ui'               => false,
473
			'show_in_menu'          => false,
474
			'show_in_admin_bar'     => false,
475
			'show_in_nav_menus'     => false,
476
			'can_export'            => true,
477
			'has_archive'           => false,
478
			'exclude_from_search'   => true,
479
			'publicly_queryable'    => false,
480
			'rewrite'               => false,
481
			'capabilities'          => $order_capabilities,
482
			'show_in_rest'          => true,
483
		);
484
		register_post_type( self::$post_type_order, $order_args );
485
486
		/*
487
		 * PRODUCT data structure. Holds:
488
		 * title - title
489
		 * content - description
490
		 * thumbnail - image
491
		 * metadata:
492
		 * spay_price - price
493
		 * spay_formatted_price
494
		 * spay_currency - currency code
495
		 * spay_cta - text with "Buy" or other CTA
496
		 * spay_email - paypal email
497
		 * spay_multiple - allow for multiple items
498
		 * spay_status - status. { enabled | disabled }
499
		 */
500
		$product_capabilities = array(
501
			'edit_post'             => 'edit_posts',
502
			'read_post'             => 'read_private_posts',
503
			'delete_post'           => 'delete_posts',
504
			'edit_posts'            => 'publish_posts',
505
			'edit_others_posts'     => 'edit_others_posts',
506
			'publish_posts'         => 'publish_posts',
507
			'read_private_posts'    => 'read_private_posts',
508
		);
509
		$product_args = array(
510
			'label'                 => esc_html__( 'Product', 'jetpack' ),
511
			'description'           => esc_html__( 'Simple Payments products', 'jetpack' ),
512
			'supports'              => array( 'title', 'editor','thumbnail', 'custom-fields', 'author' ),
513
			'hierarchical'          => false,
514
			'public'                => false,
515
			'show_ui'               => false,
516
			'show_in_menu'          => false,
517
			'show_in_admin_bar'     => false,
518
			'show_in_nav_menus'     => false,
519
			'can_export'            => true,
520
			'has_archive'           => false,
521
			'exclude_from_search'   => true,
522
			'publicly_queryable'    => false,
523
			'rewrite'               => false,
524
			'capabilities'          => $product_capabilities,
525
			'show_in_rest'          => true,
526
		);
527
		register_post_type( self::$post_type_product, $product_args );
528
	}
529
530
	/**
531
	 * Format a price for display
532
	 *
533
	 * Largely taken from WordPress.com Store_Price class
534
	 *
535
	 * The currency array will have the shape:
536
	 *   format  => string sprintf format with placeholders `%1$s`: Symbol `%2$s`: Price.
537
	 *   symbol  => string Symbol string
538
	 *   desc    => string Text description of currency
539
	 *   decimal => int    Number of decimal places
540
	 *
541
	 * @param  string $the_currency The desired currency, e.g. 'USD'.
542
	 * @return ?array               Currency object or null if not found.
0 ignored issues
show
Documentation introduced by
The doc-type ?array could not be parsed: Unknown type name "?array" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
543
	 */
544
	private static function get_currency( $the_currency ) {
545
		$currencies = array(
546
			'USD' => array(
547
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
548
				'symbol'  => '$',
549
				'decimal' => 2,
550
			),
551
			'GBP' => array(
552
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
553
				'symbol'  => '&#163;',
554
				'decimal' => 2,
555
			),
556
			'JPY' => array(
557
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
558
				'symbol'  => '&#165;',
559
				'decimal' => 0,
560
			),
561
			'BRL' => array(
562
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
563
				'symbol'  => 'R$',
564
				'decimal' => 2,
565
			),
566
			'EUR' => array(
567
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
568
				'symbol'  => '&#8364;',
569
				'decimal' => 2,
570
			),
571
			'NZD' => array(
572
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
573
				'symbol'  => 'NZ$',
574
				'decimal' => 2,
575
			),
576
			'AUD' => array(
577
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
578
				'symbol'  => 'A$',
579
				'decimal' => 2,
580
			),
581
			'CAD' => array(
582
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
583
				'symbol'  => 'C$',
584
				'decimal' => 2,
585
			),
586
			'ILS' => array(
587
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
588
				'symbol'  => '₪',
589
				'decimal' => 2,
590
			),
591
			'RUB' => array(
592
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
593
				'symbol'  => '₽',
594
				'decimal' => 2,
595
			),
596
			'MXN' => array(
597
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
598
				'symbol'  => 'MX$',
599
				'decimal' => 2,
600
			),
601
			'MYR' => array(
602
				'format'  => '%2$s%1$s', // 1: Symbol 2: currency value
603
				'symbol'  => 'RM',
604
				'decimal' => 2,
605
			),
606
			'SEK' => array(
607
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
608
				'symbol'  => 'Skr',
609
				'decimal' => 2,
610
			),
611
			'HUF' => array(
612
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
613
				'symbol'  => 'Ft',
614
				'decimal' => 0, // Decimals are supported by Stripe but not by PayPal.
615
			),
616
			'CHF' => array(
617
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
618
				'symbol'  => 'CHF',
619
				'decimal' => 2,
620
			),
621
			'CZK' => array(
622
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
623
				'symbol'  => 'Kč',
624
				'decimal' => 2,
625
			),
626
			'DKK' => array(
627
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
628
				'symbol'  => 'Dkr',
629
				'decimal' => 2,
630
			),
631
			'HKD' => array(
632
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
633
				'symbol'  => 'HK$',
634
				'decimal' => 2,
635
			),
636
			'NOK' => array(
637
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
638
				'symbol'  => 'Kr',
639
				'decimal' => 2,
640
			),
641
			'PHP' => array(
642
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
643
				'symbol'  => '₱',
644
				'decimal' => 2,
645
			),
646
			'PLN' => array(
647
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
648
				'symbol'  => 'PLN',
649
				'decimal' => 2,
650
			),
651
			'SGD' => array(
652
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
653
				'symbol'  => 'S$',
654
				'decimal' => 2,
655
			),
656
			'TWD' => array(
657
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
658
				'symbol'  => 'NT$',
659
				'decimal' => 0, // Decimals are supported by Stripe but not by PayPal.
660
			),
661
			'THB' => array(
662
				'format'  => '%2$s%1$s', // 1: Symbol 2: currency value
663
				'symbol'  => '฿',
664
				'decimal' => 2,
665
			),
666
		);
667
668
		if ( isset( $currencies[ $the_currency ] ) ) {
669
			return $currencies[ $the_currency ];
670
		}
671
		return null;
672
	}
673
}
674
Jetpack_Simple_Payments::getInstance();
675