Completed
Push — master ( e2489a...f93ff4 )
by Kirk
52:16 queued 44:06
created

Jetpack_Simple_Payments::parse_shortcode()   B

Complexity

Conditions 9
Paths 6

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

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