Google Shopping Content returnrefundlineitem API content.ContentErrorDomain Неверный формат запроса

Я пытался отправить запрос, увидев документацию в google content API, все выглядит правильно.

https://www.googleapis.com/content/v2.1sandbox/myid/orders/orderid/returnRefundLineItem

но гугл ответил 400 неправильным запросом "Неправильный запрос"

привело к 400 Bad Request.

Ответ Google Content API:

{
 "error": {
  "errors": [
   {
    "domain": "content.ContentErrorDomain",
    "reason": "malformed_request",
    "message": "Malformed request"
   }
  ],
  "code": 400,
  "message": "Malformed request"
 }
}

это тело моего запроса

{
  "operationId": "operation-6f8fa23bce94444b87e",
  "lineItemId": "QGKPTRMCKNCZESI",
  "quantity": 10,
  "reason": "other",
  "reasonText": "other",
  "priceAmount": {
    "value": "4500.00",
    "currency": "EUR"
  },
  "taxAmount": {
    "value": "0.00",
    "currency": "EUR"
  }
}

функция, которая будет выполнять жужжащий запрос

    public function execute($api, $requestType = 'GET', $body = null) {


        $client = new \GuzzleHttp\Client();
        $token = $this->container->get('config')->findOneByCode($this->configCode);
        $token = $token->getOptions();
        $requestOptions = ['headers' => ['Authorization' => 'Bearer ' . $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json']];
        if (null !== $body) {

            $requestOptions = array_merge($requestOptions, ['body' => $body]);
        }
        $response = $client->request($requestType, $this->url . '/' . $this->merchant_id . '/' . $api, $requestOptions);

        if ($response->getStatusCode() === 200) {

            return (string)$response->getBody();
        }

        return false;
    }

используемая функция для возврата


    public function refundLineItem($saleReturnId){

        $saleReturn  = $this->container->get('sale.return')->find($saleReturnId);
        $operationId = substr('operation-' . md5($saleReturn->getShipmentId() . uniqid($this->source) . time()), 0, 36);
        if($saleReturn->getIsRefunded()){
            throw new \Exception('Cette commande est déja rembourser', 953);
        }
        $saleInfo = json_decode($saleReturn->getSale()->getOrderinfo());

        $saleInfo = $saleInfo->google_order_info;
        $currentLineItem = null;

        foreach ($saleInfo->lineItems as $lineItem){
            if($lineItem->id === $saleReturn->getItemRef()){
                $currentLineItem = $lineItem;
                break;
            }
        }
        if (null === $currentLineItem) {
            throw new \Exception('Line item not found in sale info', 951);
        }

        $requestBody = [
          'operationId' => $operationId,
          'lineItemId' => $saleReturn->getItemRef(),
//          'productId' => $saleReturn->getSaleProduct()->getFinalProduct()->getId(),
          'quantity' => $saleReturn->getSaleProduct()->getQty(),
          'reason' => 'other',
          'reasonText' => 'other',
          'priceAmount' => [
              'value' => $currentLineItem->price->value,
              'currency' => $currentLineItem->price->currency,
          ],
          'taxAmount' => [
              'value' => $currentLineItem->tax->value,
              'currency' => $currentLineItem->tax->currency,
          ]
        ];



        $response = $this->execute("orders/{$saleReturn->getSaleIncrementId()}/returnRefundLineItem", 'POST', json_encode($requestBody));

        if(empty($response)){
            throw new \Exception('Empty Google Response', 952);
        }
        $saleReturn->setIsRefunded(true);
        $saleReturn = $this->container->get('sale.return')->save($saleReturn);
        $this->cancelSaleOrSaleProduct($saleReturn->getSale()->getId(), 'product', $saleReturn->getSaleProduct()->getId());

    }


person Amine Yakoubi    schedule 17.09.2019    source источник
comment
Можете ли вы показать код Guzzle?   -  person fonini    schedule 17.09.2019
comment
@fonini Я отредактировал свой пост, вы можете найти Guzzle Code в   -  person Amine Yakoubi    schedule 17.09.2019


Ответы (1)


Я устранил проблему с помощью другой функции createrefundinvoice

потому что я создал заказ с "enableOrderinvoices": true

использовать возврат средств

установка "enableOrderinvoices": false решит проблему

person Amine Yakoubi    schedule 26.09.2019