1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
<?php
defined( 'ABSPATH' ) || exit();
if ( ! class_exists( 'WC_Payment_Token_Stripe' ) ) {
return;
}
class WC_Payment_Token_Stripe_CC extends WC_Payment_Token_Stripe {
use WC_Payment_Token_Payment_Method_Trait;
protected $has_expiration = true;
protected $type = 'Stripe_CC';
protected $stripe_payment_type = 'payment_method';
protected $stripe_data = array(
'brand' => '',
'exp_month' => '',
'exp_year' => '',
'last4' => '',
'masked_number' => ''
);
public function details_to_props( $details ) {
if ( isset( $details['card'] ) ) {
$card = $details['card'];
}
if ( $details instanceof \Stripe\Card ) {
$card = $details;
}
$this->set_brand( $card['brand'] );
$this->set_last4( $card['last4'] );
$this->set_exp_month( $card['exp_month'] );
$this->set_exp_year( $card['exp_year'] );
$this->set_masked_number( sprintf( '********%s', $card['last4'] ) );
}
public function get_last4( $context = 'view' ) {
return $this->get_prop( 'last4', $context );
}
public function get_masked_number( $context = 'view' ) {
return $this->get_prop( 'masked_number', $context );
}
public function set_last4( $last4 ) {
$this->set_prop( 'last4', $last4 );
}
public function set_masked_number( $value ) {
$this->set_prop( 'masked_number', $value );
}
public function get_exp_year( $context = 'view' ) {
return $this->get_prop( 'exp_year', $context );
}
public function set_exp_year( $year ) {
$this->set_prop( 'exp_year', $year );
}
public function get_exp_month( $context = 'view' ) {
return $this->get_prop( 'exp_month', $context );
}
public function set_exp_month( $month ) {
$this->set_prop( 'exp_month', str_pad( $month, 2, '0', STR_PAD_LEFT ) );
}
public function get_html_classes() {
return sprintf( '%s', str_replace( ' ', '', strtolower( $this->get_prop( 'brand' ) ) ) );
}
public function get_card_type( $context = 'view' ) {
return $this->get_brand( $context );
}
public function get_formats() {
return apply_filters( 'wc_stripe_get_token_formats', array(
'type_ending_in' => array(
'label' => __( 'Type Ending In', 'woo-stripe-payment' ),
'example' => 'Visa ending in 1111',
'format' => __( '{brand} ending in {last4}', 'woo-stripe-payment' ),
),
'type_masked_number' => array(
'label' => __( 'Type Masked Number', 'woo-stripe-payment' ),
'example' => 'Visa ********1111',
'format' => '{brand} {masked_number}',
),
'type_dash_masked_number' => array(
'label' => __( 'Type Dash Masked Number', 'woo-stripe-payment' ),
'example' => 'Visa - ********1111',
'format' => '{brand} - {masked_number}',
),
'type_last4' => array(
'label' => __( 'Type Last 4', 'woo-stripe-payment' ),
'example' => 'Visa 1111',
'format' => '{brand} {last4}',
),
'type_dash_last4' => array(
'label' => __( 'Type Dash & Last 4', 'woo-stripe-payment' ),
'example' => 'Visa - 1111',
'format' => '{brand} - {last4}',
),
'last4' => array(
'label' => __( 'Last Four', 'woo-stripe-payment' ),
'example' => '1111',
'format' => '{last4}',
),
'card_type' => array(
'label' => __( 'Card Type', 'woo-stripe-payment' ),
'example' => 'Visa',
'format' => '{brand}',
),
'short_title' => array(
'label' => __( 'Gateway Title', 'woo-stripe-payment' ),
'example' => $this->get_basic_payment_method_title(),
'format' => '{short_title}'
)
), $this );
}
public function get_basic_payment_method_title() {
return __( 'Credit Card', 'woo-stripe-payment' );
}
}