PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / PaymentGateways / Gateways / PayPalCommerce / resources / js / createOrder.tsx

createOrder.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/PaymentGateways/Gateways/PayPalCommerce/resources/js/createOrder.tsx

32 lines 969 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import type {PayPalCommerceGateway} from '../../types';
2 import {__} from '@wordpress/i18n';
3
4 /**
5 * @since 4.16.7.1 Throw an Error carrying the server's message instead of a bare string, so the card
6 * fields error handler and the form can display it.
7 * @since 4.0.0
8 */
9 export default async function createOrder(url: string, gateway: PayPalCommerceGateway, formData: FormData) {
10 const response = await fetch(url, {
11 method: 'POST',
12 body: formData,
13 });
14
15 const responseJson = await response.json();
16
17 if (!responseJson.success) {
18 const error = responseJson.data?.error;
19
20 // The server answers with either a plain message or PayPal's own error object.
21 throw new Error(
22 typeof error === 'string' ? error : error?.message ?? __('Unable to create the PayPal order.', 'give')
23 );
24 }
25
26 const orderId = responseJson.data.id;
27
28 gateway.payPalOrderId = orderId;
29
30 return orderId;
31 }
32