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.
Files changed (60) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/CLAUDE.md +113 -24
  3. package/README.md +8 -0
  4. package/TODO-PAYMENT-v2.md +5 -2
  5. package/package.json +1 -1
  6. package/src/cli/commands/deploy.js +2 -4
  7. package/src/cli/commands/emulator.js +30 -1
  8. package/src/cli/commands/test.js +33 -2
  9. package/src/manager/events/firestore/payments-webhooks/on-write.js +17 -3
  10. package/src/manager/events/firestore/payments-webhooks/transitions/index.js +6 -0
  11. package/src/manager/libraries/payment/processors/paypal.js +587 -0
  12. package/src/manager/libraries/{payment-processors → payment/processors}/stripe.js +86 -18
  13. package/src/manager/libraries/{payment-processors → payment/processors}/test.js +15 -8
  14. package/src/manager/routes/payments/cancel/processors/paypal.js +30 -0
  15. package/src/manager/routes/payments/cancel/processors/stripe.js +1 -1
  16. package/src/manager/routes/payments/cancel/processors/test.js +4 -6
  17. package/src/manager/routes/payments/intent/post.js +3 -3
  18. package/src/manager/routes/payments/intent/processors/paypal.js +150 -0
  19. package/src/manager/routes/payments/intent/processors/stripe.js +3 -5
  20. package/src/manager/routes/payments/intent/processors/test.js +7 -8
  21. package/src/manager/routes/payments/portal/processors/paypal.js +24 -0
  22. package/src/manager/routes/payments/portal/processors/stripe.js +1 -1
  23. package/src/manager/routes/payments/refund/post.js +85 -0
  24. package/src/manager/routes/payments/refund/processors/paypal.js +117 -0
  25. package/src/manager/routes/payments/refund/processors/stripe.js +103 -0
  26. package/src/manager/routes/payments/refund/processors/test.js +98 -0
  27. package/src/manager/routes/payments/webhook/processors/paypal.js +137 -0
  28. package/src/manager/schemas/payments/refund/post.js +18 -0
  29. package/src/test/test-accounts.js +46 -0
  30. package/templates/backend-manager-config.json +20 -24
  31. package/test/events/payments/journey-payments-cancel.js +3 -3
  32. package/test/events/payments/journey-payments-failure.js +1 -1
  33. package/test/events/payments/journey-payments-one-time.js +1 -1
  34. package/test/events/payments/journey-payments-plan-change.js +4 -4
  35. package/test/events/payments/journey-payments-suspend.js +3 -3
  36. package/test/events/payments/journey-payments-trial.js +2 -2
  37. package/test/fixtures/paypal/order-approved.json +62 -0
  38. package/test/fixtures/paypal/order-completed.json +110 -0
  39. package/test/fixtures/paypal/subscription-active.json +76 -0
  40. package/test/fixtures/paypal/subscription-cancelled.json +50 -0
  41. package/test/fixtures/paypal/subscription-suspended.json +65 -0
  42. package/test/helpers/payment/paypal/parse-webhook.js +539 -0
  43. package/test/helpers/payment/paypal/to-unified-one-time.js +382 -0
  44. package/test/helpers/payment/paypal/to-unified-subscription.js +820 -0
  45. package/test/helpers/{stripe-parse-webhook.js → payment/stripe/parse-webhook.js} +4 -4
  46. package/test/helpers/{stripe-to-unified-one-time.js → payment/stripe/to-unified-one-time.js} +8 -6
  47. package/test/helpers/{stripe-to-unified.js → payment/stripe/to-unified-subscription.js} +40 -33
  48. package/test/routes/payments/refund.js +174 -0
  49. package/src/manager/libraries/payment-processors/resolve-price-id.js +0 -19
  50. package/src/manager/routes/forms/delete.js +0 -37
  51. package/src/manager/routes/forms/get.js +0 -46
  52. package/src/manager/routes/forms/post.js +0 -45
  53. package/src/manager/routes/forms/public/get.js +0 -37
  54. package/src/manager/routes/forms/put.js +0 -52
  55. package/src/manager/schemas/forms/delete.js +0 -6
  56. package/src/manager/schemas/forms/get.js +0 -6
  57. package/src/manager/schemas/forms/post.js +0 -9
  58. package/src/manager/schemas/forms/public/get.js +0 -6
  59. package/src/manager/schemas/forms/put.js +0 -10
  60. /package/src/manager/libraries/{payment-processors → payment}/order-id.js +0 -0
@@ -23,7 +23,7 @@ module.exports = {
23
23
  state.uid = uid;
24
24
  state.paidProductId = paidProduct.id;
25
25
  state.paidProductName = paidProduct.name;
26
- state.paidPriceId = paidProduct.prices.monthly.stripe;
26
+ state.paidStripeProductId = paidProduct.stripe?.productId;
27
27
 
28
28
  // Create subscription via test intent
29
29
  const response = await http.as('journey-payments-suspend').post('payments/intent', {
@@ -70,7 +70,7 @@ module.exports = {
70
70
  start_date: Math.floor(Date.now() / 1000) - 86400 * 60,
71
71
  trial_start: null,
72
72
  trial_end: null,
73
- plan: { id: state.paidPriceId, interval: 'month' },
73
+ plan: { product: state.paidStripeProductId, interval: 'month' },
74
74
  },
75
75
  },
76
76
  });
@@ -121,7 +121,7 @@ module.exports = {
121
121
  start_date: Math.floor(Date.now() / 1000) - 86400 * 60,
122
122
  trial_start: null,
123
123
  trial_end: null,
124
- plan: { id: state.paidPriceId, interval: 'month' },
124
+ plan: { product: state.paidStripeProductId, interval: 'month' },
125
125
  },
126
126
  },
127
127
  });
@@ -27,7 +27,7 @@ module.exports = {
27
27
 
28
28
  state.uid = uid;
29
29
  state.paidProductId = paidProduct.id;
30
- state.paidPriceId = paidProduct.prices.monthly.stripe;
30
+ state.paidStripeProductId = paidProduct.stripe?.productId;
31
31
  },
32
32
  },
33
33
 
@@ -103,7 +103,7 @@ module.exports = {
103
103
  start_date: Math.floor(Date.now() / 1000) - 86400 * 14,
104
104
  trial_start: Math.floor(Date.now() / 1000) - 86400 * 14,
105
105
  trial_end: Math.floor(Date.now() / 1000),
106
- plan: { id: state.paidPriceId, interval: 'month' },
106
+ plan: { product: state.paidStripeProductId, interval: 'month' },
107
107
  },
108
108
  },
109
109
  });
@@ -0,0 +1,62 @@
1
+ {
2
+ "id": "5UX02069M9686893E",
3
+ "intent": "CAPTURE",
4
+ "status": "APPROVED",
5
+ "payment_source": {
6
+ "paypal": {
7
+ "email_address": "sb-buyer@personal.example.com",
8
+ "account_id": "BUYERPAYERID123",
9
+ "account_status": "VERIFIED",
10
+ "name": {
11
+ "given_name": "Test",
12
+ "surname": "Buyer"
13
+ },
14
+ "address": {
15
+ "country_code": "US"
16
+ }
17
+ }
18
+ },
19
+ "purchase_units": [
20
+ {
21
+ "reference_id": "default",
22
+ "amount": {
23
+ "currency_code": "USD",
24
+ "value": "9.99"
25
+ },
26
+ "payee": {
27
+ "email_address": "itw.creative.works-facilitator@gmail.com",
28
+ "merchant_id": "C92NPPXDJSMXE",
29
+ "display_data": {
30
+ "brand_name": "Test Brand"
31
+ }
32
+ },
33
+ "description": "100 Credits",
34
+ "custom_id": "uid:test-user-123,orderId:ord-test-456,productId:credits-100"
35
+ }
36
+ ],
37
+ "payer": {
38
+ "name": {
39
+ "given_name": "Test",
40
+ "surname": "Buyer"
41
+ },
42
+ "email_address": "sb-buyer@personal.example.com",
43
+ "payer_id": "BUYERPAYERID123",
44
+ "address": {
45
+ "country_code": "US"
46
+ }
47
+ },
48
+ "create_time": "2026-03-04T10:09:16Z",
49
+ "update_time": "2026-03-04T10:10:30Z",
50
+ "links": [
51
+ {
52
+ "href": "https://api.sandbox.paypal.com/v2/checkout/orders/5UX02069M9686893E",
53
+ "rel": "self",
54
+ "method": "GET"
55
+ },
56
+ {
57
+ "href": "https://api.sandbox.paypal.com/v2/checkout/orders/5UX02069M9686893E/capture",
58
+ "rel": "capture",
59
+ "method": "POST"
60
+ }
61
+ ]
62
+ }
@@ -0,0 +1,110 @@
1
+ {
2
+ "id": "5UX02069M9686893E",
3
+ "intent": "CAPTURE",
4
+ "status": "COMPLETED",
5
+ "payment_source": {
6
+ "paypal": {
7
+ "email_address": "sb-buyer@personal.example.com",
8
+ "account_id": "BUYERPAYERID123",
9
+ "account_status": "VERIFIED",
10
+ "name": {
11
+ "given_name": "Test",
12
+ "surname": "Buyer"
13
+ },
14
+ "address": {
15
+ "country_code": "US"
16
+ }
17
+ }
18
+ },
19
+ "purchase_units": [
20
+ {
21
+ "reference_id": "default",
22
+ "amount": {
23
+ "currency_code": "USD",
24
+ "value": "9.99"
25
+ },
26
+ "payee": {
27
+ "email_address": "itw.creative.works-facilitator@gmail.com",
28
+ "merchant_id": "C92NPPXDJSMXE",
29
+ "display_data": {
30
+ "brand_name": "Test Brand"
31
+ }
32
+ },
33
+ "description": "100 Credits",
34
+ "custom_id": "uid:test-user-123,orderId:ord-test-456,productId:credits-100",
35
+ "payments": {
36
+ "captures": [
37
+ {
38
+ "id": "8MC585209K746631M",
39
+ "status": "COMPLETED",
40
+ "amount": {
41
+ "currency_code": "USD",
42
+ "value": "9.99"
43
+ },
44
+ "final_capture": true,
45
+ "seller_protection": {
46
+ "status": "ELIGIBLE",
47
+ "dispute_categories": [
48
+ "ITEM_NOT_RECEIVED",
49
+ "UNAUTHORIZED_TRANSACTION"
50
+ ]
51
+ },
52
+ "seller_receivable_breakdown": {
53
+ "gross_amount": {
54
+ "currency_code": "USD",
55
+ "value": "9.99"
56
+ },
57
+ "paypal_fee": {
58
+ "currency_code": "USD",
59
+ "value": "0.69"
60
+ },
61
+ "net_amount": {
62
+ "currency_code": "USD",
63
+ "value": "9.30"
64
+ }
65
+ },
66
+ "links": [
67
+ {
68
+ "href": "https://api.sandbox.paypal.com/v2/payments/captures/8MC585209K746631M",
69
+ "rel": "self",
70
+ "method": "GET"
71
+ },
72
+ {
73
+ "href": "https://api.sandbox.paypal.com/v2/payments/captures/8MC585209K746631M/refund",
74
+ "rel": "refund",
75
+ "method": "POST"
76
+ },
77
+ {
78
+ "href": "https://api.sandbox.paypal.com/v2/checkout/orders/5UX02069M9686893E",
79
+ "rel": "up",
80
+ "method": "GET"
81
+ }
82
+ ],
83
+ "create_time": "2026-03-04T10:10:45Z",
84
+ "update_time": "2026-03-04T10:10:45Z"
85
+ }
86
+ ]
87
+ }
88
+ }
89
+ ],
90
+ "payer": {
91
+ "name": {
92
+ "given_name": "Test",
93
+ "surname": "Buyer"
94
+ },
95
+ "email_address": "sb-buyer@personal.example.com",
96
+ "payer_id": "BUYERPAYERID123",
97
+ "address": {
98
+ "country_code": "US"
99
+ }
100
+ },
101
+ "create_time": "2026-03-04T10:09:16Z",
102
+ "update_time": "2026-03-04T10:10:45Z",
103
+ "links": [
104
+ {
105
+ "href": "https://api.sandbox.paypal.com/v2/checkout/orders/5UX02069M9686893E",
106
+ "rel": "self",
107
+ "method": "GET"
108
+ }
109
+ ]
110
+ }
@@ -0,0 +1,76 @@
1
+ {
2
+ "status": "ACTIVE",
3
+ "id": "I-MTPRX0B9LV4R",
4
+ "plan_id": "P-4BS10577GL664413KNGUAJ5Q",
5
+ "start_time": "2026-03-04T10:09:59Z",
6
+ "quantity": "1",
7
+ "create_time": "2026-03-04T10:09:59Z",
8
+ "update_time": "2026-03-04T10:12:00Z",
9
+ "custom_id": "uid:test-user-789,orderId:ord-sub-123",
10
+ "plan_overridden": false,
11
+ "subscriber": {
12
+ "email_address": "sb-buyer@personal.example.com",
13
+ "payer_id": "BUYERPAYERID123",
14
+ "name": {
15
+ "given_name": "Test",
16
+ "surname": "Buyer"
17
+ },
18
+ "shipping_address": {
19
+ "name": {
20
+ "full_name": "Test Buyer"
21
+ }
22
+ }
23
+ },
24
+ "billing_info": {
25
+ "outstanding_balance": {
26
+ "currency_code": "USD",
27
+ "value": "0.0"
28
+ },
29
+ "cycle_executions": [
30
+ {
31
+ "tenure_type": "REGULAR",
32
+ "sequence": 1,
33
+ "cycles_completed": 1,
34
+ "cycles_remaining": 0,
35
+ "current_pricing_scheme_version": 1,
36
+ "total_cycles": 0
37
+ }
38
+ ],
39
+ "last_payment": {
40
+ "amount": {
41
+ "currency_code": "USD",
42
+ "value": "15.0"
43
+ },
44
+ "time": "2026-03-04T10:12:00Z"
45
+ },
46
+ "next_billing_time": "2026-04-04T10:00:00Z",
47
+ "failed_payments_count": 0
48
+ },
49
+ "links": [
50
+ {
51
+ "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-MTPRX0B9LV4R",
52
+ "rel": "edit",
53
+ "method": "PATCH"
54
+ },
55
+ {
56
+ "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-MTPRX0B9LV4R",
57
+ "rel": "self",
58
+ "method": "GET"
59
+ },
60
+ {
61
+ "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-MTPRX0B9LV4R/suspend",
62
+ "rel": "suspend",
63
+ "method": "POST"
64
+ },
65
+ {
66
+ "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-MTPRX0B9LV4R/cancel",
67
+ "rel": "cancel",
68
+ "method": "POST"
69
+ },
70
+ {
71
+ "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-MTPRX0B9LV4R/capture",
72
+ "rel": "capture",
73
+ "method": "POST"
74
+ }
75
+ ]
76
+ }
@@ -0,0 +1,50 @@
1
+ {
2
+ "status": "CANCELLED",
3
+ "id": "I-MTPRX0B9LV4R",
4
+ "plan_id": "P-4BS10577GL664413KNGUAJ5Q",
5
+ "start_time": "2026-03-04T10:09:59Z",
6
+ "quantity": "1",
7
+ "create_time": "2026-03-04T10:09:59Z",
8
+ "update_time": "2026-03-15T08:30:00Z",
9
+ "custom_id": "uid:test-user-789,orderId:ord-sub-123",
10
+ "plan_overridden": false,
11
+ "subscriber": {
12
+ "email_address": "sb-buyer@personal.example.com",
13
+ "payer_id": "BUYERPAYERID123",
14
+ "name": {
15
+ "given_name": "Test",
16
+ "surname": "Buyer"
17
+ }
18
+ },
19
+ "billing_info": {
20
+ "outstanding_balance": {
21
+ "currency_code": "USD",
22
+ "value": "0.0"
23
+ },
24
+ "cycle_executions": [
25
+ {
26
+ "tenure_type": "REGULAR",
27
+ "sequence": 1,
28
+ "cycles_completed": 1,
29
+ "cycles_remaining": 0,
30
+ "current_pricing_scheme_version": 1,
31
+ "total_cycles": 0
32
+ }
33
+ ],
34
+ "last_payment": {
35
+ "amount": {
36
+ "currency_code": "USD",
37
+ "value": "15.0"
38
+ },
39
+ "time": "2026-03-04T10:12:00Z"
40
+ },
41
+ "failed_payments_count": 0
42
+ },
43
+ "links": [
44
+ {
45
+ "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-MTPRX0B9LV4R",
46
+ "rel": "self",
47
+ "method": "GET"
48
+ }
49
+ ]
50
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "status": "SUSPENDED",
3
+ "id": "I-MTPRX0B9LV4R",
4
+ "plan_id": "P-4BS10577GL664413KNGUAJ5Q",
5
+ "start_time": "2026-03-04T10:09:59Z",
6
+ "quantity": "1",
7
+ "create_time": "2026-03-04T10:09:59Z",
8
+ "update_time": "2026-03-20T14:00:00Z",
9
+ "custom_id": "uid:test-user-789,orderId:ord-sub-123",
10
+ "plan_overridden": false,
11
+ "subscriber": {
12
+ "email_address": "sb-buyer@personal.example.com",
13
+ "payer_id": "BUYERPAYERID123",
14
+ "name": {
15
+ "given_name": "Test",
16
+ "surname": "Buyer"
17
+ }
18
+ },
19
+ "billing_info": {
20
+ "outstanding_balance": {
21
+ "currency_code": "USD",
22
+ "value": "15.0"
23
+ },
24
+ "cycle_executions": [
25
+ {
26
+ "tenure_type": "REGULAR",
27
+ "sequence": 1,
28
+ "cycles_completed": 1,
29
+ "cycles_remaining": 0,
30
+ "current_pricing_scheme_version": 1,
31
+ "total_cycles": 0
32
+ }
33
+ ],
34
+ "last_payment": {
35
+ "amount": {
36
+ "currency_code": "USD",
37
+ "value": "15.0"
38
+ },
39
+ "time": "2026-03-04T10:12:00Z"
40
+ },
41
+ "failed_payments_count": 3
42
+ },
43
+ "links": [
44
+ {
45
+ "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-MTPRX0B9LV4R",
46
+ "rel": "edit",
47
+ "method": "PATCH"
48
+ },
49
+ {
50
+ "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-MTPRX0B9LV4R",
51
+ "rel": "self",
52
+ "method": "GET"
53
+ },
54
+ {
55
+ "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-MTPRX0B9LV4R/activate",
56
+ "rel": "activate",
57
+ "method": "POST"
58
+ },
59
+ {
60
+ "href": "https://api.sandbox.paypal.com/v1/billing/subscriptions/I-MTPRX0B9LV4R/cancel",
61
+ "rel": "cancel",
62
+ "method": "POST"
63
+ }
64
+ ]
65
+ }