backend-manager 5.0.103 → 5.0.105
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/CHANGELOG.md +31 -0
- package/CLAUDE.md +113 -24
- package/README.md +8 -0
- package/TODO-PAYMENT-v2.md +5 -2
- package/package.json +1 -1
- package/src/cli/commands/deploy.js +2 -4
- package/src/cli/commands/emulator.js +30 -1
- package/src/cli/commands/test.js +33 -2
- package/src/manager/events/firestore/payments-webhooks/on-write.js +17 -3
- package/src/manager/events/firestore/payments-webhooks/transitions/index.js +6 -0
- package/src/manager/libraries/payment/processors/paypal.js +587 -0
- package/src/manager/libraries/{payment-processors → payment/processors}/stripe.js +86 -18
- package/src/manager/libraries/{payment-processors → payment/processors}/test.js +15 -8
- package/src/manager/routes/payments/cancel/processors/paypal.js +30 -0
- package/src/manager/routes/payments/cancel/processors/stripe.js +1 -1
- package/src/manager/routes/payments/cancel/processors/test.js +4 -6
- package/src/manager/routes/payments/intent/post.js +3 -3
- package/src/manager/routes/payments/intent/processors/paypal.js +150 -0
- package/src/manager/routes/payments/intent/processors/stripe.js +3 -5
- package/src/manager/routes/payments/intent/processors/test.js +7 -8
- package/src/manager/routes/payments/portal/processors/paypal.js +24 -0
- package/src/manager/routes/payments/portal/processors/stripe.js +1 -1
- package/src/manager/routes/payments/refund/post.js +85 -0
- package/src/manager/routes/payments/refund/processors/paypal.js +117 -0
- package/src/manager/routes/payments/refund/processors/stripe.js +103 -0
- package/src/manager/routes/payments/refund/processors/test.js +98 -0
- package/src/manager/routes/payments/webhook/processors/paypal.js +137 -0
- package/src/manager/schemas/payments/refund/post.js +18 -0
- package/src/test/test-accounts.js +46 -0
- package/templates/backend-manager-config.json +20 -24
- package/test/events/payments/journey-payments-cancel.js +3 -3
- package/test/events/payments/journey-payments-failure.js +1 -1
- package/test/events/payments/journey-payments-one-time.js +1 -1
- package/test/events/payments/journey-payments-plan-change.js +4 -4
- package/test/events/payments/journey-payments-suspend.js +3 -3
- package/test/events/payments/journey-payments-trial.js +2 -2
- package/test/fixtures/paypal/order-approved.json +62 -0
- package/test/fixtures/paypal/order-completed.json +110 -0
- package/test/fixtures/paypal/subscription-active.json +76 -0
- package/test/fixtures/paypal/subscription-cancelled.json +50 -0
- package/test/fixtures/paypal/subscription-suspended.json +65 -0
- package/test/helpers/payment/paypal/parse-webhook.js +539 -0
- package/test/helpers/payment/paypal/to-unified-one-time.js +382 -0
- package/test/helpers/payment/paypal/to-unified-subscription.js +820 -0
- package/test/helpers/{stripe-parse-webhook.js → payment/stripe/parse-webhook.js} +4 -4
- package/test/helpers/{stripe-to-unified-one-time.js → payment/stripe/to-unified-one-time.js} +8 -6
- package/test/helpers/{stripe-to-unified.js → payment/stripe/to-unified-subscription.js} +40 -33
- package/test/routes/payments/refund.js +174 -0
- package/src/manager/libraries/payment-processors/resolve-price-id.js +0 -19
- package/src/manager/routes/forms/delete.js +0 -37
- package/src/manager/routes/forms/get.js +0 -46
- package/src/manager/routes/forms/post.js +0 -45
- package/src/manager/routes/forms/public/get.js +0 -37
- package/src/manager/routes/forms/put.js +0 -52
- package/src/manager/schemas/forms/delete.js +0 -6
- package/src/manager/schemas/forms/get.js +0 -6
- package/src/manager/schemas/forms/post.js +0 -9
- package/src/manager/schemas/forms/public/get.js +0 -6
- package/src/manager/schemas/forms/put.js +0 -10
- /package/src/manager/libraries/{payment-processors → payment}/order-id.js +0 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test: PayPal toUnifiedOneTime()
|
|
3
|
+
* Unit tests for the PayPal library's raw resource → unified one-time payment transformation
|
|
4
|
+
*
|
|
5
|
+
* Tests the pure function directly — no emulator, no Firestore, no HTTP
|
|
6
|
+
* Mirrors stripe/to-unified-one-time.js for consistent coverage
|
|
7
|
+
*/
|
|
8
|
+
const PayPal = require('../../../../src/manager/libraries/payment/processors/paypal.js');
|
|
9
|
+
|
|
10
|
+
// Real PayPal sandbox fixtures
|
|
11
|
+
const FIXTURE_ORDER_APPROVED = require('../../../fixtures/paypal/order-approved.json');
|
|
12
|
+
const FIXTURE_ORDER_COMPLETED = require('../../../fixtures/paypal/order-completed.json');
|
|
13
|
+
|
|
14
|
+
// Mock config matching the BEM template (new flat price structure)
|
|
15
|
+
const MOCK_CONFIG = {
|
|
16
|
+
payment: {
|
|
17
|
+
products: [
|
|
18
|
+
{ id: 'basic', name: 'Basic', type: 'subscription', limits: { requests: 100 } },
|
|
19
|
+
{
|
|
20
|
+
id: 'credits-100', name: '100 Credits', type: 'one-time',
|
|
21
|
+
prices: { once: 9.99 },
|
|
22
|
+
paypal: { productId: 'PROD-credits-100' },
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 'credits-500', name: '500 Credits', type: 'one-time',
|
|
26
|
+
prices: { once: 39.99 },
|
|
27
|
+
paypal: { productId: 'PROD-credits-500' },
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function toUnifiedOneTime(rawResource, options) {
|
|
34
|
+
return PayPal.toUnifiedOneTime(rawResource, { config: MOCK_CONFIG, ...options });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
description: 'PayPal toUnifiedOneTime() transformation',
|
|
39
|
+
type: 'group',
|
|
40
|
+
|
|
41
|
+
tests: [
|
|
42
|
+
// ─── Status mapping ───
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
name: 'status-completed',
|
|
46
|
+
async run({ assert }) {
|
|
47
|
+
const result = toUnifiedOneTime({ status: 'COMPLETED' });
|
|
48
|
+
assert.equal(result.status, 'complete', 'PayPal COMPLETED → unified complete');
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
{
|
|
53
|
+
name: 'status-created-lowercased',
|
|
54
|
+
async run({ assert }) {
|
|
55
|
+
const result = toUnifiedOneTime({ status: 'CREATED' });
|
|
56
|
+
assert.equal(result.status, 'created', 'PayPal CREATED → lowercase created');
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
{
|
|
61
|
+
name: 'status-approved-lowercased',
|
|
62
|
+
async run({ assert }) {
|
|
63
|
+
const result = toUnifiedOneTime({ status: 'APPROVED' });
|
|
64
|
+
assert.equal(result.status, 'approved', 'PayPal APPROVED → lowercase approved');
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
{
|
|
69
|
+
name: 'status-voided-lowercased',
|
|
70
|
+
async run({ assert }) {
|
|
71
|
+
const result = toUnifiedOneTime({ status: 'VOIDED' });
|
|
72
|
+
assert.equal(result.status, 'voided', 'PayPal VOIDED → lowercase voided');
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
{
|
|
77
|
+
name: 'status-unknown-when-missing',
|
|
78
|
+
async run({ assert }) {
|
|
79
|
+
const result = toUnifiedOneTime({});
|
|
80
|
+
assert.equal(result.status, 'unknown', 'Missing status → unknown');
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
// ─── Product resolution ───
|
|
85
|
+
|
|
86
|
+
{
|
|
87
|
+
name: 'product-resolves-from-custom-id-product-id',
|
|
88
|
+
async run({ assert }) {
|
|
89
|
+
const result = toUnifiedOneTime({ custom_id: 'uid:user1,orderId:ord1,productId:credits-100' });
|
|
90
|
+
assert.equal(result.product.id, 'credits-100', 'Should resolve from custom_id productId');
|
|
91
|
+
assert.equal(result.product.name, '100 Credits', 'Should have correct name');
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
{
|
|
96
|
+
name: 'product-resolves-second-product',
|
|
97
|
+
async run({ assert }) {
|
|
98
|
+
const result = toUnifiedOneTime({ custom_id: 'uid:user1,productId:credits-500' });
|
|
99
|
+
assert.equal(result.product.id, 'credits-500', 'Should resolve credits-500');
|
|
100
|
+
assert.equal(result.product.name, '500 Credits', 'Should have correct name');
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
{
|
|
105
|
+
name: 'product-resolves-from-purchase-units-structured',
|
|
106
|
+
async run({ assert }) {
|
|
107
|
+
const result = toUnifiedOneTime({
|
|
108
|
+
purchase_units: [{ custom_id: 'uid:user1,orderId:ord1,productId:credits-100' }],
|
|
109
|
+
});
|
|
110
|
+
assert.equal(result.product.id, 'credits-100', 'Should resolve from purchase_units structured custom_id');
|
|
111
|
+
assert.equal(result.product.name, '100 Credits', 'Should have correct name');
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
{
|
|
116
|
+
name: 'product-purchase-units-takes-priority-over-top-level',
|
|
117
|
+
async run({ assert }) {
|
|
118
|
+
const result = toUnifiedOneTime({
|
|
119
|
+
custom_id: 'productId:credits-500',
|
|
120
|
+
purchase_units: [{ custom_id: 'uid:user1,productId:credits-100' }],
|
|
121
|
+
});
|
|
122
|
+
assert.equal(result.product.id, 'credits-100', 'purchase_units custom_id takes priority over top-level');
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
{
|
|
127
|
+
name: 'product-falls-back-to-unknown-on-missing-metadata',
|
|
128
|
+
async run({ assert }) {
|
|
129
|
+
const result = toUnifiedOneTime({});
|
|
130
|
+
assert.equal(result.product.id, 'unknown', 'No metadata → unknown');
|
|
131
|
+
assert.equal(result.product.name, 'Unknown', 'No metadata → Unknown name');
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
{
|
|
136
|
+
name: 'product-falls-back-to-product-id-on-unknown-product',
|
|
137
|
+
async run({ assert }) {
|
|
138
|
+
const result = toUnifiedOneTime({ custom_id: 'productId:nonexistent-product' });
|
|
139
|
+
assert.equal(result.product.id, 'nonexistent-product', 'Unknown product → uses ID as-is');
|
|
140
|
+
assert.equal(result.product.name, 'nonexistent-product', 'Unknown product → ID as name');
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
{
|
|
145
|
+
name: 'product-without-config',
|
|
146
|
+
async run({ assert }) {
|
|
147
|
+
const result = PayPal.toUnifiedOneTime({ custom_id: 'productId:credits-100' }, {});
|
|
148
|
+
assert.equal(result.product.id, 'credits-100', 'Without config → uses productId');
|
|
149
|
+
assert.equal(result.product.name, 'Unknown', 'Without config → Unknown name');
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
// ─── Payment metadata ───
|
|
154
|
+
|
|
155
|
+
{
|
|
156
|
+
name: 'payment-processor-always-paypal',
|
|
157
|
+
async run({ assert }) {
|
|
158
|
+
const result = toUnifiedOneTime({});
|
|
159
|
+
assert.equal(result.payment.processor, 'paypal', 'Processor should always be paypal');
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
{
|
|
164
|
+
name: 'payment-resource-id-from-resource-id',
|
|
165
|
+
async run({ assert }) {
|
|
166
|
+
const result = toUnifiedOneTime({ id: 'PAYID-ABC123' });
|
|
167
|
+
assert.equal(result.payment.resourceId, 'PAYID-ABC123', 'resourceId should be PayPal resource ID');
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
{
|
|
172
|
+
name: 'payment-resource-id-null-when-missing',
|
|
173
|
+
async run({ assert }) {
|
|
174
|
+
const result = toUnifiedOneTime({});
|
|
175
|
+
assert.equal(result.payment.resourceId, null, 'Missing ID → null resourceId');
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
{
|
|
180
|
+
name: 'payment-order-id-from-custom-id',
|
|
181
|
+
async run({ assert }) {
|
|
182
|
+
const result = toUnifiedOneTime({ custom_id: 'uid:user1,orderId:1234-5678-9012' });
|
|
183
|
+
assert.equal(result.payment.orderId, '1234-5678-9012', 'orderId should come from custom_id');
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
{
|
|
188
|
+
name: 'payment-order-id-null-when-missing',
|
|
189
|
+
async run({ assert }) {
|
|
190
|
+
const result = toUnifiedOneTime({});
|
|
191
|
+
assert.equal(result.payment.orderId, null, 'Missing custom_id → null orderId');
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
|
|
195
|
+
{
|
|
196
|
+
name: 'payment-price-resolves-from-config',
|
|
197
|
+
async run({ assert }) {
|
|
198
|
+
const result = toUnifiedOneTime({ custom_id: 'productId:credits-100' });
|
|
199
|
+
assert.equal(result.payment.price, 9.99, 'Should resolve price from config');
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
{
|
|
204
|
+
name: 'payment-price-zero-on-unknown-product',
|
|
205
|
+
async run({ assert }) {
|
|
206
|
+
const result = toUnifiedOneTime({ custom_id: 'productId:nonexistent' });
|
|
207
|
+
assert.equal(result.payment.price, 0, 'Unknown product → price 0');
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
{
|
|
212
|
+
name: 'payment-price-zero-when-no-metadata',
|
|
213
|
+
async run({ assert }) {
|
|
214
|
+
const result = toUnifiedOneTime({});
|
|
215
|
+
assert.equal(result.payment.price, 0, 'No metadata → price 0');
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
{
|
|
220
|
+
name: 'payment-event-metadata-passed-through',
|
|
221
|
+
async run({ assert }) {
|
|
222
|
+
const result = toUnifiedOneTime({}, { eventName: 'CHECKOUT.ORDER.APPROVED', eventId: 'WH-123' });
|
|
223
|
+
assert.equal(result.payment.updatedBy.event.name, 'CHECKOUT.ORDER.APPROVED', 'Event name passed through');
|
|
224
|
+
assert.equal(result.payment.updatedBy.event.id, 'WH-123', 'Event ID passed through');
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
{
|
|
229
|
+
name: 'payment-event-metadata-null-when-missing',
|
|
230
|
+
async run({ assert }) {
|
|
231
|
+
const result = toUnifiedOneTime({});
|
|
232
|
+
assert.equal(result.payment.updatedBy.event.name, null, 'Missing event name → null');
|
|
233
|
+
assert.equal(result.payment.updatedBy.event.id, null, 'Missing event ID → null');
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
// ─── Full unified shape ───
|
|
238
|
+
|
|
239
|
+
{
|
|
240
|
+
name: 'full-completed-shape',
|
|
241
|
+
async run({ assert }) {
|
|
242
|
+
const result = toUnifiedOneTime({
|
|
243
|
+
id: 'PAYID-FULL',
|
|
244
|
+
status: 'COMPLETED',
|
|
245
|
+
custom_id: 'uid:user1,orderId:1234-5678-9012,productId:credits-100',
|
|
246
|
+
}, { eventName: 'CHECKOUT.ORDER.APPROVED', eventId: 'WH-FULL' });
|
|
247
|
+
|
|
248
|
+
assert.ok(result.product, 'Should have product');
|
|
249
|
+
assert.ok(result.status, 'Should have status');
|
|
250
|
+
assert.ok(result.payment, 'Should have payment');
|
|
251
|
+
|
|
252
|
+
assert.equal(result.product.id, 'credits-100', 'Product should be credits-100');
|
|
253
|
+
assert.equal(result.status, 'complete', 'Status should be complete');
|
|
254
|
+
assert.equal(result.payment.processor, 'paypal', 'Processor should be paypal');
|
|
255
|
+
assert.equal(result.payment.resourceId, 'PAYID-FULL', 'Resource ID should match');
|
|
256
|
+
assert.equal(result.payment.orderId, '1234-5678-9012', 'orderId should match');
|
|
257
|
+
assert.equal(result.payment.price, 9.99, 'Price should be resolved');
|
|
258
|
+
assert.equal(result.payment.updatedBy.event.name, 'CHECKOUT.ORDER.APPROVED', 'Event name should match');
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
{
|
|
263
|
+
name: 'empty-input-gets-safe-defaults',
|
|
264
|
+
async run({ assert }) {
|
|
265
|
+
const result = toUnifiedOneTime({});
|
|
266
|
+
|
|
267
|
+
assert.equal(result.product.id, 'unknown', 'Empty → unknown product');
|
|
268
|
+
assert.equal(result.status, 'unknown', 'Empty → unknown status');
|
|
269
|
+
assert.equal(result.payment.processor, 'paypal', 'Empty → still paypal');
|
|
270
|
+
assert.equal(result.payment.orderId, null, 'Empty → null orderId');
|
|
271
|
+
assert.equal(result.payment.resourceId, null, 'Empty → null resourceId');
|
|
272
|
+
assert.equal(result.payment.price, 0, 'Empty → price 0');
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
|
|
276
|
+
{
|
|
277
|
+
name: 'no-expires-or-trial-on-one-time',
|
|
278
|
+
async run({ assert }) {
|
|
279
|
+
const result = toUnifiedOneTime({ id: 'PAYID-SHAPE' });
|
|
280
|
+
// One-time payments do not have subscription-specific fields
|
|
281
|
+
assert.equal(result.expires, undefined, 'No expires on one-time');
|
|
282
|
+
assert.equal(result.trial, undefined, 'No trial on one-time');
|
|
283
|
+
assert.equal(result.cancellation, undefined, 'No cancellation on one-time');
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
// ─── Custom ID parsing edge cases ───
|
|
288
|
+
|
|
289
|
+
{
|
|
290
|
+
name: 'custom-id-with-colon-in-values',
|
|
291
|
+
async run({ assert }) {
|
|
292
|
+
const result = toUnifiedOneTime({
|
|
293
|
+
custom_id: 'uid:firebase:auth:user123,orderId:ord-c,productId:credits-100',
|
|
294
|
+
});
|
|
295
|
+
assert.equal(result.payment.orderId, 'ord-c', 'orderId parsed correctly');
|
|
296
|
+
assert.equal(result.product.id, 'credits-100', 'productId parsed correctly');
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
{
|
|
301
|
+
name: 'custom-id-product-id-only',
|
|
302
|
+
async run({ assert }) {
|
|
303
|
+
const result = toUnifiedOneTime({
|
|
304
|
+
custom_id: 'productId:credits-500',
|
|
305
|
+
});
|
|
306
|
+
assert.equal(result.product.id, 'credits-500', 'Should parse productId without uid/orderId');
|
|
307
|
+
assert.equal(result.payment.orderId, null, 'No orderId → null');
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
{
|
|
312
|
+
name: 'custom-id-empty-string',
|
|
313
|
+
async run({ assert }) {
|
|
314
|
+
const result = toUnifiedOneTime({ custom_id: '' });
|
|
315
|
+
assert.equal(result.product.id, 'unknown', 'Empty custom_id → unknown product');
|
|
316
|
+
assert.equal(result.payment.orderId, null, 'Empty custom_id → null orderId');
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
|
|
320
|
+
// ─── updatedBy.date shape ───
|
|
321
|
+
|
|
322
|
+
{
|
|
323
|
+
name: 'updated-by-date-has-both-formats',
|
|
324
|
+
async run({ assert }) {
|
|
325
|
+
const result = toUnifiedOneTime({});
|
|
326
|
+
assert.ok(result.payment.updatedBy.date, 'Should have updatedBy.date');
|
|
327
|
+
assert.isType(result.payment.updatedBy.date.timestamp, 'string', 'timestamp should be string');
|
|
328
|
+
assert.isType(result.payment.updatedBy.date.timestampUNIX, 'number', 'timestampUNIX should be number');
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
// ─── Real PayPal sandbox fixtures ───
|
|
333
|
+
|
|
334
|
+
{
|
|
335
|
+
name: 'fixture-order-completed-produces-valid-shape',
|
|
336
|
+
async run({ assert }) {
|
|
337
|
+
const result = toUnifiedOneTime(FIXTURE_ORDER_COMPLETED);
|
|
338
|
+
|
|
339
|
+
assert.equal(result.status, 'complete', 'COMPLETED fixture → complete');
|
|
340
|
+
assert.equal(result.payment.processor, 'paypal', 'Processor is paypal');
|
|
341
|
+
assert.equal(result.payment.resourceId, '5UX02069M9686893E', 'Resource ID from fixture');
|
|
342
|
+
assert.equal(result.payment.orderId, 'ord-test-456', 'orderId from purchase_units custom_id');
|
|
343
|
+
assert.equal(result.product.id, 'credits-100', 'Product resolved from purchase_units custom_id');
|
|
344
|
+
assert.equal(result.product.name, '100 Credits', 'Product name from config');
|
|
345
|
+
assert.equal(result.payment.price, 9.99, 'Price from config');
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
{
|
|
350
|
+
name: 'fixture-order-approved-produces-valid-shape',
|
|
351
|
+
async run({ assert }) {
|
|
352
|
+
const result = toUnifiedOneTime(FIXTURE_ORDER_APPROVED);
|
|
353
|
+
|
|
354
|
+
assert.equal(result.status, 'approved', 'APPROVED fixture → approved');
|
|
355
|
+
assert.equal(result.payment.resourceId, '5UX02069M9686893E', 'Resource ID from fixture');
|
|
356
|
+
assert.equal(result.product.id, 'credits-100', 'Product resolved from purchase_units custom_id');
|
|
357
|
+
assert.equal(result.payment.orderId, 'ord-test-456', 'orderId from purchase_units custom_id');
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
{
|
|
362
|
+
name: 'fixture-all-orders-produce-valid-unified-keys',
|
|
363
|
+
async run({ assert }) {
|
|
364
|
+
const fixtures = [FIXTURE_ORDER_APPROVED, FIXTURE_ORDER_COMPLETED];
|
|
365
|
+
|
|
366
|
+
for (let i = 0; i < fixtures.length; i++) {
|
|
367
|
+
const result = toUnifiedOneTime(fixtures[i]);
|
|
368
|
+
assert.ok(result.product, `Fixture ${i}: should have product`);
|
|
369
|
+
assert.ok(result.status, `Fixture ${i}: should have status`);
|
|
370
|
+
assert.ok(result.payment, `Fixture ${i}: should have payment`);
|
|
371
|
+
assert.equal(result.payment.processor, 'paypal', `Fixture ${i}: processor is paypal`);
|
|
372
|
+
assert.isType(result.payment.updatedBy.date.timestamp, 'string', `Fixture ${i}: updatedBy.date.timestamp is string`);
|
|
373
|
+
assert.isType(result.payment.updatedBy.date.timestampUNIX, 'number', `Fixture ${i}: updatedBy.date.timestampUNIX is number`);
|
|
374
|
+
// One-time payments should NOT have subscription fields
|
|
375
|
+
assert.equal(result.expires, undefined, `Fixture ${i}: no expires`);
|
|
376
|
+
assert.equal(result.trial, undefined, `Fixture ${i}: no trial`);
|
|
377
|
+
assert.equal(result.cancellation, undefined, `Fixture ${i}: no cancellation`);
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
};
|