我正在尝试使用 CodeIgniter 制作一个小购物车,我发现 CI-Merchant 可以通过本指南使用支付网关 http://ci-merchant.org/但我不太明白如何让它与 Paypal Sandbox 一起使用。
$this->load->library('merchant');
$this->merchant->load('paypal_express');
$settings = array(
'username' => '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e3f2e4e3d7e3f2e4e3b9f4f8fa" rel="noreferrer noopener nofollow">[email protected]</a>',
'password' => '********',
'signature' => 'Test Store',
'test_mode' => true);
$this->merchant->initialize($settings);
$params = array(
'amount' => 12.00,
'currency' => 'CAD',
'return_url' => 'http://payment.test.com',
'cancel_url' => 'http://payment.test.com/cancel');
$response = $this->merchant->purchase($params);
$this->load->view('welcome_message');
我知道这段代码不能做太多事情,但它什么也没做。只是加载 View ,什么也没有发生,我不明白。所以,我的问题是,你知道教程或者知道如何让 CI Merchant 与 Paypal Sandbox 一起使用吗?感谢您的帮助。
最佳答案
艾斯的评论很到位。您的代码没有任何问题,但您需要检查 $response
对象以查看结果(或错误消息)是什么。
$response = $this->merchant->purchase($params);
if ($response->success())
{
// mark order as complete
$gateway_reference = $response->reference();
}
else
{
$message = $response->message();
echo('Error processing payment: ' . $message);
exit;
}
您也可以简单地尝试此方法来检查对象:
$response = $this->merchant->purchase($params);
echo '<pre>';
print_r($response);
exit;
关于CodeIgniter、CI-Merchant 和 Paypal 沙盒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13224575/