give
/
src
/
PaymentGateways
/
Gateways
/
PayPalCommerce
/
resources
/
js
/
createSubscriptionPlan.tsx
createSubscriptionPlan.tsx
27 lines
| 1 | import type {PayPalCommerceGateway} from '../../types'; |
| 2 | |
| 3 | /** |
| 4 | * @since 4.0.0 |
| 5 | */ |
| 6 | export default async function createSubscriptionPlan(url: string, gateway: PayPalCommerceGateway, formData: FormData) { |
| 7 | const response = await fetch(url, { |
| 8 | method: 'POST', |
| 9 | body: formData, |
| 10 | }); |
| 11 | |
| 12 | const responseJson = await response.json(); |
| 13 | |
| 14 | if (!responseJson.success) { |
| 15 | throw responseJson.data.error; |
| 16 | } |
| 17 | |
| 18 | const planId = responseJson.data.id; |
| 19 | |
| 20 | gateway.payPalPlanId = planId; |
| 21 | |
| 22 | return { |
| 23 | planId, |
| 24 | userAction: responseJson.data?.user_action, |
| 25 | }; |
| 26 | } |
| 27 |