/**
  *
  * @param EEI_Payment $payment
  * @param array $billing_info
  * @param string        $return_url
  * @param string        $notify_url
  * @param string        $cancel_url
  * @return \EE_Payment|\EEI_Payment
  */
 public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL)
 {
     global $auto_made_thing_seed;
     $payment->set_redirect_url('http://google.com');
     $payment->set_txn_id_chq_nmbr($auto_made_thing_seed++);
     return $payment;
 }
 /**
  *
  * @param EEI_Payment $payment
  * @param array $billing_info
  * @return \EE_Payment|\EEI_Payment
  */
 public function do_direct_payment($payment, $billing_info = null)
 {
     require_once dirname(__FILE__) . '/lib/ChasePaymentech.php';
     $this->_default_error = __('An error occurred while processing your transaction. Please try again or contact us to complete your order.', 'event-espresso');
     $card_num = preg_replace('/[^0-9]+/', '', $billing_info['credit_card']);
     $cvv = preg_replace('/[^0-9]+/', '', $billing_info['cvv']);
     $payment_id = uniqid();
     $payment->set_txn_id_chq_nmbr($payment_id);
     $fields = array('AccountNum' => $card_num, 'Exp' => $billing_info['exp_month'] . $billing_info['exp_year'], 'CurrencyCode' => $payment->currency_code() === 'USD' ? '840' : '124', 'CurrencyExponent' => 2, 'CardSecValInd' => null, 'CardSecVal' => $cvv, 'Amount' => number_format($payment->amount(), 2, '', ''), 'AVSzip' => substr($billing_info['zip'], 0, 10), 'AVSaddress1' => substr($billing_info['address'], 0, 30), 'AVSaddress2' => $billing_info['address2'] ? substr($billing_info['address2'], 0, 30) : null, 'AVScity' => substr($billing_info['city'], 0, 20), 'AVSstate' => substr($billing_info['state'], 0, 2), 'AVScountryCode' => in_array($billing_info['country'], array('US', 'CA', 'GB', 'UK')) ? $billing_info['country'] : ' ', 'AVSphoneNum' => substr(preg_replace('/\\D/', '', $billing_info['phone']), 0, 14), 'AVSname' => substr($billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 30), 'OrderID' => $payment_id);
     /*
      * Visa & Discover require that the CardSecValInd be set
      *
      */
     $card_type = ChasePaymentech_Request::getCreditCardBrand($card_num);
     if (in_array($card_type, array('Visa', 'Discover'))) {
         $fields['CardSecValInd'] = is_numeric($cvv) ? 1 : 9;
     }
     $this->_log_clean_request_fields($fields, $payment);
     $sale = new ChasePaymentech_NewOrder($this->_connection_username, $this->_connection_password, $this->_merchant_id, array('bin' => $this->_bin, 'terminal_id' => $this->_terminal_id));
     if ($this->_validate_ssl_locally && file_exists(dirname(__FILE__) . '/lib/cacert.pem')) {
         $sale->setCurlOption(CURLOPT_CAINFO, dirname(__FILE__) . '/lib/cacert.pem');
     }
     if ($this->_disable_ssl_validation) {
         $sale->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
         $sale->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
     }
     $sale->setTestMode($this->_debug_mode);
     // $sale->setLogFile($this->log_file);
     // $sale->setLogRequests($this->log_requests, $force = true);
     $sale->setFields($fields);
     $response = $sale->authorizeAndCapture();
     $this->log(array('approved' => (string) $response->approved, 'declined' => (string) $response->declined, 'error' => (string) $response->error, 'ProcStatus' => (string) $response->ProcStatus instanceof SimpleXMLElement ? $response->ProcStatus->asXML() : '', 'RespCode' => (string) $response->RespCode, 'ApprovalStatus' => (string) $response->ApprovalStatus, 'response' => (string) htmlentities($response->response)), $payment);
     $payment->set_details(wp_json_encode($response));
     if (!isset($response->RespCode) || trim($response->RespCode) != '00') {
         $payment->set_status($this->_pay_model->declined_status());
         if ($this->_show_default_error !== true) {
             $error_message = $response->StatusMsg && !empty($response->StatusMsg) ? (string) $response->StatusMsg : $this->_default_error;
             $payment->set_gateway_response((string) $error_message);
         } else {
             $payment->set_gateway_response((string) $this->_default_error);
         }
     } else {
         $payment->set_status($this->_pay_model->approved_status());
         $payment->set_gateway_response(__('Payment Accepted', 'event_espresso'));
     }
     return $payment;
 }
 /**
  *
  * @param EEI_Payment $payment
  * @param type $billing_info
  * @param type $return_url
  * @param type $cancel_url
  */
 public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL)
 {
     global $auto_made_thing_seed;
     if (empty($auto_made_thing_seed)) {
         $auto_made_thing_seed = rand(1, 1000000);
     }
     $payment->set_txn_id_chq_nmbr($auto_made_thing_seed++);
     $payment->set_redirect_url(EE_NEW_PAYMENT_METHOD_URL . DS . 'payment_methods' . DS . 'New_Payment_Method_Offsite' . DS . 'pretend_offsite_page.php');
     $payment->set_redirect_args(array('amount' => $payment->amount(), 'gateway_txn_id' => $payment->txn_id_chq_nmbr(), 'return_url' => $return_url, 'uses_separate_IPN_request' => $this->uses_separate_IPN_request(), 'ipn_url' => $notify_url));
     return $payment;
 }