Completed
Push — fix/youtube-shortcode-amp-comp... ( 0aea78...87f47e )
by
unknown
08:56
created

Jetpack_Simple_Payments::output_purchase_box()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

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