@yaks/stripe 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +156 -2
- package/_dist/doors.d.ts +13 -0
- package/_dist/doors.d.ts.map +1 -0
- package/_dist/graph.d.ts +4 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/mod.d.ts +23 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/plans.d.ts +98 -0
- package/_dist/plans.d.ts.map +1 -0
- package/_dist/shops.d.ts +217 -0
- package/_dist/shops.d.ts.map +1 -0
- package/_dist/testing.d.ts +30 -0
- package/_dist/testing.d.ts.map +1 -0
- package/checkout.js +37 -0
- package/checkout.js.map +1 -0
- package/checkout.ts +74 -0
- package/deno.json +1 -0
- package/doors.js +36 -0
- package/doors.js.map +1 -0
- package/doors.ts +58 -0
- package/graph.js +17 -0
- package/graph.js.map +1 -0
- package/graph.ts +21 -0
- package/invoices.js +75 -0
- package/invoices.js.map +1 -0
- package/invoices.ts +102 -0
- package/mod.js +118 -0
- package/mod.js.map +1 -0
- package/mod.ts +154 -0
- package/package.json +38 -4
- package/plans.js +463 -0
- package/plans.js.map +1 -0
- package/plans.ts +617 -0
- package/refunds.js +65 -0
- package/refunds.js.map +1 -0
- package/refunds.ts +88 -0
- package/shop-portal.js +79 -0
- package/shop-portal.js.map +1 -0
- package/shop-portal.ts +92 -0
- package/shop-term.js +52 -0
- package/shop-term.js.map +1 -0
- package/shop-term.ts +89 -0
- package/shops.js +689 -0
- package/shops.js.map +1 -0
- package/shops.ts +820 -0
- package/testing.js +72 -0
- package/testing.js.map +1 -0
- package/testing.ts +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Jeff Peterson
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,157 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/stripe
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stripe's v1 API over `fetch`, with no SDK.
|
|
4
|
+
`ask({key, clock}, path, fields?, on?)` makes one call: a GET without `fields`,
|
|
5
|
+
otherwise a form-encoded POST (`form` nests keys as `a[b][c]`). `on` names a
|
|
6
|
+
connected account, sent as the `Stripe-Account` header, so the platform key acts
|
|
7
|
+
on that merchant's books. A call that did not get through, or that Stripe says
|
|
8
|
+
to retry (`Stripe-Should-Retry`), is asked again under one `Idempotency-Key`,
|
|
9
|
+
`TRIES` times in all, waiting on the lent clock. A refusal throws `StripeError`,
|
|
10
|
+
whose message is Stripe's own sentence and whose `code` tells one refusal from
|
|
11
|
+
another.
|
|
12
|
+
|
|
13
|
+
The host lends the key and the clock. Nothing reads the environment.
|
|
14
|
+
|
|
15
|
+
`@yaks/stripe/graph` lends Stripe as a payment provider (`payments`, from
|
|
16
|
+
`@yaks/host/payments`) named `stripe`, with `name: 'Stripe'`, its `plans`, its
|
|
17
|
+
`shops` and its `doors`, built from the options a config gives it: `key`,
|
|
18
|
+
`clock`, `prices`, each tier's price ids by `month` and `year`, `kept`, each
|
|
19
|
+
tier's price ids it no longer sells but whose subscriptions are still on it, and
|
|
20
|
+
`doors`, each webhook door's signing secret by its name.
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"use": "@yaks/stripe",
|
|
25
|
+
"with": {
|
|
26
|
+
"key": { "secret": "STRIPE_KEY" },
|
|
27
|
+
"prices": {
|
|
28
|
+
"plus": { "month": "price_plus" },
|
|
29
|
+
"pro": { "month": "price_pro", "year": "price_pro_year" }
|
|
30
|
+
},
|
|
31
|
+
"kept": { "plus": ["price_plus_before_the_raise"] },
|
|
32
|
+
"doors": {
|
|
33
|
+
"webhook": { "secret": "STRIPE_WEBHOOK_SECRET" },
|
|
34
|
+
"connect": { "secret": "STRIPE_CONNECT_WEBHOOK_SECRET" }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Key permissions
|
|
41
|
+
|
|
42
|
+
Each key is a restricted key, and Stripe refuses a call its key has no
|
|
43
|
+
permission for (`more_permissions_required`). This is every resource the package
|
|
44
|
+
calls, so a key made from this list is refused nothing. A call added to the
|
|
45
|
+
package adds its resource here.
|
|
46
|
+
|
|
47
|
+
`key`, on the platform's own account:
|
|
48
|
+
|
|
49
|
+
| resource | access | for |
|
|
50
|
+
| ------------------- | ------ | -------------------------------------------------------- |
|
|
51
|
+
| Customers | Write | a plan's payer (./plans.ts) |
|
|
52
|
+
| Subscriptions | Write | a plan's term, and a house sale's renewing term |
|
|
53
|
+
| Invoices | Read | how far a term is paid (./shop-term.ts) |
|
|
54
|
+
| Checkout Sessions | Write | buying a plan, and a house sale |
|
|
55
|
+
| Customer portal | Write | a payer's portal and its configuration |
|
|
56
|
+
| Charges and Refunds | Write | a house sale's refund, and the charge a dispute is about |
|
|
57
|
+
| Application Fees | Write | refunding the fee in proportion (`refundFee`) |
|
|
58
|
+
| Accounts | Write | a seller's connected account (./shops.ts) |
|
|
59
|
+
| Account Links | Write | a seller's onboarding link |
|
|
60
|
+
|
|
61
|
+
`key`, on connected accounts (Stripe's Connect column):
|
|
62
|
+
|
|
63
|
+
| resource | access | for |
|
|
64
|
+
| ------------------- | ------ | ---------------------------------------------------- |
|
|
65
|
+
| Checkout Sessions | Write | a seller's sale |
|
|
66
|
+
| Customer portal | Write | a buyer's portal and its configuration |
|
|
67
|
+
| Subscriptions | Write | a buyer's term, read and cancelled (./shop-term.ts) |
|
|
68
|
+
| Invoices | Read | how far a buyer's term is paid |
|
|
69
|
+
| Charges and Refunds | Write | a seller's refund, and the charge a dispute is about |
|
|
70
|
+
|
|
71
|
+
`walletKey` needs Payment Method Domains Write on connected accounts, and
|
|
72
|
+
`invoiceKey` needs Products, Invoices and Invoice Items Write on the platform's
|
|
73
|
+
own account (./invoices.ts).
|
|
74
|
+
|
|
75
|
+
## Plans
|
|
76
|
+
|
|
77
|
+
`plans(options)` (`@yaks/stripe/plans`) sells a party its plan. A payer is a
|
|
78
|
+
customer; a supplied payer key keeps retries on one customer. Checkout reuses
|
|
79
|
+
the payer's matching open session for the same reference, expiring a different
|
|
80
|
+
choice before creating its replacement. Concurrent requests share the creation
|
|
81
|
+
key derived from the preceding session. Other references and one-off purchases
|
|
82
|
+
are left alone. Checkout is a subscription session under Managed Payments, which
|
|
83
|
+
Stripe sells as merchant of record, so it sends none of the parameters Stripe
|
|
84
|
+
controls there; the tags ride the session's and the subscription's `metadata`,
|
|
85
|
+
the reference its `client_reference_id`, and time given free a `trial_end` no
|
|
86
|
+
sooner than two days away. A plan paid by invoice is a subscription made
|
|
87
|
+
directly with `collection_method: send_invoice` and `days_until_due`, under the
|
|
88
|
+
caller's idempotency key, after the customer's email and name are set to where
|
|
89
|
+
the invoices go. Managed Payments covers no subscription made outside Checkout,
|
|
90
|
+
so on these the account is the seller, and the invoice offers the payment
|
|
91
|
+
methods the account's invoice settings allow. The portal is a billing portal
|
|
92
|
+
session. A subscription reads its tier off its item's price (the first tier
|
|
93
|
+
listing it, else the first tier keeping it, else the first tier), its period end
|
|
94
|
+
off the item or the subscription, whichever the API version sends, and its
|
|
95
|
+
standing off its status: `active` and `trialing` pay, `past_due` owes,
|
|
96
|
+
`incomplete` awaits its first payment, `canceled` and `incomplete_expired` have
|
|
97
|
+
ended, and the rest have lapsed. An invoiced subscription's status is read with
|
|
98
|
+
its latest invoice (`statusOf`), since Stripe calls it `active` before anything
|
|
99
|
+
is paid: its first billed period is `incomplete` until that period's invoice is
|
|
100
|
+
paid, and `past_due` is `unpaid`, since nothing retries a check. Postponing sets
|
|
101
|
+
the trial to end later, prorating nothing. `refunded` refunds a paid one-off
|
|
102
|
+
checkout's payment whole, its key carried as the idempotency key and in the
|
|
103
|
+
refund's metadata, so a request asked again refunds once.
|
|
104
|
+
`changed(options)(event)` reads a verified event as a subscription changed: a
|
|
105
|
+
`customer.subscription.*` event carries its subscription, save an invoiced one,
|
|
106
|
+
which is asked for with its latest invoice, and a checkout session or an invoice
|
|
107
|
+
names one, read on asking; one Stripe does not hold reads as `null`.
|
|
108
|
+
|
|
109
|
+
## Shops
|
|
110
|
+
|
|
111
|
+
`shops(options)` (`@yaks/stripe/shops`), lent beside the plans, sells on Connect
|
|
112
|
+
accounts under the "charge merchants directly" model. An account is opened with
|
|
113
|
+
its four controller properties written out (the account pays Stripe's fees,
|
|
114
|
+
Stripe carries lost disputes, a full dashboard, Stripe collects the
|
|
115
|
+
requirements) and the tags as metadata; `charges_enabled` reads as `ready` and
|
|
116
|
+
`details_submitted` as `submitted`. Onboarding is an `account_onboarding`
|
|
117
|
+
Account Link returning and refreshing to the same address. A checkout is a
|
|
118
|
+
payment-mode session on the account (`Stripe-Account`), its lines inline
|
|
119
|
+
`price_data`, the fee `payment_intent_data[application_fee_amount]` (none when
|
|
120
|
+
0), and the tags on both the session and its PaymentIntent, so a refund's charge
|
|
121
|
+
carries them; a tag carries 500 characters (`tag`), as a metadata value does.
|
|
122
|
+
Its return addresses get their braces back, which `URL` percent-encodes, so
|
|
123
|
+
Stripe still finds its `{CHECKOUT_SESSION_ID}` in them. The house sells on the
|
|
124
|
+
platform's own account instead, named `''` wherever an account is: no
|
|
125
|
+
`Stripe-Account` header and no application fee. Managed Payments is turned off
|
|
126
|
+
(`managed_payments[enabled]=false`), since it is on by default for the
|
|
127
|
+
platform's plans and covers digital goods only. The sale's `descriptor` is the
|
|
128
|
+
card statement's suffix (`descriptor`, as in `YAKS.APP* PRINTBOUND`), and
|
|
129
|
+
`house: 'true'` rides the metadata. The house sells nothing that renews: those
|
|
130
|
+
events on the platform's own account would read as its plans.
|
|
131
|
+
`shopped(options)(event)` reads `account.updated`,
|
|
132
|
+
`account.application.deauthorized`, `checkout.session.completed`,
|
|
133
|
+
`checkout.session.async_payment_succeeded`,
|
|
134
|
+
`checkout.session.async_payment_failed`, `charge.refunded` and
|
|
135
|
+
`charge.dispute.created` or `.closed`; a dispute's charge is read back on the
|
|
136
|
+
account, since a dispute carries no metadata.
|
|
137
|
+
|
|
138
|
+
## Doors
|
|
139
|
+
|
|
140
|
+
`doors(options)` (`@yaks/stripe/doors`) are Stripe's two webhook endpoints,
|
|
141
|
+
which a host serves at `/stripe/<name>`: `webhook`, events from the platform's
|
|
142
|
+
own account, read by `changed` save the house's sales, refunds and disputes
|
|
143
|
+
(`housed`), read by `shopped` naming no account, and `connect`, events from
|
|
144
|
+
connected accounts, read by `shopped`. Stripe signs each endpoint's events with
|
|
145
|
+
its own `whsec_…`, so each door verifies the raw body with its own secret
|
|
146
|
+
(@yaks/hook's `refusal('stripe', …)`) and answers `{heard}` or
|
|
147
|
+
`{refused, ours}`, `ours` where a well-formed signature did not match, which is
|
|
148
|
+
what a wrong secret looks like. A door with no secret answers `undefined`.
|
|
149
|
+
|
|
150
|
+
`@yaks/stripe/testing` stands in for Stripe in a test: `signed(secret, raw, at)`
|
|
151
|
+
is the `Stripe-Signature` header Stripe puts on a webhook,
|
|
152
|
+
`delivered(post,
|
|
153
|
+
path, secret, type, object, on?, at?)` posts a signed event
|
|
154
|
+
through `post` and answers the door's body, and `fakeSub(metadata, over?)` is a
|
|
155
|
+
subscription shaped as `read` reads one.
|
|
156
|
+
|
|
157
|
+
[Stripe API reference](https://docs.stripe.com/api)
|
package/_dist/doors.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Door } from "@yaks/host/payments";
|
|
2
|
+
import { type Options as Priced } from "./plans.js";
|
|
3
|
+
import { type Options as Shopping } from "./shops.js";
|
|
4
|
+
/** What a config gives the provider: the plans' key, clock and prices, the
|
|
5
|
+
* shops' Connect client, and each door's signing secret by its name. A door
|
|
6
|
+
* with none hears nothing. */ export type Options = Priced & Shopping & {
|
|
7
|
+
doors?: {
|
|
8
|
+
webhook?: string;
|
|
9
|
+
connect?: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/** Stripe's doors, each secret read from `options` as a request arrives. */ export declare let doors: (options: Options) => Record<string, Door>;
|
|
13
|
+
//# sourceMappingURL=doors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doors.d.ts","sources":["../doors.ts"],"names":[],"mappings":"AAYA,cAAc,IAAI,mCAA+C;AAEjE,SAAkB,KAAK,WAAW,MAAM,qBAAoB;AAC5D,SAAiB,KAAK,WAAW,QAAQ,qBAA6B;AAEtE;;4BAE4B,GAC5B,YAAY,UAAU,SAAS;EAC7B;IAAU,UAAU,MAAM;IAAE,UAAU,MAAM;;;AAwB9C,0EAA0E,GAC1E,OAAO,YAAI,QAAS,SAAS,YAAU,OAAO,MAAM,EAAE,MAWrD"}
|
package/_dist/graph.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAKA,cAAc,QAAQ,mCAAwC;AAC9D,SAAgB,KAAK,OAAO,qBAAoB;AAIhD,OAAO,YAAI,WACT,OAAO,OAAO,EACd,SAAS,YACR,OAAO,MAAM,EAAE,UAOhB"}
|
package/_dist/mod.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Clock } from "@yaks/fp";
|
|
2
|
+
export declare let form: (fields: Record<string, unknown>, prefix?: string) => [string, string][];
|
|
3
|
+
export declare class StripeError extends Error {
|
|
4
|
+
code?: string;
|
|
5
|
+
constructor(body: unknown, status: number);
|
|
6
|
+
}
|
|
7
|
+
/** The least Stripe charges in a currency, in its smallest unit; 0 where
|
|
8
|
+
* none is known here. */ export declare let minimum: (currency: string) => number;
|
|
9
|
+
/** The id of an object Stripe names by id or expanded whole. */ export declare let idOf: (v: string | {
|
|
10
|
+
id?: string;
|
|
11
|
+
} | null | undefined) => string;
|
|
12
|
+
/** What Stripe holds at `path`, on account `on` where one is named; null
|
|
13
|
+
* where it holds nothing by that name, which Stripe says as a refusal. */ export declare let found: (at: Keyed, path: string, on?: string) => Promise<Record<string, unknown> | null>;
|
|
14
|
+
/** Rows from a Stripe list, including every page. */ export declare let list: <T extends {
|
|
15
|
+
id: string;
|
|
16
|
+
}>(at: Keyed, path: string, fields: Record<string, string>) => AsyncGenerator<T>;
|
|
17
|
+
export declare let TRIES: number;
|
|
18
|
+
/** What a call is made with: the secret key, and the clock retries wait on. */ export type Keyed = {
|
|
19
|
+
key?: string;
|
|
20
|
+
clock?: Clock;
|
|
21
|
+
};
|
|
22
|
+
export declare let ask: (at: Keyed, path: string, fields?: Record<string, unknown>, on?: string, key?: string) => Promise<Record<string, unknown>>;
|
|
23
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAMA,SAAS,KAAK,KAAK,wBAAoC;AAOvD,OAAO,YAAI,OACT,QAAQ,OAAO,MAAM,EAAE,OAAO,GAC9B,qBACE,MAAM,EAAE,MAAM,IAUjB;AAMD,OAAO,cAAM,oBAAoB;EAC/B,OAAO,MAAM,CAAA;EACb,YAAY,MAAM,OAAO,EAAE,QAAQ,MAAM;AAiB3C;AAEA;uBACuB,GACvB,OAAO,YAAI,UAAW,UAAU,MAAM,KAAG,MAAM,CACL;AAE1C,8DAA8D,GAC9D,OAAO,YAAI,OACT,GAAG,MAAM;EAAK,KAAK,MAAM;IAAK,IAAI,GAAG,SAAS,KAC7C,MAAM,CAA0C;AAEnD;wEACwE,GACxE,OAAO,YAAI,QACT,IAAI,OACJ,MAAM,MAAM,EACZ,KAAK,MAAM,KACV,QAAQ,OAAO,MAAM,EAAE,OAAO,IAAI,IAAI,EAIrC;AAEJ,mDAAmD,GACnD,OAAO,YAAI,OAAwB;EAAY,IAAI,MAAM;GACvD,IAAI,OACJ,MAAM,MAAM,EACZ,QAAQ,OAAO,MAAM,EAAE,MAAM,MAC5B,eAAe,GAejB;AAkBD,OAAO,YAAI,cAAS;AAEpB,6EAA6E,GAC7E,YAAY;EAAU,MAAM,MAAM;EAAE,QAAQ;;AAE5C,OAAO,YAAI,MACT,IAAI,OACJ,MAAM,MAAM,EACZ,SAAS,OAAO,MAAM,EAAE,OAAO,GAC/B,KAAK,MAAM,EAEX,MAAM,MAAM,KACX,QAAQ,OAAO,MAAM,EAAE,OAAO,GA4BhC"}
|
package/_dist/plans.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Bought, Changed, Per, Plans, Standing, Subscription, Tags } from "@yaks/host/payments";
|
|
2
|
+
import { type Keyed } from "./mod.js";
|
|
3
|
+
/** What a config gives the plans: the key and clock every call is made with
|
|
4
|
+
* (`Keyed`), each tier's price ids by how often it is paid for, in the order
|
|
5
|
+
* a price none lists falls back to the first of, and each tier's price ids it
|
|
6
|
+
* no longer sells but whose subscriptions are still on it. */ export type Options = Keyed & {
|
|
7
|
+
invoiceKey?: string;
|
|
8
|
+
prices?: Record<string, Partial<Record<Per, string>>>;
|
|
9
|
+
kept?: Record<string, string[] | undefined>;
|
|
10
|
+
};
|
|
11
|
+
/** What a subscription's tier is read with. */ export type Pricing = Pick<Options, 'prices' | 'kept'>;
|
|
12
|
+
export type Bill = {
|
|
13
|
+
status?: string;
|
|
14
|
+
total?: number;
|
|
15
|
+
};
|
|
16
|
+
export type Sub = {
|
|
17
|
+
id?: string;
|
|
18
|
+
customer?: string | {
|
|
19
|
+
id?: string;
|
|
20
|
+
};
|
|
21
|
+
status?: string;
|
|
22
|
+
collection_method?: string;
|
|
23
|
+
created?: number;
|
|
24
|
+
start_date?: number;
|
|
25
|
+
metadata?: Record<string, string>;
|
|
26
|
+
cancel_at?: number | null;
|
|
27
|
+
cancel_at_period_end?: boolean;
|
|
28
|
+
canceled_at?: number | null;
|
|
29
|
+
ended_at?: number | null;
|
|
30
|
+
trial_end?: number | null;
|
|
31
|
+
current_period_start?: number | null;
|
|
32
|
+
current_period_end?: number | null;
|
|
33
|
+
billing_cycle_anchor?: number;
|
|
34
|
+
/** expanded where it is asked for; an id otherwise */ latest_invoice?: string | Bill | null;
|
|
35
|
+
items?: {
|
|
36
|
+
data?: {
|
|
37
|
+
id?: string;
|
|
38
|
+
metadata?: Tags;
|
|
39
|
+
current_period_start?: number | null;
|
|
40
|
+
current_period_end?: number | null;
|
|
41
|
+
price?: string | {
|
|
42
|
+
id?: string;
|
|
43
|
+
unit_amount?: number;
|
|
44
|
+
recurring?: {
|
|
45
|
+
interval?: string;
|
|
46
|
+
};
|
|
47
|
+
} | null;
|
|
48
|
+
}[];
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/** Where a subscription with this status stands. */ export declare let standing: (status: string) => Standing;
|
|
52
|
+
/** A Stripe time, in seconds, as an ISO date. */ export declare let when: (unix?: number | null) => string | null;
|
|
53
|
+
/** When the paid-for period runs out. The field moved off the subscription
|
|
54
|
+
* onto each of its items in API version 2025-03-31.basil, and the webhook
|
|
55
|
+
* endpoint pins no version of its own, so the version it sends can move under
|
|
56
|
+
* us. Either shape is read: the latest item wins, since a subscription of
|
|
57
|
+
* these has one item. */ export declare let periodEnd: (sub: Sub) => number | null;
|
|
58
|
+
/** When the current period began, read off either shape as `periodEnd`
|
|
59
|
+
* reads its end. */ export declare let periodStart: (sub: Sub) => number | null;
|
|
60
|
+
/** Stripe's status for a subscription, with an invoiced one's invoice read
|
|
61
|
+
* into it. Stripe calls a subscription sent its invoices `active` the moment
|
|
62
|
+
* it is made and `past_due` once an invoice is late, and neither is a plan
|
|
63
|
+
* paid for. Its first billed period, the one starting when it was made or
|
|
64
|
+
* when its trial ends, holds once that period's invoice is paid: until then
|
|
65
|
+
* it is `incomplete`, as Stripe says of a charged subscription whose first
|
|
66
|
+
* payment has not come, and a trial given free (`trialFor`) is no payment.
|
|
67
|
+
* A later period holds while its invoice is not yet due, and one past due is
|
|
68
|
+
* `unpaid`: nothing retries a check. The latest invoice is read only where it
|
|
69
|
+
* was expanded, and one that was not is taken as unpaid. */ export declare let statusOf: (sub: Sub) => string;
|
|
70
|
+
/** The tier a subscription's price buys: the first of `prices` listing one of
|
|
71
|
+
* its items' prices, else the first of `kept` listing one, else the first of
|
|
72
|
+
* `prices`. */ export declare let tierFor: (sub: Sub, _dts_1: never) => string;
|
|
73
|
+
/** When a subscription with this status stops, set only when it will not
|
|
74
|
+
* renew, so "cancelled, but paid through the 14th" is one row to read: an
|
|
75
|
+
* explicit `cancel_at`, else the period end it is riding out, else, for one
|
|
76
|
+
* already over, when it ended. */ export declare let ending: (sub: Sub, status: string) => string | null;
|
|
77
|
+
/** A Stripe subscription in the host's words. */ export declare let read: (sub: Sub, pricing?: Pricing) => Subscription;
|
|
78
|
+
/** The trial a subscription bought while time given free runs starts with,
|
|
79
|
+
* so the free time is kept and the first charge falls when it ends. Stripe
|
|
80
|
+
* takes a trial ending no sooner than two days away, so one ending sooner is
|
|
81
|
+
* two days. */ export declare let trialFor: (free: string | null | undefined, now: number) => {
|
|
82
|
+
trial_end?: number;
|
|
83
|
+
};
|
|
84
|
+
/** The tax code a one-off purchase is sold under: artificial intelligence as
|
|
85
|
+
* a service, cloud based, for business use, which Managed Payments takes
|
|
86
|
+
* (its eligibility page). A product made inline carries its own. */ export declare let ONCE_TAX: string;
|
|
87
|
+
/** Stripe's plans, every call made with `options` as they read at the
|
|
88
|
+
* time. */ export declare let plans: (options: Options) => Plans;
|
|
89
|
+
/** A verified event Stripe posted to the platform's own endpoint, read: a
|
|
90
|
+
* `customer.subscription.*` event carries its subscription whole, save an
|
|
91
|
+
* invoiced one's latest invoice, so that one is asked for with it, and a
|
|
92
|
+
* checkout session or an invoice names it, which one GET answers. An
|
|
93
|
+
* invoice's name for it moved under `parent` in API 2025-03-31.basil, and the
|
|
94
|
+
* old field is read too, for the reason `periodEnd` reads both. A checkout
|
|
95
|
+
* session in payment mode is a purchase: completed, its money there or on
|
|
96
|
+
* its way, and `checkout.session.async_payment_succeeded` when what was on
|
|
97
|
+
* its way arrives. */ export declare let changed: (options: Options) => any;
|
|
98
|
+
//# sourceMappingURL=plans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plans.d.ts","sources":["../plans.ts"],"names":[],"mappings":"AAwBA,cACE,MAAM,EACN,OAAO,EACP,GAAG,EACH,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,IAAI,mCACiC;AACvC,SAA2B,KAAK,KAAK,mBAAiC;AAKtE;;;4DAG4D,GAC5D,YAAY,UAAU;EACpB,aAAa,MAAM;EACnB,SAAS,OAAO,MAAM,EAAE,QAAQ,OAAO,KAAK,MAAM;EAClD,OAAO,OAAO,MAAM,EAAE,MAAM,KAAK,SAAS;;AAG5C,6CAA6C,GAC7C,YAAY,UAAU,KAAK,SAAS,WAAW;AAI/C,YAAY;EAAS,SAAS,MAAM;EAAE,QAAQ,MAAM;;AAKpD,YAAY;EACV,KAAK,MAAM;EACX,WAAW,MAAM;IAAK,KAAK,MAAM;;EACjC,SAAS,MAAM;EACf,oBAAoB,MAAM;EAC1B,UAAU,MAAM;EAChB,aAAa,MAAM;EACnB,WAAW,OAAO,MAAM,EAAE,MAAM;EAChC,YAAY,MAAM,GAAG,IAAI;EACzB,uBAAuB,OAAO;EAC9B,cAAc,MAAM,GAAG,IAAI;EAC3B,WAAW,MAAM,GAAG,IAAI;EACxB,YAAY,MAAM,GAAG,IAAI;EACzB,uBAAuB,MAAM,GAAG,IAAI;EACpC,qBAAqB,MAAM,GAAG,IAAI;EAClC,uBAAuB,MAAM;EAC7B,oDAAoD,GACpD,iBAAiB,MAAM,GAAG,OAAO,IAAI;EACrC;IACE;MACE,KAAK,MAAM;MACX,WAAW;MACX,uBAAuB,MAAM,GAAG,IAAI;MACpC,qBAAqB,MAAM,GAAG,IAAI;MAClC,QAAQ,MAAM;QACZ,KAAK,MAAM;QACX,cAAc,MAAM;QACpB;UAAc,WAAW,MAAM;;UAC7B,IAAI;;;;AAuBd,kDAAkD,GAClD,OAAO,YAAI,WAAY,QAAQ,MAAM,KAAG,SACuB;AAI/D,+CAA+C,GAC/C,OAAO,YAAI,OAAQ,OAAO,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,IAAI,CACI;AAE3D;;;;uBAIuB,GACvB,OAAO,YAAI,YAAa,KAAK,QAAM,MAAM,GAAG,IAAI,CAM/C;AAED;kBACkB,GAClB,OAAO,YAAI,cAAe,KAAK,QAAM,MAAM,GAAG,IAAI,CAMjD;AAED;;;;;;;;;0DAS0D,GAC1D,OAAO,YAAI,WAAY,KAAK,QAAM,MAAM,CAUvC;AAED;;aAEa,GACb,OAAO,YAAI,UACT,KAAK,KACL,kBACC,MAAM,CAQR;AAED;;;gCAGgC,GAChC,OAAO,YAAI,SAAU,KAAK,KAAK,QAAQ,MAAM,KAAG,MAAM,GAAG,IAAI,CAS5D;AAkBD,+CAA+C,GAC/C,OAAO,YAAI,OAAQ,KAAK,KAAK,UAAU,YAAU,aAchD;AAED;;;aAGa,GACb,OAAO,YAAI,WACT,MAAM,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,KAAK,MAAM;EACR,YAAY,MAAM;EAOf;AA2BR;;kEAEkE,GAClE,OAAO,YAAI,iBAA0B;AAUrC;SACS,GACT,OAAO,YAAI,QAAS,SAAS,YAAU,MAyPtC;AAED;;;;;;;;oBAQoB,GACpB,OAAO,YAAI,UACR,SAAS,gBAuET"}
|