/**
  * Add payment and transaction information as class members of WC_Order
  * instance.  The standard information that can be added includes:
  *
  * $order->payment_total           - the payment total
  * $order->customer_id             - optional payment gateway customer id (useful for tokenized payments for certain gateways, etc)
  * $order->payment->account_number - the credit card or checking account number
  * $order->payment->last_four      - the last four digits of the account number
  * $order->payment->card_type      - the card type (e.g. visa) derived from the account number
  * $order->payment->routing_number - account routing number (check transactions only)
  * $order->payment->account_type   - optional type of account one of 'checking' or 'savings' if type is 'check'
  * $order->payment->card_type      - optional card type, ie one of 'visa', etc
  * $order->payment->exp_month      - the credit card expiration month (for credit card gateways)
  * $order->payment->exp_year       - the credit card expiration year (for credit card gateways)
  * $order->payment->csc            - the card security code (for credit card gateways)
  * $order->payment->check_number   - optional check number (check transactions only)
  * $order->payment->drivers_license_number - optional driver license number (check transactions only)
  * $order->payment->drivers_license_state  - optional driver license state code (check transactions only)
  * $order->payment->token          - payment token (for tokenized transactions)
  *
  * Note that not all gateways will necessarily pass or require all of the
  * above.  These represent the most common attributes used among a variety
  * of gateways, it's up to the specific gateway implementation to make use
  * of, or ignore them, or add custom ones by overridding this method.
  *
  * @since 1.0.0
  * @see SV_WC_Payment_Gateway::get_order()
  * @param int|\WC_Order $order_id order ID being processed
  * @return WC_Order object with payment and transaction information attached
  */
 public function get_order($order_id)
 {
     $order = parent::get_order($order_id);
     // payment info
     if (SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-account-number') && !SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-payment-token')) {
         // common attributes
         $order->payment->account_number = str_replace(array(' ', '-'), '', SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-account-number'));
         $order->payment->last_four = substr($order->payment->account_number, -4);
         if ($this->is_credit_card_gateway()) {
             // credit card specific attributes
             $order->payment->card_type = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-card-type');
             $order->payment->exp_month = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-exp-month');
             $order->payment->exp_year = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-exp-year');
             // add card type for gateways that don't require it displayed at checkout
             if (empty($order->payment->card_type)) {
                 $order->payment->card_type = SV_WC_Payment_Gateway_Helper::card_type_from_account_number($order->payment->account_number);
             }
             // handle single expiry field formatted like "MM / YY" or "MM / YYYY"
             if (SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-expiry')) {
                 list($order->payment->exp_month, $order->payment->exp_year) = array_map('trim', explode('/', SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-expiry')));
             }
             // add CSC if enabled
             if ($this->csc_enabled()) {
                 $order->payment->csc = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-csc');
             }
         } elseif ($this->is_echeck_gateway()) {
             // echeck specific attributes
             $order->payment->routing_number = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-routing-number');
             $order->payment->account_type = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-account-type');
             $order->payment->check_number = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-check-number');
             $order->payment->drivers_license_number = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-drivers-license-number');
             $order->payment->drivers_license_state = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-drivers-license-state');
         }
     } elseif (SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-payment-token')) {
         // paying with tokenized payment method (we've already verified that this token exists in the validate_fields method)
         $token = $this->get_payment_token($order->get_user_id(), SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-payment-token'));
         $order->payment->token = $token->get_token();
         $order->payment->account_number = $token->get_last_four();
         $order->payment->last_four = $token->get_last_four();
         if ($this->is_credit_card_gateway()) {
             // credit card specific attributes
             $order->payment->card_type = $token->get_card_type();
             $order->payment->exp_month = $token->get_exp_month();
             $order->payment->exp_year = $token->get_exp_year();
             if ($this->csc_enabled()) {
                 $order->payment->csc = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-csc');
             }
         } elseif ($this->is_echeck_gateway()) {
             // echeck specific attributes
             $order->payment->account_type = $token->get_account_type();
         }
         // make this the new default payment token
         $this->set_default_payment_token($order->get_user_id(), $token);
     }
     // allow other actors to modify the order object
     return apply_filters('wc_payment_gateway_' . $this->get_id() . '_get_order', $order, $this);
 }
 /**
  * Add payment and transaction information as class members of WC_Order
  * instance.  The standard information that can be added includes:
  *
  * $order->payment_total           - the payment total
  * $order->customer_id             - optional payment gateway customer id (useful for tokenized payments, etc)
  * $order->payment->account_number - the credit card or checking account number
  * $order->payment->routing_number - account routing number (check transactions only)
  * $order->payment->account_type   - optional type of account one of 'checking' or 'savings' if type is 'check'
  * $order->payment->card_type      - optional card type, ie one of 'visa', etc
  * $order->payment->exp_month      - the credit card expiration month (for credit card gateways)
  * $order->payment->exp_year       - the credit card expiration year (for credit card gateways)
  * $order->payment->csc            - the card security code (for credit card gateways)
  * $order->payment->check_number   - optional check number (check transactions only)
  * $order->payment->drivers_license_number - optional driver license number (check transactions only)
  * $order->payment->drivers_license_state  - optional driver license state code (check transactions only)
  * $order->payment->token          - payment token (for tokenized transactions)
  *
  * Note that not all gateways will necessarily pass or require all of the
  * above.  These represent the most common attributes used among a variety
  * of gateways, it's up to the specific gateway implementation to make use
  * of, or ignore them, or add custom ones by overridding this method.
  *
  * Note: we could consider adding birthday to the list here, but do any gateways besides NETBilling use this one?
  *
  * @since 1.0.0
  * @see SV_WC_Payment_Gateway::get_order()
  * @param int $order_id order ID being processed
  * @return WC_Order object with payment and transaction information attached
  */
 protected function get_order($order_id)
 {
     $order = parent::get_order($order_id);
     // payment info
     if (SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-account-number') && !SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-payment-token')) {
         // common attributes
         $order->payment->account_number = str_replace(array(' ', '-'), '', SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-account-number'));
         if ($this->is_credit_card_gateway()) {
             // credit card specific attributes
             $order->payment->card_type = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-card-type');
             $order->payment->exp_month = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-exp-month');
             $order->payment->exp_year = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-exp-year');
             if ($this->csc_enabled()) {
                 $order->payment->csc = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-csc');
             }
         } elseif ($this->is_echeck_gateway()) {
             // echeck specific attributes
             $order->payment->routing_number = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-routing-number');
             $order->payment->account_type = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-account-type');
             $order->payment->check_number = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-check-number');
             $order->payment->drivers_license_number = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-drivers-license-number');
             $order->payment->drivers_license_state = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-drivers-license-state');
         }
     } elseif (SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-payment-token')) {
         // paying with tokenized payment method (we've already verified that this token exists in the validate_fields method)
         $token = $this->get_payment_token(SV_WC_Plugin_Compatibility::get_order_user_id($order), SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-payment-token'));
         $order->payment->token = $token->get_token();
         $order->payment->account_number = $token->get_last_four();
         if ($this->is_credit_card_gateway()) {
             // credit card specific attributes
             $order->payment->card_type = $token->get_card_type();
             $order->payment->exp_month = $token->get_exp_month();
             $order->payment->exp_year = $token->get_exp_year();
             if ($this->csc_enabled()) {
                 $order->payment->csc = SV_WC_Helper::get_post('wc-' . $this->get_id_dasherized() . '-csc');
             }
         } elseif ($this->is_echeck_gateway()) {
             // echeck specific attributes
             $order->payment->account_type = $token->get_account_type();
         }
         // make this the new default payment token
         $this->set_default_payment_token(SV_WC_Plugin_Compatibility::get_order_user_id($order), $token);
     }
     // allow other actors to modify the order object
     return apply_filters('wc_payment_gateway_' . $this->get_id() . '_get_order', $order, $this);
 }