Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PayPal SDK(PHP)项目从数据库动态创建_Php_Laravel_Paypal - Fatal编程技术网

PayPal SDK(PHP)项目从数据库动态创建

PayPal SDK(PHP)项目从数据库动态创建,php,laravel,paypal,Php,Laravel,Paypal,我正在使用PayPalSDK(PHP)。我正在尝试从数据库动态创建项。所有计算都将通过动态方式完成。但我是faile。有人能帮我吗?此处代码: $item_1 = new Item(); $item_1->setName('Item 1') /** item name **/ ->setCurrency('USD') ->setQuantity(1) ->setPrice($reque

我正在使用PayPalSDK(PHP)。我正在尝试从数据库动态创建项。所有计算都将通过动态方式完成。但我是faile。有人能帮我吗?此处代码:

$item_1 = new Item();
        $item_1->setName('Item 1') /** item name **/
            ->setCurrency('USD')
            ->setQuantity(1)
            ->setPrice($request->get('amount')); /** unit price **/
        $item_list = new ItemList();
        $item_list->setItems(array($item_1));
        $amount = new Amount();
        $amount->setCurrency('USD')
            ->setTotal($request->get('amount'));
        $transaction = new Transaction();
        $transaction->setAmount($amount)
            ->setItemList($item_list)
            ->setDescription('Your transaction description') 

但问题是:PayPalHttpConnection.php第154行中的PayPalConnectionException:在访问时获得Http响应代码400。
$order_discount = $order->invoice->discount;
$order_subtotal = $order->invoice->sub_total;
$order_grandtotal = $order->invoice->grand_total;

$i = 1;
$order_items = array();
foreach ($order->invoice->products as $product) {

$order_items[$i] = new Item();
$order_items[$i]->setName($product->name)
->setCurrency('USD')
->setQuantity($product->qty)
->setPrice($product->price);

$i++;
}

if ($order->order_discount > 0) {
$order_items[$i] = new Item();
$order_items[$i]->setName('Discount')
->setCurrency('USD')
->setQuantity(1)
->setPrice('-' . $order_discount);
}

$item_list = new ItemList();
$item_list->setItems($order_items);

$amount_details = new Details();
$amount_details->setSubtotal($order_subtotal);

$amount = new Amount();
$amount->setCurrency('USD')
->setDetails($amount_details)
->setTotal($order_grandtotal);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($item_list)
->setDescription('Your transaction description')
->setInvoiceNumber($order->invoice->invoice_no);
$order_subtotal = $order->invoice->sub_total;
       $ship_tax = 0;
       $ship_cost = 0;
       $shipping_discount = $order->invoice->discount;
       $total = $order_subtotal + $ship_tax + $ship_cost - $shipping_discount;
        $items = [];
    foreach($order->invoice->products as $product)
    {
        $item = new Item();
        $item->setName($product->name)
            ->setPrice($product->price)
            ->setCurrency('USD')
            ->setQuantity($product->qty);
        $items[] = $item; 
    }
    $itemList = new ItemList();
    $itemList->setItems($items);

    $details = new Details();
    $details->setSubtotal($order_subtotal)
            ->setTax($ship_tax)
            ->setShipping($ship_cost)
            ->setShippingDiscount(- $shipping_discount);


    $amount = new Amount();
    $amount->setCurrency('USD')
        ->setDetails($details)
            ->setTotal($total);