Completed
Push — master ( 36e98a...2d3538 )
by Bernhard
07:39
created

Jetpack_Simple_Payments   C

Complexity

Total Complexity 53

Size/Duplication

Total Lines 680
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 680
rs 6.88
c 0
b 0
f 0
wmc 53
lcom 2
cbo 3

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A getInstance() 0 7 2
A register_scripts_and_styles() 0 10 1
A register_init_hooks() 0 5 1
A register_shortcode() 0 3 1
A init_hook_action() 0 11 2
A register_gutenberg_block() 0 11 3
A remove_auto_paragraph_from_product_description() 0 7 2
A get_blog_id() 0 7 3
B is_enabled_jetpack_simple_payments() 0 21 6
B parse_shortcode() 0 52 10
A output_admin_warning() 0 37 4
B output_shortcode() 0 58 3
A format_price() 0 24 4
A allow_rest_api_types() 0 5 1
A allow_sync_post_meta() 0 15 1
A register_meta_fields_in_rest_api() 0 54 1
A sanitize_currency() 0 30 2
A sanitize_price() 0 3 2
B setup_cpts() 0 87 1
B get_currency() 0 129 2

How to fix   Complexity   

Complex Class

Complex classes like Jetpack_Simple_Payments often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Jetpack_Simple_Payments, and based on these observations, apply Extract Interface, too.

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