gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:45:33 25 4
gpt4 key购买 nike

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

有人知道我怎样才能让它工作吗?

谢谢伊万

最佳答案

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。

对于您尝试执行的操作(在您的通知 URL 中标识交易),诀窍是使用自定义 return_url。例如:

'return_url' => base_url('callback/transaction/'.$transaction_id),

这意味着您可以在该页面上从段变量中获取交易 ID。您的回调 Controller 将如下所示:

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

关于paypal - CI-Merchant 中的自定义付款值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14638163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com