Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/simple-p...
File: simple-payments.php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
[0] Fix | Delete
/**
[1] Fix | Delete
* Simple Payments lets users embed a PayPal button fully integrated with wpcom to sell products on the site.
[2] Fix | Delete
* This is not a proper module yet, because not all the pieces are in place. Until everything is shipped, it can be turned
[3] Fix | Delete
* into module that can be enabled/disabled.
[4] Fix | Delete
*
[5] Fix | Delete
* @package automattic/jetpack
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
use Automattic\Jetpack\Paypal_Payments\Simple_Payments as PayPal_Simple_Payments;
[9] Fix | Delete
[10] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[11] Fix | Delete
exit( 0 );
[12] Fix | Delete
}
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Jetpack_Simple_Payments
[16] Fix | Delete
*/
[17] Fix | Delete
class Jetpack_Simple_Payments {
[18] Fix | Delete
// These have to be under 20 chars because that is CPT limit.
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Post type order.
[22] Fix | Delete
*
[23] Fix | Delete
* @var string
[24] Fix | Delete
*/
[25] Fix | Delete
public static $post_type_order = 'jp_pay_order';
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Post type product.
[29] Fix | Delete
*
[30] Fix | Delete
* @var string
[31] Fix | Delete
*/
[32] Fix | Delete
public static $post_type_product = 'jp_pay_product';
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Define simple payment shortcode.
[36] Fix | Delete
*
[37] Fix | Delete
* @var string
[38] Fix | Delete
*/
[39] Fix | Delete
public static $shortcode = 'simple-payment';
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Define simple payment CSS prefix.
[43] Fix | Delete
*
[44] Fix | Delete
* @var string
[45] Fix | Delete
*/
[46] Fix | Delete
public static $css_classname_prefix = 'jetpack-simple-payments';
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Which plan the user is on.
[50] Fix | Delete
*
[51] Fix | Delete
* @var string value_bundle or jetpack_premium
[52] Fix | Delete
*/
[53] Fix | Delete
public static $required_plan;
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Instance of the class.
[57] Fix | Delete
*
[58] Fix | Delete
* @var Jetpack_Simple_Payments
[59] Fix | Delete
*/
[60] Fix | Delete
private static $instance;
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Construction function.
[64] Fix | Delete
*/
[65] Fix | Delete
private function __construct() {}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Original singleton.
[69] Fix | Delete
*
[70] Fix | Delete
* @todo Remove this when nothing calles getInstance anymore.
[71] Fix | Delete
*/
[72] Fix | Delete
public static function getInstance() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
[73] Fix | Delete
return self::get_instance();
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Create instance of class.
[78] Fix | Delete
*/
[79] Fix | Delete
public static function get_instance() {
[80] Fix | Delete
if ( ! self::$instance ) {
[81] Fix | Delete
self::$instance = new self();
[82] Fix | Delete
self::$instance->init_hook_action();
[83] Fix | Delete
self::$required_plan = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? 'value_bundle' : 'jetpack_premium';
[84] Fix | Delete
}
[85] Fix | Delete
return self::$instance;
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* Actions that are run on init.
[90] Fix | Delete
*/
[91] Fix | Delete
public function init_hook_action() {
[92] Fix | Delete
return PayPal_Simple_Payments::get_instance()->init_hook_action();
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Enqueue the static assets needed in the frontend.
[97] Fix | Delete
*/
[98] Fix | Delete
public function enqueue_frontend_assets() {
[99] Fix | Delete
return PayPal_Simple_Payments::get_instance()->enqueue_frontend_assets();
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Add an inline script for setting up the PayPal checkout button.
[104] Fix | Delete
*
[105] Fix | Delete
* @param int $id Product ID.
[106] Fix | Delete
* @param int $dom_id ID of the DOM element with the purchase message.
[107] Fix | Delete
* @param boolean $is_multiple Whether multiple items of the same product can be purchased.
[108] Fix | Delete
*/
[109] Fix | Delete
public function setup_paypal_checkout_button( $id, $dom_id, $is_multiple ) {
[110] Fix | Delete
return PayPal_Simple_Payments::get_instance()->setup_paypal_checkout_button( $id, $dom_id, $is_multiple );
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Remove auto paragraph from product description.
[115] Fix | Delete
*
[116] Fix | Delete
* @param string $content - the content of the post.
[117] Fix | Delete
*/
[118] Fix | Delete
public function remove_auto_paragraph_from_product_description( $content ) {
[119] Fix | Delete
return PayPal_Simple_Payments::get_instance()->remove_auto_paragraph_from_product_description( $content );
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/** Return the blog ID */
[123] Fix | Delete
public function get_blog_id() {
[124] Fix | Delete
return PayPal_Simple_Payments::get_instance()->get_blog_id();
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Used to check whether Simple Payments are enabled for given site.
[129] Fix | Delete
*
[130] Fix | Delete
* @return bool True if Simple Payments are enabled, false otherwise.
[131] Fix | Delete
*/
[132] Fix | Delete
public function is_enabled_jetpack_simple_payments() {
[133] Fix | Delete
return PayPal_Simple_Payments::is_enabled_jetpack_simple_payments();
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Creates the content from a shortcode
[138] Fix | Delete
*
[139] Fix | Delete
* @param array $attrs Shortcode attributes.
[140] Fix | Delete
* @param mixed $content unused.
[141] Fix | Delete
*
[142] Fix | Delete
* @return string|void
[143] Fix | Delete
*/
[144] Fix | Delete
public function parse_shortcode( $attrs, $content = false ) {
[145] Fix | Delete
return PayPal_Simple_Payments::get_instance()->parse_shortcode( $attrs, $content );
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Output an admin warning if user can't use Pay with PayPal.
[150] Fix | Delete
*
[151] Fix | Delete
* @param array $data unused.
[152] Fix | Delete
*/
[153] Fix | Delete
public function output_admin_warning( $data ) {
[154] Fix | Delete
return PayPal_Simple_Payments::get_instance()->output_admin_warning( $data );
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Get the HTML output to use as PayPal purchase box.
[159] Fix | Delete
*
[160] Fix | Delete
* @param string $dom_id ID of the DOM element with the purchase message.
[161] Fix | Delete
* @param boolean $is_multiple Whether multiple items of the same product can be purchased.
[162] Fix | Delete
*
[163] Fix | Delete
* @return string
[164] Fix | Delete
*/
[165] Fix | Delete
public function output_purchase_box( $dom_id, $is_multiple ) {
[166] Fix | Delete
return PayPal_Simple_Payments::get_instance()->output_purchase_box( $dom_id, $is_multiple );
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Get the HTML output to replace the `simple-payments` shortcode.
[171] Fix | Delete
*
[172] Fix | Delete
* @param array $data Product data.
[173] Fix | Delete
* @return string
[174] Fix | Delete
*/
[175] Fix | Delete
public function output_shortcode( $data ) {
[176] Fix | Delete
return PayPal_Simple_Payments::get_instance()->output_shortcode( $data );
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Allows custom post types to be used by REST API.
[181] Fix | Delete
*
[182] Fix | Delete
* @param array $post_types - the allows post types.
[183] Fix | Delete
* @see hook 'rest_api_allowed_post_types'
[184] Fix | Delete
* @return array
[185] Fix | Delete
*/
[186] Fix | Delete
public function allow_rest_api_types( $post_types ) {
[187] Fix | Delete
return PayPal_Simple_Payments::get_instance()->allow_rest_api_types( $post_types );
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
/**
[191] Fix | Delete
* Merge $post_meta with additional meta information.
[192] Fix | Delete
*
[193] Fix | Delete
* @param array $post_meta - the post's meta information.
[194] Fix | Delete
*/
[195] Fix | Delete
public function allow_sync_post_meta( $post_meta ) {
[196] Fix | Delete
return PayPal_Simple_Payments::get_instance()->allow_sync_post_meta( $post_meta );
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Enable Simple payments custom meta values for access through the REST API.
[201] Fix | Delete
* Field's value will be exposed on a .meta key in the endpoint response,
[202] Fix | Delete
* and WordPress will handle setting up the callbacks for reading and writing
[203] Fix | Delete
* to that meta key.
[204] Fix | Delete
*
[205] Fix | Delete
* @link https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/
[206] Fix | Delete
*/
[207] Fix | Delete
public function register_meta_fields_in_rest_api() {
[208] Fix | Delete
return PayPal_Simple_Payments::get_instance()->register_meta_fields_in_rest_api();
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Sanitize three-character ISO-4217 Simple payments currency
[213] Fix | Delete
*
[214] Fix | Delete
* List has to be in sync with list at the block's client side and widget's backend side:
[215] Fix | Delete
*
[216] Fix | Delete
* @param array $currency - list of currencies.
[217] Fix | Delete
* @link https://github.com/Automattic/jetpack/blob/31efa189ad223c0eb7ad085ac0650a23facf9ef5/extensions/blocks/simple-payments/constants.js#L9-L39
[218] Fix | Delete
* @link https://github.com/Automattic/jetpack/blob/31efa189ad223c0eb7ad085ac0650a23facf9ef5/modules/widgets/simple-payments.php#L19-L44
[219] Fix | Delete
*
[220] Fix | Delete
* Currencies should be supported by PayPal:
[221] Fix | Delete
* @link https://developer.paypal.com/docs/api/reference/currency-codes/
[222] Fix | Delete
*
[223] Fix | Delete
* Indian Rupee (INR) not supported because at the time of the creation of this file
[224] Fix | Delete
* because it's limited to in-country PayPal India accounts only.
[225] Fix | Delete
* Discussion: https://github.com/Automattic/wp-calypso/pull/28236
[226] Fix | Delete
*/
[227] Fix | Delete
public static function sanitize_currency( $currency ) {
[228] Fix | Delete
return PayPal_Simple_Payments::sanitize_currency( $currency );
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
/**
[232] Fix | Delete
* Sanitize price:
[233] Fix | Delete
*
[234] Fix | Delete
* Positive integers and floats
[235] Fix | Delete
* Supports two decimal places.
[236] Fix | Delete
* Maximum length: 10.
[237] Fix | Delete
*
[238] Fix | Delete
* See `price` from PayPal docs:
[239] Fix | Delete
*
[240] Fix | Delete
* @link https://developer.paypal.com/docs/api/orders/v1/#definition-item
[241] Fix | Delete
*
[242] Fix | Delete
* @param string $price - the price we want to sanitize.
[243] Fix | Delete
* @return null|string
[244] Fix | Delete
*/
[245] Fix | Delete
public static function sanitize_price( $price ) {
[246] Fix | Delete
return PayPal_Simple_Payments::sanitize_price( $price );
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Sets up the custom post types for the module.
[251] Fix | Delete
*/
[252] Fix | Delete
public function setup_cpts() {
[253] Fix | Delete
return PayPal_Simple_Payments::get_instance()->setup_cpts();
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Validate the block attributes
[258] Fix | Delete
*
[259] Fix | Delete
* @param array $attrs The block attributes, expected to contain:
[260] Fix | Delete
* * email - an email address.
[261] Fix | Delete
* * price - a float between 0.01 and 9999999999.99.
[262] Fix | Delete
* * productId - the ID of the product being paid for.
[263] Fix | Delete
*
[264] Fix | Delete
* @return bool
[265] Fix | Delete
*/
[266] Fix | Delete
public function is_valid( $attrs ) {
[267] Fix | Delete
return PayPal_Simple_Payments::get_instance()->is_valid( $attrs );
[268] Fix | Delete
}
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
PayPal_Simple_Payments::get_instance();
[272] Fix | Delete
[273] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function