有没有人可以参考使用 Omnipay 集成 SagePay 服务器集成方法(场外付款)的示例?不幸的是,文档有点稀疏,我只是对我打算使用的方法感到困惑!
这是我的代码(我正在使用 CodeIgniter):
use Omnipay\Omnipay;
class Payment_gateway extends CI_Controller {
//live details
private $live_merchant_id = 'xxx';
//test details
private $test_merchant_id = 'yyy';
//payment settings
private $test_mode = TRUE;
private $merchant_id = '';
private $gateway = NULL;
public function __construct()
{
parent::__construct();
if ($this->test_mode) :
$this->merchant_id = $this->test_merchant_id;
else :
$this->merchant_id = $this->live_merchant_id;
endif;
$this->gateway = Omnipay::create('SagePay_Server');
$this->gateway->setVendor($this->merchant_id);
$this->gateway->setTestMode($this->test_mode);
$this->gateway->setSimulatorMode($this->test_mode);
}
public function index()
{
$response = $this->gateway->Purchase();
var_dump($response);
}
}
我确实使用上面的代码得到了一个响应对象。如果我尝试使用:
if ($response->isRedirect()) :
$response->redirect(); // this will automatically forward the customer
else :
// not successful
endif;
相反,我收到一个错误:
致命错误:调用未定义的方法 Omnipay\SagePay\Message\ServerPurchaseRequest::isRedirect()
如果我尝试使用:
$response = $this->gateway->Purchase()->send();
我收到一条消息说某些参数是必需的,所以如果我添加它们:
$response = $this->gateway->Purchase(array(
'returnUrl' => 'http://www.madeupdomain.com/',
'amount' => '10.00'
))->send();
我得到错误:
卡参数是必需的。
如果我尝试:
$response = $this->gateway->completePurchase(array(
'transactionId' => 111,
'transactionReference' => 'Online payment'
))->send();
我得到:
来自支付网关的无效响应
更新: 我误解了“需要卡参数”错误,因为我没有将任何信用卡详细信息传递给 SagePay,而不是我没有在 completePurchase 函数中传递卡数组,例如,我的索引函数应该如下所示:
public function index()
{
$response = $this->gateway->Purchase(array(
'description'=> 'Online order',
'currency'=> 'GBP',
'transactionId'=> mt_rand(99, 9999),
'transactionReference' => 'test order',
'amount'=> '1.00',
'returnUrl' => 'http://www.test.com/returnURL/',
'cancelUrl' => 'http://www.test.com/cancelURL/',
'card' => array(
'email' => 'test@test.com',
'clientIp' => '123.123.123.123',
'firstName' => 'Joe',
'LastName' => 'Bloggs',
'billingAddress1' => 'Address 1',
'billingAddress2' => 'Address 2',
'billingCity' => 'City',
'billingPostcode' => 'AB1 1BA',
'billingCountry' => 'GB',
'billingPhone' => '01234 567 890'
)))->send();
$response = $this->gateway->Purchase($this->params)->send();
if ($response->isRedirect()) {
$response->redirect();
} else {
echo '<pre> ';
var_dump($response);
echo '</pre> ';
exit;
}
}
这给了我一个全新的问题,但我认为我现在使用的是正确的功能。