Completed
Push — renovate/automattic-jetpack-bl... ( 92e79a )
by
unknown
16:38 queued 10:00
created

Jetpack_Simple_Payments::get_block_availability()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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( 'init', array( $this, 'register_gutenberg_block' ), 40 );
44
		add_action( 'rest_api_init', array( $this, 'register_meta_fields_in_rest_api' ) );
45
	}
46
47
	private function register_shortcode() {
48
		add_shortcode( self::$shortcode, array( $this, 'parse_shortcode' ) );
49
	}
50
51
	public function init_hook_action() {
52
		add_filter( 'rest_api_allowed_post_types', array( $this, 'allow_rest_api_types' ) );
53
		add_filter( 'jetpack_sync_post_meta_whitelist', array( $this, 'allow_sync_post_meta' ) );
54
		if ( ! is_admin() ) {
55
			$this->register_scripts_and_styles();
56
		}
57
		$this->register_shortcode();
58
		$this->setup_cpts();
59
60
		add_filter( 'the_content', array( $this, 'remove_auto_paragraph_from_product_description' ), 0 );
61
	}
62
63
	function register_gutenberg_block() {
64
		if ( $this->is_enabled_jetpack_simple_payments() ) {
65
			jetpack_register_block( 'simple-payments' );
66
		} else {
67
			jetpack_set_extension_unavailability_reason( 'simple-payments', 'missing_plan' );
68
		}
69
	}
70
71
	function remove_auto_paragraph_from_product_description( $content ) {
72
		if ( get_post_type() === self::$post_type_product ) {
73
			remove_filter( 'the_content', 'wpautop' );
74
		}
75
76
		return $content;
77
	}
78
79
	function get_blog_id() {
80
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
81
			return get_current_blog_id();
82
		}
83
84
		return Jetpack_Options::get_option( 'id' );
85
	}
86
87
	/**
88
	 * Used to check whether Simple Payments are enabled for given site.
89
	 *
90
	 * @return bool True if Simple Payments are enabled, false otherwise.
91
	 */
92
	function is_enabled_jetpack_simple_payments() {
93
		/**
94
		 * Can be used by plugin authors to disable the conflicting output of Simple Payments.
95
		 *
96
		 * @since 6.3.0
97
		 *
98
		 * @param bool True if Simple Payments should be disabled, false otherwise.
99
		 */
100
		if ( apply_filters( 'jetpack_disable_simple_payments', false ) ) {
101
			return false;
102
		}
103
104
		// For WPCOM sites
105
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM && function_exists( 'has_any_blog_stickers' ) ) {
106
			$site_id = $this->get_blog_id();
107
			return has_any_blog_stickers( array( 'premium-plan', 'business-plan', 'ecommerce-plan' ), $site_id );
108
		}
109
110
		// For all Jetpack sites
111
		return Jetpack::is_active() && Jetpack::active_plan_supports( 'simple-payments');
112
	}
113
114
	function parse_shortcode( $attrs, $content = false ) {
115
		if ( empty( $attrs['id'] ) ) {
116
			return;
117
		}
118
		$product = get_post( $attrs['id'] );
119
		if ( ! $product || is_wp_error( $product ) ) {
120
			return;
121
		}
122
		if ( $product->post_type !== self::$post_type_product || 'publish' !== $product->post_status ) {
123
			return;
124
		}
125
126
		// We allow for overriding the presentation labels
127
		$data = shortcode_atts( array(
128
			'blog_id'     => $this->get_blog_id(),
129
			'dom_id'      => uniqid( self::$css_classname_prefix . '-' . $product->ID . '_', true ),
130
			'class'       => self::$css_classname_prefix . '-' . $product->ID,
131
			'title'       => get_the_title( $product ),
132
			'description' => $product->post_content,
133
			'cta'         => get_post_meta( $product->ID, 'spay_cta', true ),
134
			'multiple'    => get_post_meta( $product->ID, 'spay_multiple', true ) || '0'
135
		), $attrs );
136
137
		$data['price'] = $this->format_price(
138
			get_post_meta( $product->ID, 'spay_price', true ),
139
			get_post_meta( $product->ID, 'spay_currency', true )
140
		);
141
142
		$data['id'] = $attrs['id'];
143
144
		if( ! wp_style_is( 'jetpack-simple-payments', 'enqueue' ) ) {
145
			wp_enqueue_style( 'jetpack-simple-payments' );
146
		}
147
148
		if ( ! $this->is_enabled_jetpack_simple_payments() ) {
149
			return $this->output_admin_warning( $data );
150
		}
151
152
		if ( ! wp_script_is( 'paypal-express-checkout', 'enqueued' ) ) {
153
			wp_enqueue_script( 'paypal-express-checkout' );
154
		}
155
156
		wp_add_inline_script( 'paypal-express-checkout', sprintf(
157
			"try{PaypalExpressCheckout.renderButton( '%d', '%d', '%s', '%d' );}catch(e){}",
158
			esc_js( $data['blog_id'] ),
159
			esc_js( $attrs['id'] ),
160
			esc_js( $data['dom_id'] ),
161
			esc_js( $data['multiple'] )
162
		) );
163
164
		return $this->output_shortcode( $data );
165
	}
166
167
	function output_admin_warning( $data ) {
168
		if ( ! current_user_can( 'manage_options' ) ) {
169
			return;
170
		}
171
		$css_prefix = self::$css_classname_prefix;
172
173
		$support_url = ( defined( 'IS_WPCOM' ) && IS_WPCOM )
174
			? 'https://support.wordpress.com/simple-payments/'
175
			: 'https://jetpack.com/support/simple-payment-button/';
176
177
		return sprintf( '
178
<div class="%1$s">
179
	<div class="%2$s">
180
		<div class="%3$s">
181
			<div class="%4$s" id="%5$s">
182
				<p>%6$s</p>
183
				<p>%7$s</p>
184
			</div>
185
		</div>
186
	</div>
187
</div>
188
',
189
			esc_attr( "{$data['class']} ${css_prefix}-wrapper" ),
190
			esc_attr( "${css_prefix}-product" ),
191
			esc_attr( "${css_prefix}-details" ),
192
			esc_attr( "${css_prefix}-purchase-message show error" ),
193
			esc_attr( "{$data['dom_id']}-message-container" ),
194
			sprintf(
195
				wp_kses(
196
					__( 'Your plan doesn\'t include Simple Payments. <a href="%s" rel="noopener noreferrer" target="_blank">Learn more and upgrade</a>.', 'jetpack' ),
197
					array( 'a' => array( 'href' => array(), 'rel' => array(), 'target' => array() ) )
198
				),
199
				esc_url( $support_url )
200
			),
201
			esc_html__( '(Only administrators will see this message.)', 'jetpack' )
202
		);
203
	}
204
205
	function output_shortcode( $data ) {
206
		$items = '';
207
		$css_prefix = self::$css_classname_prefix;
208
209
		if ( $data['multiple'] ) {
210
			$items = sprintf( '
211
				<div class="%1$s">
212
					<input class="%2$s" type="number" value="1" min="1" id="%3$s" />
213
				</div>
214
				',
215
				esc_attr( "${css_prefix}-items" ),
216
				esc_attr( "${css_prefix}-items-number" ),
217
				esc_attr( "{$data['dom_id']}_number" )
218
			);
219
		}
220
		$image = "";
221
		if( has_post_thumbnail( $data['id'] ) ) {
222
			$image = sprintf( '<div class="%1$s"><div class="%2$s">%3$s</div></div>',
223
				esc_attr( "${css_prefix}-product-image" ),
224
				esc_attr( "${css_prefix}-image" ),
225
				get_the_post_thumbnail( $data['id'], 'full' )
226
			);
227
		}
228
		return sprintf( '
229
<div class="%1$s">
230
	<div class="%2$s">
231
		%3$s
232
		<div class="%4$s">
233
			<div class="%5$s"><p>%6$s</p></div>
234
			<div class="%7$s"><p>%8$s</p></div>
235
			<div class="%9$s"><p>%10$s</p></div>
236
			<div class="%11$s" id="%12$s"></div>
237
			<div class="%13$s">
238
				%14$s
239
				<div class="%15$s" id="%16$s"></div>
240
			</div>
241
		</div>
242
	</div>
243
</div>
244
',
245
			esc_attr( "{$data['class']} ${css_prefix}-wrapper" ),
246
			esc_attr( "${css_prefix}-product" ),
247
			$image,
248
			esc_attr( "${css_prefix}-details" ),
249
			esc_attr( "${css_prefix}-title" ),
250
			$data['title'],
251
			esc_attr( "${css_prefix}-description" ),
252
			$data['description'],
253
			esc_attr( "${css_prefix}-price" ),
254
			esc_html( $data['price'] ),
255
			esc_attr( "${css_prefix}-purchase-message" ),
256
			esc_attr( "{$data['dom_id']}-message-container" ),
257
			esc_attr( "${css_prefix}-purchase-box" ),
258
			$items,
259
			esc_attr( "${css_prefix}-button" ),
260
			esc_attr( "{$data['dom_id']}_button" )
261
		);
262
	}
263
264
	/**
265
	 * Format a price with currency
266
	 *
267
	 * Uses currency-aware formatting to output a formatted price with a simple fallback.
268
	 *
269
	 * Largely inspired by WordPress.com's Store_Price::display_currency
270
	 *
271
	 * @param  string $price    Price.
272
	 * @param  string $currency Currency.
273
	 * @return string           Formatted price.
274
	 */
275
	private function format_price( $price, $currency ) {
276
		$currency_details = self::get_currency( $currency );
277
278
		if ( $currency_details ) {
279
			// Ensure USD displays as 1234.56 even in non-US locales.
280
			$amount = 'USD' === $currency
281
				? number_format( $price, $currency_details['decimal'], '.', ',' )
282
				: number_format_i18n( $price, $currency_details['decimal'] );
283
284
			return sprintf(
285
				$currency_details['format'],
286
				$currency_details['symbol'],
287
				$amount
288
			);
289
		}
290
291
		return "$price $currency";
292
	}
293
294
	/**
295
	 * Allows custom post types to be used by REST API.
296
	 * @param $post_types
297
	 * @see hook 'rest_api_allowed_post_types'
298
	 * @return array
299
	 */
300
	function allow_rest_api_types( $post_types ) {
301
		$post_types[] = self::$post_type_order;
302
		$post_types[] = self::$post_type_product;
303
		return $post_types;
304
	}
305
306
	function allow_sync_post_meta( $post_meta ) {
307
		return array_merge( $post_meta, array(
308
			'spay_paypal_id',
309
			'spay_status',
310
			'spay_product_id',
311
			'spay_quantity',
312
			'spay_price',
313
			'spay_customer_email',
314
			'spay_currency',
315
			'spay_cta',
316
			'spay_email',
317
			'spay_multiple',
318
			'spay_formatted_price',
319
		) );
320
	}
321
322
	/**
323
	 * Enable Simple payments custom meta values for access through the REST API.
324
	 * Field’s value will be exposed on a .meta key in the endpoint response,
325
	 * and WordPress will handle setting up the callbacks for reading and writing
326
	 * to that meta key.
327
	 *
328
	 * @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
329
	 */
330
	public function register_meta_fields_in_rest_api() {
331
		register_meta( 'post', 'spay_price', array(
332
			'description'       => esc_html__( 'Simple payments; price.', 'jetpack' ),
333
			'object_subtype'    => self::$post_type_product,
334
			'sanitize_callback' => array( $this, 'sanitize_price' ),
335
			'show_in_rest'      => true,
336
			'single'            => true,
337
			'type'              => 'number',
338
		) );
339
340
		register_meta( 'post', 'spay_currency', array(
341
			'description'       => esc_html__( 'Simple payments; currency code.', 'jetpack' ),
342
			'object_subtype'    => self::$post_type_product,
343
			'sanitize_callback' => array( $this, 'sanitize_currency' ),
344
			'show_in_rest'      => true,
345
			'single'            => true,
346
			'type'              => 'string',
347
		) );
348
349
		register_meta( 'post', 'spay_cta', array(
350
			'description'       => esc_html__( 'Simple payments; text with "Buy" or other CTA', 'jetpack' ),
351
			'object_subtype'    => self::$post_type_product,
352
			'sanitize_callback' => 'sanitize_text_field',
353
			'show_in_rest'      => true,
354
			'single'            => true,
355
			'type'              => 'string',
356
		) );
357
358
		register_meta( 'post', 'spay_multiple', array(
359
			'description'       => esc_html__( 'Simple payments; allow multiple items', 'jetpack' ),
360
			'object_subtype'    => self::$post_type_product,
361
			'sanitize_callback' => 'rest_sanitize_boolean',
362
			'show_in_rest'      => true,
363
			'single'            => true,
364
			'type'              => 'boolean',
365
		) );
366
367
		register_meta( 'post', 'spay_email', array(
368
			'description'       => esc_html__( 'Simple payments button; paypal email.', 'jetpack' ),
369
			'sanitize_callback' => 'sanitize_email',
370
			'show_in_rest'      => true,
371
			'single'            => true,
372
			'type'              => 'string',
373
		) );
374
375
		register_meta( 'post', 'spay_status', array(
376
			'description'       => esc_html__( 'Simple payments; status.', 'jetpack' ),
377
			'object_subtype'    => self::$post_type_product,
378
			'sanitize_callback' => 'sanitize_text_field',
379
			'show_in_rest'      => true,
380
			'single'            => true,
381
			'type'              => 'string',
382
		) );
383
	}
384
385
	/**
386
	 * Sanitize three-character ISO-4217 Simple payments currency
387
	 *
388
	 * List has to be in sync with list at the client side:
389
	 * @link https://github.com/Automattic/wp-calypso/blob/6d02ffe73cc073dea7270a22dc30881bff17d8fb/client/lib/simple-payments/constants.js
390
	 *
391
	 * Currencies should be supported by PayPal:
392
	 * @link https://developer.paypal.com/docs/integration/direct/rest/currency-codes/
393
	 */
394
	public static function sanitize_currency( $currency ) {
395
		$valid_currencies = array(
396
			'USD',
397
			'EUR',
398
			'AUD',
399
			'BRL',
400
			'CAD',
401
			'CZK',
402
			'DKK',
403
			'HKD',
404
			'HUF',
405
			'ILS',
406
			'JPY',
407
			'MYR',
408
			'MXN',
409
			'TWD',
410
			'NZD',
411
			'NOK',
412
			'PHP',
413
			'PLN',
414
			'GBP',
415
			'RUB',
416
			'SGD',
417
			'SEK',
418
			'CHF',
419
			'THB',
420
		);
421
422
		return in_array( $currency, $valid_currencies ) ? $currency : false;
423
	}
424
425
	/**
426
	 * Sanitize price:
427
	 *
428
	 * Positive integers and floats
429
	 * Supports two decimal places.
430
	 * Maximum length: 10.
431
	 *
432
	 * See `price` from PayPal docs:
433
	 * @link https://developer.paypal.com/docs/api/orders/v1/#definition-item
434
	 *
435
	 * @param      $value
436
	 * @return null|string
437
	 */
438
	public static function sanitize_price( $price ) {
439
		return preg_match( '/^[0-9]{0,10}(\.[0-9]{0,2})?$/', $price ) ? $price : false;
440
	}
441
442
	/**
443
	 * Sets up the custom post types for the module.
444
	 */
445
	function setup_cpts() {
446
447
		/*
448
		 * ORDER data structure. holds:
449
		 * title = customer_name | 4xproduct_name
450
		 * excerpt = customer_name + customer contact info + customer notes from paypal form
451
		 * metadata:
452
		 * spay_paypal_id - paypal id of transaction
453
		 * spay_status
454
		 * spay_product_id - post_id of bought product
455
		 * spay_quantity - quantity of product
456
		 * spay_price - item price at the time of purchase
457
		 * spay_customer_email - customer email
458
		 * ... (WIP)
459
		 */
460
		$order_capabilities = array(
461
			'edit_post'             => 'edit_posts',
462
			'read_post'             => 'read_private_posts',
463
			'delete_post'           => 'delete_posts',
464
			'edit_posts'            => 'edit_posts',
465
			'edit_others_posts'     => 'edit_others_posts',
466
			'publish_posts'         => 'publish_posts',
467
			'read_private_posts'    => 'read_private_posts',
468
		);
469
		$order_args = array(
470
			'label'                 => esc_html_x( 'Order', 'noun: a quantity of goods or items purchased or sold', 'jetpack' ),
471
			'description'           => esc_html__( 'Simple Payments orders', 'jetpack' ),
472
			'supports'              => array( 'custom-fields', 'excerpt' ),
473
			'hierarchical'          => false,
474
			'public'                => false,
475
			'show_ui'               => false,
476
			'show_in_menu'          => false,
477
			'show_in_admin_bar'     => false,
478
			'show_in_nav_menus'     => false,
479
			'can_export'            => true,
480
			'has_archive'           => false,
481
			'exclude_from_search'   => true,
482
			'publicly_queryable'    => false,
483
			'rewrite'               => false,
484
			'capabilities'          => $order_capabilities,
485
			'show_in_rest'          => true,
486
		);
487
		register_post_type( self::$post_type_order, $order_args );
488
489
		/*
490
		 * PRODUCT data structure. Holds:
491
		 * title - title
492
		 * content - description
493
		 * thumbnail - image
494
		 * metadata:
495
		 * spay_price - price
496
		 * spay_formatted_price
497
		 * spay_currency - currency code
498
		 * spay_cta - text with "Buy" or other CTA
499
		 * spay_email - paypal email
500
		 * spay_multiple - allow for multiple items
501
		 * spay_status - status. { enabled | disabled }
502
		 */
503
		$product_capabilities = array(
504
			'edit_post'             => 'edit_posts',
505
			'read_post'             => 'read_private_posts',
506
			'delete_post'           => 'delete_posts',
507
			'edit_posts'            => 'publish_posts',
508
			'edit_others_posts'     => 'edit_others_posts',
509
			'publish_posts'         => 'publish_posts',
510
			'read_private_posts'    => 'read_private_posts',
511
		);
512
		$product_args = array(
513
			'label'                 => esc_html__( 'Product', 'jetpack' ),
514
			'description'           => esc_html__( 'Simple Payments products', 'jetpack' ),
515
			'supports'              => array( 'title', 'editor','thumbnail', 'custom-fields', 'author' ),
516
			'hierarchical'          => false,
517
			'public'                => false,
518
			'show_ui'               => false,
519
			'show_in_menu'          => false,
520
			'show_in_admin_bar'     => false,
521
			'show_in_nav_menus'     => false,
522
			'can_export'            => true,
523
			'has_archive'           => false,
524
			'exclude_from_search'   => true,
525
			'publicly_queryable'    => false,
526
			'rewrite'               => false,
527
			'capabilities'          => $product_capabilities,
528
			'show_in_rest'          => true,
529
		);
530
		register_post_type( self::$post_type_product, $product_args );
531
	}
532
533
	/**
534
	 * Format a price for display
535
	 *
536
	 * Largely taken from WordPress.com Store_Price class
537
	 *
538
	 * The currency array will have the shape:
539
	 *   format  => string sprintf format with placeholders `%1$s`: Symbol `%2$s`: Price.
540
	 *   symbol  => string Symbol string
541
	 *   desc    => string Text description of currency
542
	 *   decimal => int    Number of decimal places
543
	 *
544
	 * @param  string $the_currency The desired currency, e.g. 'USD'.
545
	 * @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...
546
	 */
547
	private static function get_currency( $the_currency ) {
548
		$currencies = array(
549
			'USD' => array(
550
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
551
				'symbol'  => '$',
552
				'decimal' => 2,
553
			),
554
			'GBP' => array(
555
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
556
				'symbol'  => '&#163;',
557
				'decimal' => 2,
558
			),
559
			'JPY' => array(
560
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
561
				'symbol'  => '&#165;',
562
				'decimal' => 0,
563
			),
564
			'BRL' => array(
565
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
566
				'symbol'  => 'R$',
567
				'decimal' => 2,
568
			),
569
			'EUR' => array(
570
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
571
				'symbol'  => '&#8364;',
572
				'decimal' => 2,
573
			),
574
			'NZD' => array(
575
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
576
				'symbol'  => 'NZ$',
577
				'decimal' => 2,
578
			),
579
			'AUD' => array(
580
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
581
				'symbol'  => 'A$',
582
				'decimal' => 2,
583
			),
584
			'CAD' => array(
585
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
586
				'symbol'  => 'C$',
587
				'decimal' => 2,
588
			),
589
			'ILS' => array(
590
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
591
				'symbol'  => '₪',
592
				'decimal' => 2,
593
			),
594
			'RUB' => array(
595
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
596
				'symbol'  => '₽',
597
				'decimal' => 2,
598
			),
599
			'MXN' => array(
600
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
601
				'symbol'  => 'MX$',
602
				'decimal' => 2,
603
			),
604
			'MYR' => array(
605
				'format'  => '%2$s%1$s', // 1: Symbol 2: currency value
606
				'symbol'  => 'RM',
607
				'decimal' => 2,
608
			),
609
			'SEK' => array(
610
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
611
				'symbol'  => 'Skr',
612
				'decimal' => 2,
613
			),
614
			'HUF' => array(
615
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
616
				'symbol'  => 'Ft',
617
				'decimal' => 0, // Decimals are supported by Stripe but not by PayPal.
618
			),
619
			'CHF' => array(
620
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
621
				'symbol'  => 'CHF',
622
				'decimal' => 2,
623
			),
624
			'CZK' => array(
625
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
626
				'symbol'  => 'Kč',
627
				'decimal' => 2,
628
			),
629
			'DKK' => array(
630
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
631
				'symbol'  => 'Dkr',
632
				'decimal' => 2,
633
			),
634
			'HKD' => array(
635
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
636
				'symbol'  => 'HK$',
637
				'decimal' => 2,
638
			),
639
			'NOK' => array(
640
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
641
				'symbol'  => 'Kr',
642
				'decimal' => 2,
643
			),
644
			'PHP' => array(
645
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
646
				'symbol'  => '₱',
647
				'decimal' => 2,
648
			),
649
			'PLN' => array(
650
				'format'  => '%2$s %1$s', // 1: Symbol 2: currency value
651
				'symbol'  => 'PLN',
652
				'decimal' => 2,
653
			),
654
			'SGD' => array(
655
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
656
				'symbol'  => 'S$',
657
				'decimal' => 2,
658
			),
659
			'TWD' => array(
660
				'format'  => '%1$s%2$s', // 1: Symbol 2: currency value
661
				'symbol'  => 'NT$',
662
				'decimal' => 0, // Decimals are supported by Stripe but not by PayPal.
663
			),
664
			'THB' => array(
665
				'format'  => '%2$s%1$s', // 1: Symbol 2: currency value
666
				'symbol'  => '฿',
667
				'decimal' => 2,
668
			),
669
		);
670
671
		if ( isset( $currencies[ $the_currency ] ) ) {
672
			return $currencies[ $the_currency ];
673
		}
674
		return null;
675
	}
676
}
677
Jetpack_Simple_Payments::getInstance();
678