# give/4.18.0.1/src/PaymentGateways/Gateways/PayPalCommerce/resources/js/createOrder.tsx

GiveWP – Donation Plugin and Fundraising Platform, version 4.18.0.1. 32 lines.

- Page: https://pluginprobe.com/plugins/give/4.18.0.1/code/src/PaymentGateways/Gateways/PayPalCommerce/resources/js/createOrder.tsx
- Raw: https://pluginprobe.com/plugins/give/4.18.0.1/raw/src/PaymentGateways/Gateways/PayPalCommerce/resources/js/createOrder.tsx
- Modified: 2026-08-24T19:37:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.18.0.1/code/src/PaymentGateways/Gateways/PayPalCommerce/resources/js/createOrder.tsx#L10-L20`.

```tsx
import type {PayPalCommerceGateway} from '../../types';
import {__} from '@wordpress/i18n';

/**
 * @since 4.16.7.1 Throw an Error carrying the server's message instead of a bare string, so the card
 *            fields error handler and the form can display it.
 * @since 4.0.0
 */
export default async function createOrder(url: string, gateway: PayPalCommerceGateway, formData: FormData) {
    const response = await fetch(url, {
        method: 'POST',
        body: formData,
    });

    const responseJson = await response.json();

    if (!responseJson.success) {
        const error = responseJson.data?.error;

        // The server answers with either a plain message or PayPal's own error object.
        throw new Error(
            typeof error === 'string' ? error : error?.message ?? __('Unable to create the PayPal order.', 'give')
        );
    }

    const orderId = responseJson.data.id;

    gateway.payPalOrderId = orderId;

    return orderId;
}

```
