Esempio n. 1
0
 /**
  * Post Charge
  */
 function post()
 {
     $this->load->library('opengateway');
     if ($this->input->post('recurring') == '0') {
         $charge = new Charge();
     } else {
         $charge = new Recur();
     }
     $api_url = site_url('api');
     $api_url = $this->config->item('ssl_active') == TRUE ? str_replace('http://', 'https://', $api_url) : $api_url;
     $charge->Authenticate($this->user->Get('api_id'), $this->user->Get('secret_key'), site_url('api'));
     $charge->Amount($this->input->post('amount'));
     // coupon
     if ($this->input->post('coupon')) {
         $charge->Coupon($this->input->post('coupon'));
     }
     if ($this->input->post('cc_number')) {
         $charge->CreditCard($this->input->post('cc_name'), $this->input->post('cc_number'), $this->input->post('cc_expiry_month'), $this->input->post('cc_expiry_year'), $this->input->post('cc_security'));
     }
     if ($this->input->post('recurring') == '1') {
         $charge->UsePlan($this->input->post('recurring_plan'));
     } elseif ($this->input->post('recurring') == '2') {
         $free_trial = $this->input->post('free_trial');
         $free_trial = empty($free_trial) ? FALSE : $free_trial;
         $occurrences = $this->input->post('recurring_end') == 'occurrences' ? $this->input->post('occurrences') : FALSE;
         $start_date = $this->input->post('start_date_year') . '-' . $this->input->post('start_date_month') . '-' . $this->input->post('start_date_day');
         $end_date = $this->input->post('end_date_year') . '-' . $this->input->post('end_date_month') . '-' . $this->input->post('end_date_day');
         $end_date = $this->input->post('recurring_end') == 'date' ? $end_date : FALSE;
         $charge->Schedule($this->input->post('interval'), $free_trial, $occurrences, $start_date, $end_date);
     }
     if ($this->input->post('customer_id') != '') {
         $charge->UseCustomer($this->input->post('customer_id'));
     } else {
         $first_name = $this->input->post('first_name') == 'First Name' ? '' : $this->input->post('first_name');
         $last_name = $this->input->post('last_name') == 'Last Name' ? '' : $this->input->post('last_name');
         $email = $this->input->post('email') == '*****@*****.**' ? '' : $this->input->post('email');
         $state = ($this->input->post('country') == 'US' or $this->input->post('country') == 'CA') ? $this->input->post('state_select') : $this->input->post('state');
         if (!empty($first_name) and !empty($last_name)) {
             $charge->Customer($first_name, $last_name, $this->input->post('company'), $this->input->post('address_1'), $this->input->post('address_2'), $this->input->post('city'), $state, $this->input->post('country'), $this->input->post('postal_code'), $this->input->post('phone'), $email);
         }
     }
     if ($this->input->post('gateway_type') == 'specify') {
         $charge->UseGateway($this->input->post('gateway'));
     }
     // set return URL
     if ($this->input->post('recurring') == '0') {
         $charge->Param('return_url', site_url('transactions/latest_charge'));
     } else {
         $charge->Param('return_url', site_url('transactions/latest_recur'));
     }
     $charge->Param('cancel_url', site_url('transactions/create'));
     $response = $charge->Charge();
     if (!is_array($response) or isset($response['error'])) {
         $this->notices->SetError($this->lang->line('transaction_error') . $response['error_text'] . ' (#' . $response['error'] . ')');
     } elseif (isset($response['response_code']) and $response['response_code'] == '2') {
         $this->notices->SetError($this->lang->line('transaction_error') . $response['response_text'] . '. ' . $response['reason'] . ' (#' . $response['response_code'] . ')');
     } else {
         $this->notices->SetNotice($this->lang->line('transaction_ok'));
     }
     if (isset($response['recurring_id'])) {
         $redirect = site_url('transactions/recurring/' . $response['recurring_id']);
     } elseif (isset($response['charge_id'])) {
         $redirect = site_url('transactions/charge/' . $response['charge_id']);
     } else {
         $redirect = site_url('transactions/create');
     }
     redirect($redirect);
     return TRUE;
 }