Php 格式错误的_请求,传入的JSON请求未映射到API请求

Php 格式错误的_请求,传入的JSON请求未映射到API请求,php,paypal,paypal-rest-sdk,Php,Paypal,Paypal Rest Sdk,我面临一个我无法解决的问题,我不知道在哪里解决这个问题,我做错了什么?。。以下是包含所有数据的响应: "{"intent":"sale","payer":{"payment_method":"paypal"},"redirect_urls":{"return_url":"http://domain.ttl/api/paypal/success/","cancel_url":"http://domain.ttl/api/paypal/error/"},"transactions":[{"amoun

我面临一个我无法解决的问题,我不知道在哪里解决这个问题,我做错了什么?。。以下是包含所有数据的响应:

"{"intent":"sale","payer":{"payment_method":"paypal"},"redirect_urls":{"return_url":"http://domain.ttl/api/paypal/success/","cancel_url":"http://domain.ttl/api/paypal/error/"},"transactions":[{"amount":{"currency":"USD","total":"4250","details":{"shipping":"250.00","subtotal":"4000.00"}},"item_list":{"items":[[{"name":"Diesel Men's Happy Hours Lounge Sneaker","description":"Diesel Men's Happy Hours Lounge Sneaker","currency":"USD","quantity":"1","sku":"2","price":"3500.00"},{"name":"Hush Puppies Men's Herbie Roadside Slip-On Loafer","description":"Hush Puppies Men's Herbie Roadside Slip-On Loafer","currency":"USD","quantity":"1","sku":"3","price":"500.00"}]]},"description":"Pay from PayPal","invoice_number":"580cee9e1c8c6"}]}"
下面是我的PHP代码:

 // Getting items from database...
 // Geting $subtotal sum("field");
 //Getting sum of shipping by product..

   $payer = new \PayPal\Api\Payer();
    $payer->setPaymentMethod("paypal");

    $i = 0;
    $items = [];
    foreach($ToPay as $pay){
        $items[$i] = new \PayPal\Api\Item();
        $items[$i]->setName($pay->product->name)
            ->setDescription($pay->product->name)
            ->setCurrency("USD")
            ->setQuantity($pay->quantity)
            ->setSku($pay->product->id)
            ->setPrice($pay->price);
        $i++;
    }
    $total = $subtotal + $shipping;

    $itemList = new \PayPal\Api\ItemList();
    $itemList->setItems([$items]);

    $details = new \PayPal\Api\Details();
    $details->setShipping($shipping)
        ->setSubtotal($subtotal);

    $amount = new \PayPal\Api\Amount();
    $amount->setCurrency("USD")
        ->setTotal($total)
        ->setDetails($details);

    $transaction = new \PayPal\Api\Transaction();
    $transaction->setAmount($amount)
        ->setItemList($itemList)
        ->setDescription("Pay from PayPal")
        ->setInvoiceNumber(uniqid());

    $redirectUrls = new \PayPal\Api\RedirectUrls();
    $redirectUrls->setReturnUrl(SITE_URL . '/api/paypal/success/')
            ->setCancelUrl(SITE_URL . '/api/paypal/error/');

    $payment = new \PayPal\Api\Payment();
    $payment->setIntent('sale')
        ->setPayer($payer)
        ->setRedirectUrls($redirectUrls)
        ->setTransactions([$transaction]);

    try{
        $payment->create($paypal);
    }catch(\PayPal\Exception\PayPalConnectionException $e){
        trace_log($e->getData());
        echo $e->getCode();
        echo $e->getData();
        die($e);
    }catch (Exception $e) {
        die($e);
    }

    $approvalUrl = $payment->getApprovalLink();
    return \Redirect::to($approvalUrl);