First of all, you shouldn't grab a file on the internet like paypalplatform.php
.
Paypal use Github a lot to share all APIs for all differents languages. I really recommend you to take a look at some repository such as :
The last two are interesting for you. They both provide useful code sample for your case.
codesamples-php
It presents a simple call to the function you mention and describes all return message that can be found using one variable $response->status
. Comments reveal all case this variable can have:
if ($response->responseEnvelope->ack == "Success")
{
// The status of the payment. Possible values are:
//
// * CREATED - The payment request was received; funds will be
// transferred once the payment is approved
// * COMPLETED - The payment was successful
// * INCOMPLETE - Some transfers succeeded and some failed for a
// parallel payment or, for a delayed chained payment, secondary
// receivers have not been paid
// * ERROR - The payment failed and all attempted transfers failed
// or all completed transfers were successfully reversed
// * REVERSALERROR - One or more transfers failed when attempting
// to reverse a payment
// * PROCESSING - The payment is in progress
// * PENDING - The payment is awaiting processing
$logger->log("Payment Status : ".$response->status);
}
adaptivepayments-sdk-php
It presents a more detailed example on how to use your function. It takes values from an html form, easier to test it. Like the previous example, we can see same states returned by the API:
$ack = strtoupper($response->responseEnvelope->ack);
if($ack != "SUCCESS"){
echo "<b>Error </b>";
echo "<pre>";
print_r($response);
echo "</pre>";
} else {
/*
* The status of the payment. Possible values are:
* CREATED - The payment request was received; funds will be
transferred once the payment is approved
* COMPLETED - The payment was successful
* INCOMPLETE - Some transfers succeeded and some failed for a
parallel payment or, for a delayed chained payment, secondary
receivers have not been paid
* ERROR - The payment failed and all attempted transfers failed
or all completed transfers were successfully reversed
* REVERSALERROR - One or more transfers failed when attempting
to reverse a payment
* PROCESSING - The payment is in progress
* PENDING - The payment is awaiting processing
*/
echo "<table>";
echo "<tr><td>Ack :</td><td><div id='Ack'>$ack</div> </td></tr>";
echo "<tr><td>PayKey :</td><td><div id='PayKey'>$response->payKey</div> </td></tr>";
echo "<tr><td>Status :</td><td><div id='Status'>$response->status</div> </td></tr>";
echo "</table>";
echo "<pre>";
print_r($response);
echo "</pre>";
}
In both case, you only need a simple switch/case to handle response state. Something like that:
switch ($status)
{
case 'CREATED':
// handle CREATED state
break;
case 'COMPLETED':
// handle COMPLETED state
break;
case 'INCOMPLETE':
// handle INCOMPLETE state
break;
case 'ERROR':
// handle ERROR state
break;
case 'REVERSALERROR':
// handle REVERSALERROR state
break;
case 'PROCESSING':
// handle PROCESSING state
break;
case 'PENDING':
// handle PENDING state
break;
default:
throw new Exception(sprintf("State '%s' isn't handle.", $status));
}