@@ -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 | |
@@ -62,67 +62,67 @@ discard block |
||
| 62 | 62 | * @param array $tokens |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public function woocommerce_get_customer_payment_tokens( $tokens = array(), $customer_id, $gateway_id ) { |
|
| 66 | - if ( is_user_logged_in() && class_exists( 'WC_Payment_Token_CC' ) ) { |
|
| 65 | + public function woocommerce_get_customer_payment_tokens($tokens = array(), $customer_id, $gateway_id) { |
|
| 66 | + if (is_user_logged_in() && class_exists('WC_Payment_Token_CC')) { |
|
| 67 | 67 | $stored_tokens = array(); |
| 68 | 68 | |
| 69 | - foreach ( $tokens as $token ) { |
|
| 69 | + foreach ($tokens as $token) { |
|
| 70 | 70 | $stored_tokens[] = $token->get_token(); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if ( 'stripe' === $gateway_id ) { |
|
| 74 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 73 | + if ('stripe' === $gateway_id) { |
|
| 74 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 75 | 75 | $stripe_sources = $stripe_customer->get_sources(); |
| 76 | 76 | |
| 77 | - foreach ( $stripe_sources as $source ) { |
|
| 78 | - if ( isset( $source->type ) && 'card' === $source->type ) { |
|
| 79 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
| 77 | + foreach ($stripe_sources as $source) { |
|
| 78 | + if (isset($source->type) && 'card' === $source->type) { |
|
| 79 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
| 80 | 80 | $token = new WC_Payment_Token_CC(); |
| 81 | - $token->set_token( $source->id ); |
|
| 82 | - $token->set_gateway_id( 'stripe' ); |
|
| 83 | - |
|
| 84 | - if ( 'source' === $source->object && 'card' === $source->type ) { |
|
| 85 | - $token->set_card_type( strtolower( $source->card->brand ) ); |
|
| 86 | - $token->set_last4( $source->card->last4 ); |
|
| 87 | - $token->set_expiry_month( $source->card->exp_month ); |
|
| 88 | - $token->set_expiry_year( $source->card->exp_year ); |
|
| 81 | + $token->set_token($source->id); |
|
| 82 | + $token->set_gateway_id('stripe'); |
|
| 83 | + |
|
| 84 | + if ('source' === $source->object && 'card' === $source->type) { |
|
| 85 | + $token->set_card_type(strtolower($source->card->brand)); |
|
| 86 | + $token->set_last4($source->card->last4); |
|
| 87 | + $token->set_expiry_month($source->card->exp_month); |
|
| 88 | + $token->set_expiry_year($source->card->exp_year); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - $token->set_user_id( $customer_id ); |
|
| 91 | + $token->set_user_id($customer_id); |
|
| 92 | 92 | $token->save(); |
| 93 | - $tokens[ $token->get_id() ] = $token; |
|
| 93 | + $tokens[$token->get_id()] = $token; |
|
| 94 | 94 | } |
| 95 | 95 | } else { |
| 96 | - if ( ! in_array( $source->id, $stored_tokens ) && 'card' === $source->object ) { |
|
| 96 | + if ( ! in_array($source->id, $stored_tokens) && 'card' === $source->object) { |
|
| 97 | 97 | $token = new WC_Payment_Token_CC(); |
| 98 | - $token->set_token( $source->id ); |
|
| 99 | - $token->set_gateway_id( 'stripe' ); |
|
| 100 | - $token->set_card_type( strtolower( $source->brand ) ); |
|
| 101 | - $token->set_last4( $source->last4 ); |
|
| 102 | - $token->set_expiry_month( $source->exp_month ); |
|
| 103 | - $token->set_expiry_year( $source->exp_year ); |
|
| 104 | - $token->set_user_id( $customer_id ); |
|
| 98 | + $token->set_token($source->id); |
|
| 99 | + $token->set_gateway_id('stripe'); |
|
| 100 | + $token->set_card_type(strtolower($source->brand)); |
|
| 101 | + $token->set_last4($source->last4); |
|
| 102 | + $token->set_expiry_month($source->exp_month); |
|
| 103 | + $token->set_expiry_year($source->exp_year); |
|
| 104 | + $token->set_user_id($customer_id); |
|
| 105 | 105 | $token->save(); |
| 106 | - $tokens[ $token->get_id() ] = $token; |
|
| 106 | + $tokens[$token->get_id()] = $token; |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if ( 'stripe_sepa' === $gateway_id ) { |
|
| 113 | - $stripe_customer = new WC_Stripe_Customer( $customer_id ); |
|
| 112 | + if ('stripe_sepa' === $gateway_id) { |
|
| 113 | + $stripe_customer = new WC_Stripe_Customer($customer_id); |
|
| 114 | 114 | $stripe_sources = $stripe_customer->get_sources(); |
| 115 | 115 | |
| 116 | - foreach ( $stripe_sources as $source ) { |
|
| 117 | - if ( isset( $source->type ) && 'sepa_debit' === $source->type ) { |
|
| 118 | - if ( ! in_array( $source->id, $stored_tokens ) ) { |
|
| 116 | + foreach ($stripe_sources as $source) { |
|
| 117 | + if (isset($source->type) && 'sepa_debit' === $source->type) { |
|
| 118 | + if ( ! in_array($source->id, $stored_tokens)) { |
|
| 119 | 119 | $token = new WC_Payment_Token_SEPA(); |
| 120 | - $token->set_token( $source->id ); |
|
| 121 | - $token->set_gateway_id( 'stripe_sepa' ); |
|
| 122 | - $token->set_last4( $source->sepa_debit->last4 ); |
|
| 123 | - $token->set_user_id( $customer_id ); |
|
| 120 | + $token->set_token($source->id); |
|
| 121 | + $token->set_gateway_id('stripe_sepa'); |
|
| 122 | + $token->set_last4($source->sepa_debit->last4); |
|
| 123 | + $token->set_user_id($customer_id); |
|
| 124 | 124 | $token->save(); |
| 125 | - $tokens[ $token->get_id() ] = $token; |
|
| 125 | + $tokens[$token->get_id()] = $token; |
|
| 126 | 126 | } |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | * @param WC_Payment_Token $payment_token The payment token associated with this method entry |
| 142 | 142 | * @return array Filtered item |
| 143 | 143 | */ |
| 144 | - public function get_account_saved_payment_methods_list_item_sepa( $item, $payment_token ) { |
|
| 145 | - if ( 'sepa' === strtolower( $payment_token->get_type() ) ) { |
|
| 144 | + public function get_account_saved_payment_methods_list_item_sepa($item, $payment_token) { |
|
| 145 | + if ('sepa' === strtolower($payment_token->get_type())) { |
|
| 146 | 146 | $item['method']['last4'] = $payment_token->get_last4(); |
| 147 | - $item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' ); |
|
| 147 | + $item['method']['brand'] = esc_html__('SEPA IBAN', 'woocommerce-gateway-stripe'); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return $item; |
@@ -156,10 +156,10 @@ discard block |
||
| 156 | 156 | * @since 3.1.0 |
| 157 | 157 | * @version 4.0.0 |
| 158 | 158 | */ |
| 159 | - public function woocommerce_payment_token_deleted( $token_id, $token ) { |
|
| 160 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
| 161 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 162 | - $stripe_customer->delete_source( $token->get_token() ); |
|
| 159 | + public function woocommerce_payment_token_deleted($token_id, $token) { |
|
| 160 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
| 161 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 162 | + $stripe_customer->delete_source($token->get_token()); |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | * @since 3.1.0 |
| 170 | 170 | * @version 4.0.0 |
| 171 | 171 | */ |
| 172 | - public function woocommerce_payment_token_set_default( $token_id ) { |
|
| 173 | - $token = WC_Payment_Tokens::get( $token_id ); |
|
| 172 | + public function woocommerce_payment_token_set_default($token_id) { |
|
| 173 | + $token = WC_Payment_Tokens::get($token_id); |
|
| 174 | 174 | |
| 175 | - if ( 'stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id() ) { |
|
| 176 | - $stripe_customer = new WC_Stripe_Customer( get_current_user_id() ); |
|
| 177 | - $stripe_customer->set_default_source( $token->get_token() ); |
|
| 175 | + if ('stripe' === $token->get_gateway_id() || 'stripe_sepa' === $token->get_gateway_id()) { |
|
| 176 | + $stripe_customer = new WC_Stripe_Customer(get_current_user_id()); |
|
| 177 | + $stripe_customer->set_default_source($token->get_token()); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | } |