For PayPal integration all their documentation tells you to call server-side script running on Node.js, and here the client-side call to the CreateOrder function in the server:
async createOrder() { const response = await fetch("/api/orders", { method: "POST", headers: {"Content-Type": "application/json", }, body: JSON.stringify({ cart: [ { id: "NQ888P", quantity: "3", }, ], }), });
But there is not a single document on this much better alternative: The code below, 100% running from client, does not call any server-side script at all. It goes straight to PayPal's site and does the same or even better job than the mechanism above:
createOrder: function (data, actions) { return actions.order.create({ intent: 'CAPTURE', purchase_units: [{ amount: { value: "14.99", currency_code: "USD" } }] }) },
This code can only be found in stackoverflow and other forums. So does anyone know why PayPal suppresses the client-only mechanism from all the documents?