Php 贝宝&x27;s CallPaymentDetails函数
我下载了PaypaplPlatform.php,不记得从哪里下载的,但它给了我一个很好的小功能,可以让我检查付款状态:Php 贝宝&x27;s CallPaymentDetails函数,php,paypal,paypal-adaptive-payments,paypal-nvp,Php,Paypal,Paypal Adaptive Payments,Paypal Nvp,我下载了PaypaplPlatform.php,不记得从哪里下载的,但它给了我一个很好的小功能,可以让我检查付款状态: CallPaymentDetails( $payKey, $transactionId, $trackingId ); 这将返回大量有用的数据,如状态和付款信息列表.paymentInfo(0).交易状态等 我知道我可以编写大量的if语句来解释调用CallPaymentDetails时返回给我的所有值,我觉得这可能非常容易出错,也可能导致我过度关注某个场景 所以我的问题是,是
CallPaymentDetails( $payKey, $transactionId, $trackingId );
这将返回大量有用的数据,如状态
和付款信息列表.paymentInfo(0).交易状态
等
我知道我可以编写大量的if
语句来解释调用CallPaymentDetails
时返回给我的所有值,我觉得这可能非常容易出错,也可能导致我过度关注某个场景
所以我的问题是,是否存在一个将所有值都考虑在内的示例模板,也就是说,我不必重新发明轮子,它可以考虑所有场景
例如,目前我有:
$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语句满足所有场景?首先,你不应该在互联网上抓取像
paypalplatform.php
这样的文件
共享所有不同语言的所有API有很多好处。我真的建议您查看一些存储库,例如:
$response->status
可以找到的所有返回消息。注释显示此变量可能具有的所有情况:
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);
}
自适应支付sdk php
它介绍了如何使用您的函数。它从html表单中获取值,更易于测试。与前面的示例一样,我们可以看到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>";
}
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));
}