我正在尝试了解使用 Omnipay/SecurePay 进行付款的流程,但在尝试完成购买时总是出错。
从在线文档中我可以看到,completePurchase
应该使用与函数相同的参数purchase
调用函数,但是当我调用时,completePurchase
我收到“无效指纹”异常。
这些错误也被抛出:
Undefined index: merchant in /var/www/vendor/omnipay/securepay/src/Message/DirectPostCompletePurchaseRequest.php on line 28
Undefined index: refid in /var/www/vendor/omnipay/securepay/src/Message/DirectPostCompletePurchaseRequest.php on line 30
Undefined index: timestamp in /var/www/vendor/omnipay/securepay/src/Message/DirectPostCompletePurchaseRequest.php on line 32
Undefined index: summarycode in /var/www/vendor/omnipay/securepay/src/Message/DirectPostCompletePurchaseRequest.php on line 33
我是否错过了添加这些缺失数据的步骤?还是应该在响应中返回这些数据?
代码:
$params = array(
'amount' => $data->payment['amount'] . '.00',
'currency' => $this->getOptions()->getCurrency(),
'description' => 'test purchase',
'transactionId' => '12345',
'transactionReference' => $data->course['course_code'],
'returnUrl' => 'http://test.localhost/register/55622/confirmation',
'cancelUrl' => 'http://test.localhost/register/55622/summary',
'card'=>$card
);
$gateway = new DirectPostGateway();
$gateway->setMerchantId( $this->getOptions()->getGateway( $type )['merchant_id'] );
$gateway->setTransactionPassword( $this->getOptions()->getGateway( $type )['password'] );
$gateway->setTestMode( $this->getOptions()->getTestMode() );
$response = $gateway->purchase($params)->send();
var_dump($response->getRedirectData());
$response = $gateway->completePurchase($params)->send();
var_dump($response);
//"Invalid fingerprint" exception thrown
if ($response->isSuccessful()) {
// payment was successful: update database
return $response;
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
if($response->getRedirectData()){
var_dump($response->getRedirectData());
} else {
return $response->redirect();
}
exit;
return $response->redirect();
} else {
// payment failed: display message to customer
// echo $response->getMessage();
throw new Exception("Error Processing Request", 1);
}