我正在尝试在支付过程中通过paypal传递一些自定义值,以便paypal在调用IPSN端点时将其返回给我。
我使用常规的html表单执行此操作,一切正常,但如果我使用CI-Merchant执行此操作,则自定义值为空。
$params = array(
'amount' => $amount_dollars,
'currency' => 'CAD',
'description' => $paypal_description,
'custom' => 'some_id='.$some_id_value,
'return_url' => base_url('callback'),
'cancel_url' => base_url('callback-cancelled'));
$response = $this->merchant->purchase($params);有谁知道我怎么才能让它工作吗?
谢谢,伊万
发布于 2013-02-01 10:22:42
CI Merchant允许您不必担心自己处理IPN,因此我认为您遇到了问题,因为您正在尝试做太多的工作:)
下面概述了处理PayPal付款的一般流程:http://ci-merchant.org/
首先,正如您所做的,您将在您的数据库中记录付款。这通常与您的orders表是分开的,所以创建一个transactions表或其他东西。将事务的状态设置为in_progress或其他值(在您的数据库中,具体情况由您决定)。
然后,按照您所做的那样创建付款申请(确保您使用的是paypal_express驱动程序,而不是旧的过时的paypal驱动程序):
$this->load->library('merchant');
$this->merchant->load('paypal_express');
$params = array(
'amount' => $amount_dollars,
'currency' => 'CAD',
'description' => $paypal_description,
'return_url' => base_url('callback'),
'cancel_url' => base_url('callback-cancelled'));
$response = $this->merchant->purchase($params);此时,仔细检查响应是否失败。如果成功,用户应该已经被重定向到Paypal。
对于您尝试执行的操作(在通知return_url中标识事务),诀窍是使用自定义的URL。例如:
'return_url' => base_url('callback/transaction/'.$transaction_id),这意味着在该页面上,您可以从segment变量中获取事务ID。您的回调控制器将如下所示:
// which transaction did we just complete
$transaction_id = $this->uri->segment(3);
// query database to find out transaction details
$transaction = $this->db->where('transaction_id', $transaction_id)->get('transactions')->row();
// confirm the paypal payment
$this->load->library('merchant');
$this->merchant->load('paypal_express');
// params array should be identical to what you passed to the `purchase()` method
// normally you would have some shared method somewhere to generate the $params
$params = array(
'amount' => $transaction->amount_dollars,
'currency' => 'CAD',
'description' => $transaction->description);
$response = $this->merchant->purchase_return($params);此时,您可以检查$response以检查支付是否成功,并相应地更新您的数据库/操作。
https://stackoverflow.com/questions/14638163
复制相似问题