@@ -6,14 +6,14 @@ discard block |
||
| 6 | 6 | * @version 4.3.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Output the email header. |
| 15 | 15 | */ |
| 16 | -do_action( 'woocommerce_email_header', $email_heading, $email ); ?> |
|
| 16 | +do_action('woocommerce_email_header', $email_heading, $email); ?> |
|
| 17 | 17 | |
| 18 | 18 | <p> |
| 19 | 19 | <?php |
@@ -27,31 +27,31 @@ discard block |
||
| 27 | 27 | ), |
| 28 | 28 | $order->get_order_number(), |
| 29 | 29 | $order->get_formatted_billing_full_name(), |
| 30 | - wcs_get_human_time_diff( $retry->get_time() ) |
|
| 30 | + wcs_get_human_time_diff($retry->get_time()) |
|
| 31 | 31 | ) |
| 32 | 32 | ); |
| 33 | 33 | ?> |
| 34 | 34 | </p> |
| 35 | -<p><?php esc_html_e( 'The renewal order is as follows:', 'woocommerce-gateway-stripe' ); ?></p> |
|
| 35 | +<p><?php esc_html_e('The renewal order is as follows:', 'woocommerce-gateway-stripe'); ?></p> |
|
| 36 | 36 | |
| 37 | 37 | <?php |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Shows the order details table. |
| 41 | 41 | */ |
| 42 | -do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email ); |
|
| 42 | +do_action('woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email); |
|
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * Shows order meta data. |
| 46 | 46 | */ |
| 47 | -do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email ); |
|
| 47 | +do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email); |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Shows customer details, and email address. |
| 51 | 51 | */ |
| 52 | -do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email ); |
|
| 52 | +do_action('woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email); |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Output the email footer. |
| 56 | 56 | */ |
| 57 | -do_action( 'woocommerce_email_footer', $email ); |
|
| 57 | +do_action('woocommerce_email_footer', $email); |
|
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @version 4.3.0 |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if ( ! defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -21,29 +21,29 @@ discard block |
||
| 21 | 21 | ), |
| 22 | 22 | $order->get_order_number(), |
| 23 | 23 | $order->get_formatted_billing_full_name(), |
| 24 | - wcs_get_human_time_diff( $retry->get_time() ) |
|
| 24 | + wcs_get_human_time_diff($retry->get_time()) |
|
| 25 | 25 | ) . "\n\n"; |
| 26 | -printf( __( 'The renewal order is as follows:', 'woocommerce-gateway-stripe' ) ) . "\n\n"; |
|
| 26 | +printf(__('The renewal order is as follows:', 'woocommerce-gateway-stripe')) . "\n\n"; |
|
| 27 | 27 | |
| 28 | 28 | echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Shows the order details table. |
| 32 | 32 | */ |
| 33 | -do_action( 'woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email ); |
|
| 33 | +do_action('woocommerce_email_order_details', $order, $sent_to_admin, $plain_text, $email); |
|
| 34 | 34 | |
| 35 | 35 | echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Shows order meta data. |
| 39 | 39 | */ |
| 40 | -do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email ); |
|
| 40 | +do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email); |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Shows customer details, and email address. |
| 44 | 44 | */ |
| 45 | -do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email ); |
|
| 45 | +do_action('woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email); |
|
| 46 | 46 | |
| 47 | 47 | echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n"; |
| 48 | 48 | |
| 49 | -echo apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) ); |
|
| 49 | +echo apply_filters('woocommerce_email_footer_text', get_option('woocommerce_email_footer_text')); |
|
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @extends WC_Email_Failed_Order |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -26,17 +26,17 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function __construct() { |
| 28 | 28 | $this->id = 'failed_authentication_requested'; |
| 29 | - $this->title = __( 'Payment Authentication Requested Email', 'woocommerce-gateway-stripe' ); |
|
| 30 | - $this->description = __( 'Payment authentication requested emails are sent to chosen recipient(s) when an attempt to automatically process a subscription renewal payment fails because the transaction requires an SCA verification, the customer is requested to authenticate the payment, and a retry rule has been applied to notify the customer again within a certain time period.', 'woocommerce-gateway-stripe' ); |
|
| 29 | + $this->title = __('Payment Authentication Requested Email', 'woocommerce-gateway-stripe'); |
|
| 30 | + $this->description = __('Payment authentication requested emails are sent to chosen recipient(s) when an attempt to automatically process a subscription renewal payment fails because the transaction requires an SCA verification, the customer is requested to authenticate the payment, and a retry rule has been applied to notify the customer again within a certain time period.', 'woocommerce-gateway-stripe'); |
|
| 31 | 31 | |
| 32 | - $this->heading = __( 'Automatic renewal payment failed due to authentication required', 'woocommerce-gateway-stripe' ); |
|
| 33 | - $this->subject = __( '[{site_title}] Automatic payment failed for {order_number}. Customer asked to authenticate payment and will be notified again {retry_time}', 'woocommerce-gateway-stripe' ); |
|
| 32 | + $this->heading = __('Automatic renewal payment failed due to authentication required', 'woocommerce-gateway-stripe'); |
|
| 33 | + $this->subject = __('[{site_title}] Automatic payment failed for {order_number}. Customer asked to authenticate payment and will be notified again {retry_time}', 'woocommerce-gateway-stripe'); |
|
| 34 | 34 | |
| 35 | 35 | $this->template_html = 'emails/failed-renewal-authentication-requested.php'; |
| 36 | 36 | $this->template_plain = 'emails/plain/failed-renewal-authentication-requested.php'; |
| 37 | - $this->template_base = plugin_dir_path( WC_STRIPE_MAIN_FILE ) . 'templates/'; |
|
| 37 | + $this->template_base = plugin_dir_path(WC_STRIPE_MAIN_FILE) . 'templates/'; |
|
| 38 | 38 | |
| 39 | - $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) ); |
|
| 39 | + $this->recipient = $this->get_option('recipient', get_option('admin_email')); |
|
| 40 | 40 | |
| 41 | 41 | // We want all the parent's methods, with none of its properties, so call its parent's constructor, rather than my parent constructor. |
| 42 | 42 | WC_Email::__construct(); |
@@ -66,26 +66,26 @@ discard block |
||
| 66 | 66 | * @param int $order_id The order ID. |
| 67 | 67 | * @param WC_Order|null $order Order object. |
| 68 | 68 | */ |
| 69 | - public function trigger( $order_id, $order = null ) { |
|
| 69 | + public function trigger($order_id, $order = null) { |
|
| 70 | 70 | $this->object = $order; |
| 71 | 71 | |
| 72 | 72 | $this->find['retry-time'] = '{retry_time}'; |
| 73 | - if ( class_exists( 'WCS_Retry_Manager' ) && function_exists( 'wcs_get_human_time_diff' ) ) { |
|
| 74 | - $this->retry = WCS_Retry_Manager::store()->get_last_retry_for_order( wcs_get_objects_property( $order, 'id' ) ); |
|
| 75 | - $this->replace['retry-time'] = wcs_get_human_time_diff( $this->retry->get_time() ); |
|
| 73 | + if (class_exists('WCS_Retry_Manager') && function_exists('wcs_get_human_time_diff')) { |
|
| 74 | + $this->retry = WCS_Retry_Manager::store()->get_last_retry_for_order(wcs_get_objects_property($order, 'id')); |
|
| 75 | + $this->replace['retry-time'] = wcs_get_human_time_diff($this->retry->get_time()); |
|
| 76 | 76 | } else { |
| 77 | - WC_Stripe_Logger::log( 'WCS_Retry_Manager class or does not exist. Not able to send admnin email about customer notification for authentication required for renewal payment.' ); |
|
| 77 | + WC_Stripe_Logger::log('WCS_Retry_Manager class or does not exist. Not able to send admnin email about customer notification for authentication required for renewal payment.'); |
|
| 78 | 78 | return; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $this->find['order-number'] = '{order_number}'; |
| 82 | 82 | $this->replace['order-number'] = $this->object->get_order_number(); |
| 83 | 83 | |
| 84 | - if ( ! $this->is_enabled() || ! $this->get_recipient() ) { |
|
| 84 | + if ( ! $this->is_enabled() || ! $this->get_recipient()) { |
|
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); |
|
| 88 | + $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments()); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly. |
| 4 | 4 | } |
| 5 | 5 | |
@@ -14,20 +14,20 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @param WC_Email[] $email_classes All existing instances of WooCommerce emails. |
| 16 | 16 | */ |
| 17 | - public function __construct( $email_classes = array() ) { |
|
| 17 | + public function __construct($email_classes = array()) { |
|
| 18 | 18 | $this->id = 'failed_renewal_authentication'; |
| 19 | - $this->title = __( 'Failed Subscription Renewal SCA Authentication', 'woocommerce-gateway-stripe' ); |
|
| 20 | - $this->description = __( 'Sent to a customer when a renewal fails because the transaction requires an SCA verification. The email contains renewal order information and payment links.', 'woocommerce-gateway-stripe' ); |
|
| 19 | + $this->title = __('Failed Subscription Renewal SCA Authentication', 'woocommerce-gateway-stripe'); |
|
| 20 | + $this->description = __('Sent to a customer when a renewal fails because the transaction requires an SCA verification. The email contains renewal order information and payment links.', 'woocommerce-gateway-stripe'); |
|
| 21 | 21 | $this->customer_email = true; |
| 22 | 22 | |
| 23 | 23 | $this->template_html = 'emails/failed-renewal-authentication.php'; |
| 24 | 24 | $this->template_plain = 'emails/plain/failed-renewal-authentication.php'; |
| 25 | - $this->template_base = plugin_dir_path( WC_STRIPE_MAIN_FILE ) . 'templates/'; |
|
| 25 | + $this->template_base = plugin_dir_path(WC_STRIPE_MAIN_FILE) . 'templates/'; |
|
| 26 | 26 | |
| 27 | 27 | // Triggers the email at the correct hook. |
| 28 | - add_action( 'wc_gateway_stripe_process_payment_authentication_required', array( $this, 'trigger' ) ); |
|
| 28 | + add_action('wc_gateway_stripe_process_payment_authentication_required', array($this, 'trigger')); |
|
| 29 | 29 | |
| 30 | - if ( isset( $email_classes['WCS_Email_Customer_Renewal_Invoice'] ) ) { |
|
| 30 | + if (isset($email_classes['WCS_Email_Customer_Renewal_Invoice'])) { |
|
| 31 | 31 | $this->original_email = $email_classes['WCS_Email_Customer_Renewal_Invoice']; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -40,21 +40,21 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @param WC_Order $order The order that is being paid. |
| 42 | 42 | */ |
| 43 | - public function trigger( $order ) { |
|
| 44 | - if ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order->get_id() ) || wcs_is_subscription( $order->get_id() ) || wcs_order_contains_renewal( $order->get_id() ) ) ) { |
|
| 45 | - parent::trigger( $order ); |
|
| 43 | + public function trigger($order) { |
|
| 44 | + if (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order->get_id()) || wcs_is_subscription($order->get_id()) || wcs_order_contains_renewal($order->get_id()))) { |
|
| 45 | + parent::trigger($order); |
|
| 46 | 46 | |
| 47 | 47 | // Prevent the renewal email from WooCommerce Subscriptions from being sent. |
| 48 | - if ( isset( $this->original_email ) ) { |
|
| 49 | - remove_action( 'woocommerce_generated_manual_renewal_order_renewal_notification', array( $this->original_email, 'trigger' ) ); |
|
| 50 | - remove_action( 'woocommerce_order_status_failed_renewal_notification', array( $this->original_email, 'trigger' ) ); |
|
| 48 | + if (isset($this->original_email)) { |
|
| 49 | + remove_action('woocommerce_generated_manual_renewal_order_renewal_notification', array($this->original_email, 'trigger')); |
|
| 50 | + remove_action('woocommerce_order_status_failed_renewal_notification', array($this->original_email, 'trigger')); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Prevent the retry email from WooCommerce Subscriptions from being sent. |
| 54 | - add_filter( 'wcs_get_retry_rule_raw', array( $this, 'prevent_retry_notification_email' ), 100, 3 ); |
|
| 54 | + add_filter('wcs_get_retry_rule_raw', array($this, 'prevent_retry_notification_email'), 100, 3); |
|
| 55 | 55 | |
| 56 | 56 | // Send email to store owner indicating communication is happening with the customer to request authentication. |
| 57 | - add_filter( 'wcs_get_retry_rule_raw', array( $this, 'set_store_owner_custom_email' ), 100, 3 ); |
|
| 57 | + add_filter('wcs_get_retry_rule_raw', array($this, 'set_store_owner_custom_email'), 100, 3); |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return string |
| 65 | 65 | */ |
| 66 | 66 | public function get_default_subject() { |
| 67 | - return __( 'Payment authorization needed for renewal of {site_title} order {order_number}', 'woocommerce-gateway-stripe' ); |
|
| 67 | + return __('Payment authorization needed for renewal of {site_title} order {order_number}', 'woocommerce-gateway-stripe'); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @return string |
| 74 | 74 | */ |
| 75 | 75 | public function get_default_heading() { |
| 76 | - return __( 'Payment authorization needed for renewal of order {order_number}', 'woocommerce-gateway-stripe' ); |
|
| 76 | + return __('Payment authorization needed for renewal of order {order_number}', 'woocommerce-gateway-stripe'); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | * @param int $order_id The ID of the order that needs payment. |
| 85 | 85 | * @return array |
| 86 | 86 | */ |
| 87 | - public function prevent_retry_notification_email( $rule_array, $retry_number, $order_id ) { |
|
| 88 | - if ( wcs_get_objects_property( $this->object, 'id' ) === $order_id ) { |
|
| 87 | + public function prevent_retry_notification_email($rule_array, $retry_number, $order_id) { |
|
| 88 | + if (wcs_get_objects_property($this->object, 'id') === $order_id) { |
|
| 89 | 89 | $rule_array['email_template_customer'] = ''; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | * @param int $order_id The ID of the order that needs payment. |
| 101 | 101 | * @return array |
| 102 | 102 | */ |
| 103 | - public function set_store_owner_custom_email( $rule_array, $retry_number, $order_id ) { |
|
| 103 | + public function set_store_owner_custom_email($rule_array, $retry_number, $order_id) { |
|
| 104 | 104 | if ( |
| 105 | - wcs_get_objects_property( $this->object, 'id' ) === $order_id && |
|
| 105 | + wcs_get_objects_property($this->object, 'id') === $order_id && |
|
| 106 | 106 | '' !== $rule_array['email_template_admin'] // Only send our email if a retry admin email was already going to be sent. |
| 107 | 107 | ) { |
| 108 | 108 | $rule_array['email_template_admin'] = 'WC_Stripe_Email_Failed_Authentication_Retry'; |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * @since 4.0.6 |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 8 | +if ( ! defined('ABSPATH')) { |
|
| 9 | 9 | exit; |
| 10 | 10 | } |
| 11 | 11 | |
@@ -60,23 +60,23 @@ discard block |
||
| 60 | 60 | public $apple_pay_verify_notice; |
| 61 | 61 | |
| 62 | 62 | public function __construct() { |
| 63 | - add_action( 'woocommerce_stripe_updated', array( $this, 'update_verification_file' ) ); |
|
| 63 | + add_action('woocommerce_stripe_updated', array($this, 'update_verification_file')); |
|
| 64 | 64 | |
| 65 | - $this->stripe_settings = get_option( 'woocommerce_stripe_settings', array() ); |
|
| 66 | - $this->stripe_enabled = $this->get_option( 'enabled' ); |
|
| 67 | - $this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' ); |
|
| 68 | - $this->apple_pay_domain_set = 'yes' === $this->get_option( 'apple_pay_domain_set', 'no' ); |
|
| 65 | + $this->stripe_settings = get_option('woocommerce_stripe_settings', array()); |
|
| 66 | + $this->stripe_enabled = $this->get_option('enabled'); |
|
| 67 | + $this->payment_request = 'yes' === $this->get_option('payment_request', 'yes'); |
|
| 68 | + $this->apple_pay_domain_set = 'yes' === $this->get_option('apple_pay_domain_set', 'no'); |
|
| 69 | 69 | $this->apple_pay_verify_notice = ''; |
| 70 | - $this->testmode = 'yes' === $this->get_option( 'testmode', 'no' ); |
|
| 71 | - $this->secret_key = $this->testmode ? $this->get_option( 'test_secret_key' ) : $this->get_option( 'secret_key' ); |
|
| 70 | + $this->testmode = 'yes' === $this->get_option('testmode', 'no'); |
|
| 71 | + $this->secret_key = $this->testmode ? $this->get_option('test_secret_key') : $this->get_option('secret_key'); |
|
| 72 | 72 | |
| 73 | - if ( empty( $this->stripe_settings ) ) { |
|
| 73 | + if (empty($this->stripe_settings)) { |
|
| 74 | 74 | return; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $this->init_apple_pay(); |
| 78 | 78 | |
| 79 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
| 79 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
@@ -87,13 +87,13 @@ discard block |
||
| 87 | 87 | * @param string default |
| 88 | 88 | * @return string $setting_value |
| 89 | 89 | */ |
| 90 | - public function get_option( $setting = '', $default = '' ) { |
|
| 91 | - if ( empty( $this->stripe_settings ) ) { |
|
| 90 | + public function get_option($setting = '', $default = '') { |
|
| 91 | + if (empty($this->stripe_settings)) { |
|
| 92 | 92 | return $default; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if ( ! empty( $this->stripe_settings[ $setting ] ) ) { |
|
| 96 | - return $this->stripe_settings[ $setting ]; |
|
| 95 | + if ( ! empty($this->stripe_settings[$setting])) { |
|
| 96 | + return $this->stripe_settings[$setting]; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | return $default; |
@@ -108,9 +108,9 @@ discard block |
||
| 108 | 108 | public function init_apple_pay() { |
| 109 | 109 | if ( |
| 110 | 110 | is_admin() && |
| 111 | - isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] && |
|
| 112 | - isset( $_GET['tab'] ) && 'checkout' === $_GET['tab'] && |
|
| 113 | - isset( $_GET['section'] ) && 'stripe' === $_GET['section'] && |
|
| 111 | + isset($_GET['page']) && 'wc-settings' === $_GET['page'] && |
|
| 112 | + isset($_GET['tab']) && 'checkout' === $_GET['tab'] && |
|
| 113 | + isset($_GET['section']) && 'stripe' === $_GET['section'] && |
|
| 114 | 114 | $this->payment_request |
| 115 | 115 | ) { |
| 116 | 116 | $this->process_apple_pay_verification(); |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | * @version 3.1.0 |
| 125 | 125 | * @param string $secret_key |
| 126 | 126 | */ |
| 127 | - private function register_apple_pay_domain( $secret_key = '' ) { |
|
| 128 | - if ( empty( $secret_key ) ) { |
|
| 129 | - throw new Exception( __( 'Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe' ) ); |
|
| 127 | + private function register_apple_pay_domain($secret_key = '') { |
|
| 128 | + if (empty($secret_key)) { |
|
| 129 | + throw new Exception(__('Unable to verify domain - missing secret key.', 'woocommerce-gateway-stripe')); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $endpoint = 'https://api.stripe.com/v1/apple_pay/domains'; |
@@ -144,22 +144,22 @@ discard block |
||
| 144 | 144 | $endpoint, |
| 145 | 145 | array( |
| 146 | 146 | 'headers' => $headers, |
| 147 | - 'body' => http_build_query( $data ), |
|
| 147 | + 'body' => http_build_query($data), |
|
| 148 | 148 | ) |
| 149 | 149 | ); |
| 150 | 150 | |
| 151 | - if ( is_wp_error( $response ) ) { |
|
| 151 | + if (is_wp_error($response)) { |
|
| 152 | 152 | /* translators: error message */ |
| 153 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $response->get_error_message() ) ); |
|
| 153 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $response->get_error_message())); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if ( 200 !== $response['response']['code'] ) { |
|
| 157 | - $parsed_response = json_decode( $response['body'] ); |
|
| 156 | + if (200 !== $response['response']['code']) { |
|
| 157 | + $parsed_response = json_decode($response['body']); |
|
| 158 | 158 | |
| 159 | 159 | $this->apple_pay_verify_notice = $parsed_response->error->message; |
| 160 | 160 | |
| 161 | 161 | /* translators: error message */ |
| 162 | - throw new Exception( sprintf( __( 'Unable to verify domain - %s', 'woocommerce-gateway-stripe' ), $parsed_response->error->message ) ); |
|
| 162 | + throw new Exception(sprintf(__('Unable to verify domain - %s', 'woocommerce-gateway-stripe'), $parsed_response->error->message)); |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
@@ -172,31 +172,31 @@ discard block |
||
| 172 | 172 | * @since 4.3.0 |
| 173 | 173 | * @return bool True on success, false on failure. |
| 174 | 174 | */ |
| 175 | - public function update_verification_file( $force = false ) { |
|
| 176 | - $path = untrailingslashit( $_SERVER['DOCUMENT_ROOT'] ); |
|
| 175 | + public function update_verification_file($force = false) { |
|
| 176 | + $path = untrailingslashit($_SERVER['DOCUMENT_ROOT']); |
|
| 177 | 177 | $dir = '.well-known'; |
| 178 | 178 | $file = 'apple-developer-merchantid-domain-association'; |
| 179 | 179 | $fullpath = $path . '/' . $dir . '/' . $file; |
| 180 | 180 | |
| 181 | - $existing_contents = @file_get_contents( $fullpath ); |
|
| 182 | - $new_contents = @file_get_contents( WC_STRIPE_PLUGIN_PATH . '/' . $file ); |
|
| 183 | - if ( ( ! $existing_contents && ! $force ) || $existing_contents === $new_contents ) { |
|
| 181 | + $existing_contents = @file_get_contents($fullpath); |
|
| 182 | + $new_contents = @file_get_contents(WC_STRIPE_PLUGIN_PATH . '/' . $file); |
|
| 183 | + if (( ! $existing_contents && ! $force) || $existing_contents === $new_contents) { |
|
| 184 | 184 | return true; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if ( ! file_exists( $path . '/' . $dir ) ) { |
|
| 188 | - if ( ! @mkdir( $path . '/' . $dir, 0755 ) ) { // @codingStandardsIgnoreLine |
|
| 189 | - WC_Stripe_Logger::log( 'Error: ' . __( 'Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 187 | + if ( ! file_exists($path . '/' . $dir)) { |
|
| 188 | + if ( ! @mkdir($path . '/' . $dir, 0755)) { // @codingStandardsIgnoreLine |
|
| 189 | + WC_Stripe_Logger::log('Error: ' . __('Unable to create domain association folder to domain root.', 'woocommerce-gateway-stripe')); |
|
| 190 | 190 | return false; |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - if ( ! @copy( WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath ) ) { // @codingStandardsIgnoreLine |
|
| 195 | - WC_Stripe_Logger::log( 'Error: ' . __( 'Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe' ) ); |
|
| 194 | + if ( ! @copy(WC_STRIPE_PLUGIN_PATH . '/' . $file, $fullpath)) { // @codingStandardsIgnoreLine |
|
| 195 | + WC_Stripe_Logger::log('Error: ' . __('Unable to copy domain association file to domain root.', 'woocommerce-gateway-stripe')); |
|
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - WC_Stripe_Logger::log( 'Domain association file updated.' ); |
|
| 199 | + WC_Stripe_Logger::log('Domain association file updated.'); |
|
| 200 | 200 | return true; |
| 201 | 201 | } |
| 202 | 202 | |
@@ -207,31 +207,31 @@ discard block |
||
| 207 | 207 | * @version 3.1.0 |
| 208 | 208 | */ |
| 209 | 209 | public function process_apple_pay_verification() { |
| 210 | - if ( ! $this->update_verification_file( true ) ) { |
|
| 210 | + if ( ! $this->update_verification_file(true)) { |
|
| 211 | 211 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
| 212 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
| 212 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
| 213 | 213 | return; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | try { |
| 217 | 217 | // At this point then the domain association folder and file should be available. |
| 218 | 218 | // Proceed to verify/and or verify again. |
| 219 | - $this->register_apple_pay_domain( $this->secret_key ); |
|
| 219 | + $this->register_apple_pay_domain($this->secret_key); |
|
| 220 | 220 | |
| 221 | 221 | // No errors to this point, verification success! |
| 222 | 222 | $this->stripe_settings['apple_pay_domain_set'] = 'yes'; |
| 223 | 223 | $this->apple_pay_domain_set = true; |
| 224 | 224 | |
| 225 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
| 225 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
| 226 | 226 | |
| 227 | - WC_Stripe_Logger::log( 'Your domain has been verified with Apple Pay!' ); |
|
| 227 | + WC_Stripe_Logger::log('Your domain has been verified with Apple Pay!'); |
|
| 228 | 228 | |
| 229 | - } catch ( Exception $e ) { |
|
| 229 | + } catch (Exception $e) { |
|
| 230 | 230 | $this->stripe_settings['apple_pay_domain_set'] = 'no'; |
| 231 | 231 | |
| 232 | - update_option( 'woocommerce_stripe_settings', $this->stripe_settings ); |
|
| 232 | + update_option('woocommerce_stripe_settings', $this->stripe_settings); |
|
| 233 | 233 | |
| 234 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 234 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 235 | 235 | } |
| 236 | 236 | } |
| 237 | 237 | |
@@ -241,15 +241,15 @@ discard block |
||
| 241 | 241 | * @since 4.0.6 |
| 242 | 242 | */ |
| 243 | 243 | public function admin_notices() { |
| 244 | - if ( ! $this->stripe_enabled ) { |
|
| 244 | + if ( ! $this->stripe_enabled) { |
|
| 245 | 245 | return; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if ( ! current_user_can( 'manage_woocommerce' ) ) { |
|
| 248 | + if ( ! current_user_can('manage_woocommerce')) { |
|
| 249 | 249 | return; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - if ( $this->payment_request && ! empty( $this->apple_pay_verify_notice ) ) { |
|
| 252 | + if ($this->payment_request && ! empty($this->apple_pay_verify_notice)) { |
|
| 253 | 253 | $allowed_html = array( |
| 254 | 254 | 'a' => array( |
| 255 | 255 | 'href' => array(), |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | ), |
| 258 | 258 | ); |
| 259 | 259 | |
| 260 | - echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses( make_clickable( $this->apple_pay_verify_notice ), $allowed_html ) . '</p></div>'; |
|
| 260 | + echo '<div class="error stripe-apple-pay-message"><p>' . wp_kses(make_clickable($this->apple_pay_verify_notice), $allowed_html) . '</p></div>'; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -265,9 +265,9 @@ discard block |
||
| 265 | 265 | * when setting screen is displayed. So if domain verification is not set, |
| 266 | 266 | * something went wrong so lets notify user. |
| 267 | 267 | */ |
| 268 | - if ( ! empty( $this->secret_key ) && $this->payment_request && ! $this->apple_pay_domain_set ) { |
|
| 268 | + if ( ! empty($this->secret_key) && $this->payment_request && ! $this->apple_pay_domain_set) { |
|
| 269 | 269 | /* translators: 1) HTML anchor open tag 2) HTML anchor closing tag */ |
| 270 | - echo '<div class="error stripe-apple-pay-message"><p>' . sprintf( __( 'Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '">', '</a>' ) . '</p></div>'; |
|
| 270 | + echo '<div class="error stripe-apple-pay-message"><p>' . sprintf(__('Apple Pay domain verification failed. Please check the %1$slog%2$s to see the issue. (Logging must be enabled to see recorded logs)', 'woocommerce-gateway-stripe'), '<a href="' . admin_url('admin.php?page=wc-status&tab=logs') . '">', '</a>') . '</p></div>'; |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -7,36 +7,36 @@ discard block |
||
| 7 | 7 | 'wc_stripe_eps_settings', |
| 8 | 8 | array( |
| 9 | 9 | 'geo_target' => array( |
| 10 | - 'description' => __( 'Relevant Payer Geography: Austria', 'woocommerce-gateway-stripe' ), |
|
| 10 | + 'description' => __('Relevant Payer Geography: Austria', 'woocommerce-gateway-stripe'), |
|
| 11 | 11 | 'type' => 'title', |
| 12 | 12 | ), |
| 13 | 13 | 'activation' => array( |
| 14 | - 'description' => __( 'Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe' ), |
|
| 14 | + 'description' => __('Must be activated from your Stripe Dashboard Settings <a href="https://dashboard.stripe.com/account/payments/settings" target="_blank">here</a>', 'woocommerce-gateway-stripe'), |
|
| 15 | 15 | 'type' => 'title', |
| 16 | 16 | ), |
| 17 | 17 | 'enabled' => array( |
| 18 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
| 19 | - 'label' => __( 'Enable Stripe EPS', 'woocommerce-gateway-stripe' ), |
|
| 18 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
| 19 | + 'label' => __('Enable Stripe EPS', 'woocommerce-gateway-stripe'), |
|
| 20 | 20 | 'type' => 'checkbox', |
| 21 | 21 | 'description' => '', |
| 22 | 22 | 'default' => 'no', |
| 23 | 23 | ), |
| 24 | 24 | 'title' => array( |
| 25 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
| 25 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
| 26 | 26 | 'type' => 'text', |
| 27 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
| 28 | - 'default' => __( 'EPS', 'woocommerce-gateway-stripe' ), |
|
| 27 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
| 28 | + 'default' => __('EPS', 'woocommerce-gateway-stripe'), |
|
| 29 | 29 | 'desc_tip' => true, |
| 30 | 30 | ), |
| 31 | 31 | 'description' => array( |
| 32 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
| 32 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
| 33 | 33 | 'type' => 'text', |
| 34 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
| 35 | - 'default' => __( 'You will be redirected to EPS.', 'woocommerce-gateway-stripe' ), |
|
| 34 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
| 35 | + 'default' => __('You will be redirected to EPS.', 'woocommerce-gateway-stripe'), |
|
| 36 | 36 | 'desc_tip' => true, |
| 37 | 37 | ), |
| 38 | 38 | 'webhook' => array( |
| 39 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
| 39 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
| 40 | 40 | 'type' => 'title', |
| 41 | 41 | /* translators: webhook URL */ |
| 42 | 42 | 'description' => $this->display_admin_settings_webhook_description(), |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! class_exists( 'WC_Abstract_Privacy' ) ) { |
|
| 2 | +if ( ! class_exists('WC_Abstract_Privacy')) { |
|
| 3 | 3 | return; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -9,20 +9,20 @@ discard block |
||
| 9 | 9 | * |
| 10 | 10 | */ |
| 11 | 11 | public function __construct() { |
| 12 | - parent::__construct( __( 'Stripe', 'woocommerce-gateway-stripe' ) ); |
|
| 12 | + parent::__construct(__('Stripe', 'woocommerce-gateway-stripe')); |
|
| 13 | 13 | |
| 14 | - $this->add_exporter( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe' ), array( $this, 'order_data_exporter' ) ); |
|
| 14 | + $this->add_exporter('woocommerce-gateway-stripe-order-data', __('WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe'), array($this, 'order_data_exporter')); |
|
| 15 | 15 | |
| 16 | - if ( function_exists( 'wcs_get_subscriptions' ) ) { |
|
| 17 | - $this->add_exporter( 'woocommerce-gateway-stripe-subscriptions-data', __( 'WooCommerce Stripe Subscriptions Data', 'woocommerce-gateway-stripe' ), array( $this, 'subscriptions_data_exporter' ) ); |
|
| 16 | + if (function_exists('wcs_get_subscriptions')) { |
|
| 17 | + $this->add_exporter('woocommerce-gateway-stripe-subscriptions-data', __('WooCommerce Stripe Subscriptions Data', 'woocommerce-gateway-stripe'), array($this, 'subscriptions_data_exporter')); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - $this->add_exporter( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), array( $this, 'customer_data_exporter' ) ); |
|
| 20 | + $this->add_exporter('woocommerce-gateway-stripe-customer-data', __('WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe'), array($this, 'customer_data_exporter')); |
|
| 21 | 21 | |
| 22 | - $this->add_eraser( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), array( $this, 'customer_data_eraser' ) ); |
|
| 23 | - $this->add_eraser( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Data', 'woocommerce-gateway-stripe' ), array( $this, 'order_data_eraser' ) ); |
|
| 22 | + $this->add_eraser('woocommerce-gateway-stripe-customer-data', __('WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe'), array($this, 'customer_data_eraser')); |
|
| 23 | + $this->add_eraser('woocommerce-gateway-stripe-order-data', __('WooCommerce Stripe Data', 'woocommerce-gateway-stripe'), array($this, 'order_data_eraser')); |
|
| 24 | 24 | |
| 25 | - add_filter( 'woocommerce_get_settings_account', array( $this, 'account_settings' ) ); |
|
| 25 | + add_filter('woocommerce_get_settings_account', array($this, 'account_settings')); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -31,14 +31,14 @@ discard block |
||
| 31 | 31 | * @param array $settings |
| 32 | 32 | * @return array $settings Updated |
| 33 | 33 | */ |
| 34 | - public function account_settings( $settings ) { |
|
| 34 | + public function account_settings($settings) { |
|
| 35 | 35 | $insert_setting = array( |
| 36 | 36 | array( |
| 37 | - 'title' => __( 'Retain Stripe Data', 'woocommerce-gateway-stripe' ), |
|
| 38 | - 'desc_tip' => __( 'Retains any Stripe data such as Stripe customer ID, source ID.', 'woocommerce-gateway-stripe' ), |
|
| 37 | + 'title' => __('Retain Stripe Data', 'woocommerce-gateway-stripe'), |
|
| 38 | + 'desc_tip' => __('Retains any Stripe data such as Stripe customer ID, source ID.', 'woocommerce-gateway-stripe'), |
|
| 39 | 39 | 'id' => 'woocommerce_gateway_stripe_retention', |
| 40 | 40 | 'type' => 'relative_date_selector', |
| 41 | - 'placeholder' => __( 'N/A', 'woocommerce-gateway-stripe' ), |
|
| 41 | + 'placeholder' => __('N/A', 'woocommerce-gateway-stripe'), |
|
| 42 | 42 | 'default' => '', |
| 43 | 43 | 'autoload' => false, |
| 44 | 44 | ), |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | $index = null; |
| 48 | 48 | |
| 49 | - foreach ( $settings as $key => $value) { |
|
| 50 | - if ( 'sectionend' === $value[ 'type' ] && 'personal_data_retention' === $value[ 'id' ] ) { |
|
| 49 | + foreach ($settings as $key => $value) { |
|
| 50 | + if ('sectionend' === $value['type'] && 'personal_data_retention' === $value['id']) { |
|
| 51 | 51 | $index = $key; |
| 52 | 52 | break; |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if ( ! is_null( $index ) ) { |
|
| 57 | - array_splice( $settings, $index, 0, $insert_setting ); |
|
| 56 | + if ( ! is_null($index)) { |
|
| 57 | + array_splice($settings, $index, 0, $insert_setting); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | return $settings; |
@@ -68,22 +68,22 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @return array WP_Post |
| 70 | 70 | */ |
| 71 | - protected function get_stripe_orders( $email_address, $page ) { |
|
| 72 | - $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
|
| 71 | + protected function get_stripe_orders($email_address, $page) { |
|
| 72 | + $user = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data. |
|
| 73 | 73 | |
| 74 | 74 | $order_query = array( |
| 75 | - 'payment_method' => array( 'stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort' ), |
|
| 75 | + 'payment_method' => array('stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort'), |
|
| 76 | 76 | 'limit' => 10, |
| 77 | 77 | 'page' => $page, |
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | - if ( $user instanceof WP_User ) { |
|
| 80 | + if ($user instanceof WP_User) { |
|
| 81 | 81 | $order_query['customer_id'] = (int) $user->ID; |
| 82 | 82 | } else { |
| 83 | 83 | $order_query['billing_email'] = $email_address; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - return wc_get_orders( $order_query ); |
|
| 86 | + return wc_get_orders($order_query); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function get_privacy_message() { |
| 94 | 94 | /* translators: %s URL to docs */ |
| 95 | - return wpautop( sprintf( __( 'By using this extension, you may be storing personal data or sharing data with an external service. <a href="%s" target="_blank">Learn more about how this works, including what you may want to include in your privacy policy.</a>', 'woocommerce-gateway-stripe' ), 'https://docs.woocommerce.com/document/privacy-payments/#woocommerce-gateway-stripe' ) ); |
|
| 95 | + return wpautop(sprintf(__('By using this extension, you may be storing personal data or sharing data with an external service. <a href="%s" target="_blank">Learn more about how this works, including what you may want to include in your privacy policy.</a>', 'woocommerce-gateway-stripe'), 'https://docs.woocommerce.com/document/privacy-payments/#woocommerce-gateway-stripe')); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -103,34 +103,34 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return array |
| 105 | 105 | */ |
| 106 | - public function order_data_exporter( $email_address, $page = 1 ) { |
|
| 106 | + public function order_data_exporter($email_address, $page = 1) { |
|
| 107 | 107 | $done = false; |
| 108 | 108 | $data_to_export = array(); |
| 109 | 109 | |
| 110 | - $orders = $this->get_stripe_orders( $email_address, (int) $page ); |
|
| 110 | + $orders = $this->get_stripe_orders($email_address, (int) $page); |
|
| 111 | 111 | |
| 112 | 112 | $done = true; |
| 113 | 113 | |
| 114 | - if ( 0 < count( $orders ) ) { |
|
| 115 | - foreach ( $orders as $order ) { |
|
| 114 | + if (0 < count($orders)) { |
|
| 115 | + foreach ($orders as $order) { |
|
| 116 | 116 | $data_to_export[] = array( |
| 117 | 117 | 'group_id' => 'woocommerce_orders', |
| 118 | - 'group_label' => __( 'Orders', 'woocommerce-gateway-stripe' ), |
|
| 118 | + 'group_label' => __('Orders', 'woocommerce-gateway-stripe'), |
|
| 119 | 119 | 'item_id' => 'order-' . $order->get_id(), |
| 120 | 120 | 'data' => array( |
| 121 | 121 | array( |
| 122 | - 'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ), |
|
| 123 | - 'value' => get_post_meta( $order->get_id(), '_stripe_source_id', true ), |
|
| 122 | + 'name' => __('Stripe payment id', 'woocommerce-gateway-stripe'), |
|
| 123 | + 'value' => get_post_meta($order->get_id(), '_stripe_source_id', true), |
|
| 124 | 124 | ), |
| 125 | 125 | array( |
| 126 | - 'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ), |
|
| 127 | - 'value' => get_post_meta( $order->get_id(), '_stripe_customer_id', true ), |
|
| 126 | + 'name' => __('Stripe customer id', 'woocommerce-gateway-stripe'), |
|
| 127 | + 'value' => get_post_meta($order->get_id(), '_stripe_customer_id', true), |
|
| 128 | 128 | ), |
| 129 | 129 | ), |
| 130 | 130 | ); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $done = 10 > count( $orders ); |
|
| 133 | + $done = 10 > count($orders); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | return array( |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @return array |
| 149 | 149 | */ |
| 150 | - public function subscriptions_data_exporter( $email_address, $page = 1 ) { |
|
| 150 | + public function subscriptions_data_exporter($email_address, $page = 1) { |
|
| 151 | 151 | $done = false; |
| 152 | 152 | $page = (int) $page; |
| 153 | 153 | $data_to_export = array(); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | 'relation' => 'AND', |
| 157 | 157 | array( |
| 158 | 158 | 'key' => '_payment_method', |
| 159 | - 'value' => array( 'stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort' ), |
|
| 159 | + 'value' => array('stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort'), |
|
| 160 | 160 | 'compare' => 'IN', |
| 161 | 161 | ), |
| 162 | 162 | array( |
@@ -172,30 +172,30 @@ discard block |
||
| 172 | 172 | 'meta_query' => $meta_query, |
| 173 | 173 | ); |
| 174 | 174 | |
| 175 | - $subscriptions = wcs_get_subscriptions( $subscription_query ); |
|
| 175 | + $subscriptions = wcs_get_subscriptions($subscription_query); |
|
| 176 | 176 | |
| 177 | 177 | $done = true; |
| 178 | 178 | |
| 179 | - if ( 0 < count( $subscriptions ) ) { |
|
| 180 | - foreach ( $subscriptions as $subscription ) { |
|
| 179 | + if (0 < count($subscriptions)) { |
|
| 180 | + foreach ($subscriptions as $subscription) { |
|
| 181 | 181 | $data_to_export[] = array( |
| 182 | 182 | 'group_id' => 'woocommerce_subscriptions', |
| 183 | - 'group_label' => __( 'Subscriptions', 'woocommerce-gateway-stripe' ), |
|
| 183 | + 'group_label' => __('Subscriptions', 'woocommerce-gateway-stripe'), |
|
| 184 | 184 | 'item_id' => 'subscription-' . $subscription->get_id(), |
| 185 | 185 | 'data' => array( |
| 186 | 186 | array( |
| 187 | - 'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ), |
|
| 188 | - 'value' => get_post_meta( $subscription->get_id(), '_stripe_source_id', true ), |
|
| 187 | + 'name' => __('Stripe payment id', 'woocommerce-gateway-stripe'), |
|
| 188 | + 'value' => get_post_meta($subscription->get_id(), '_stripe_source_id', true), |
|
| 189 | 189 | ), |
| 190 | 190 | array( |
| 191 | - 'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ), |
|
| 192 | - 'value' => get_post_meta( $subscription->get_id(), '_stripe_customer_id', true ), |
|
| 191 | + 'name' => __('Stripe customer id', 'woocommerce-gateway-stripe'), |
|
| 192 | + 'value' => get_post_meta($subscription->get_id(), '_stripe_customer_id', true), |
|
| 193 | 193 | ), |
| 194 | 194 | ), |
| 195 | 195 | ); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - $done = 10 > count( $subscriptions ); |
|
| 198 | + $done = 10 > count($subscriptions); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | return array( |
@@ -211,24 +211,24 @@ discard block |
||
| 211 | 211 | * @param int $page Page. |
| 212 | 212 | * @return array An array of personal data in name value pairs |
| 213 | 213 | */ |
| 214 | - public function customer_data_exporter( $email_address, $page ) { |
|
| 215 | - $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
|
| 214 | + public function customer_data_exporter($email_address, $page) { |
|
| 215 | + $user = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data. |
|
| 216 | 216 | $data_to_export = array(); |
| 217 | 217 | |
| 218 | - if ( $user instanceof WP_User ) { |
|
| 219 | - $stripe_user = new WC_Stripe_Customer( $user->ID ); |
|
| 218 | + if ($user instanceof WP_User) { |
|
| 219 | + $stripe_user = new WC_Stripe_Customer($user->ID); |
|
| 220 | 220 | |
| 221 | 221 | $data_to_export[] = array( |
| 222 | 222 | 'group_id' => 'woocommerce_customer', |
| 223 | - 'group_label' => __( 'Customer Data', 'woocommerce-gateway-stripe' ), |
|
| 223 | + 'group_label' => __('Customer Data', 'woocommerce-gateway-stripe'), |
|
| 224 | 224 | 'item_id' => 'user', |
| 225 | 225 | 'data' => array( |
| 226 | 226 | array( |
| 227 | - 'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ), |
|
| 228 | - 'value' => get_user_option( '_stripe_source_id', $user->ID ), |
|
| 227 | + 'name' => __('Stripe payment id', 'woocommerce-gateway-stripe'), |
|
| 228 | + 'value' => get_user_option('_stripe_source_id', $user->ID), |
|
| 229 | 229 | ), |
| 230 | 230 | array( |
| 231 | - 'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ), |
|
| 231 | + 'name' => __('Stripe customer id', 'woocommerce-gateway-stripe'), |
|
| 232 | 232 | 'value' => $stripe_user->get_id(), |
| 233 | 233 | ), |
| 234 | 234 | ), |
@@ -248,25 +248,25 @@ discard block |
||
| 248 | 248 | * @param int $page Page. |
| 249 | 249 | * @return array An array of personal data in name value pairs |
| 250 | 250 | */ |
| 251 | - public function customer_data_eraser( $email_address, $page ) { |
|
| 251 | + public function customer_data_eraser($email_address, $page) { |
|
| 252 | 252 | $page = (int) $page; |
| 253 | - $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. |
|
| 253 | + $user = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data. |
|
| 254 | 254 | $stripe_customer_id = ''; |
| 255 | 255 | $stripe_source_id = ''; |
| 256 | 256 | |
| 257 | - if ( $user instanceof WP_User ) { |
|
| 258 | - $stripe_customer_id = get_user_option( '_stripe_customer_id', $user->ID ); |
|
| 259 | - $stripe_source_id = get_user_option( '_stripe_source_id', $user->ID ); |
|
| 257 | + if ($user instanceof WP_User) { |
|
| 258 | + $stripe_customer_id = get_user_option('_stripe_customer_id', $user->ID); |
|
| 259 | + $stripe_source_id = get_user_option('_stripe_source_id', $user->ID); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | $items_removed = false; |
| 263 | 263 | $messages = array(); |
| 264 | 264 | |
| 265 | - if ( ! empty( $stripe_customer_id ) || ! empty( $stripe_source_id ) ) { |
|
| 265 | + if ( ! empty($stripe_customer_id) || ! empty($stripe_source_id)) { |
|
| 266 | 266 | $items_removed = true; |
| 267 | - delete_user_option( $user->ID, '_stripe_customer_id' ); |
|
| 268 | - delete_user_option( $user->ID, '_stripe_source_id' ); |
|
| 269 | - $messages[] = __( 'Stripe User Data Erased.', 'woocommerce-gateway-stripe' ); |
|
| 267 | + delete_user_option($user->ID, '_stripe_customer_id'); |
|
| 268 | + delete_user_option($user->ID, '_stripe_source_id'); |
|
| 269 | + $messages[] = __('Stripe User Data Erased.', 'woocommerce-gateway-stripe'); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | return array( |
@@ -284,29 +284,29 @@ discard block |
||
| 284 | 284 | * @param int $page Page. |
| 285 | 285 | * @return array An array of personal data in name value pairs |
| 286 | 286 | */ |
| 287 | - public function order_data_eraser( $email_address, $page ) { |
|
| 288 | - $orders = $this->get_stripe_orders( $email_address, (int) $page ); |
|
| 287 | + public function order_data_eraser($email_address, $page) { |
|
| 288 | + $orders = $this->get_stripe_orders($email_address, (int) $page); |
|
| 289 | 289 | |
| 290 | 290 | $items_removed = false; |
| 291 | 291 | $items_retained = false; |
| 292 | 292 | $messages = array(); |
| 293 | 293 | |
| 294 | - foreach ( (array) $orders as $order ) { |
|
| 295 | - $order = wc_get_order( $order->get_id() ); |
|
| 294 | + foreach ((array) $orders as $order) { |
|
| 295 | + $order = wc_get_order($order->get_id()); |
|
| 296 | 296 | |
| 297 | - list( $removed, $retained, $msgs ) = $this->maybe_handle_order( $order ); |
|
| 297 | + list($removed, $retained, $msgs) = $this->maybe_handle_order($order); |
|
| 298 | 298 | $items_removed |= $removed; |
| 299 | 299 | $items_retained |= $retained; |
| 300 | - $messages = array_merge( $messages, $msgs ); |
|
| 300 | + $messages = array_merge($messages, $msgs); |
|
| 301 | 301 | |
| 302 | - list( $removed, $retained, $msgs ) = $this->maybe_handle_subscription( $order ); |
|
| 302 | + list($removed, $retained, $msgs) = $this->maybe_handle_subscription($order); |
|
| 303 | 303 | $items_removed |= $removed; |
| 304 | 304 | $items_retained |= $retained; |
| 305 | - $messages = array_merge( $messages, $msgs ); |
|
| 305 | + $messages = array_merge($messages, $msgs); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | // Tell core if we have more orders to work on still |
| 309 | - $done = count( $orders ) < 10; |
|
| 309 | + $done = count($orders) < 10; |
|
| 310 | 310 | |
| 311 | 311 | return array( |
| 312 | 312 | 'items_removed' => $items_removed, |
@@ -322,47 +322,47 @@ discard block |
||
| 322 | 322 | * @param WC_Order $order |
| 323 | 323 | * @return array |
| 324 | 324 | */ |
| 325 | - protected function maybe_handle_subscription( $order ) { |
|
| 326 | - if ( ! class_exists( 'WC_Subscriptions' ) ) { |
|
| 327 | - return array( false, false, array() ); |
|
| 325 | + protected function maybe_handle_subscription($order) { |
|
| 326 | + if ( ! class_exists('WC_Subscriptions')) { |
|
| 327 | + return array(false, false, array()); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - if ( ! wcs_order_contains_subscription( $order ) ) { |
|
| 331 | - return array( false, false, array() ); |
|
| 330 | + if ( ! wcs_order_contains_subscription($order)) { |
|
| 331 | + return array(false, false, array()); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - $subscription = current( wcs_get_subscriptions_for_order( $order->get_id() ) ); |
|
| 334 | + $subscription = current(wcs_get_subscriptions_for_order($order->get_id())); |
|
| 335 | 335 | $subscription_id = $subscription->get_id(); |
| 336 | 336 | |
| 337 | - $stripe_source_id = get_post_meta( $subscription_id, '_stripe_source_id', true ); |
|
| 337 | + $stripe_source_id = get_post_meta($subscription_id, '_stripe_source_id', true); |
|
| 338 | 338 | |
| 339 | - if ( empty( $stripe_source_id ) ) { |
|
| 340 | - return array( false, false, array() ); |
|
| 339 | + if (empty($stripe_source_id)) { |
|
| 340 | + return array(false, false, array()); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - if ( ! $this->is_retention_expired( $order->get_date_created()->getTimestamp() ) ) { |
|
| 343 | + if ( ! $this->is_retention_expired($order->get_date_created()->getTimestamp())) { |
|
| 344 | 344 | /* translators: %d Order ID */ |
| 345 | - return array( false, true, array( sprintf( __( 'Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe' ), $order->get_id() ) ) ); |
|
| 345 | + return array(false, true, array(sprintf(__('Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe'), $order->get_id()))); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - if ( $subscription->has_status( apply_filters( 'wc_stripe_privacy_eraser_subs_statuses', array( 'on-hold', 'active' ) ) ) ) { |
|
| 348 | + if ($subscription->has_status(apply_filters('wc_stripe_privacy_eraser_subs_statuses', array('on-hold', 'active')))) { |
|
| 349 | 349 | /* translators: %d Order ID */ |
| 350 | - return array( false, true, array( sprintf( __( 'Order ID %d contains an active Subscription. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe' ), $order->get_id() ) ) ); |
|
| 350 | + return array(false, true, array(sprintf(__('Order ID %d contains an active Subscription. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe'), $order->get_id()))); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - $renewal_orders = WC_Subscriptions_Renewal_Order::get_renewal_orders( $order->get_id() ); |
|
| 353 | + $renewal_orders = WC_Subscriptions_Renewal_Order::get_renewal_orders($order->get_id()); |
|
| 354 | 354 | |
| 355 | - foreach ( $renewal_orders as $renewal_order_id ) { |
|
| 356 | - delete_post_meta( $renewal_order_id, '_stripe_source_id' ); |
|
| 357 | - delete_post_meta( $renewal_order_id, '_stripe_refund_id' ); |
|
| 358 | - delete_post_meta( $renewal_order_id, '_stripe_customer_id' ); |
|
| 355 | + foreach ($renewal_orders as $renewal_order_id) { |
|
| 356 | + delete_post_meta($renewal_order_id, '_stripe_source_id'); |
|
| 357 | + delete_post_meta($renewal_order_id, '_stripe_refund_id'); |
|
| 358 | + delete_post_meta($renewal_order_id, '_stripe_customer_id'); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - delete_post_meta( $subscription_id, '_stripe_source_id' ); |
|
| 362 | - delete_post_meta( $subscription_id, '_stripe_refund_id' ); |
|
| 363 | - delete_post_meta( $subscription_id, '_stripe_customer_id' ); |
|
| 361 | + delete_post_meta($subscription_id, '_stripe_source_id'); |
|
| 362 | + delete_post_meta($subscription_id, '_stripe_refund_id'); |
|
| 363 | + delete_post_meta($subscription_id, '_stripe_customer_id'); |
|
| 364 | 364 | |
| 365 | - return array( true, false, array( __( 'Stripe Subscription Data Erased.', 'woocommerce-gateway-stripe' ) ) ); |
|
| 365 | + return array(true, false, array(__('Stripe Subscription Data Erased.', 'woocommerce-gateway-stripe'))); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | /** |
@@ -371,61 +371,61 @@ discard block |
||
| 371 | 371 | * @param WC_Order $order |
| 372 | 372 | * @return array |
| 373 | 373 | */ |
| 374 | - protected function maybe_handle_order( $order ) { |
|
| 374 | + protected function maybe_handle_order($order) { |
|
| 375 | 375 | $order_id = $order->get_id(); |
| 376 | - $stripe_source_id = get_post_meta( $order_id, '_stripe_source_id', true ); |
|
| 377 | - $stripe_refund_id = get_post_meta( $order_id, '_stripe_refund_id', true ); |
|
| 378 | - $stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true ); |
|
| 376 | + $stripe_source_id = get_post_meta($order_id, '_stripe_source_id', true); |
|
| 377 | + $stripe_refund_id = get_post_meta($order_id, '_stripe_refund_id', true); |
|
| 378 | + $stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true); |
|
| 379 | 379 | |
| 380 | - if ( ! $this->is_retention_expired( $order->get_date_created()->getTimestamp() ) ) { |
|
| 380 | + if ( ! $this->is_retention_expired($order->get_date_created()->getTimestamp())) { |
|
| 381 | 381 | /* translators: %d Order ID */ |
| 382 | - return array( false, true, array( sprintf( __( 'Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe' ), $order->get_id() ) ) ); |
|
| 382 | + return array(false, true, array(sprintf(__('Order ID %d is less than set retention days. Personal data retained. (Stripe)', 'woocommerce-gateway-stripe'), $order->get_id()))); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if ( empty( $stripe_source_id ) && empty( $stripe_refund_id ) && empty( $stripe_customer_id ) ) { |
|
| 386 | - return array( false, false, array() ); |
|
| 385 | + if (empty($stripe_source_id) && empty($stripe_refund_id) && empty($stripe_customer_id)) { |
|
| 386 | + return array(false, false, array()); |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - delete_post_meta( $order_id, '_stripe_source_id' ); |
|
| 390 | - delete_post_meta( $order_id, '_stripe_refund_id' ); |
|
| 391 | - delete_post_meta( $order_id, '_stripe_customer_id' ); |
|
| 389 | + delete_post_meta($order_id, '_stripe_source_id'); |
|
| 390 | + delete_post_meta($order_id, '_stripe_refund_id'); |
|
| 391 | + delete_post_meta($order_id, '_stripe_customer_id'); |
|
| 392 | 392 | |
| 393 | - return array( true, false, array( __( 'Stripe personal data erased.', 'woocommerce-gateway-stripe' ) ) ); |
|
| 393 | + return array(true, false, array(__('Stripe personal data erased.', 'woocommerce-gateway-stripe'))); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
| 397 | 397 | * Checks if create date is passed retention duration. |
| 398 | 398 | * |
| 399 | 399 | */ |
| 400 | - public function is_retention_expired( $created_date ) { |
|
| 401 | - $retention = wc_parse_relative_date_option( get_option( 'woocommerce_gateway_stripe_retention' ) ); |
|
| 400 | + public function is_retention_expired($created_date) { |
|
| 401 | + $retention = wc_parse_relative_date_option(get_option('woocommerce_gateway_stripe_retention')); |
|
| 402 | 402 | $is_expired = false; |
| 403 | - $time_span = time() - strtotime( $created_date ); |
|
| 404 | - if ( empty( $retention ) || empty( $created_date ) ) { |
|
| 403 | + $time_span = time() - strtotime($created_date); |
|
| 404 | + if (empty($retention) || empty($created_date)) { |
|
| 405 | 405 | return false; |
| 406 | 406 | } |
| 407 | - switch ( $retention['unit'] ) { |
|
| 407 | + switch ($retention['unit']) { |
|
| 408 | 408 | case 'days': |
| 409 | 409 | $retention = $retention['number'] * DAY_IN_SECONDS; |
| 410 | - if ( $time_span > $retention ) { |
|
| 410 | + if ($time_span > $retention) { |
|
| 411 | 411 | $is_expired = true; |
| 412 | 412 | } |
| 413 | 413 | break; |
| 414 | 414 | case 'weeks': |
| 415 | 415 | $retention = $retention['number'] * WEEK_IN_SECONDS; |
| 416 | - if ( $time_span > $retention ) { |
|
| 416 | + if ($time_span > $retention) { |
|
| 417 | 417 | $is_expired = true; |
| 418 | 418 | } |
| 419 | 419 | break; |
| 420 | 420 | case 'months': |
| 421 | 421 | $retention = $retention['number'] * MONTH_IN_SECONDS; |
| 422 | - if ( $time_span > $retention ) { |
|
| 422 | + if ($time_span > $retention) { |
|
| 423 | 423 | $is_expired = true; |
| 424 | 424 | } |
| 425 | 425 | break; |
| 426 | 426 | case 'years': |
| 427 | 427 | $retention = $retention['number'] * YEAR_IN_SECONDS; |
| 428 | - if ( $time_span > $retention ) { |
|
| 428 | + if ($time_span > $retention) { |
|
| 429 | 429 | $is_expired = true; |
| 430 | 430 | } |
| 431 | 431 | break; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * Set secret API Key. |
| 27 | 27 | * @param string $key |
| 28 | 28 | */ |
| 29 | - public static function set_secret_key( $secret_key ) { |
|
| 29 | + public static function set_secret_key($secret_key) { |
|
| 30 | 30 | self::$secret_key = $secret_key; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | 37 | public static function get_secret_key() { |
| 38 | - if ( ! self::$secret_key ) { |
|
| 39 | - $options = get_option( 'woocommerce_stripe_settings' ); |
|
| 38 | + if ( ! self::$secret_key) { |
|
| 39 | + $options = get_option('woocommerce_stripe_settings'); |
|
| 40 | 40 | |
| 41 | - if ( isset( $options['testmode'], $options['secret_key'], $options['test_secret_key'] ) ) { |
|
| 42 | - self::set_secret_key( 'yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key'] ); |
|
| 41 | + if (isset($options['testmode'], $options['secret_key'], $options['test_secret_key'])) { |
|
| 42 | + self::set_secret_key('yes' === $options['testmode'] ? $options['test_secret_key'] : $options['secret_key']); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | return self::$secret_key; |
@@ -81,10 +81,10 @@ discard block |
||
| 81 | 81 | return apply_filters( |
| 82 | 82 | 'woocommerce_stripe_request_headers', |
| 83 | 83 | array( |
| 84 | - 'Authorization' => 'Basic ' . base64_encode( self::get_secret_key() . ':' ), |
|
| 84 | + 'Authorization' => 'Basic ' . base64_encode(self::get_secret_key() . ':'), |
|
| 85 | 85 | 'Stripe-Version' => self::STRIPE_API_VERSION, |
| 86 | 86 | 'User-Agent' => $app_info['name'] . '/' . $app_info['version'] . ' (' . $app_info['url'] . ')', |
| 87 | - 'X-Stripe-Client-User-Agent' => json_encode( $user_agent ), |
|
| 87 | + 'X-Stripe-Client-User-Agent' => json_encode($user_agent), |
|
| 88 | 88 | ) |
| 89 | 89 | ); |
| 90 | 90 | } |
@@ -101,16 +101,16 @@ discard block |
||
| 101 | 101 | * @return stdClass|array |
| 102 | 102 | * @throws WC_Stripe_Exception |
| 103 | 103 | */ |
| 104 | - public static function request( $request, $api = 'charges', $method = 'POST', $with_headers = false ) { |
|
| 105 | - WC_Stripe_Logger::log( "{$api} request: " . print_r( $request, true ) ); |
|
| 104 | + public static function request($request, $api = 'charges', $method = 'POST', $with_headers = false) { |
|
| 105 | + WC_Stripe_Logger::log("{$api} request: " . print_r($request, true)); |
|
| 106 | 106 | |
| 107 | 107 | $headers = self::get_headers(); |
| 108 | 108 | $idempotency_key = ''; |
| 109 | 109 | |
| 110 | - if ( 'charges' === $api && 'POST' === $method ) { |
|
| 111 | - $customer = ! empty( $request['customer'] ) ? $request['customer'] : ''; |
|
| 112 | - $source = ! empty( $request['source'] ) ? $request['source'] : $customer; |
|
| 113 | - $idempotency_key = apply_filters( 'wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request ); |
|
| 110 | + if ('charges' === $api && 'POST' === $method) { |
|
| 111 | + $customer = ! empty($request['customer']) ? $request['customer'] : ''; |
|
| 112 | + $source = ! empty($request['source']) ? $request['source'] : $customer; |
|
| 113 | + $idempotency_key = apply_filters('wc_stripe_idempotency_key', $request['metadata']['order_id'] . '-' . $source, $request); |
|
| 114 | 114 | |
| 115 | 115 | $headers['Idempotency-Key'] = $idempotency_key; |
| 116 | 116 | } |
@@ -120,14 +120,14 @@ discard block |
||
| 120 | 120 | array( |
| 121 | 121 | 'method' => $method, |
| 122 | 122 | 'headers' => $headers, |
| 123 | - 'body' => apply_filters( 'woocommerce_stripe_request_body', $request, $api ), |
|
| 123 | + 'body' => apply_filters('woocommerce_stripe_request_body', $request, $api), |
|
| 124 | 124 | 'timeout' => 70, |
| 125 | 125 | ) |
| 126 | 126 | ); |
| 127 | 127 | |
| 128 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 128 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 129 | 129 | WC_Stripe_Logger::log( |
| 130 | - 'Error Response: ' . print_r( $response, true ) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( |
|
| 130 | + 'Error Response: ' . print_r($response, true) . PHP_EOL . PHP_EOL . 'Failed request: ' . print_r( |
|
| 131 | 131 | array( |
| 132 | 132 | 'api' => $api, |
| 133 | 133 | 'request' => $request, |
@@ -137,17 +137,17 @@ discard block |
||
| 137 | 137 | ) |
| 138 | 138 | ); |
| 139 | 139 | |
| 140 | - throw new WC_Stripe_Exception( print_r( $response, true ), __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 140 | + throw new WC_Stripe_Exception(print_r($response, true), __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if ( $with_headers ) { |
|
| 143 | + if ($with_headers) { |
|
| 144 | 144 | return array( |
| 145 | - 'headers' => wp_remote_retrieve_headers( $response ), |
|
| 146 | - 'body' => json_decode( $response['body'] ), |
|
| 145 | + 'headers' => wp_remote_retrieve_headers($response), |
|
| 146 | + 'body' => json_decode($response['body']), |
|
| 147 | 147 | ); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - return json_decode( $response['body'] ); |
|
| 150 | + return json_decode($response['body']); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | * @version 4.0.0 |
| 158 | 158 | * @param string $api |
| 159 | 159 | */ |
| 160 | - public static function retrieve( $api ) { |
|
| 161 | - WC_Stripe_Logger::log( "{$api}" ); |
|
| 160 | + public static function retrieve($api) { |
|
| 161 | + WC_Stripe_Logger::log("{$api}"); |
|
| 162 | 162 | |
| 163 | 163 | $response = wp_safe_remote_get( |
| 164 | 164 | self::ENDPOINT . $api, |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | ) |
| 170 | 170 | ); |
| 171 | 171 | |
| 172 | - if ( is_wp_error( $response ) || empty( $response['body'] ) ) { |
|
| 173 | - WC_Stripe_Logger::log( 'Error Response: ' . print_r( $response, true ) ); |
|
| 174 | - return new WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe' ) ); |
|
| 172 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 173 | + WC_Stripe_Logger::log('Error Response: ' . print_r($response, true)); |
|
| 174 | + return new WP_Error('stripe_error', __('There was a problem connecting to the Stripe API endpoint.', 'woocommerce-gateway-stripe')); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - return json_decode( $response['body'] ); |
|
| 177 | + return json_decode($response['body']); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -193,9 +193,9 @@ discard block |
||
| 193 | 193 | * |
| 194 | 194 | * @return stdClass|array The response |
| 195 | 195 | */ |
| 196 | - public static function request_with_level3_data( $request, $api, $level3_data, $order ) { |
|
| 196 | + public static function request_with_level3_data($request, $api, $level3_data, $order) { |
|
| 197 | 197 | // Do not add level3 data it's the array is empty. |
| 198 | - if ( empty( $level3_data ) ) { |
|
| 198 | + if (empty($level3_data)) { |
|
| 199 | 199 | return self::request( |
| 200 | 200 | $request, |
| 201 | 201 | $api |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | // If there's a transient indicating that level3 data was not accepted by |
| 206 | 206 | // Stripe in the past for this account, do not try to add level3 data. |
| 207 | - if ( get_transient( 'wc_stripe_level3_not_allowed' ) ) { |
|
| 207 | + if (get_transient('wc_stripe_level3_not_allowed')) { |
|
| 208 | 208 | return self::request( |
| 209 | 209 | $request, |
| 210 | 210 | $api |
@@ -220,40 +220,40 @@ discard block |
||
| 220 | 220 | ); |
| 221 | 221 | |
| 222 | 222 | $is_level3_param_not_allowed = ( |
| 223 | - isset( $result->error ) |
|
| 224 | - && isset( $result->error->code ) |
|
| 223 | + isset($result->error) |
|
| 224 | + && isset($result->error->code) |
|
| 225 | 225 | && 'parameter_unknown' === $result->error->code |
| 226 | - && isset( $result->error->param ) |
|
| 226 | + && isset($result->error->param) |
|
| 227 | 227 | && 'level3' === $result->error->param |
| 228 | 228 | ); |
| 229 | 229 | |
| 230 | 230 | $is_level_3data_incorrect = ( |
| 231 | - isset( $result->error ) |
|
| 232 | - && isset( $result->error->type ) |
|
| 231 | + isset($result->error) |
|
| 232 | + && isset($result->error->type) |
|
| 233 | 233 | && 'invalid_request_error' === $result->error->type |
| 234 | 234 | ); |
| 235 | 235 | |
| 236 | - if ( $is_level3_param_not_allowed ) { |
|
| 236 | + if ($is_level3_param_not_allowed) { |
|
| 237 | 237 | // Set a transient so that future requests do not add level 3 data. |
| 238 | 238 | // Transient is set to expire in 3 months, can be manually removed if needed. |
| 239 | - set_transient( 'wc_stripe_level3_not_allowed', true, 3 * MONTH_IN_SECONDS ); |
|
| 240 | - } else if ( $is_level_3data_incorrect ) { |
|
| 239 | + set_transient('wc_stripe_level3_not_allowed', true, 3 * MONTH_IN_SECONDS); |
|
| 240 | + } else if ($is_level_3data_incorrect) { |
|
| 241 | 241 | // Log the issue so we could debug it. |
| 242 | 242 | WC_Stripe_Logger::log( |
| 243 | 243 | 'Level3 data sum incorrect: ' . PHP_EOL |
| 244 | - . print_r( $result->error->message, true ) . PHP_EOL |
|
| 245 | - . print_r( 'Order line items: ', true ) . PHP_EOL |
|
| 246 | - . print_r( $order->get_items(), true ) . PHP_EOL |
|
| 247 | - . print_r( 'Order shipping amount: ', true ) . PHP_EOL |
|
| 248 | - . print_r( $order->get_shipping_total(), true ) . PHP_EOL |
|
| 249 | - . print_r( 'Order currency: ', true ) . PHP_EOL |
|
| 250 | - . print_r( $order->get_currency(), true ) |
|
| 244 | + . print_r($result->error->message, true) . PHP_EOL |
|
| 245 | + . print_r('Order line items: ', true) . PHP_EOL |
|
| 246 | + . print_r($order->get_items(), true) . PHP_EOL |
|
| 247 | + . print_r('Order shipping amount: ', true) . PHP_EOL |
|
| 248 | + . print_r($order->get_shipping_total(), true) . PHP_EOL |
|
| 249 | + . print_r('Order currency: ', true) . PHP_EOL |
|
| 250 | + . print_r($order->get_currency(), true) |
|
| 251 | 251 | ); |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // Make the request again without level 3 data. |
| 255 | - if ( $is_level3_param_not_allowed || $is_level_3data_incorrect ) { |
|
| 256 | - unset( $request['level3'] ); |
|
| 255 | + if ($is_level3_param_not_allowed || $is_level_3data_incorrect) { |
|
| 256 | + unset($request['level3']); |
|
| 257 | 257 | return WC_Stripe_API::request( |
| 258 | 258 | $request, |
| 259 | 259 | $api |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | * Constructor |
| 33 | 33 | * @param int $user_id The WP user ID |
| 34 | 34 | */ |
| 35 | - public function __construct( $user_id = 0 ) { |
|
| 36 | - if ( $user_id ) { |
|
| 37 | - $this->set_user_id( $user_id ); |
|
| 38 | - $this->set_id( $this->get_id_from_meta( $user_id ) ); |
|
| 35 | + public function __construct($user_id = 0) { |
|
| 36 | + if ($user_id) { |
|
| 37 | + $this->set_user_id($user_id); |
|
| 38 | + $this->set_id($this->get_id_from_meta($user_id)); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -51,15 +51,15 @@ discard block |
||
| 51 | 51 | * Set Stripe customer ID. |
| 52 | 52 | * @param [type] $id [description] |
| 53 | 53 | */ |
| 54 | - public function set_id( $id ) { |
|
| 54 | + public function set_id($id) { |
|
| 55 | 55 | // Backwards compat for customer ID stored in array format. (Pre 3.0) |
| 56 | - if ( is_array( $id ) && isset( $id['customer_id'] ) ) { |
|
| 56 | + if (is_array($id) && isset($id['customer_id'])) { |
|
| 57 | 57 | $id = $id['customer_id']; |
| 58 | 58 | |
| 59 | - $this->update_id_in_meta( $id ); |
|
| 59 | + $this->update_id_in_meta($id); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $this->id = wc_clean( $id ); |
|
| 62 | + $this->id = wc_clean($id); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return int |
| 68 | 68 | */ |
| 69 | 69 | public function get_user_id() { |
| 70 | - return absint( $this->user_id ); |
|
| 70 | + return absint($this->user_id); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Set User ID used by WordPress. |
| 75 | 75 | * @param int $user_id |
| 76 | 76 | */ |
| 77 | - public function set_user_id( $user_id ) { |
|
| 78 | - $this->user_id = absint( $user_id ); |
|
| 77 | + public function set_user_id($user_id) { |
|
| 78 | + $this->user_id = absint($user_id); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | * @return WP_User |
| 84 | 84 | */ |
| 85 | 85 | protected function get_user() { |
| 86 | - return $this->get_user_id() ? get_user_by( 'id', $this->get_user_id() ) : false; |
|
| 86 | + return $this->get_user_id() ? get_user_by('id', $this->get_user_id()) : false; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * Store data from the Stripe API about this customer |
| 91 | 91 | */ |
| 92 | - public function set_customer_data( $data ) { |
|
| 92 | + public function set_customer_data($data) { |
|
| 93 | 93 | $this->customer_data = $data; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -99,37 +99,37 @@ discard block |
||
| 99 | 99 | * @param array $args Additional arguments (optional). |
| 100 | 100 | * @return array |
| 101 | 101 | */ |
| 102 | - protected function generate_customer_request( $args = array() ) { |
|
| 103 | - $billing_email = isset( $_POST['billing_email'] ) ? filter_var( $_POST['billing_email'], FILTER_SANITIZE_EMAIL ) : ''; |
|
| 102 | + protected function generate_customer_request($args = array()) { |
|
| 103 | + $billing_email = isset($_POST['billing_email']) ? filter_var($_POST['billing_email'], FILTER_SANITIZE_EMAIL) : ''; |
|
| 104 | 104 | $user = $this->get_user(); |
| 105 | 105 | |
| 106 | - if ( $user ) { |
|
| 107 | - $billing_first_name = get_user_meta( $user->ID, 'billing_first_name', true ); |
|
| 108 | - $billing_last_name = get_user_meta( $user->ID, 'billing_last_name', true ); |
|
| 106 | + if ($user) { |
|
| 107 | + $billing_first_name = get_user_meta($user->ID, 'billing_first_name', true); |
|
| 108 | + $billing_last_name = get_user_meta($user->ID, 'billing_last_name', true); |
|
| 109 | 109 | |
| 110 | 110 | // If billing first name does not exists try the user first name. |
| 111 | - if ( empty( $billing_first_name ) ) { |
|
| 112 | - $billing_first_name = get_user_meta( $user->ID, 'first_name', true ); |
|
| 111 | + if (empty($billing_first_name)) { |
|
| 112 | + $billing_first_name = get_user_meta($user->ID, 'first_name', true); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // If billing last name does not exists try the user last name. |
| 116 | - if ( empty( $billing_last_name ) ) { |
|
| 117 | - $billing_last_name = get_user_meta( $user->ID, 'last_name', true ); |
|
| 116 | + if (empty($billing_last_name)) { |
|
| 117 | + $billing_last_name = get_user_meta($user->ID, 'last_name', true); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // translators: %1$s First name, %2$s Second name, %3$s Username. |
| 121 | - $description = sprintf( __( 'Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name, $user->user_login ); |
|
| 121 | + $description = sprintf(__('Name: %1$s %2$s, Username: %s', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name, $user->user_login); |
|
| 122 | 122 | |
| 123 | 123 | $defaults = array( |
| 124 | 124 | 'email' => $user->user_email, |
| 125 | 125 | 'description' => $description, |
| 126 | 126 | ); |
| 127 | 127 | } else { |
| 128 | - $billing_first_name = isset( $_POST['billing_first_name'] ) ? filter_var( wp_unslash( $_POST['billing_first_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 129 | - $billing_last_name = isset( $_POST['billing_last_name'] ) ? filter_var( wp_unslash( $_POST['billing_last_name'] ), FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 128 | + $billing_first_name = isset($_POST['billing_first_name']) ? filter_var(wp_unslash($_POST['billing_first_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 129 | + $billing_last_name = isset($_POST['billing_last_name']) ? filter_var(wp_unslash($_POST['billing_last_name']), FILTER_SANITIZE_STRING) : ''; // phpcs:ignore WordPress.Security.NonceVerification |
|
| 130 | 130 | |
| 131 | 131 | // translators: %1$s First name, %2$s Second name. |
| 132 | - $description = sprintf( __( 'Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe' ), $billing_first_name, $billing_last_name ); |
|
| 132 | + $description = sprintf(__('Name: %1$s %2$s, Guest', 'woocommerce-gateway-stripe'), $billing_first_name, $billing_last_name); |
|
| 133 | 133 | |
| 134 | 134 | $defaults = array( |
| 135 | 135 | 'email' => $billing_email, |
@@ -138,9 +138,9 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $metadata = array(); |
| 141 | - $defaults['metadata'] = apply_filters( 'wc_stripe_customer_metadata', $metadata, $user ); |
|
| 141 | + $defaults['metadata'] = apply_filters('wc_stripe_customer_metadata', $metadata, $user); |
|
| 142 | 142 | |
| 143 | - return wp_parse_args( $args, $defaults ); |
|
| 143 | + return wp_parse_args($args, $defaults); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -148,23 +148,23 @@ discard block |
||
| 148 | 148 | * @param array $args |
| 149 | 149 | * @return WP_Error|int |
| 150 | 150 | */ |
| 151 | - public function create_customer( $args = array() ) { |
|
| 152 | - $args = $this->generate_customer_request( $args ); |
|
| 153 | - $response = WC_Stripe_API::request( apply_filters( 'wc_stripe_create_customer_args', $args ), 'customers' ); |
|
| 151 | + public function create_customer($args = array()) { |
|
| 152 | + $args = $this->generate_customer_request($args); |
|
| 153 | + $response = WC_Stripe_API::request(apply_filters('wc_stripe_create_customer_args', $args), 'customers'); |
|
| 154 | 154 | |
| 155 | - if ( ! empty( $response->error ) ) { |
|
| 156 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 155 | + if ( ! empty($response->error)) { |
|
| 156 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $this->set_id( $response->id ); |
|
| 159 | + $this->set_id($response->id); |
|
| 160 | 160 | $this->clear_cache(); |
| 161 | - $this->set_customer_data( $response ); |
|
| 161 | + $this->set_customer_data($response); |
|
| 162 | 162 | |
| 163 | - if ( $this->get_user_id() ) { |
|
| 164 | - $this->update_id_in_meta( $response->id ); |
|
| 163 | + if ($this->get_user_id()) { |
|
| 164 | + $this->update_id_in_meta($response->id); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - do_action( 'woocommerce_stripe_add_customer', $args, $response ); |
|
| 167 | + do_action('woocommerce_stripe_add_customer', $args, $response); |
|
| 168 | 168 | |
| 169 | 169 | return $response->id; |
| 170 | 170 | } |
@@ -179,30 +179,30 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @throws WC_Stripe_Exception |
| 181 | 181 | */ |
| 182 | - public function update_customer( $args = array(), $is_retry = false ) { |
|
| 183 | - if ( empty( $this->get_id() ) ) { |
|
| 184 | - throw new WC_Stripe_Exception( 'id_required_to_update_user', __( 'Attempting to update a Stripe customer without a customer ID.', 'woocommerce-gateway-stripe' ) ); |
|
| 182 | + public function update_customer($args = array(), $is_retry = false) { |
|
| 183 | + if (empty($this->get_id())) { |
|
| 184 | + throw new WC_Stripe_Exception('id_required_to_update_user', __('Attempting to update a Stripe customer without a customer ID.', 'woocommerce-gateway-stripe')); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - $args = $this->generate_customer_request( $args ); |
|
| 188 | - $args = apply_filters( 'wc_stripe_update_customer_args', $args ); |
|
| 189 | - $response = WC_Stripe_API::request( $args, 'customers/' . $this->get_id() ); |
|
| 187 | + $args = $this->generate_customer_request($args); |
|
| 188 | + $args = apply_filters('wc_stripe_update_customer_args', $args); |
|
| 189 | + $response = WC_Stripe_API::request($args, 'customers/' . $this->get_id()); |
|
| 190 | 190 | |
| 191 | - if ( ! empty( $response->error ) ) { |
|
| 192 | - if ( $this->is_no_such_customer_error( $response->error ) && ! $is_retry ) { |
|
| 191 | + if ( ! empty($response->error)) { |
|
| 192 | + if ($this->is_no_such_customer_error($response->error) && ! $is_retry) { |
|
| 193 | 193 | // This can happen when switching the main Stripe account or importing users from another site. |
| 194 | 194 | // If not already retrying, recreate the customer and then try updating it again. |
| 195 | 195 | $this->recreate_customer(); |
| 196 | - return $this->update_customer( $args, true ); |
|
| 196 | + return $this->update_customer($args, true); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - throw new WC_Stripe_Exception( print_r( $response, true ), $response->error->message ); |
|
| 199 | + throw new WC_Stripe_Exception(print_r($response, true), $response->error->message); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | $this->clear_cache(); |
| 203 | - $this->set_customer_data( $response ); |
|
| 203 | + $this->set_customer_data($response); |
|
| 204 | 204 | |
| 205 | - do_action( 'woocommerce_stripe_update_customer', $args, $response ); |
|
| 205 | + do_action('woocommerce_stripe_update_customer', $args, $response); |
|
| 206 | 206 | |
| 207 | 207 | return $this->get_id(); |
| 208 | 208 | } |
@@ -214,11 +214,11 @@ discard block |
||
| 214 | 214 | * @since 4.1.2 |
| 215 | 215 | * @param array $error |
| 216 | 216 | */ |
| 217 | - public function is_no_such_customer_error( $error ) { |
|
| 217 | + public function is_no_such_customer_error($error) { |
|
| 218 | 218 | return ( |
| 219 | 219 | $error && |
| 220 | 220 | 'invalid_request_error' === $error->type && |
| 221 | - preg_match( '/No such customer/i', $error->message ) |
|
| 221 | + preg_match('/No such customer/i', $error->message) |
|
| 222 | 222 | ); |
| 223 | 223 | } |
| 224 | 224 | |
@@ -227,9 +227,9 @@ discard block |
||
| 227 | 227 | * @param string $source_id |
| 228 | 228 | * @return WP_Error|int |
| 229 | 229 | */ |
| 230 | - public function add_source( $source_id ) { |
|
| 231 | - if ( ! $this->get_id() ) { |
|
| 232 | - $this->set_id( $this->create_customer() ); |
|
| 230 | + public function add_source($source_id) { |
|
| 231 | + if ( ! $this->get_id()) { |
|
| 232 | + $this->set_id($this->create_customer()); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | $response = WC_Stripe_API::request( |
@@ -241,62 +241,62 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | $wc_token = false; |
| 243 | 243 | |
| 244 | - if ( ! empty( $response->error ) ) { |
|
| 244 | + if ( ! empty($response->error)) { |
|
| 245 | 245 | // It is possible the WC user once was linked to a customer on Stripe |
| 246 | 246 | // but no longer exists. Instead of failing, lets try to create a |
| 247 | 247 | // new customer. |
| 248 | - if ( $this->is_no_such_customer_error( $response->error ) ) { |
|
| 248 | + if ($this->is_no_such_customer_error($response->error)) { |
|
| 249 | 249 | $this->recreate_customer(); |
| 250 | - return $this->add_source( $source_id ); |
|
| 250 | + return $this->add_source($source_id); |
|
| 251 | 251 | } else { |
| 252 | 252 | return $response; |
| 253 | 253 | } |
| 254 | - } elseif ( empty( $response->id ) ) { |
|
| 255 | - return new WP_Error( 'error', __( 'Unable to add payment source.', 'woocommerce-gateway-stripe' ) ); |
|
| 254 | + } elseif (empty($response->id)) { |
|
| 255 | + return new WP_Error('error', __('Unable to add payment source.', 'woocommerce-gateway-stripe')); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | // Add token to WooCommerce. |
| 259 | - if ( $this->get_user_id() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 260 | - if ( ! empty( $response->type ) ) { |
|
| 261 | - switch ( $response->type ) { |
|
| 259 | + if ($this->get_user_id() && class_exists('WC_Payment_Token_CC')) { |
|
| 260 | + if ( ! empty($response->type)) { |
|
| 261 | + switch ($response->type) { |
|
| 262 | 262 | case 'alipay': |
| 263 | 263 | break; |
| 264 | 264 | case 'sepa_debit': |
| 265 | 265 | $wc_token = new WC_Payment_Token_SEPA(); |
| 266 | - $wc_token->set_token( $response->id ); |
|
| 267 | - $wc_token->set_gateway_id( 'stripe_sepa' ); |
|
| 268 | - $wc_token->set_last4( $response->sepa_debit->last4 ); |
|
| 266 | + $wc_token->set_token($response->id); |
|
| 267 | + $wc_token->set_gateway_id('stripe_sepa'); |
|
| 268 | + $wc_token->set_last4($response->sepa_debit->last4); |
|
| 269 | 269 | break; |
| 270 | 270 | default: |
| 271 | - if ( 'source' === $response->object && 'card' === $response->type ) { |
|
| 271 | + if ('source' === $response->object && 'card' === $response->type) { |
|
| 272 | 272 | $wc_token = new WC_Payment_Token_CC(); |
| 273 | - $wc_token->set_token( $response->id ); |
|
| 274 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 275 | - $wc_token->set_card_type( strtolower( $response->card->brand ) ); |
|
| 276 | - $wc_token->set_last4( $response->card->last4 ); |
|
| 277 | - $wc_token->set_expiry_month( $response->card->exp_month ); |
|
| 278 | - $wc_token->set_expiry_year( $response->card->exp_year ); |
|
| 273 | + $wc_token->set_token($response->id); |
|
| 274 | + $wc_token->set_gateway_id('stripe'); |
|
| 275 | + $wc_token->set_card_type(strtolower($response->card->brand)); |
|
| 276 | + $wc_token->set_last4($response->card->last4); |
|
| 277 | + $wc_token->set_expiry_month($response->card->exp_month); |
|
| 278 | + $wc_token->set_expiry_year($response->card->exp_year); |
|
| 279 | 279 | } |
| 280 | 280 | break; |
| 281 | 281 | } |
| 282 | 282 | } else { |
| 283 | 283 | // Legacy. |
| 284 | 284 | $wc_token = new WC_Payment_Token_CC(); |
| 285 | - $wc_token->set_token( $response->id ); |
|
| 286 | - $wc_token->set_gateway_id( 'stripe' ); |
|
| 287 | - $wc_token->set_card_type( strtolower( $response->brand ) ); |
|
| 288 | - $wc_token->set_last4( $response->last4 ); |
|
| 289 | - $wc_token->set_expiry_month( $response->exp_month ); |
|
| 290 | - $wc_token->set_expiry_year( $response->exp_year ); |
|
| 285 | + $wc_token->set_token($response->id); |
|
| 286 | + $wc_token->set_gateway_id('stripe'); |
|
| 287 | + $wc_token->set_card_type(strtolower($response->brand)); |
|
| 288 | + $wc_token->set_last4($response->last4); |
|
| 289 | + $wc_token->set_expiry_month($response->exp_month); |
|
| 290 | + $wc_token->set_expiry_year($response->exp_year); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - $wc_token->set_user_id( $this->get_user_id() ); |
|
| 293 | + $wc_token->set_user_id($this->get_user_id()); |
|
| 294 | 294 | $wc_token->save(); |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | $this->clear_cache(); |
| 298 | 298 | |
| 299 | - do_action( 'woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id ); |
|
| 299 | + do_action('woocommerce_stripe_add_source', $this->get_id(), $wc_token, $response, $source_id); |
|
| 300 | 300 | |
| 301 | 301 | return $response->id; |
| 302 | 302 | } |
@@ -308,13 +308,13 @@ discard block |
||
| 308 | 308 | * @return array |
| 309 | 309 | */ |
| 310 | 310 | public function get_sources() { |
| 311 | - if ( ! $this->get_id() ) { |
|
| 311 | + if ( ! $this->get_id()) { |
|
| 312 | 312 | return array(); |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - $sources = get_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 315 | + $sources = get_transient('stripe_sources_' . $this->get_id()); |
|
| 316 | 316 | |
| 317 | - if ( false === $sources ) { |
|
| 317 | + if (false === $sources) { |
|
| 318 | 318 | $response = WC_Stripe_API::request( |
| 319 | 319 | array( |
| 320 | 320 | 'limit' => 100, |
@@ -323,35 +323,35 @@ discard block |
||
| 323 | 323 | 'GET' |
| 324 | 324 | ); |
| 325 | 325 | |
| 326 | - if ( ! empty( $response->error ) ) { |
|
| 326 | + if ( ! empty($response->error)) { |
|
| 327 | 327 | return array(); |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - if ( is_array( $response->data ) ) { |
|
| 330 | + if (is_array($response->data)) { |
|
| 331 | 331 | $sources = $response->data; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - set_transient( 'stripe_sources_' . $this->get_id(), $sources, DAY_IN_SECONDS ); |
|
| 334 | + set_transient('stripe_sources_' . $this->get_id(), $sources, DAY_IN_SECONDS); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - return empty( $sources ) ? array() : $sources; |
|
| 337 | + return empty($sources) ? array() : $sources; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
| 341 | 341 | * Delete a source from stripe. |
| 342 | 342 | * @param string $source_id |
| 343 | 343 | */ |
| 344 | - public function delete_source( $source_id ) { |
|
| 345 | - if ( ! $this->get_id() ) { |
|
| 344 | + public function delete_source($source_id) { |
|
| 345 | + if ( ! $this->get_id()) { |
|
| 346 | 346 | return false; |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - $response = WC_Stripe_API::request( array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field( $source_id ), 'DELETE' ); |
|
| 349 | + $response = WC_Stripe_API::request(array(), 'customers/' . $this->get_id() . '/sources/' . sanitize_text_field($source_id), 'DELETE'); |
|
| 350 | 350 | |
| 351 | 351 | $this->clear_cache(); |
| 352 | 352 | |
| 353 | - if ( empty( $response->error ) ) { |
|
| 354 | - do_action( 'wc_stripe_delete_source', $this->get_id(), $response ); |
|
| 353 | + if (empty($response->error)) { |
|
| 354 | + do_action('wc_stripe_delete_source', $this->get_id(), $response); |
|
| 355 | 355 | |
| 356 | 356 | return true; |
| 357 | 357 | } |
@@ -363,10 +363,10 @@ discard block |
||
| 363 | 363 | * Set default source in Stripe |
| 364 | 364 | * @param string $source_id |
| 365 | 365 | */ |
| 366 | - public function set_default_source( $source_id ) { |
|
| 366 | + public function set_default_source($source_id) { |
|
| 367 | 367 | $response = WC_Stripe_API::request( |
| 368 | 368 | array( |
| 369 | - 'default_source' => sanitize_text_field( $source_id ), |
|
| 369 | + 'default_source' => sanitize_text_field($source_id), |
|
| 370 | 370 | ), |
| 371 | 371 | 'customers/' . $this->get_id(), |
| 372 | 372 | 'POST' |
@@ -374,8 +374,8 @@ discard block |
||
| 374 | 374 | |
| 375 | 375 | $this->clear_cache(); |
| 376 | 376 | |
| 377 | - if ( empty( $response->error ) ) { |
|
| 378 | - do_action( 'wc_stripe_set_default_source', $this->get_id(), $response ); |
|
| 377 | + if (empty($response->error)) { |
|
| 378 | + do_action('wc_stripe_set_default_source', $this->get_id(), $response); |
|
| 379 | 379 | |
| 380 | 380 | return true; |
| 381 | 381 | } |
@@ -387,8 +387,8 @@ discard block |
||
| 387 | 387 | * Deletes caches for this users cards. |
| 388 | 388 | */ |
| 389 | 389 | public function clear_cache() { |
| 390 | - delete_transient( 'stripe_sources_' . $this->get_id() ); |
|
| 391 | - delete_transient( 'stripe_customer_' . $this->get_id() ); |
|
| 390 | + delete_transient('stripe_sources_' . $this->get_id()); |
|
| 391 | + delete_transient('stripe_customer_' . $this->get_id()); |
|
| 392 | 392 | $this->customer_data = array(); |
| 393 | 393 | } |
| 394 | 394 | |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | * @param int $user_id The ID of the WordPress user. |
| 399 | 399 | * @return string|bool Either the Stripe ID or false. |
| 400 | 400 | */ |
| 401 | - public function get_id_from_meta( $user_id ) { |
|
| 402 | - return get_user_option( '_stripe_customer_id', $user_id ); |
|
| 401 | + public function get_id_from_meta($user_id) { |
|
| 402 | + return get_user_option('_stripe_customer_id', $user_id); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -407,15 +407,15 @@ discard block |
||
| 407 | 407 | * |
| 408 | 408 | * @param string $id The Stripe customer ID. |
| 409 | 409 | */ |
| 410 | - public function update_id_in_meta( $id ) { |
|
| 411 | - update_user_option( $this->get_user_id(), '_stripe_customer_id', $id, false ); |
|
| 410 | + public function update_id_in_meta($id) { |
|
| 411 | + update_user_option($this->get_user_id(), '_stripe_customer_id', $id, false); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
| 415 | 415 | * Deletes the user ID from the meta table with the right key. |
| 416 | 416 | */ |
| 417 | 417 | public function delete_id_from_meta() { |
| 418 | - delete_user_option( $this->get_user_id(), '_stripe_customer_id', false ); |
|
| 418 | + delete_user_option($this->get_user_id(), '_stripe_customer_id', false); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | /** |