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

Iva*_*ati 2 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);
Run Code Online (Sandbox Code Playgroud)

有谁知道我怎么能让这个工作?

谢谢伊万

Adr*_*eil 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);
Run Code Online (Sandbox Code Playgroud)

此时,请仔细检查响应是否失败.如果成功,用户应该已经被重定向到Paypal.

对于您要执行的操作(在通知URL中标识事务),诀窍是使用自定义return_url.例如:

'return_url' => base_url('callback/transaction/'.$transaction_id),
Run Code Online (Sandbox Code Playgroud)

这意味着在该页面上,您可以从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);
Run Code Online (Sandbox Code Playgroud)

此时,您可以检查$response以检查付款是否成功,并相应地更新您的数据库/操作.