Php Codeigniter:如何获得paypal支付的购物车价值

Php Codeigniter:如何获得paypal支付的购物车价值,php,codeigniter,paypal,Php,Codeigniter,Paypal,这是paypal控制器代码: 我想知道如何才能从购物车中获取数据,以便我能够在paypal中添加价值,以便用户能够继续使用paypal?请帮忙 为此使用CI购物车库方法 $this->cart->total() 你得到了总金额的价格与此,如果你想使折扣超过这个你需要做一个方法独家为这个 [编辑] 当您获得总金额时,请根据Paypal文档使用Curl解析Paypal库,您可以使用Curl方法解析该值 curl -v -X 'POST' 'https://api.sandbox.pa

这是paypal控制器代码:


我想知道如何才能从购物车中获取数据,以便我能够在paypal中添加价值,以便用户能够继续使用paypal?请帮忙

为此使用CI购物车库方法

$this->cart->total()
你得到了总金额的价格与此,如果你想使折扣超过这个你需要做一个方法独家为这个

[编辑]

当您获得总金额时,请根据Paypal文档使用Curl解析Paypal库,您可以使用Curl方法解析该值

curl -v -X 'POST' 'https://api.sandbox.paypal.com/v1/invoicing/invoices' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <Access-Token>' \
-d '{
  "merchant_info": {
    "email": "dennis@sample.com",
    "first_name": "Dennis",
    "last_name": "Doctor",
    "business_name": "Medical Professionals, LLC",
    "phone": {
      "country_code": "001",
      "national_number": "5032141716"
    },
    "address": {
      "line1": "1234 Main St.",
      "city": "Portland",
      "state": "OR",
      "postal_code": "97217",
      "country_code": "US"
    }
  },
  "billing_info": [
  {
    "email": "example@example.com"
  }
  ],
  "items": [
  {
    "name": "Sutures",
    "quantity": 100,
    "unit_price": {
    "currency": "USD",
    "value": 5
    }
  }
  ],
  "note": "Medical Invoice 16 Jul, 2013 PST",
  "payment_term" :{
      "term_type": "NET_45"
  },
  "shipping_info": {
    "first_name": "Sally",
    "last_name": "Patient",
    "business_name": "Not applicable",
    "address": {
    "line1": "1234 Broad St.",
    "city": "Portland",
    "state": "OR",
    "postal_code": "97216",
    "country_code": "US"
    }
  }
}'

来源:CodeIgniter文档和PayPal API文档

根据控制器中的代码判断,我认为您可以使用PayPal库,在do_purchase函数中通过循环购物车内容添加产品:

foreach ($this->cart->contents() as $item) {
    $this->paypal->add($item['name'], $item['price'], $item['qty']);
}

$total = $this->cart->total();
您可以了解更多关于CodeIgniter的购物车类的信息

在一个完全不相关的注释中,您可以使用base_url作为函数,而不是向其附加字符串。例如,与cart/remove相比,它更具可读性/

curl -v -X 'POST' 'https://api.sandbox.paypal.com/v1/invoicing/invoices' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <Access-Token>' \
-d '{
  "merchant_info": {
    "email": "dennis@sample.com",
    "first_name": "Dennis",
    "last_name": "Doctor",
    "business_name": "Medical Professionals, LLC",
    "phone": {
      "country_code": "001",
      "national_number": "5032141716"
    },
    "address": {
      "line1": "1234 Main St.",
      "city": "Portland",
      "state": "OR",
      "postal_code": "97217",
      "country_code": "US"
    }
  },
  "billing_info": [
  {
    "email": "example@example.com"
  }
  ],
  "items": [
  {
    "name": "Sutures",
    "quantity": 100,
    "unit_price": {
    "currency": "USD",
    "value": 5
    }
  }
  ],
  "note": "Medical Invoice 16 Jul, 2013 PST",
  "payment_term" :{
      "term_type": "NET_45"
  },
  "shipping_info": {
    "first_name": "Sally",
    "last_name": "Patient",
    "business_name": "Not applicable",
    "address": {
    "line1": "1234 Broad St.",
    "city": "Portland",
    "state": "OR",
    "postal_code": "97216",
    "country_code": "US"
    }
  }
}'
foreach ($this->cart->contents() as $item) {
    $this->paypal->add($item['name'], $item['price'], $item['qty']);
}

$total = $this->cart->total();