我从这里使用 Paypal PHP Rest API进行信用卡支付。我可以使用演示数据成功付款。当用户实时面临信用卡支付错误时,我需要一种以用户友好的方式而不是程序化的方式来显示它的方法。
从贝宝开发者网站,我找到了返回的错误对象的格式,但不知道如何使用它。
我的代码如下:
try {
$payment->create($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
echo "Exception: " . $ex->getMessage() . PHP_EOL;
var_dump($ex->getData());
}
故意输入错误数据,出现以下错误消息:
Exception: Got Http response code 400 when accessing
https://api.sandbox.paypal.com/v1/payments/payment.
string '{"name":"VALIDATION_ERROR","details":
[{"field":"payer.funding_instruments[0].credit_card",
"issue":"Invalid expiration (cannot be in the past)"},
{"field":"payer.funding_instruments[0].credit_card.number",
"issue":"Value is invalid"},{"field":
"payer.funding_instruments[0].credit_card.cvv2",
"issue":"Length is invalid (must be 3 or 4,
depending on card type)"}],"message":"Invalid request
- see details","information_link":
"https://developer.paypal.com/webapps
/developer/docs/api/#VALIDATION_ERROR","debug_id":
"bdcc'... (length=523)
那么我怎样才能得到上面提到的 Paypal 开发者网站中所说的错误对象,以及如何使用它向非技术人员显示错误?