I downloaded paypalplatform.php, can't remember where from, but it gives me a nice little function which allows me to check the state of a payment:
CallPaymentDetails( $payKey, $transactionId, $trackingId );
This returns lots of useful data like status
and paymentInfoList.paymentInfo(0).transactionStatus
and much more.
I know I can write lots of if
statements to try to account for all the values returned to me when I call CallPaymentDetails
, which I feel can be very error prone, or it could result in me over looking a scenario.
So my question is, does a sample template exist which takes all values into consideration, i.e. so I don't have to re-invent the wheel, which takes care of all scenarios?
For example, at the moment I have:
$resArray = CallPaymentDetails( $payKey, $transactionId, $trackingId );
if(strtoupper($resArray["responseEnvelope.ack"]) == "SUCCESS") {
if(strtoupper($resArray["status"]) == "CREATED") {
// do something
} elseif(strtoupper($resArray["status"]) == "EXPIRED") {
// do something
} elseif(strtoupper($resArray["status"]) == "COMPLETED") {
// do something
if(strtoupper($resArray["paymentInfoList.paymentInfo(0).transactionStatus"]) == "PENDING") {
// do something
} elseif(strtoupper($resArray["paymentInfoList.paymentInfo(0).transactionStatus"]) == "FAILED") {
// do something
} else {
// what other value could be returned
}
} else {
// what other value could be returned
}
} else {
// what other value could be returned
}
If I try to do all the variables, I could be at this forever trying to capture all scenarios, which is why I was wondering if such a template already exists which caters for all scenarios via if statements?