CI-Merchant中的付款自定义价值

时间:2013-02-01 01:15:42

标签: paypal express-checkout ci-merchant

我正在尝试在付款期间通过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);

有人知道我怎么能让它发挥作用?

由于 伊万

1 个答案:

答案 0 :(得分:6)

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。例如:

'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以检查付款是否成功,并相应地更新您的数据库/行为。

相关问题