2

I am a newbie to codeigniter and so far I have been doing great in developing my first application. However, when I tried to integrate CI_MERCHANT library to the site I am getting redirected to paypal just fine and I can even complete the transaction successfully and get redirected to my website. However, I am stuck on how to verify the "hidden information" sent by paypal to my application in addition to extracting this information and posting it to the database.

in my controller I have this:

public function place_order($id=NULL){
    $this->merchant->load('paypal_express');


    $id=$this->session->userdata('id');
    $customer_id=$id;
    $rules=$this->order_m->rules_place_order;
    $this->form_validation->set_rules($rules);

    if ($this->form_validation->run() == FALSE) // validation hasn't been passed
    {
        $this->data['subview']='customer/order_view';
        $this->load->view('templates/header_customer');
        $this->load->view('customer/_layout_main',$this->data);
        $this->load->view('templates/footer_customer');


    }
    else // passed validation proceed to post success logic
    {
        // build array for the model


        $data=$this->order_m->array_from_order(array('topic_title','discipline','academic_level','type_of_service','paper_format','pages','no_of_sources','no_of_slides','paper_details','deadline','timezones'));
        $data['customer_id']=$id;
        $this->order_m->save_data($data);

            $this->db->where('customer_id',$id);
            //get the last inserted id
            $no=$this->db->insert_id();




                $settings=$this->merchant->default_settings();

                //payment for order
                $params = array(
                            'amount' => 100.00,
                            'currency' => 'USD',
                            'return_url' => 'http://localhost/customers/order/paypal',
                            'cancel_url' => 'http://localhost/customers/order'
                            );

                $response=$this->merchant->purchase($params);


        }
    }
 public function paypal(){
    var_dump($_GET);
    $this->merchant->load('paypal_express');
    $settings=$this->merchant->default_settings();
    $params = array(
                            'amount' => 100.00,
                            'currency' => 'USD',
                            );

    $response=$this->merchant->purchase_return($params);
    var_dump($response);
    if ($response->status() == Merchant_response::AUTHORIZED)
    {
        echo "status is AUTHORIZED";
    }
    if ($response->status() == Merchant_response::FAILED)
    {
        echo "status is FAILED";
    }
    if ($response->status() == Merchant_response::REDIRECT)
    {
        echo "status is REDIRECT";
    }
    if ($response->status() == Merchant_response::COMPLETE)
    {
        echo "status is COMPLETE";
    }
    if ($response->status() == Merchant_response::REFUNDED)
    {
        echo "status is REFUNDED";
    }

This redirects me successfully to paypal and I can complete the transaction. However, I am unable to proceed from here since I am a newbie to payment processing. Kindly point me in the right direction on how to: 1. Verify every transaction with paypal and be able to visualize and post this information to my database. 2. Compare the information I posted to the database prior to redirecting the customer to paypal with what I receive from paypal.

kelvin
  • 51
  • 7

2 Answers2

1

First check the detailed info about IPN here

enter image description here

When you are creating button in step3 you can specify IPN the url

Key points

You will receive the data at IPN url in $_POST variable

read that $_POST variable with mail('email', 'subject', 'data with $_POST') or writing into the log file

mrsrinivas
  • 34,112
  • 13
  • 125
  • 125
  • How am I supposed to capture and display information being sent to my IPN LISTENER and confirm that it is correct? Your help is highly appreciated :) – kelvin Jun 24 '13 at 08:37
0

You need to call the purchase_return() method when the customer is sent to your return_url. This will confirm the transaction with PayPal.

Jez D
  • 1,461
  • 2
  • 25
  • 52
Adrian Macneil
  • 13,017
  • 5
  • 57
  • 70
  • Should I have a function such as the one below that the return_url specifies or how should I go about it? public function paypal(){ $this->merchant->load('paypal_express'); $settings=$this->merchant->default_settings(); $params = array( 'amount' => 100.00, 'currency' => 'USD', ); $response=$this->merchant->purchase_return($params); var_dump($response);// to see what the response is} – kelvin Jun 24 '13 at 08:50
  • Yes, you need to put that in the controller method which runs on your return URL. Paypal will pass some query parameters through $_GET and ci-merchant will automatically pick them up and verify the response with paypal. – Adrian Macneil Jun 24 '13 at 09:44
  • Awesome! Now I am able to get the status "COMPLETE". One reason to smile now. One more question, let's say I want to pass information before redirecting to paypal and the capture it when the redirect and payment processing is over, how am I supposed to achieve this. Sorry for the trouble and thank you very much for the help. Another problem I am unable to see the transfer of funds from the one account to the other. Please address. – kelvin Jun 24 '13 at 09:52
  • I have actually figured out how to go about it thanks to your assistance @Adrian Macneil – kelvin Jun 25 '13 at 03:17