0

We are updating our system and the old IPNs need to be processed differently. However, I cannot change the original IPN send-to addresses. So I have to "bounce" the IPN message off of old_IPNProcessor.php and forward it to new_IPNProcessor.php. I cannot modify old_IPNProcessor.php for technical reasons that go beyond the scope of this question.

From what I have read, I have to use cURL to accomplish this. I have seen some code for this, but I am unsure as to how it's implemented. For instance, the $post var in the code below (from https://stackoverflow.com/a/6213693/1390395) is the raw json straight from PayPal. Does it have to be in a PHP array for this to work?

function forwardIPN($post){
        $url = "new_IPNProcessor.php";

        // $post is the ipn message from PayPal
        $content = $post;

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER,
                array("Content-type: application/json"));
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

        $json_response = curl_exec($curl);

        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        if ( $status != 201 ) {
            die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
        }


        curl_close($curl);

        $response = json_decode($json_response, true);


    }
Community
  • 1
  • 1
frankie
  • 661
  • 2
  • 10
  • 25

0 Answers0