Django Paypal Client/Server Данные, похоже, не поступают на сервер

Я использую эту реализацию для фронтенда: https://developer.paypal.com/demo/checkout/#/pattern/server

в частности, мой фронтенд:

............
// Call your server to set up the transaction
          createOrder: function (data, actions) {
            return fetch("/createOrder", {
              method: "post",
              credentials: "same-origin",
              headers: {
                "X-CSRFToken": csrftoken,
              },
            })
              .then(function (res) {
                console.log("res");
                console.log(res);
                return res;
              })
              .then(function (orderData) {
                console.log("orderData");
                console.log(orderData);
                return orderData.id;
              });
          },
......................

Мой бэкенд:

def sth(request):
    logger.error('called')
    t = gettoken()
    d = {"intent": "CAPTURE","purchase_units": [{"amount": {"currency_code": "USD","value": "100.00"}}]}
    h = {"Content-Type": "application/json", "Authorization": "Bearer "+t}
    r = requests.post('https://api-m.sandbox.paypal.com/v2/checkout/orders', headers=h, json=d).json()
    logger.error(r)
    return r

Консоль Python (logger.error(r)):

{'id': '597275692P0354804', 'status': 'CREATED', 'links': [{'href': 'https://api.sandbox.paypal.com/v2/checkout/orders/597275692P0354804', 'rel': 'self', 'method': 'GET'}, {'href': 'https://www.sandbox.paypal.com/checkoutnow?token=597275692P0354804', 'rel': 'approve', 'method': 'GET'}, {'href': 'https://api.sandbox.paypal.com/v2/checkout/orders/597275692P0354804', 'rel': 'update', 'method': 'PATCH'}, {'href': 'https://api.sandbox.paypal.com/v2/checkout/orders/597275692P0354804/capture', 'rel': 'capture', 'method': 'POST'}]}

Мой код ошибки в Frontend

Uncaught Error: Expected an order id to be passed

Для меня это выглядит так, как будто ответ не доходит до моего фронтенда. Может я что-то упустил?

измените среднюю часть на

.then(function (res) {
            console.log("res");
            console.log(res);
            return res.json();
          })

вам также может понадобиться обернуть его в ответ

возможно JSONResponse, но я думаю, что в данном случае достаточно обычного HTTPResponse

в python

return HTTPResponse(content=json.dumps(r))
Вернуться на верх