@storecraft/payments-paypal 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapter.html.js +6 -2
- package/adapter.js +22 -31
- package/adapter.utils.js +3 -4
- package/package.json +1 -1
package/adapter.html.js
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* @import { Config } from './types.public.js'
|
3
|
+
* @import { OrderData } from '@storecraft/core/api'
|
4
|
+
*/
|
1
5
|
/**
|
2
6
|
*
|
3
7
|
* @description Official PayPal UI integration with `storecraft`.
|
@@ -10,8 +14,8 @@
|
|
10
14
|
* - Expiry date: 12/2027
|
11
15
|
* - CVC code: 897
|
12
16
|
*
|
13
|
-
* @param {
|
14
|
-
* @param {Partial<
|
17
|
+
* @param {Config} config
|
18
|
+
* @param {Partial<OrderData>} order_data
|
15
19
|
*/
|
16
20
|
export default function html_buy_ui(config, order_data) {
|
17
21
|
const orderData = order_data?.payment_gateway?.on_checkout_create;
|
package/adapter.js
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* @import { Config } from './types.public.js'
|
3
|
+
* @import { OrderData, PaymentGatewayStatus } from '@storecraft/core/api'
|
4
|
+
* @import { payment_gateway } from '@storecraft/core/payments'
|
5
|
+
* @import { paypal_order, paypal_order_request } from './types.private.js'
|
6
|
+
*/
|
1
7
|
import {
|
2
8
|
CheckoutStatusEnum, PaymentOptionsEnum
|
3
9
|
} from '@storecraft/core/api/types.api.enums.js';
|
@@ -6,19 +12,15 @@ import { StorecraftError } from '@storecraft/core/api/utils.func.js';
|
|
6
12
|
import html_buy_ui from './adapter.html.js';
|
7
13
|
|
8
14
|
/**
|
9
|
-
* @typedef {
|
10
|
-
* @typedef {
|
11
|
-
* @typedef {import('@storecraft/core/api').CheckoutStatusEnum} CheckoutStatusOptions
|
12
|
-
* @typedef {import('@storecraft/core/api').OrderData} OrderData
|
13
|
-
* @typedef {import('./types.public.d.ts').Config} Config
|
14
|
-
* @typedef {import('@storecraft/core/payments').payment_gateway<Config, CreateResult>} payment_gateway
|
15
|
+
* @typedef {paypal_order} CreateResult
|
16
|
+
* @typedef {payment_gateway<Config, CreateResult>} Impl
|
15
17
|
*/
|
16
18
|
|
17
19
|
/**
|
18
|
-
* @implements {payment_gateway}
|
19
|
-
*
|
20
20
|
* @description **Paypal Payment** gateway (https://developer.paypal.com/docs/checkout/)
|
21
|
-
|
21
|
+
*
|
22
|
+
* @implements {Impl}
|
23
|
+
*/
|
22
24
|
export class Paypal {
|
23
25
|
|
24
26
|
/** @type {Config} */ #_config;
|
@@ -91,7 +93,7 @@ export class Paypal {
|
|
91
93
|
|
92
94
|
/**
|
93
95
|
*
|
94
|
-
* @type {
|
96
|
+
* @type {Impl["invokeAction"]}
|
95
97
|
*/
|
96
98
|
invokeAction(action_handle) {
|
97
99
|
switch (action_handle) {
|
@@ -108,11 +110,7 @@ export class Paypal {
|
|
108
110
|
}
|
109
111
|
|
110
112
|
/**
|
111
|
-
* @
|
112
|
-
*
|
113
|
-
* @param {Partial<OrderData>} order
|
114
|
-
*
|
115
|
-
* @return {Promise<string>} html
|
113
|
+
* @type {Impl["onBuyLinkHtml"]}
|
116
114
|
*/
|
117
115
|
async onBuyLinkHtml(order) {
|
118
116
|
|
@@ -124,14 +122,12 @@ export class Paypal {
|
|
124
122
|
/**
|
125
123
|
* @description TODO: the user prefers to capture intent instead
|
126
124
|
*
|
127
|
-
* @
|
128
|
-
*
|
129
|
-
* @return {Promise<CreateResult>}
|
125
|
+
* @type {Impl["onCheckoutCreate"]}
|
130
126
|
*/
|
131
127
|
async onCheckoutCreate(order) {
|
132
128
|
const { default_currency_code: currency_code, intent_on_checkout } = this.config;
|
133
129
|
|
134
|
-
/** @type {
|
130
|
+
/** @type {paypal_order_request} */
|
135
131
|
const body = {
|
136
132
|
intent: intent_on_checkout==='AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE',
|
137
133
|
purchase_units: [
|
@@ -163,9 +159,7 @@ export class Paypal {
|
|
163
159
|
/**
|
164
160
|
* @description todo: logic for if user wanted capture at approval
|
165
161
|
*
|
166
|
-
* @
|
167
|
-
*
|
168
|
-
* @return {ReturnType<payment_gateway["onCheckoutComplete"]>}
|
162
|
+
* @type {Impl["onCheckoutComplete"]}
|
169
163
|
*/
|
170
164
|
async onCheckoutComplete(create_result) {
|
171
165
|
// the url based on authorize or capture intent
|
@@ -179,7 +173,7 @@ export class Paypal {
|
|
179
173
|
|
180
174
|
await throw_bad_response(response);
|
181
175
|
|
182
|
-
/** @type {
|
176
|
+
/** @type {paypal_order} */
|
183
177
|
const payload = await response.json();
|
184
178
|
|
185
179
|
let status;
|
@@ -211,11 +205,7 @@ export class Paypal {
|
|
211
205
|
/**
|
212
206
|
* @description Fetch the order and analyze it's status
|
213
207
|
*
|
214
|
-
*
|
215
|
-
* @param {CreateResult} create_result
|
216
|
-
*
|
217
|
-
*
|
218
|
-
* @returns {Promise<PaymentGatewayStatus>}
|
208
|
+
* @type {Impl["status"]}
|
219
209
|
*/
|
220
210
|
async status(create_result) {
|
221
211
|
const o = await this.retrieve_order(create_result);
|
@@ -286,9 +276,10 @@ export class Paypal {
|
|
286
276
|
/**
|
287
277
|
* @description [https://developer.paypal.com/api/rest/webhooks/rest/](https://developer.paypal.com/api/rest/webhooks/rest/)
|
288
278
|
*
|
289
|
-
* @
|
279
|
+
* @type {Impl["webhook"]}
|
290
280
|
*/
|
291
281
|
async webhook(request) {
|
282
|
+
throw new Error('Paypal:: webhook - not supported yet !');
|
292
283
|
return null;
|
293
284
|
}
|
294
285
|
|
@@ -297,7 +288,7 @@ export class Paypal {
|
|
297
288
|
*
|
298
289
|
* @param {CreateResult} create_result first create result, holds paypal id
|
299
290
|
*
|
300
|
-
* @return {Promise<
|
291
|
+
* @return {Promise<paypal_order>}
|
301
292
|
*/
|
302
293
|
retrieve_order = async (create_result) => {
|
303
294
|
const response = await fetch_with_auth(
|
@@ -308,7 +299,7 @@ export class Paypal {
|
|
308
299
|
|
309
300
|
await throw_bad_response(response);
|
310
301
|
|
311
|
-
/** @type {
|
302
|
+
/** @type {paypal_order} */
|
312
303
|
const jsonData = await response.json();
|
313
304
|
return jsonData;
|
314
305
|
}
|
package/adapter.utils.js
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
+
/**
|
2
|
+
* @import { Config } from './types.public.js'
|
3
|
+
*/
|
1
4
|
|
2
5
|
export const endpoints = {
|
3
6
|
test: 'https://api-m.sandbox.paypal.com',
|
4
7
|
prod: 'https://api-m.paypal.com'
|
5
8
|
}
|
6
9
|
|
7
|
-
/**
|
8
|
-
* @typedef {import("./types.public.d.ts").Config} Config
|
9
|
-
*/
|
10
|
-
|
11
10
|
/**
|
12
11
|
* @param {Config} config
|
13
12
|
*/
|