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
<?php
defined( 'ABSPATH' ) || exit();
if ( ! class_exists( 'WC_Payment_Token' ) ) {
exit();
}
use \PaymentPlugins\WC_Braintree_Constants as Constants;
class WC_Payment_Token_Braintree_PayPal extends WC_Payment_Token_Braintree {
protected $type = 'Braintree_PayPal';
protected $braintree_data = array(
'method_type' => 'PayPal',
'email' => '',
'first_name' => '',
'last_name' => '',
'payer_id' => '',
);
public function init_from_payment_method( $method ) {
$this->set_method_type( 'PayPal' );
if ( $method instanceof \Braintree\Transaction\PayPalDetails ) {
$this->set_email( $method->payerEmail );
$this->set_first_name( $method->payerFirstName );
$this->set_last_name( $method->payerLastName );
$this->set_authorization_id( $method->authorizationId );
$this->set_capture_id( $method->captureId );
$this->set_payer_id( $method->payerId );
} else {
$this->set_email( $method->email );
}
$this->set_payment_instrument_type( \Braintree\PaymentInstrumentType::PAYPAL_ACCOUNT );
$this->set_token( $method->token );
}
public function set_email( $value ) {
$this->set_prop( 'email', $value );
}
public function get_email() {
return $this->get_prop( 'email' );
}
public function set_authorization_id( $value ) {
$this->set_prop( 'authorization_id', $value );
}
public function get_authorization_id() {
return $this->get_prop( 'authorization_id' );
}
public function set_first_name( $value ) {
$this->set_prop( 'first_name', $value );
}
public function get_first_name() {
return $this->get_prop( 'first_name' );
}
public function set_last_name( $value ) {
$this->set_prop( 'last_name', $value );
}
public function set_capture_id( $value ) {
$this->data['capture_id'] = $value;
}
public function get_capture_id() {
return isset( $this->data['capture_id'] ) ? $this->data['capture_id'] : '';
}
public function get_last_name() {
return $this->get_prop( 'last_name' );
}
public function set_payer_id( $value ) {
$this->set_prop( 'payer_id', $value );
}
public function get_payer_id() {
return $this->get_prop( 'payer_id' );
}
public function init_payment_formats() {
$this->payment_formats = array(
'paypal_and_email' => array(
'label' => __( 'PayPal & Email', 'woo-payment-gateway' ),
'example' => 'PayPal - [email protected]',
'format' => 'PayPal - {email}',
),
'email' => array(
'label' => __( 'Email', 'woo-payment-gateway' ),
'example' => '[email protected]',
'format' => '{email}',
),
'paypal' => array(
'label' => __( 'PayPal', 'woo-payment-gateway' ),
'example' => 'PayPal',
'format' => __( 'PayPal', 'woo-payment-gateway' ),
),
);
}
public function add_meta_data_to_order( $order ) {
$order->update_meta_data( Constants::PAYPAL_TRANSACTION, $this->get_capture_id() );
}
}