Reputation: 997
I am new to CodeIgniter. I am trying to implement stripe payment gateway integration
. It is working fine with payment success status. I am trying to display to the user when it is failed. But passing failure data to my view is not working. Below is my code.
public function stripepay()
{
// some post variables
try {
require_once APPPATH."third_party/stripe/init.php";
//set api key
$stripe = array(
"secret_key" => "sk_test_gSev8A4OJf0F3BXXXXXXXX",
"publishable_key" => "pk_test_XZZxorO1rYsZTJXXXXXXXX"
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
// some more code
}catch ( Stripe\Error\Base $e )
{
// Code to do something with the $e exception object when an error occurs.
$body = $e->getJsonBody();
$err = $body['error'];
$data['failure_response'] = $err;
$data['response_status'] = $e->getHttpStatus();
$where = array('id' => $this->session->userdata('id'));
$payment_info = $this->baseM->getOneRowData('users', $where);
// this redirct is not working
//redirect('service/failure_402'.$data);
}
}
When it enters into this catch block I am trying to redirect to failue402 view.
public function failure_402($data)
{
$where = array('id' => $this->session->userdata('id'));
$payment_info = $this->baseM->getOneRowData('users', $where);
$this->load->view('page_layout/header', $data);
$this->load->view('service/failure_402',$data);
$this->load->view('page_layout/footer', $data);
}
In the above stripePay() function
// this redirect is not working
redirect('service/failure_402'.$data);
is not working.
Please guide me where I am doing the mistake. Any help would be greatly appreciated.
Upvotes: 0
Views: 1950
Reputation: 9717
You can use codeigniter session's set_flashdata()
method
{
$body = $e->getJsonBody();
$err = $body['error'];
$data['failure_response'] = $err;
$data['response_status'] = $e->getHttpStatus();
$where = array('id' => $this->session->userdata('id'));
$payment_info = $this->baseM->getOneRowData('users', $where);
/* EITHER */
$this->session->set_flashdata('failure_response' ,$err);
$this->session->set_flashdata('failure_response' ,$e->getHttpStatus());
/* OR */
$this->session->set_flashdata($data);
redirect('service/failure_402');
}
In falure_402()
public function failure_402()
{
print_r($this->session->flashdata());
/*OR this way */
echo $this->session->flashdata('failure_response')
}
For more : https://www.codeigniter.com/user_guide/libraries/sessions.html#flashdata
Upvotes: 3