/**
  * Returns true if the gateway supports the charge capture operation and it
  * can be invoked
  *
  * @since 1.0.0
  * @param \SV_WC_Payment_Gateway $gateway the payment gateway
  * @return boolean true if the gateway supports the charge capture operation and it can be invoked
  */
 public function can_capture_charge($gateway)
 {
     return $this->supports(self::FEATURE_CAPTURE_CHARGE) && $this->get_gateway()->is_available() && $gateway->supports(self::FEATURE_CAPTURE_CHARGE);
 }
 /**
  * Adds the standard transaction data to the order
  *
  * @since 1.0.0
  * @see SV_WC_Payment_Gateway::add_transaction_data()
  * @param WC_Order $order the order object
  * @param SV_WC_Payment_Gateway_API_Response|null $response optional transaction response
  */
 public function add_transaction_data($order, $response = null)
 {
     // add parent transaction data
     parent::add_transaction_data($order, $response);
     // payment info
     if (isset($order->payment->token) && $order->payment->token) {
         $this->update_order_meta($order->id, 'payment_token', $order->payment->token);
     }
     // account number
     if (isset($order->payment->account_number) && $order->payment->account_number) {
         $this->update_order_meta($order->id, 'account_four', substr($order->payment->account_number, -4));
     }
     if ($this->is_credit_card_gateway()) {
         // credit card gateway data
         if ($response && $response instanceof SV_WC_Payment_Gateway_API_Authorization_Response) {
             if ($response->get_authorization_code()) {
                 $this->update_order_meta($order->id, 'authorization_code', $response->get_authorization_code());
             }
             if ($order->payment_total > 0) {
                 // mark as captured
                 if ($this->perform_credit_card_charge()) {
                     $captured = 'yes';
                 } else {
                     $captured = 'no';
                 }
                 $this->update_order_meta($order->id, 'charge_captured', $captured);
             }
         }
         if (isset($order->payment->exp_year) && $order->payment->exp_year && isset($order->payment->exp_month) && $order->payment->exp_month) {
             $this->update_order_meta($order->id, 'card_expiry_date', $order->payment->exp_year . '-' . $order->payment->exp_month);
         }
         if (isset($order->payment->card_type) && $order->payment->card_type) {
             $this->update_order_meta($order->id, 'card_type', $order->payment->card_type);
         }
     } elseif ($this->is_echeck_gateway()) {
         // checking gateway data
         // optional account type (checking/savings)
         if (isset($order->payment->account_type) && $order->payment->account_type) {
             $this->update_order_meta($order->id, 'account_type', $order->payment->account_type);
         }
         // optional check number
         if (isset($order->payment->check_number) && $order->payment->check_number) {
             $this->update_order_meta($order->id, 'check_number', $order->payment->check_number);
         }
     }
 }
 /**
  * Save the Admin User Edit screen payment token fields, if any
  *
  * @see SV_WC_Payment_Gateway_Plugin::maybe_add_user_profile_tokenization_fields()
  * @param SV_WC_Payment_Gateway $gateway the gateway instance
  * @param int $user_id identifies the user to save the settings for
  */
 protected function save_user_profile_tokenization_fields($gateway, $user_id)
 {
     foreach (array_keys($gateway->get_environments()) as $environment_id) {
         // deleting any payment tokens?
         $payment_tokens_deleted_name = 'wc_' . $gateway->get_id() . '_payment_tokens_deleted_' . $environment_id;
         $delete_payment_tokens = SV_WC_Helper::get_post($payment_tokens_deleted_name) ? explode(',', trim(SV_WC_Helper::get_post($payment_tokens_deleted_name), ',')) : array();
         // see whether we're deleting any
         foreach ($delete_payment_tokens as $token) {
             $gateway->remove_payment_token($user_id, $token, $environment_id);
         }
         // adding a new payment token?
         $payment_token_name = 'wc_' . $gateway->get_id() . '_payment_token_' . $environment_id;
         if (SV_WC_Helper::get_post($payment_token_name)) {
             $exp_date = explode('/', SV_WC_Helper::get_post('wc_' . $gateway->get_id() . '_payment_token_exp_date_' . $environment_id));
             // add the new payment token, making it active if this is the first card
             $gateway->add_payment_token($user_id, $gateway->build_payment_token(SV_WC_Helper::get_post($payment_token_name), array('type' => $gateway->is_credit_card_gateway() ? 'credit_card' : 'check', 'card_type' => SV_WC_Helper::get_post('wc_' . $gateway->get_id() . '_payment_token_type_' . $environment_id), 'last_four' => SV_WC_Helper::get_post('wc_' . $gateway->get_id() . '_payment_token_last_four_' . $environment_id), 'exp_month' => count($exp_date) > 1 ? sprintf('%02s', $exp_date[0]) : null, 'exp_year' => count($exp_date) > 1 ? $exp_date[1] : null)));
         }
     }
 }
 /**
  * Adds the standard transaction data to the order
  *
  * @since 2.2.0
  * @see SV_WC_Payment_Gateway::add_transaction_data()
  * @param WC_Order $order the order object
  * @param SV_WC_Payment_Gateway_API_Response|null $response optional transaction response
  */
 public function add_transaction_data($order, $response = null)
 {
     // add parent transaction data
     parent::add_transaction_data($order, $response);
     // account number
     if ($response->get_account_number()) {
         $this->update_order_meta($order->id, 'account_four', substr($response->get_account_number(), -4));
     }
     if (self::PAYMENT_TYPE_CREDIT_CARD == $response->get_payment_type()) {
         if ($response->get_authorization_code()) {
             $this->update_order_meta($order->id, 'authorization_code', $response->get_authorization_code());
         }
         if ($order->get_total() > 0) {
             // mark as captured
             if ($response->is_charge()) {
                 $captured = 'yes';
             } else {
                 $captured = 'no';
             }
             $this->update_order_meta($order->id, 'charge_captured', $captured);
         }
         if ($response->get_exp_month() && $response->get_exp_year()) {
             $this->update_order_meta($order->id, 'card_expiry_date', $response->get_exp_year() . '-' . $response->get_exp_month());
         }
         if ($response->get_card_type()) {
             $this->update_order_meta($order->id, 'card_type', $response->get_card_type());
         }
     } elseif (self::PAYMENT_TYPE_ECHECK == $response->get_payment_type()) {
         // optional account type (checking/savings)
         if ($response->get_account_type()) {
             $this->update_order_meta($order->id, 'account_type', $response->get_account_type());
         }
         // optional check number
         if ($response->get_check_number()) {
             $this->update_order_meta($order->id, 'check_number', $response->get_check_number());
         }
     }
 }
 /**
  * Render the payment page for gateways that use a form post method
  *
  * @since 2.1
  * @see SV_WC_Payment_Gateway::payment_page()
  * @see SV_WC_Payment_Gateway_Hosted::use_form_post()
  * @see SV_WC_Payment_Gateway_Hosted::add_pay_page_handler()
  * @param int $order_id identifies the order
  */
 public function payment_page($order_id)
 {
     if (!$this->use_form_post()) {
         // default behavior: pay page is not used, direct-redirect from checkout
         parent::payment_page($order_id);
     } else {
         echo '<p>' . __('Thank you for your order, please click the button below to pay.', $this->text_domain) . '</p>';
         echo $this->generate_pay_form($order_id);
     }
 }