我使用以下代码处理使用MercadoPago和信用卡付款:
$mp = new MP($access_token);
$payment = array();
$payment["transaction_amount"] = 100.00;
$payment["token"] = $token;
$result = $mp->post("/v1/payments", $payment);
echo "<pre>";
print_r($result);
echo "</pre>";
我已经拥有信用卡令牌,但我仍然收到此错误:
Fatal error: Uncaught exception 'Exception' with message 'Params Error - 1: Params Error'
任何帮助将不胜感激。
感谢。
答案 0 :(得分:1)
这是一篇非常古老的帖子,但它可以帮助某人......
尝试捕获异常,以便您可以处理它并更轻松地进行调试。
我已经能够抓住它了:
// import
use \MP;
use \MercadoPagoException;
// try payment
try {
$payment = $this->mp->post("/v1/payments", $this->paymentData);
}
catch (MercadoPagoException $e) {
$paymentError = new \stdClass();
$paymentError->parsed = $this->parseException($e->getMessage());
$paymentError->data = $e->getMessage();
$paymentError->code = $e->getCode();
}
// parse the excepetion "message" to get the code and detail, if exists
private function parseException($message) {
$error = new \stdClass();
$error->code = 0;
$error->detail = '';
$posA = strpos($message, '-');
$posB = strpos($message, ':');
if($posA && $posB) {
$posA+=2;
$length = $posB - $posA;
// get code
$error->code = substr($message, $posA, $length);
// get message
$error->detail = substr($message, $posB+2);
}
return $error;
}