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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
<?php
defined( 'ABSPATH' ) || exit();
abstract class WC_Payment_Token_Braintree extends WC_Payment_Token {
protected $object_type = 'payment_token';
protected $extra_data = array(
'payment_instrument_type' => '',
'format' => '',
'method_type' => '',
'environment' => 'production',
);
protected $payment_formats = array();
protected $braintree_data = array();
protected $format = '';
public function __construct( $token = '' ) {
$this->extra_data = array_merge( $this->extra_data, $this->get_braintree_data( $this ) );
$this->init_payment_formats();
parent::__construct( $token );
}
public function set_format( $value ) {
$this->format = $value;
}
public function set_payment_instrument_type( $value ) {
$this->set_prop( 'payment_instrument_type', $value );
}
public function set_method_type( $value ) {
$this->set_prop( 'method_type', $value );
}
public function set_environment( $value ) {
$this->set_prop( 'environment', $value );
}
public function get_method_type() {
return $this->get_prop( 'method_type' );
}
public function get_format() {
return $this->format;
}
public function get_environment() {
return $this->get_prop( 'environment' );
}
public function get_payment_instrument_type() {
return $this->get_prop( 'payment_instrument_type' );
}
public function get_payment_method_title( $format = '' ) {
$format = empty( $format ) ? $this->get_format() : $format;
$data = $this->get_props_data();
$format = $this->get_formats()[ $format ]['format'];
return apply_filters( 'wc_braintree_token_payment_method_title', str_replace( array_keys( $data ), $data, $format ), $this );
}
public function get_formats() {
return apply_filters( 'wc_braintree_payment_token_formats', $this->payment_formats, $this );
}
public abstract function init_from_payment_method( $method );
public function get_props_data() {
$data = array();
foreach ( $this->extra_data as $k => $v ) {
if ( method_exists( $this, "get_$k" ) ) {
$data[ '{' . $k . '}' ] = $this->{"get_$k"}();
} else {
$data[ '{' . $k . '}' ] = $this->get_prop( $k );
}
}
return $data;
}
public function get_braintree_data( $instance ) {
$data = array();
try {
$class = new ReflectionClass( $instance );
$props = $class->getDefaultProperties();
if ( isset( $props['braintree_data'] ) ) {
$data = $props['braintree_data'];
}
if ( is_subclass_of( get_parent_class( $instance ), 'WC_Payment_Token_Braintree' ) ) {
$data = array_merge( $this->get_braintree_data( get_parent_class( $instance ) ), $data );
}
return $data;
} catch ( Exception $e ) {
return array();
}
}
public function to_json() {
return apply_filters(
'wc_braintree_get_' . $this->object_type . '_json',
array(
'id' => $this->get_id(),
'type' => $this->get_type(),
'method_type' => $this->get_method_type(),
'token' => $this->get_token(),
'title' => $this->get_payment_method_title(),
)
);
}
public function add_meta_data_to_order( $order ) {
}
public abstract function init_payment_formats();
}