Durgaprasad Gudi
Durgaprasad Gudi

Reputation: 16

How to instamojo payment gateway integrate with codeigniter

How to implement instamojo payment gateway integrate, it is unable to redirect payment gateway page...

 public function gatway() {
        $this->load->helper('url');
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://www.instamojo.com/api/1.1/payment-requests/');
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Api-Key:161ad93497e1af7efa6088621c75161f",
            "X-Auth-Token:b87b7fe1bc1fa56ad7bbcd1025f9f6aa"));
        $payload = Array(
            'purpose' => 'FIFA 16',
            'amount' => '2500',
            'phone' => '9999999999',
            'buyer_name' => 'John Doe',
            'redirect_url' => '',
            'send_email' => true,
            'webhook' => '',
            'send_sms' => true,
            'email' => '[email protected]',
            'allow_repeated_payments' => false,
        );
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
        $response = curl_exec($ch);
        curl_close($ch);
        $data = json_decode($response, TRUE);
        //echo $data;
        //var_dump($data);
        redirect($site, 'refresh');

Upvotes: 0

Views: 829

Answers (1)

B. Desai
B. Desai

Reputation: 16436

When you use htpps in curl you have to attach ssl certificate with curl request or set CURLOPT_SSL_VERIFYPEER to false

public function gatway() {
        $this->load->helper('url');
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://www.instamojo.com/api/1.1/payment-requests/');
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //<---- add this line or attach ssl certi
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Api-Key:161ad93497e1af7efa6088621c75161f",
            "X-Auth-Token:b87b7fe1bc1fa56ad7bbcd1025f9f6aa"));
        $payload = Array(
            'purpose' => 'FIFA 16',
            'amount' => '2500',
            'phone' => '9999999999',
            'buyer_name' => 'John Doe',
            'redirect_url' => '',
            'send_email' => true,
            'webhook' => '',
            'send_sms' => true,
            'email' => '[email protected]',
            'allow_repeated_payments' => false,
        );
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
        $response = curl_exec($ch);
        curl_close($ch);
        $data = json_decode($response, TRUE);
        if(isset($data['success']) && $data['success'] === true)
        {
          $site = $data['payment_request']['longurl'];
          redirect($site, 'refresh');
        }

Upvotes: 1

Related Questions