Codeigniter会话不保存数据

时间:2017-02-22 12:38:43

标签: codeigniter session paypal

标题说我正在使用codeigniter(v2.X),我包括angelleye's Paypal library。起初很难理解,但我设法定期付款。 现在我面临着与此相关的另一个问题。我需要为SetExpressCheckout()生成购物车数组并将其保存到用户的数据会话中,以便在用户登录到paypal帐户后使用它。 这里有一些代码

private function _setPaypalPayment($data)
{

    $cart['items'][0] = array(
        'id' => '1',
        'name' => "Payment ",
        'qty' => '1',
        'price' => (float)$data->money,
    );

    $cart['shopping_cart'] = array(
        'items' => $cart['items'],
        'subtotal' => (float)$data->money,
        'shipping' => 0,
        'handling' => 0,
        'tax' => 0,
    );

    $cart['shopping_cart']['grand_total'] = (float)$data->money;
    $this->session->set_userdata('shopping_cart', $cart);

    $SECFields = array(
        'maxamt' => (float)$data->money,
        'returnurl' => site_url('payment/confirmTrackPayment'),
        'cancelurl' => 'http://xxx',
        'hdrimg' => 'http://xxx/assets/images/logo_750X90.png',
        'logoimg' => 'http://xxx/assets/images/logo_190X60.png',
        'brandname' => 'xxx',
        'surveyquestion' => '',
        'customerservicenumber' => '',
    );

    $Payments = array();
    $Payment = array(
        'amt' => (float)$data->money,
    );

    array_push($Payments, $Payment);

    $PayPalRequestData = array(
        'SECFields' => $SECFields,
        'Payments' => $Payments,
    );

    $PayPalResult = $this->paypal_pro->SetExpressCheckout($PayPalRequestData);

    if(!$this->paypal_pro->APICallSuccessful($PayPalResult['ACK']))
    {
        return null;
    }
    else
    {
        return $PayPalResult['REDIRECTURL'];
    }
}

这部分工作正常,它返回URL,用户可以登录他的帐户。但当他返回付款/ confirmTrackPayment并且我做了

$cart = $this->session->userdata('shopping_cart');

$all = $this->session->all_userdata();

shopping_cart的信息不存在。我找不到任何答案,请帮助我!

提前致谢

1 个答案:

答案 0 :(得分:0)

我不确定(我没有Angeleyes的经验)但是我看了一下github repo中的代码,我认为你需要像这样设置shopping_cart(我也整理了一下): -

$items = array(
    array(
        'id' => '1',
        'name' => "Payment ",
        'qty' => '1',
        'price' => (float)$data->money,
    ),
);

$cart = array(
    'items' => $items,
    'subtotal' => (float)$data->money,
    'shipping' => 0,
    'handling' => 0,
    'tax' => 0,
    'grand_total' => (float)$data->money,
);

$this->session->set_userdata('shopping_cart', $cart);