Search code examples
phppaypalpayment-gatewaypayflowpro

How do I handle response data from payment gateway?


I'm using the PayPal PayFlow Pro payment gateway. I've tested the PHP/CURL code given on https://ppmts.custhelp.com/app/answers/detail/a_id/618 and it returned:

HTTP/1.1 200 OK Connection: close Server: VPS-3.033.00 X-VPS-Request-ID: 20140619132842 Date: Thu, 19 Jun 2014 20:28:43 GMT Content-type: text/namevalue Content-length: 98 RESULT=0&PNREF=A71E6C7596B6&RESPMSG=Approved&AUTHCODE=010101&AVSADDR=Y&AVSZIP=Y&CVV2MATCH=Y&IAVS=N

Can I turn this response into an array or something that I can actually do something with? I don't know how I'm supposed to handle this data and I couldn't find any clear answers to this that worked when testing.


Solution

  • In PHP this is fairly easy. Here's a function that can turn it into an array

    function process_response($str) {
        $data = array();
        $x = explode('&', $str);
        foreach($x as $val) {
             $y = explode('=', $val);
             if(!empty($y[1]))
             $data[$y[0]] = urldecode($y[1]);
        }
        return $data;
    }
    

    As to the other data, here's an educated guess, based on PayPal Classic NVP

    • RESPMSG - Looks like the payment was approved
    • CVV2MATCH - The customer's CVV2 (3 or 4 digit code outside the card number) matched
    • AVS - The zip code matched the billing zip code
    • PNREF - Probably the unique identifier used for this transaction. Will probably be used if you need to issue a refund.