@@ -2,12 +2,12 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class WC_Stripe_Test extends WP_UnitTestCase { |
| 4 | 4 | public function test_constants_defined() { |
| 5 | - $this->assertTrue( defined( 'WC_STRIPE_VERSION' ) ); |
|
| 6 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_PHP_VER' ) ); |
|
| 7 | - $this->assertTrue( defined( 'WC_STRIPE_MIN_WC_VER' ) ); |
|
| 8 | - $this->assertTrue( defined( 'WC_STRIPE_MAIN_FILE' ) ); |
|
| 9 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_URL' ) ); |
|
| 10 | - $this->assertTrue( defined( 'WC_STRIPE_PLUGIN_PATH' ) ); |
|
| 5 | + $this->assertTrue(defined('WC_STRIPE_VERSION')); |
|
| 6 | + $this->assertTrue(defined('WC_STRIPE_MIN_PHP_VER')); |
|
| 7 | + $this->assertTrue(defined('WC_STRIPE_MIN_WC_VER')); |
|
| 8 | + $this->assertTrue(defined('WC_STRIPE_MAIN_FILE')); |
|
| 9 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_URL')); |
|
| 10 | + $this->assertTrue(defined('WC_STRIPE_PLUGIN_PATH')); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | * This test will see if we're indeed converting the price correctly. |
| 16 | 16 | */ |
| 17 | 17 | public function test_price_conversion_before_send_to_stripe() { |
| 18 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
| 19 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 10050, 'JPY' ) ); |
|
| 20 | - $this->assertEquals( 100, WC_Stripe_Helper::get_stripe_amount( 100.50, 'JPY' ) ); |
|
| 21 | - $this->assertEquals( 10050, WC_Stripe_Helper::get_stripe_amount( 100.50 ) ); |
|
| 22 | - $this->assertInternalType( 'int', WC_Stripe_Helper::get_stripe_amount( 100.50, 'USD' ) ); |
|
| 18 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
| 19 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(10050, 'JPY')); |
|
| 20 | + $this->assertEquals(100, WC_Stripe_Helper::get_stripe_amount(100.50, 'JPY')); |
|
| 21 | + $this->assertEquals(10050, WC_Stripe_Helper::get_stripe_amount(100.50)); |
|
| 22 | + $this->assertInternalType('int', WC_Stripe_Helper::get_stripe_amount(100.50, 'USD')); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -33,37 +33,37 @@ discard block |
||
| 33 | 33 | $balance_fee1->net = 10000; |
| 34 | 34 | $balance_fee1->currency = 'USD'; |
| 35 | 35 | |
| 36 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee1, 'fee' ) ); |
|
| 36 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee1, 'fee')); |
|
| 37 | 37 | |
| 38 | 38 | $balance_fee2 = new stdClass(); |
| 39 | 39 | $balance_fee2->fee = 10500; |
| 40 | 40 | $balance_fee2->net = 10000; |
| 41 | 41 | $balance_fee2->currency = 'JPY'; |
| 42 | 42 | |
| 43 | - $this->assertEquals( 10500, WC_Stripe_Helper::format_balance_fee( $balance_fee2, 'fee' ) ); |
|
| 43 | + $this->assertEquals(10500, WC_Stripe_Helper::format_balance_fee($balance_fee2, 'fee')); |
|
| 44 | 44 | |
| 45 | 45 | $balance_fee3 = new stdClass(); |
| 46 | 46 | $balance_fee3->fee = 10500; |
| 47 | 47 | $balance_fee3->net = 10000; |
| 48 | 48 | $balance_fee3->currency = 'USD'; |
| 49 | 49 | |
| 50 | - $this->assertEquals( 100.00, WC_Stripe_Helper::format_balance_fee( $balance_fee3, 'net' ) ); |
|
| 50 | + $this->assertEquals(100.00, WC_Stripe_Helper::format_balance_fee($balance_fee3, 'net')); |
|
| 51 | 51 | |
| 52 | 52 | $balance_fee4 = new stdClass(); |
| 53 | 53 | $balance_fee4->fee = 10500; |
| 54 | 54 | $balance_fee4->net = 10000; |
| 55 | 55 | $balance_fee4->currency = 'JPY'; |
| 56 | 56 | |
| 57 | - $this->assertEquals( 10000, WC_Stripe_Helper::format_balance_fee( $balance_fee4, 'net' ) ); |
|
| 57 | + $this->assertEquals(10000, WC_Stripe_Helper::format_balance_fee($balance_fee4, 'net')); |
|
| 58 | 58 | |
| 59 | 59 | $balance_fee5 = new stdClass(); |
| 60 | 60 | $balance_fee5->fee = 10500; |
| 61 | 61 | $balance_fee5->net = 10000; |
| 62 | 62 | $balance_fee5->currency = 'USD'; |
| 63 | 63 | |
| 64 | - $this->assertEquals( 105.00, WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
| 64 | + $this->assertEquals(105.00, WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
| 65 | 65 | |
| 66 | - $this->assertInternalType( 'string', WC_Stripe_Helper::format_balance_fee( $balance_fee5 ) ); |
|
| 66 | + $this->assertInternalType('string', WC_Stripe_Helper::format_balance_fee($balance_fee5)); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -76,27 +76,27 @@ discard block |
||
| 76 | 76 | 'expected' => 'Tests Store', |
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | - $this->assertEquals( $statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor1['actual'] ) ); |
|
| 79 | + $this->assertEquals($statement_descriptor1['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor1['actual'])); |
|
| 80 | 80 | |
| 81 | 81 | $statement_descriptor2 = array( |
| 82 | 82 | 'actual' => 'Test\'s Store > Driving Course Range', |
| 83 | 83 | 'expected' => 'Tests Store Driving C', |
| 84 | 84 | ); |
| 85 | 85 | |
| 86 | - $this->assertEquals( $statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor2['actual'] ) ); |
|
| 86 | + $this->assertEquals($statement_descriptor2['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor2['actual'])); |
|
| 87 | 87 | |
| 88 | 88 | $statement_descriptor3 = array( |
| 89 | 89 | 'actual' => 'Test\'s Store < Driving Course Range', |
| 90 | 90 | 'expected' => 'Tests Store Driving C', |
| 91 | 91 | ); |
| 92 | 92 | |
| 93 | - $this->assertEquals( $statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor3['actual'] ) ); |
|
| 93 | + $this->assertEquals($statement_descriptor3['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor3['actual'])); |
|
| 94 | 94 | |
| 95 | 95 | $statement_descriptor4 = array( |
| 96 | 96 | 'actual' => 'Test\'s Store " Driving Course Range', |
| 97 | 97 | 'expected' => 'Tests Store Driving C', |
| 98 | 98 | ); |
| 99 | 99 | |
| 100 | - $this->assertEquals( $statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor4['actual'] ) ); |
|
| 100 | + $this->assertEquals($statement_descriptor4['expected'], WC_Stripe_Helper::clean_statement_descriptor($statement_descriptor4['actual'])); |
|
| 101 | 101 | } |
| 102 | 102 | } |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * DEPRECATED DO NOT USE!! |
| 8 | 8 | */ |
| 9 | -if ( ! class_exists( 'WC_Stripe_Apple_Pay' ) ) { |
|
| 9 | +if ( ! class_exists('WC_Stripe_Apple_Pay')) { |
|
| 10 | 10 | class WC_Stripe_Apple_Pay { |
| 11 | 11 | /** |
| 12 | 12 | * This Instance. |
@@ -20,15 +20,15 @@ discard block |
||
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public static function instance() { |
| 23 | - WC_Stripe_Logger::log( 'DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 4.2' ); |
|
| 23 | + WC_Stripe_Logger::log('DEPRECATED! WC_Stripe_Apple_Pay class has been hard deprecated. Please remove any code that references this class or instance. This class will be removed by version 4.2'); |
|
| 24 | 24 | return self::$_this; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - public function __get( $var ) { |
|
| 27 | + public function __get($var) { |
|
| 28 | 28 | return null; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function __call( $name, $arguments ) { |
|
| 31 | + public function __call($name, $arguments) { |
|
| 32 | 32 | return null; |
| 33 | 33 | } |
| 34 | 34 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | public function __construct() { |
| 22 | 22 | self::$_this = $this; |
| 23 | 23 | |
| 24 | - add_filter( 'woocommerce_get_customer_payment_tokens', array( $this, 'woocommerce_get_customer_payment_tokens' ), 10, 3 ); |
|
| 25 | - add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'get_account_saved_payment_methods_list_item_sepa' ), 10, 2 ); |
|
| 26 | - add_filter( 'woocommerce_get_credit_card_type_label', array( $this, 'normalize_sepa_label' ) ); |
|
| 27 | - add_action( 'woocommerce_payment_token_deleted', array( $this, 'woocommerce_payment_token_deleted' ), 10, 2 ); |
|
| 28 | - add_action( 'woocommerce_payment_token_set_default', array( $this, 'woocommerce_payment_token_set_default' ) ); |
|
| 24 | + add_filter('woocommerce_get_customer_payment_tokens', array($this, 'woocommerce_get_customer_payment_tokens'), 10, 3); |
|
| 25 | + add_filter('woocommerce_payment_methods_list_item', array($this, 'get_account_saved_payment_methods_list_item_sepa'), 10, 2); |
|
| 26 | + add_filter('woocommerce_get_credit_card_type_label', array($this, 'normalize_sepa_label')); |
|
| 27 | + add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted'), 10, 2); |
|
| 28 | + add_action('woocommerce_payment_token_set_default', array($this, 'woocommerce_payment_token_set_default')); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | * @param string $label |
| 47 | 47 | * @return string $label |
| 48 | 48 | */ |
| 49 | - public function normalize_sepa_label( $label ) { |
|
| 50 | - if ( 'sepa iban' === strtolower( $label ) ) { |
|
| 49 | + public function normalize_sepa_label($label) { |
|
| 50 | + if ('sepa iban' === strtolower($label)) { |
|
| 51 | 51 | return 'SEPA IBAN'; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -61,19 +61,19 @@ discard block |
||
| 61 | 61 | * @param int $customer_id |
| 62 | 62 | * @return bool |
| 63 | 63 | */ |
| 64 | - public static function customer_has_saved_methods( $customer_id ) { |
|
| 65 | - $gateways = array( 'stripe', 'stripe_sepa' ); |
|
| 64 | + public static function customer_has_saved_methods($customer_id) { |
|
| 65 | + $gateways = array('stripe', 'stripe_sepa'); |
|
| 66 | 66 | |
| 67 | - if ( empty( $customer_id ) ) { |
|
| 67 | + if (empty($customer_id)) { |
|
| 68 | 68 | return false; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $has_token = false; |
| 72 | 72 | |
| 73 | - foreach ( $gateways as $gateway ) { |
|
| 74 | - $tokens = WC_Payment_Tokens::get_customer_tokens( $customer_id, $gateway ); |
|
| 73 | + foreach ($gateways as $gateway) { |
|
| 74 | + $tokens = WC_Payment_Tokens::get_customer_tokens($customer_id, $gateway); |
|
| 75 | 75 | |
| 76 | - if ( ! empty( $tokens ) ) { |
|
| 76 | + if ( ! empty($tokens)) { |
|
| 77 | 77 | $has_token = true; |
| 78 | 78 | break; |
| 79 | 79 | } |
@@ -90,67 +90,67 @@ discard block |
||
| 90 | 90 | * @param array $tokens |
| 91 | 91 | * @return array |
| 92 | 92 | */ |
| 93 | - public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) { |
|
| 94 | - if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 93 | + public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) { |
|
| 94 | + if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) { |
|
| 95 | 95 | $stored_tokens = array(); |
| 96 | 96 | |
| 97 | - foreach ( $tokens as $token ) { |
|
| 97 | + foreach ($tokens as $token) { |
|
| 98 | 98 | $stored_tokens[] = $token->get_token(); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - if ( 'stripe' === $gateway_id ) { |
|
| 102 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 101 | + if ('stripe' === $gateway_id) { |
|
| 102 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 103 | 103 | $stripe_sources = $stripe_customer->get_sources(); |
| 104 | 104 | |
| 105 | - foreach ( $stripe_sources as $source ) { |
|
| 106 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 107 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
| 105 | + foreach ($stripe_sources as $source) { |
|
| 106 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 107 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
| 108 | 108 | $token = new WC_Payment_Token_CC(); |
| 109 | - $token->set_token( $source->id ); |
|
| 110 | - $token->set_gateway_id( 'stripe' ); |
|
| 111 | - |
|
| 112 | - if ( 'source' === $source->object && 'card' === $source->type ) { |
|
| 113 | - $token->set_card_type( strtolower( $source->card->brand ) ); |
|
| 114 | - $token->set_last4( $source->card->last4 ); |
|
| 115 | - $token->set_expiry_month( $source->card->exp_month ); |
|
| 116 | - $token->set_expiry_year( $source->card->exp_year ); |
|
| 109 | + $token->set_token($source->id); |
|
| 110 | + $token->set_gateway_id('stripe'); |
|
| 111 | + |
|
| 112 | + if ('source' === $source->object && 'card' === $source->type) { |
|
| 113 | + $token->set_card_type(strtolower($source->card->brand)); |
|
| 114 | + $token->set_last4($source->card->last4); |
|
| 115 | + $token->set_expiry_month($source->card->exp_month); |
|
| 116 | + $token->set_expiry_year($source->card->exp_year); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $token->set_user_id( $customer_id ); |
|
| 119 | + $token->set_user_id($customer_id); |
|
| 120 | 120 | $token->save(); |
| 121 | - $tokens[ $token->get_id() ] = $token; |
|
| 121 | + $tokens[$token->get_id()] = $token; |
|
| 122 | 122 | } |
| 123 | 123 | } else { |
| 124 | - if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) { |
|
| 124 | + if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) { |
|
| 125 | 125 | $token = new WC_Payment_Token_CC(); |
| 126 | - $token->set_token( $source->id ); |
|
| 127 | - $token->set_gateway_id( 'stripe' ); |
|
| 128 | - $token->set_card_type( strtolower( $source->brand ) ); |
|
| 129 | - $token->set_last4( $source->last4 ); |
|
| 130 | - $token->set_expiry_month( $source->exp_month ); |
|
| 131 | - $token->set_expiry_year( $source->exp_year ); |
|
| 132 | - $token->set_user_id( $customer_id ); |
|
| 126 | + $token->set_token($source->id); |
|
| 127 | + $token->set_gateway_id('stripe'); |
|
| 128 | + $token->set_card_type(strtolower($source->brand)); |
|
| 129 | + $token->set_last4($source->last4); |
|
| 130 | + $token->set_expiry_month($source->exp_month); |
|
| 131 | + $token->set_expiry_year($source->exp_year); |
|
| 132 | + $token->set_user_id($customer_id); |
|
| 133 | 133 | $token->save(); |
| 134 | - $tokens[ $token->get_id() ] = $token; |
|
| 134 | + $tokens[$token->get_id()] = $token; |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ( 'stripe_sepa' === $gateway_id ) { |
|
| 141 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 140 | + if ('stripe_sepa' === $gateway_id) { |
|
| 141 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 142 | 142 | $stripe_sources = $stripe_customer->get_sources(); |
| 143 | 143 | |
| 144 | - foreach ( $stripe_sources as $source ) { |
|
| 145 | - if ( isset( $source->type ) && 'sepa_debit' === $source->type ) { |
|
| 146 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
| 144 | + foreach ($stripe_sources as $source) { |
|
| 145 | + if (isset($source->type) && 'sepa_debit' === $source->type) { |
|
| 146 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
| 147 | 147 | $token = new WC_Payment_Token_SEPA(); |
| 148 | - $token->set_token( $source->id ); |
|
| 149 | - $token->set_gateway_id( 'stripe_sepa' ); |
|
| 150 | - $token->set_last4( $source->sepa_debit->last4 ); |
|
| 151 | - $token->set_user_id( $customer_id ); |
|
| 148 | + $token->set_token($source->id); |
|
| 149 | + $token->set_gateway_id('stripe_sepa'); |
|
| 150 | + $token->set_last4($source->sepa_debit->last4); |
|
| 151 | + $token->set_user_id($customer_id); |
|
| 152 | 152 | $token->save(); |
| 153 | - $tokens[ $token->get_id() ] = $token; |
|
| 153 | + $tokens[$token->get_id()] = $token; |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | } |
@@ -169,10 +169,10 @@ discard block |
||
| 169 | 169 | * @param WC_Payment_Token $payment_token The payment token associated with this method entry |
| 170 | 170 | * @return array Filtered item |
| 171 | 171 | */ |
| 172 | - public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) { |
|
| 173 | - if ( 'sepa' === strtolower( $payment_token->get_type() ) ) { |
|
| 172 | + public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) { |
|
| 173 | + if ('sepa' === strtolower($payment_token->get_type())) { |
|
| 174 | 174 | $item['method']['last4'] = $payment_token->get_last4(); |
| 175 | - $item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' ); |
|
| 175 | + $item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe'); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return $item; |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | * @since 3.1.0 |
| 185 | 185 | * @version 4.0.0 |
| 186 | 186 | */ |
| 187 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
| 188 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
| 189 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 190 | - $stripe_customer->delete_source( $token->get_token() ); |
|
| 187 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
| 188 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
| 189 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 190 | + $stripe_customer->delete_source($token->get_token()); |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |
@@ -197,12 +197,12 @@ discard block |
||
| 197 | 197 | * @since 3.1.0 |
| 198 | 198 | * @version 4.0.0 |
| 199 | 199 | */ |
| 200 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
| 201 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 200 | + public function woocommerce_payment_token_set_default($token_id) { |
|
| 201 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 202 | 202 | |
| 203 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
| 204 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 205 | - $stripe_customer->set_default_source( $token->get_token() ); |
|
| 203 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
| 204 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 205 | + $stripe_customer->set_default_source($token->get_token()); |
|
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | } |
@@ -1,27 +1,27 @@ |
||
| 1 | 1 | <?php |
| 2 | -$_tests_dir = getenv( 'WP_TESTS_DIR' ); |
|
| 3 | -if ( ! $_tests_dir ) { |
|
| 2 | +$_tests_dir = getenv('WP_TESTS_DIR'); |
|
| 3 | +if ( ! $_tests_dir) { |
|
| 4 | 4 | $_tests_dir = '/tmp/wordpress-tests-lib'; |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | require_once $_tests_dir . '/includes/functions.php'; |
| 8 | 8 | |
| 9 | 9 | function _manually_load_plugin() { |
| 10 | - $plugin_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/'; |
|
| 10 | + $plugin_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/'; |
|
| 11 | 11 | require $plugin_dir . 'woocommerce/woocommerce.php'; |
| 12 | 12 | require $plugin_dir . 'woocommerce-gateway-stripe/woocommerce-gateway-stripe.php'; |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); |
|
| 15 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); |
|
| 16 | 16 | |
| 17 | 17 | require $_tests_dir . '/includes/bootstrap.php'; |
| 18 | 18 | |
| 19 | -$wc_tests_framework_base_dir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/woocommerce/tests/framework/'; |
|
| 20 | -require_once( $wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php' ); |
|
| 19 | +$wc_tests_framework_base_dir = dirname(dirname(dirname(dirname(__FILE__)))) . '/woocommerce/tests/framework/'; |
|
| 20 | +require_once($wc_tests_framework_base_dir . 'class-wc-mock-session-handler.php'); |
|
| 21 | 21 | //require_once( $wc_tests_framework_base_dir . 'class-wc-unit-test-case.php' ); |
| 22 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php' ); |
|
| 23 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php' ); |
|
| 24 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php' ); |
|
| 25 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php' ); |
|
| 26 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php' ); |
|
| 27 | -require_once( $wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php' ); |
|
| 22 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-product.php'); |
|
| 23 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-coupon.php'); |
|
| 24 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-fee.php'); |
|
| 25 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-shipping.php'); |
|
| 26 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-customer.php'); |
|
| 27 | +require_once($wc_tests_framework_base_dir . 'helpers/class-wc-helper-order.php'); |
|
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | +if ( ! defined('ABSPATH')) { |
|
| 4 | 4 | exit; // Exit if accessed directly |
| 5 | 5 | } |
| 6 | 6 | |
@@ -35,10 +35,10 @@ discard block |
||
| 35 | 35 | * @param string $deprecated Deprecated since WooCommerce 3.0 |
| 36 | 36 | * @return string |
| 37 | 37 | */ |
| 38 | - public function get_display_name( $deprecated = '' ) { |
|
| 38 | + public function get_display_name($deprecated = '') { |
|
| 39 | 39 | $display = sprintf( |
| 40 | 40 | /* translators: last 4 digits of IBAN account */ |
| 41 | - __( 'SEPA IBAN ending in %s', 'woocommerce-gateway-stripe' ), |
|
| 41 | + __('SEPA IBAN ending in %s', 'woocommerce-gateway-stripe'), |
|
| 42 | 42 | $this->get_last4() |
| 43 | 43 | ); |
| 44 | 44 | |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | * @return boolean True if the passed data is valid |
| 67 | 67 | */ |
| 68 | 68 | public function validate() { |
| 69 | - if ( false === parent::validate() ) { |
|
| 69 | + if (false === parent::validate()) { |
|
| 70 | 70 | return false; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if ( ! $this->get_last4( 'edit' ) ) { |
|
| 73 | + if ( ! $this->get_last4('edit')) { |
|
| 74 | 74 | return false; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | * @param string $context |
| 86 | 86 | * @return string Last 4 digits |
| 87 | 87 | */ |
| 88 | - public function get_last4( $context = 'view' ) { |
|
| 89 | - return WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $this->get_meta( 'last4' ) : $this->get_prop( 'last4', $context ); |
|
| 88 | + public function get_last4($context = 'view') { |
|
| 89 | + return WC_Stripe_Helper::is_wc_lt('3.0') ? $this->get_meta('last4') : $this->get_prop('last4', $context); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @version 4.0.0 |
| 96 | 96 | * @param string $last4 |
| 97 | 97 | */ |
| 98 | - public function set_last4( $last4 ) { |
|
| 99 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $this->add_meta_data( 'last4', $last4, true ) : $this->set_prop( 'last4', $last4 ); |
|
| 98 | + public function set_last4($last4) { |
|
| 99 | + WC_Stripe_Helper::is_wc_lt('3.0') ? $this->add_meta_data('last4', $last4, true) : $this->set_prop('last4', $last4); |
|
| 100 | 100 | } |
| 101 | 101 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if ( ! defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -15,21 +15,21 @@ discard block |
||
| 15 | 15 | public function __construct() { |
| 16 | 16 | parent::__construct(); |
| 17 | 17 | |
| 18 | - if ( class_exists( 'WC_Subscriptions_Order' ) ) { |
|
| 19 | - add_action( 'woocommerce_scheduled_subscription_payment_' . $this->id, array( $this, 'scheduled_subscription_payment' ), 10, 2 ); |
|
| 20 | - add_action( 'wcs_resubscribe_order_created', array( $this, 'delete_resubscribe_meta' ), 10 ); |
|
| 21 | - add_action( 'wcs_renewal_order_created', array( $this, 'delete_renewal_meta' ), 10 ); |
|
| 22 | - add_action( 'woocommerce_subscription_failing_payment_method_updated_stripe', array( $this, 'update_failing_payment_method' ), 10, 2 ); |
|
| 23 | - add_action( 'wc_stripe_sepa_payment_fields', array( $this, 'display_update_subs_payment_checkout' ) ); |
|
| 24 | - add_action( 'wc_stripe_add_payment_method_' . $this->id . '_success', array( $this, 'handle_add_payment_method_success' ), 10, 2 ); |
|
| 18 | + if (class_exists('WC_Subscriptions_Order')) { |
|
| 19 | + add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2); |
|
| 20 | + add_action('wcs_resubscribe_order_created', array($this, 'delete_resubscribe_meta'), 10); |
|
| 21 | + add_action('wcs_renewal_order_created', array($this, 'delete_renewal_meta'), 10); |
|
| 22 | + add_action('woocommerce_subscription_failing_payment_method_updated_stripe', array($this, 'update_failing_payment_method'), 10, 2); |
|
| 23 | + add_action('wc_stripe_sepa_payment_fields', array($this, 'display_update_subs_payment_checkout')); |
|
| 24 | + add_action('wc_stripe_add_payment_method_' . $this->id . '_success', array($this, 'handle_add_payment_method_success'), 10, 2); |
|
| 25 | 25 | |
| 26 | 26 | // Display the credit card used for a subscription in the "My Subscriptions" table. |
| 27 | - add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_subscription_payment_method' ), 10, 2 ); |
|
| 27 | + add_filter('woocommerce_my_subscriptions_payment_method', array($this, 'maybe_render_subscription_payment_method'), 10, 2); |
|
| 28 | 28 | |
| 29 | 29 | // Allow store managers to manually set Stripe as the payment method on a subscription. |
| 30 | - add_filter( 'woocommerce_subscription_payment_meta', array( $this, 'add_subscription_payment_meta' ), 10, 2 ); |
|
| 31 | - add_filter( 'woocommerce_subscription_validate_payment_meta', array( $this, 'validate_subscription_payment_meta' ), 10, 2 ); |
|
| 32 | - add_filter( 'wc_stripe_display_save_payment_method_checkbox', array( $this, 'maybe_hide_save_checkbox' ) ); |
|
| 30 | + add_filter('woocommerce_subscription_payment_meta', array($this, 'add_subscription_payment_meta'), 10, 2); |
|
| 31 | + add_filter('woocommerce_subscription_validate_payment_meta', array($this, 'validate_subscription_payment_meta'), 10, 2); |
|
| 32 | + add_filter('wc_stripe_display_save_payment_method_checkbox', array($this, 'maybe_hide_save_checkbox')); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * @since 4.0.0 |
| 50 | 50 | * @version 4.0.0 |
| 51 | 51 | */ |
| 52 | - public function maybe_hide_save_checkbox( $display_tokenization ) { |
|
| 53 | - if ( WC_Subscriptions_Cart::cart_contains_subscription() ) { |
|
| 52 | + public function maybe_hide_save_checkbox($display_tokenization) { |
|
| 53 | + if (WC_Subscriptions_Cart::cart_contains_subscription()) { |
|
| 54 | 54 | return false; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * @param int $order_id |
| 63 | 63 | * @return boolean |
| 64 | 64 | */ |
| 65 | - public function has_subscription( $order_id ) { |
|
| 66 | - return ( function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_is_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) ) ); |
|
| 65 | + public function has_subscription($order_id) { |
|
| 66 | + return (function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id))); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @return bool |
| 74 | 74 | */ |
| 75 | 75 | public function is_subs_change_payment() { |
| 76 | - return ( isset( $_GET['pay_for_order'] ) && isset( $_GET['change_payment_method'] ) ); |
|
| 76 | + return (isset($_GET['pay_for_order']) && isset($_GET['change_payment_method'])); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function display_update_subs_payment_checkout() { |
| 86 | 86 | if ( |
| 87 | - apply_filters( 'wc_stripe_display_update_subs_payment_method_card_checkbox', true ) && |
|
| 88 | - wcs_user_has_subscription( get_current_user_id(), '', 'active' ) && |
|
| 87 | + apply_filters('wc_stripe_display_update_subs_payment_method_card_checkbox', true) && |
|
| 88 | + wcs_user_has_subscription(get_current_user_id(), '', 'active') && |
|
| 89 | 89 | is_add_payment_method_page() |
| 90 | 90 | ) { |
| 91 | 91 | printf( |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | <input id="wc-%1$s-update-subs-payment-method-card" name="wc-%1$s-update-subs-payment-method-card" type="checkbox" value="true" style="width:auto;" /> |
| 94 | 94 | <label for="wc-%1$s-update-subs-payment-method-card" style="display:inline;">%2$s</label> |
| 95 | 95 | </p>', |
| 96 | - esc_attr( $this->id ), |
|
| 97 | - esc_html( apply_filters( 'wc_stripe_save_to_subs_text', __( 'Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe' ) ) ) |
|
| 96 | + esc_attr($this->id), |
|
| 97 | + esc_html(apply_filters('wc_stripe_save_to_subs_text', __('Update the Payment Method used for all of my active subscriptions (optional).', 'woocommerce-gateway-stripe'))) |
|
| 98 | 98 | ); |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * @param string $source_id |
| 107 | 107 | * @param object $source_object |
| 108 | 108 | */ |
| 109 | - public function handle_add_payment_method_success( $source_id, $source_object ) { |
|
| 110 | - if ( isset( $_POST[ 'wc-' . $this->id . '-update-subs-payment-method-card' ] ) ) { |
|
| 109 | + public function handle_add_payment_method_success($source_id, $source_object) { |
|
| 110 | + if (isset($_POST['wc-' . $this->id . '-update-subs-payment-method-card'])) { |
|
| 111 | 111 | $all_subs = wcs_get_users_subscriptions(); |
| 112 | 112 | |
| 113 | - if ( ! empty( $all_subs ) ) { |
|
| 114 | - foreach ( $all_subs as $sub ) { |
|
| 115 | - if ( 'active' === $sub->get_status() ) { |
|
| 116 | - update_post_meta( $sub->get_id(), '_stripe_source_id', $source_id ); |
|
| 117 | - update_post_meta( $sub->get_id(), '_payment_method', $this->id ); |
|
| 118 | - update_post_meta( $sub->get_id(), '_payment_method_title', $this->method_title ); |
|
| 113 | + if ( ! empty($all_subs)) { |
|
| 114 | + foreach ($all_subs as $sub) { |
|
| 115 | + if ('active' === $sub->get_status()) { |
|
| 116 | + update_post_meta($sub->get_id(), '_stripe_source_id', $source_id); |
|
| 117 | + update_post_meta($sub->get_id(), '_payment_method', $this->id); |
|
| 118 | + update_post_meta($sub->get_id(), '_payment_method_title', $this->method_title); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -128,24 +128,24 @@ discard block |
||
| 128 | 128 | * @since 3.1.0 |
| 129 | 129 | * @version 4.0.0 |
| 130 | 130 | */ |
| 131 | - public function save_source_to_order( $order, $source ) { |
|
| 132 | - parent::save_source_to_order( $order, $source ); |
|
| 131 | + public function save_source_to_order($order, $source) { |
|
| 132 | + parent::save_source_to_order($order, $source); |
|
| 133 | 133 | |
| 134 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $order->id : $order->get_id(); |
|
| 134 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $order->id : $order->get_id(); |
|
| 135 | 135 | |
| 136 | 136 | // Also store it on the subscriptions being purchased or paid for in the order. |
| 137 | - if ( function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order_id ) ) { |
|
| 138 | - $subscriptions = wcs_get_subscriptions_for_order( $order_id ); |
|
| 139 | - } elseif ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order_id ) ) { |
|
| 140 | - $subscriptions = wcs_get_subscriptions_for_renewal_order( $order_id ); |
|
| 137 | + if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($order_id)) { |
|
| 138 | + $subscriptions = wcs_get_subscriptions_for_order($order_id); |
|
| 139 | + } elseif (function_exists('wcs_order_contains_renewal') && wcs_order_contains_renewal($order_id)) { |
|
| 140 | + $subscriptions = wcs_get_subscriptions_for_renewal_order($order_id); |
|
| 141 | 141 | } else { |
| 142 | 142 | $subscriptions = array(); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - foreach ( $subscriptions as $subscription ) { |
|
| 146 | - $subscription_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id(); |
|
| 147 | - update_post_meta( $subscription_id, '_stripe_customer_id', $source->customer ); |
|
| 148 | - update_post_meta( $subscription_id, '_stripe_source_id', $source->source ); |
|
| 145 | + foreach ($subscriptions as $subscription) { |
|
| 146 | + $subscription_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id(); |
|
| 147 | + update_post_meta($subscription_id, '_stripe_customer_id', $source->customer); |
|
| 148 | + update_post_meta($subscription_id, '_stripe_source_id', $source->source); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
@@ -154,16 +154,16 @@ discard block |
||
| 154 | 154 | * @param int $order_id |
| 155 | 155 | * @return array |
| 156 | 156 | */ |
| 157 | - public function process_payment( $order_id, $retry = true, $force_save_source = false, $previous_error = false ) { |
|
| 158 | - if ( $this->has_subscription( $order_id ) ) { |
|
| 159 | - if ( $this->is_subs_change_payment() ) { |
|
| 160 | - return $this->change_subs_payment_method( $order_id ); |
|
| 157 | + public function process_payment($order_id, $retry = true, $force_save_source = false, $previous_error = false) { |
|
| 158 | + if ($this->has_subscription($order_id)) { |
|
| 159 | + if ($this->is_subs_change_payment()) { |
|
| 160 | + return $this->change_subs_payment_method($order_id); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Regular payment with force customer enabled |
| 164 | - return parent::process_payment( $order_id, $retry, true, $previous_error ); |
|
| 164 | + return parent::process_payment($order_id, $retry, true, $previous_error); |
|
| 165 | 165 | } else { |
| 166 | - return parent::process_payment( $order_id, $retry, $force_save_source, $previous_error ); |
|
| 166 | + return parent::process_payment($order_id, $retry, $force_save_source, $previous_error); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
@@ -173,27 +173,27 @@ discard block |
||
| 173 | 173 | * @since 4.0.4 |
| 174 | 174 | * @param int $order_id |
| 175 | 175 | */ |
| 176 | - public function change_subs_payment_method( $order_id ) { |
|
| 176 | + public function change_subs_payment_method($order_id) { |
|
| 177 | 177 | try { |
| 178 | - $subscription = wc_get_order( $order_id ); |
|
| 179 | - $prepared_source = $this->prepare_source( get_current_user_id(), true ); |
|
| 178 | + $subscription = wc_get_order($order_id); |
|
| 179 | + $prepared_source = $this->prepare_source(get_current_user_id(), true); |
|
| 180 | 180 | |
| 181 | - if ( empty( $prepared_source->source ) ) { |
|
| 182 | - $localized_message = __( 'Payment processing failed. Please retry.', 'woocommerce-gateway-stripe' ); |
|
| 183 | - throw new WC_Stripe_Exception( print_r( $prepared_source, true ), $localized_message ); |
|
| 181 | + if (empty($prepared_source->source)) { |
|
| 182 | + $localized_message = __('Payment processing failed. Please retry.', 'woocommerce-gateway-stripe'); |
|
| 183 | + throw new WC_Stripe_Exception(print_r($prepared_source, true), $localized_message); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - $this->save_source_to_order( $subscription, $prepared_source ); |
|
| 186 | + $this->save_source_to_order($subscription, $prepared_source); |
|
| 187 | 187 | |
| 188 | - do_action( 'wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source ); |
|
| 188 | + do_action('wc_stripe_change_subs_payment_method_success', $prepared_source->source, $prepared_source); |
|
| 189 | 189 | |
| 190 | 190 | return array( |
| 191 | 191 | 'result' => 'success', |
| 192 | - 'redirect' => $this->get_return_url( $subscription ), |
|
| 192 | + 'redirect' => $this->get_return_url($subscription), |
|
| 193 | 193 | ); |
| 194 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 195 | - wc_add_notice( $e->getLocalizedMessage(), 'error' ); |
|
| 196 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 194 | + } catch (WC_Stripe_Exception $e) { |
|
| 195 | + wc_add_notice($e->getLocalizedMessage(), 'error'); |
|
| 196 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | * @param $amount_to_charge float The amount to charge. |
| 204 | 204 | * @param $renewal_order WC_Order A WC_Order object created to record the renewal payment. |
| 205 | 205 | */ |
| 206 | - public function scheduled_subscription_payment( $amount_to_charge, $renewal_order ) { |
|
| 207 | - $this->process_subscription_payment( $amount_to_charge, $renewal_order, true, false ); |
|
| 206 | + public function scheduled_subscription_payment($amount_to_charge, $renewal_order) { |
|
| 207 | + $this->process_subscription_payment($amount_to_charge, $renewal_order, true, false); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -218,86 +218,86 @@ discard block |
||
| 218 | 218 | * @param bool $retry Should we retry the process? |
| 219 | 219 | * @param object $previous_error |
| 220 | 220 | */ |
| 221 | - public function process_subscription_payment( $amount = 0.0, $renewal_order, $retry = true, $previous_error ) { |
|
| 221 | + public function process_subscription_payment($amount = 0.0, $renewal_order, $retry = true, $previous_error) { |
|
| 222 | 222 | try { |
| 223 | - if ( $amount * 100 < WC_Stripe_Helper::get_minimum_amount() ) { |
|
| 223 | + if ($amount * 100 < WC_Stripe_Helper::get_minimum_amount()) { |
|
| 224 | 224 | /* translators: minimum amount */ |
| 225 | - return new WP_Error( 'stripe_error', sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( WC_Stripe_Helper::get_minimum_amount() / 100 ) ) ); |
|
| 225 | + return new WP_Error('stripe_error', sprintf(__('Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe'), wc_price(WC_Stripe_Helper::get_minimum_amount() / 100))); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - $order_id = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $renewal_order->id : $renewal_order->get_id(); |
|
| 228 | + $order_id = WC_Stripe_Helper::is_wc_lt('3.0') ? $renewal_order->id : $renewal_order->get_id(); |
|
| 229 | 229 | |
| 230 | 230 | // Get source from order |
| 231 | - $prepared_source = $this->prepare_order_source( $renewal_order ); |
|
| 231 | + $prepared_source = $this->prepare_order_source($renewal_order); |
|
| 232 | 232 | $source_object = $prepared_source->source_object; |
| 233 | 233 | |
| 234 | - if ( ! $prepared_source->customer ) { |
|
| 235 | - return new WP_Error( 'stripe_error', __( 'Customer not found', 'woocommerce-gateway-stripe' ) ); |
|
| 234 | + if ( ! $prepared_source->customer) { |
|
| 235 | + return new WP_Error('stripe_error', __('Customer not found', 'woocommerce-gateway-stripe')); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - WC_Stripe_Logger::log( "Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}" ); |
|
| 238 | + WC_Stripe_Logger::log("Info: Begin processing subscription payment for order {$order_id} for the amount of {$amount}"); |
|
| 239 | 239 | |
| 240 | 240 | /* If we're doing a retry and source is chargeable, we need to pass |
| 241 | 241 | * a different idempotency key and retry for success. |
| 242 | 242 | */ |
| 243 | - if ( is_object( $source_object ) && empty( $source_object->error ) && $this->need_update_idempotency_key( $source_object, $previous_error ) ) { |
|
| 244 | - add_filter( 'wc_stripe_idempotency_key', array( $this, 'change_idempotency_key' ), 10, 2 ); |
|
| 243 | + if (is_object($source_object) && empty($source_object->error) && $this->need_update_idempotency_key($source_object, $previous_error)) { |
|
| 244 | + add_filter('wc_stripe_idempotency_key', array($this, 'change_idempotency_key'), 10, 2); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - if ( ( $this->is_no_such_source_error( $previous_error ) || $this->is_no_linked_source_error( $previous_error ) ) && apply_filters( 'wc_stripe_use_default_customer_source', true ) ) { |
|
| 247 | + if (($this->is_no_such_source_error($previous_error) || $this->is_no_linked_source_error($previous_error)) && apply_filters('wc_stripe_use_default_customer_source', true)) { |
|
| 248 | 248 | // Passing empty source will charge customer default. |
| 249 | 249 | $prepared_source->source = ''; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - $request = $this->generate_payment_request( $renewal_order, $prepared_source ); |
|
| 252 | + $request = $this->generate_payment_request($renewal_order, $prepared_source); |
|
| 253 | 253 | $request['capture'] = 'true'; |
| 254 | - $request['amount'] = WC_Stripe_Helper::get_stripe_amount( $amount, $request['currency'] ); |
|
| 255 | - $response = WC_Stripe_API::request( $request ); |
|
| 254 | + $request['amount'] = WC_Stripe_Helper::get_stripe_amount($amount, $request['currency']); |
|
| 255 | + $response = WC_Stripe_API::request($request); |
|
| 256 | 256 | |
| 257 | - if ( ! empty( $response->error ) ) { |
|
| 257 | + if ( ! empty($response->error)) { |
|
| 258 | 258 | // We want to retry. |
| 259 | - if ( $this->is_retryable_error( $response->error ) ) { |
|
| 260 | - if ( $retry ) { |
|
| 259 | + if ($this->is_retryable_error($response->error)) { |
|
| 260 | + if ($retry) { |
|
| 261 | 261 | // Don't do anymore retries after this. |
| 262 | - if ( 5 <= $this->retry_interval ) { |
|
| 263 | - return $this->process_subscription_payment( $amount, $renewal_order, false, $response->error ); |
|
| 262 | + if (5 <= $this->retry_interval) { |
|
| 263 | + return $this->process_subscription_payment($amount, $renewal_order, false, $response->error); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - sleep( $this->retry_interval ); |
|
| 266 | + sleep($this->retry_interval); |
|
| 267 | 267 | |
| 268 | 268 | $this->retry_interval++; |
| 269 | 269 | |
| 270 | - return $this->process_subscription_payment( $amount, $renewal_order, true, $response->error ); |
|
| 270 | + return $this->process_subscription_payment($amount, $renewal_order, true, $response->error); |
|
| 271 | 271 | } else { |
| 272 | - $localized_message = __( 'Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe' ); |
|
| 273 | - $renewal_order->add_order_note( $localized_message ); |
|
| 274 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 272 | + $localized_message = __('Sorry, we are unable to process your payment at this time. Please retry later.', 'woocommerce-gateway-stripe'); |
|
| 273 | + $renewal_order->add_order_note($localized_message); |
|
| 274 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | $localized_messages = WC_Stripe_Helper::get_localized_messages(); |
| 279 | 279 | |
| 280 | - if ( 'card_error' === $response->error->type ) { |
|
| 281 | - $localized_message = isset( $localized_messages[ $response->error->code ] ) ? $localized_messages[ $response->error->code ] : $response->error->message; |
|
| 280 | + if ('card_error' === $response->error->type) { |
|
| 281 | + $localized_message = isset($localized_messages[$response->error->code]) ? $localized_messages[$response->error->code] : $response->error->message; |
|
| 282 | 282 | } else { |
| 283 | - $localized_message = isset( $localized_messages[ $response->error->type ] ) ? $localized_messages[ $response->error->type ] : $response->error->message; |
|
| 283 | + $localized_message = isset($localized_messages[$response->error->type]) ? $localized_messages[$response->error->type] : $response->error->message; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $renewal_order->add_order_note( $localized_message ); |
|
| 286 | + $renewal_order->add_order_note($localized_message); |
|
| 287 | 287 | |
| 288 | - throw new WC_Stripe_Exception( print_r( $response, true ), $localized_message ); |
|
| 288 | + throw new WC_Stripe_Exception(print_r($response, true), $localized_message); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - do_action( 'wc_gateway_stripe_process_payment', $response, $renewal_order ); |
|
| 291 | + do_action('wc_gateway_stripe_process_payment', $response, $renewal_order); |
|
| 292 | 292 | |
| 293 | - $this->process_response( $response, $renewal_order ); |
|
| 294 | - } catch ( WC_Stripe_Exception $e ) { |
|
| 295 | - WC_Stripe_Logger::log( 'Error: ' . $e->getMessage() ); |
|
| 293 | + $this->process_response($response, $renewal_order); |
|
| 294 | + } catch (WC_Stripe_Exception $e) { |
|
| 295 | + WC_Stripe_Logger::log('Error: ' . $e->getMessage()); |
|
| 296 | 296 | |
| 297 | - do_action( 'wc_gateway_stripe_process_payment_error', $e, $renewal_order ); |
|
| 297 | + do_action('wc_gateway_stripe_process_payment_error', $e, $renewal_order); |
|
| 298 | 298 | |
| 299 | 299 | /* translators: error message */ |
| 300 | - $renewal_order->update_status( 'failed' ); |
|
| 300 | + $renewal_order->update_status('failed'); |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | |
@@ -305,21 +305,21 @@ discard block |
||
| 305 | 305 | * Don't transfer Stripe customer/token meta to resubscribe orders. |
| 306 | 306 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 307 | 307 | */ |
| 308 | - public function delete_resubscribe_meta( $resubscribe_order ) { |
|
| 309 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_customer_id' ); |
|
| 310 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_source_id' ); |
|
| 308 | + public function delete_resubscribe_meta($resubscribe_order) { |
|
| 309 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_customer_id'); |
|
| 310 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_source_id'); |
|
| 311 | 311 | // For BW compat will remove in future |
| 312 | - delete_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $resubscribe_order->id : $resubscribe_order->get_id() ), '_stripe_card_id' ); |
|
| 313 | - $this->delete_renewal_meta( $resubscribe_order ); |
|
| 312 | + delete_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $resubscribe_order->id : $resubscribe_order->get_id()), '_stripe_card_id'); |
|
| 313 | + $this->delete_renewal_meta($resubscribe_order); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
| 317 | 317 | * Don't transfer Stripe fee/ID meta to renewal orders. |
| 318 | 318 | * @param int $resubscribe_order The order created for the customer to resubscribe to the old expired/cancelled subscription |
| 319 | 319 | */ |
| 320 | - public function delete_renewal_meta( $renewal_order ) { |
|
| 321 | - WC_Stripe_Helper::delete_stripe_fee( $renewal_order ); |
|
| 322 | - WC_Stripe_Helper::delete_stripe_net( $renewal_order ); |
|
| 320 | + public function delete_renewal_meta($renewal_order) { |
|
| 321 | + WC_Stripe_Helper::delete_stripe_fee($renewal_order); |
|
| 322 | + WC_Stripe_Helper::delete_stripe_net($renewal_order); |
|
| 323 | 323 | |
| 324 | 324 | return $renewal_order; |
| 325 | 325 | } |
@@ -333,14 +333,14 @@ discard block |
||
| 333 | 333 | * @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment). |
| 334 | 334 | * @return void |
| 335 | 335 | */ |
| 336 | - public function update_failing_payment_method( $subscription, $renewal_order ) { |
|
| 337 | - if ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ) { |
|
| 338 | - update_post_meta( $subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id ); |
|
| 339 | - update_post_meta( $subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id ); |
|
| 336 | + public function update_failing_payment_method($subscription, $renewal_order) { |
|
| 337 | + if (WC_Stripe_Helper::is_wc_lt('3.0')) { |
|
| 338 | + update_post_meta($subscription->id, '_stripe_customer_id', $renewal_order->stripe_customer_id); |
|
| 339 | + update_post_meta($subscription->id, '_stripe_source_id', $renewal_order->stripe_source_id); |
|
| 340 | 340 | |
| 341 | 341 | } else { |
| 342 | - update_post_meta( $subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta( '_stripe_customer_id', true ) ); |
|
| 343 | - update_post_meta( $subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta( '_stripe_source_id', true ) ); |
|
| 342 | + update_post_meta($subscription->get_id(), '_stripe_customer_id', $renewal_order->get_meta('_stripe_customer_id', true)); |
|
| 343 | + update_post_meta($subscription->get_id(), '_stripe_source_id', $renewal_order->get_meta('_stripe_source_id', true)); |
|
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
@@ -353,21 +353,21 @@ discard block |
||
| 353 | 353 | * @param WC_Subscription $subscription An instance of a subscription object |
| 354 | 354 | * @return array |
| 355 | 355 | */ |
| 356 | - public function add_subscription_payment_meta( $payment_meta, $subscription ) { |
|
| 357 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 356 | + public function add_subscription_payment_meta($payment_meta, $subscription) { |
|
| 357 | + $source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 358 | 358 | |
| 359 | 359 | // For BW compat will remove in future. |
| 360 | - if ( empty( $source_id ) ) { |
|
| 361 | - $source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 360 | + if (empty($source_id)) { |
|
| 361 | + $source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 362 | 362 | |
| 363 | 363 | // Take this opportunity to update the key name. |
| 364 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $source_id ); |
|
| 364 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $source_id); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - $payment_meta[ $this->id ] = array( |
|
| 367 | + $payment_meta[$this->id] = array( |
|
| 368 | 368 | 'post_meta' => array( |
| 369 | 369 | '_stripe_customer_id' => array( |
| 370 | - 'value' => get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ), |
|
| 370 | + 'value' => get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true), |
|
| 371 | 371 | 'label' => 'Stripe Customer ID', |
| 372 | 372 | ), |
| 373 | 373 | '_stripe_source_id' => array( |
@@ -388,22 +388,22 @@ discard block |
||
| 388 | 388 | * @param array $payment_meta associative array of meta data required for automatic payments |
| 389 | 389 | * @return array |
| 390 | 390 | */ |
| 391 | - public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) { |
|
| 392 | - if ( $this->id === $payment_method_id ) { |
|
| 391 | + public function validate_subscription_payment_meta($payment_method_id, $payment_meta) { |
|
| 392 | + if ($this->id === $payment_method_id) { |
|
| 393 | 393 | |
| 394 | - if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) { |
|
| 395 | - throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) ); |
|
| 396 | - } elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) { |
|
| 397 | - throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) ); |
|
| 394 | + if ( ! isset($payment_meta['post_meta']['_stripe_customer_id']['value']) || empty($payment_meta['post_meta']['_stripe_customer_id']['value'])) { |
|
| 395 | + throw new Exception(__('A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe')); |
|
| 396 | + } elseif (0 !== strpos($payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_')) { |
|
| 397 | + throw new Exception(__('Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe')); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | if ( |
| 401 | - ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 402 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) ) |
|
| 403 | - && ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] ) |
|
| 404 | - && 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) { |
|
| 401 | + ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 402 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'card_')) |
|
| 403 | + && ( ! empty($payment_meta['post_meta']['_stripe_source_id']['value']) |
|
| 404 | + && 0 !== strpos($payment_meta['post_meta']['_stripe_source_id']['value'], 'src_')) ) { |
|
| 405 | 405 | |
| 406 | - throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) ); |
|
| 406 | + throw new Exception(__('Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe')); |
|
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | } |
@@ -416,67 +416,67 @@ discard block |
||
| 416 | 416 | * @param WC_Subscription $subscription the subscription details |
| 417 | 417 | * @return string the subscription payment method |
| 418 | 418 | */ |
| 419 | - public function maybe_render_subscription_payment_method( $payment_method_to_display, $subscription ) { |
|
| 420 | - $customer_user = WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->customer_user : $subscription->get_customer_id(); |
|
| 419 | + public function maybe_render_subscription_payment_method($payment_method_to_display, $subscription) { |
|
| 420 | + $customer_user = WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->customer_user : $subscription->get_customer_id(); |
|
| 421 | 421 | |
| 422 | 422 | // bail for other payment methods |
| 423 | - if ( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->payment_method : $subscription->get_payment_method() ) !== $this->id || ! $customer_user ) { |
|
| 423 | + if ((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->payment_method : $subscription->get_payment_method()) !== $this->id || ! $customer_user) { |
|
| 424 | 424 | return $payment_method_to_display; |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_source_id', true ); |
|
| 427 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_source_id', true); |
|
| 428 | 428 | |
| 429 | 429 | // For BW compat will remove in future. |
| 430 | - if ( empty( $stripe_source_id ) ) { |
|
| 431 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_card_id', true ); |
|
| 430 | + if (empty($stripe_source_id)) { |
|
| 431 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_card_id', true); |
|
| 432 | 432 | |
| 433 | 433 | // Take this opportunity to update the key name. |
| 434 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 434 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_id(), '_stripe_source_id', $stripe_source_id); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | $stripe_customer = new WC_Stripe_Customer(); |
| 438 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->id : $subscription->get_id() ), '_stripe_customer_id', true ); |
|
| 438 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->id : $subscription->get_id()), '_stripe_customer_id', true); |
|
| 439 | 439 | |
| 440 | 440 | // If we couldn't find a Stripe customer linked to the subscription, fallback to the user meta data. |
| 441 | - if ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) { |
|
| 441 | + if ( ! $stripe_customer_id || ! is_string($stripe_customer_id)) { |
|
| 442 | 442 | $user_id = $customer_user; |
| 443 | - $stripe_customer_id = get_user_meta( $user_id, '_stripe_customer_id', true ); |
|
| 444 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_source_id', true ); |
|
| 443 | + $stripe_customer_id = get_user_meta($user_id, '_stripe_customer_id', true); |
|
| 444 | + $stripe_source_id = get_user_meta($user_id, '_stripe_source_id', true); |
|
| 445 | 445 | |
| 446 | 446 | // For BW compat will remove in future. |
| 447 | - if ( empty( $stripe_source_id ) ) { |
|
| 448 | - $stripe_source_id = get_user_meta( $user_id, '_stripe_card_id', true ); |
|
| 447 | + if (empty($stripe_source_id)) { |
|
| 448 | + $stripe_source_id = get_user_meta($user_id, '_stripe_card_id', true); |
|
| 449 | 449 | |
| 450 | 450 | // Take this opportunity to update the key name. |
| 451 | - update_user_meta( $user_id, '_stripe_source_id', $stripe_source_id ); |
|
| 451 | + update_user_meta($user_id, '_stripe_source_id', $stripe_source_id); |
|
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | // If we couldn't find a Stripe customer linked to the account, fallback to the order meta data. |
| 456 | - if ( ( ! $stripe_customer_id || ! is_string( $stripe_customer_id ) ) && false !== $subscription->order ) { |
|
| 457 | - $stripe_customer_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_customer_id', true ); |
|
| 458 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_source_id', true ); |
|
| 456 | + if (( ! $stripe_customer_id || ! is_string($stripe_customer_id)) && false !== $subscription->order) { |
|
| 457 | + $stripe_customer_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_customer_id', true); |
|
| 458 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_source_id', true); |
|
| 459 | 459 | |
| 460 | 460 | // For BW compat will remove in future. |
| 461 | - if ( empty( $stripe_source_id ) ) { |
|
| 462 | - $stripe_source_id = get_post_meta( ( WC_Stripe_Helper::is_wc_lt( '3.0' ) ? $subscription->order->id : $subscription->get_parent_id() ), '_stripe_card_id', true ); |
|
| 461 | + if (empty($stripe_source_id)) { |
|
| 462 | + $stripe_source_id = get_post_meta((WC_Stripe_Helper::is_wc_lt('3.0') ? $subscription->order->id : $subscription->get_parent_id()), '_stripe_card_id', true); |
|
| 463 | 463 | |
| 464 | 464 | // Take this opportunity to update the key name. |
| 465 | - WC_Stripe_Helper::is_wc_lt( '3.0' ) ? update_post_meta( $subscription->order->id, '_stripe_source_id', $stripe_source_id ) : update_post_meta( $subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id ); |
|
| 465 | + WC_Stripe_Helper::is_wc_lt('3.0') ? update_post_meta($subscription->order->id, '_stripe_source_id', $stripe_source_id) : update_post_meta($subscription->get_parent_id(), '_stripe_source_id', $stripe_source_id); |
|
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - $stripe_customer->set_id( $stripe_customer_id ); |
|
| 469 | + $stripe_customer->set_id($stripe_customer_id); |
|
| 470 | 470 | |
| 471 | 471 | $sources = $stripe_customer->get_sources(); |
| 472 | - $payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' ); |
|
| 472 | + $payment_method_to_display = __('N/A', 'woocommerce-gateway-stripe'); |
|
| 473 | 473 | |
| 474 | - if ( $sources ) { |
|
| 475 | - foreach ( $sources as $source ) { |
|
| 476 | - if ( $source->id === $stripe_source_id ) { |
|
| 477 | - if ( $source->sepa_debit ) { |
|
| 474 | + if ($sources) { |
|
| 475 | + foreach ($sources as $source) { |
|
| 476 | + if ($source->id === $stripe_source_id) { |
|
| 477 | + if ($source->sepa_debit) { |
|
| 478 | 478 | /* translators: 1) last 4 digits of SEPA Direct Debit */ |
| 479 | - $payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 ); |
|
| 479 | + $payment_method_to_display = sprintf(__('Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe'), $source->sepa_debit->last4); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | 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 | |
@@ -7,40 +7,40 @@ discard block |
||
| 7 | 7 | 'wc_stripe_giropay_settings', |
| 8 | 8 | array( |
| 9 | 9 | 'geo_target' => array( |
| 10 | - 'description' => __( 'Relevant Payer Geography: Germany', 'woocommerce-gateway-stripe' ), |
|
| 10 | + 'description' => __('Relevant Payer Geography: Germany', 'woocommerce-gateway-stripe'), |
|
| 11 | 11 | 'type' => 'title', |
| 12 | 12 | ), |
| 13 | 13 | 'guide' => array( |
| 14 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#giropay" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
| 14 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#giropay" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
| 15 | 15 | 'type' => 'title', |
| 16 | 16 | ), |
| 17 | 17 | 'activation' => array( |
| 18 | - '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' ), |
|
| 18 | + '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'), |
|
| 19 | 19 | 'type' => 'title', |
| 20 | 20 | ), |
| 21 | 21 | 'enabled' => array( |
| 22 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
| 23 | - 'label' => __( 'Enable Stripe Giropay', 'woocommerce-gateway-stripe' ), |
|
| 22 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
| 23 | + 'label' => __('Enable Stripe Giropay', 'woocommerce-gateway-stripe'), |
|
| 24 | 24 | 'type' => 'checkbox', |
| 25 | 25 | 'description' => '', |
| 26 | 26 | 'default' => 'no', |
| 27 | 27 | ), |
| 28 | 28 | 'title' => array( |
| 29 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
| 29 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
| 30 | 30 | 'type' => 'text', |
| 31 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
| 32 | - 'default' => __( 'Giropay', 'woocommerce-gateway-stripe' ), |
|
| 31 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
| 32 | + 'default' => __('Giropay', 'woocommerce-gateway-stripe'), |
|
| 33 | 33 | 'desc_tip' => true, |
| 34 | 34 | ), |
| 35 | 35 | 'description' => array( |
| 36 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
| 36 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
| 37 | 37 | 'type' => 'text', |
| 38 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
| 39 | - 'default' => __( 'You will be redirected to Giropay.', 'woocommerce-gateway-stripe' ), |
|
| 38 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
| 39 | + 'default' => __('You will be redirected to Giropay.', 'woocommerce-gateway-stripe'), |
|
| 40 | 40 | 'desc_tip' => true, |
| 41 | 41 | ), |
| 42 | 42 | 'webhook' => array( |
| 43 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
| 43 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
| 44 | 44 | 'type' => 'title', |
| 45 | 45 | /* translators: webhook URL */ |
| 46 | 46 | 'description' => $this->display_admin_settings_webhook_description(), |
@@ -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,40 +7,40 @@ discard block |
||
| 7 | 7 | 'wc_stripe_bancontact_settings', |
| 8 | 8 | array( |
| 9 | 9 | 'geo_target' => array( |
| 10 | - 'description' => __( 'Relevant Payer Geography: Belgium', 'woocommerce-gateway-stripe' ), |
|
| 10 | + 'description' => __('Relevant Payer Geography: Belgium', 'woocommerce-gateway-stripe'), |
|
| 11 | 11 | 'type' => 'title', |
| 12 | 12 | ), |
| 13 | 13 | 'guide' => array( |
| 14 | - 'description' => __( '<a href="https://stripe.com/payments/payment-methods-guide#bancontact" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe' ), |
|
| 14 | + 'description' => __('<a href="https://stripe.com/payments/payment-methods-guide#bancontact" target="_blank">Payment Method Guide</a>', 'woocommerce-gateway-stripe'), |
|
| 15 | 15 | 'type' => 'title', |
| 16 | 16 | ), |
| 17 | 17 | 'activation' => array( |
| 18 | - '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' ), |
|
| 18 | + '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'), |
|
| 19 | 19 | 'type' => 'title', |
| 20 | 20 | ), |
| 21 | 21 | 'enabled' => array( |
| 22 | - 'title' => __( 'Enable/Disable', 'woocommerce-gateway-stripe' ), |
|
| 23 | - 'label' => __( 'Enable Stripe Bancontact', 'woocommerce-gateway-stripe' ), |
|
| 22 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
| 23 | + 'label' => __('Enable Stripe Bancontact', 'woocommerce-gateway-stripe'), |
|
| 24 | 24 | 'type' => 'checkbox', |
| 25 | 25 | 'description' => '', |
| 26 | 26 | 'default' => 'no', |
| 27 | 27 | ), |
| 28 | 28 | 'title' => array( |
| 29 | - 'title' => __( 'Title', 'woocommerce-gateway-stripe' ), |
|
| 29 | + 'title' => __('Title', 'woocommerce-gateway-stripe'), |
|
| 30 | 30 | 'type' => 'text', |
| 31 | - 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
| 32 | - 'default' => __( 'Bancontact', 'woocommerce-gateway-stripe' ), |
|
| 31 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
| 32 | + 'default' => __('Bancontact', 'woocommerce-gateway-stripe'), |
|
| 33 | 33 | 'desc_tip' => true, |
| 34 | 34 | ), |
| 35 | 35 | 'description' => array( |
| 36 | - 'title' => __( 'Description', 'woocommerce-gateway-stripe' ), |
|
| 36 | + 'title' => __('Description', 'woocommerce-gateway-stripe'), |
|
| 37 | 37 | 'type' => 'text', |
| 38 | - 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe' ), |
|
| 39 | - 'default' => __( 'You will be redirected to Bancontact.', 'woocommerce-gateway-stripe' ), |
|
| 38 | + 'description' => __('This controls the description which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
| 39 | + 'default' => __('You will be redirected to Bancontact.', 'woocommerce-gateway-stripe'), |
|
| 40 | 40 | 'desc_tip' => true, |
| 41 | 41 | ), |
| 42 | 42 | 'webhook' => array( |
| 43 | - 'title' => __( 'Webhook Endpoints', 'woocommerce-gateway-stripe' ), |
|
| 43 | + 'title' => __('Webhook Endpoints', 'woocommerce-gateway-stripe'), |
|
| 44 | 44 | 'type' => 'title', |
| 45 | 45 | /* translators: webhook URL */ |
| 46 | 46 | 'description' => $this->display_admin_settings_webhook_description(), |
@@ -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_multibanco_settings', |
| 8 | 8 | array( |
| 9 | 9 | 'geo_target' => array( |
| 10 | - 'description' => __( 'Relevant Payer Geography: Portugal', 'woocommerce-gateway-stripe' ), |
|
| 10 | + 'description' => __('Relevant Payer Geography: Portugal', '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 Multibanco', 'woocommerce-gateway-stripe' ), |
|
| 18 | + 'title' => __('Enable/Disable', 'woocommerce-gateway-stripe'), |
|
| 19 | + 'label' => __('Enable Stripe Multibanco', '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' => __( 'Multibanco', 'woocommerce-gateway-stripe' ), |
|
| 27 | + 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce-gateway-stripe'), |
|
| 28 | + 'default' => __('Multibanco', '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 Multibanco.', '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 Multibanco.', '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(), |