@proveanything/smartlinks 2.2.7 → 2.2.9

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/docs/payments.md CHANGED
@@ -1,87 +1,94 @@
1
- # Payments
2
-
3
- A business connects **one** Stripe account, once, in **Studio → Payments** (Stripe Connect: Stripe's own
4
- set-up pages, no keys to copy). Every app then takes money on that account through SmartLinks. Apps never
5
- hold Stripe keys.
6
-
7
- - **The business is the merchant of record**: its name on the card statement, its refunds and disputes, its
8
- Stripe dashboard. SmartLinks never holds the money. SmartLinks may take a small fee per app (often none).
9
- - **Money is in minor units** (pence, cents): `500` is £5.00.
10
- - **Two ways to take a payment:**
11
- - **Hosted checkout** for fixed prices the server knows: `shop.checkout` (docs/shop.md), memberships.
12
- The server prices it and only Stripe's webhook marks it paid.
13
- - **In-page payment** for pay-what-you-want moments (a donation, a tip): `payments.createIntent`, confirmed
14
- in the page with Stripe.js (Payment Element, Apple Pay, Google Pay). The browser chooses the amount, so
15
- don't use it for a fixed price.
16
-
17
- ## In-page payment (React)
18
-
19
- ```typescript
20
- import { payments } from '@proveanything/smartlinks'
21
- import { loadStripe } from '@stripe/stripe-js'
22
- import { Elements, PaymentElement, useStripe, useElements } from '@stripe/react-stripe-js'
23
-
24
- const cfg = await payments.config(collectionId)
25
- if (!cfg.ready) {
26
- // The business hasn't connected Stripe yet: say so, and point admins to Studio → Payments.
27
- }
28
-
29
- // The account id matters: the payment is made on the BUSINESS's account, not SmartLinks'.
30
- const stripePromise = loadStripe(cfg.publishableKey!, { stripeAccount: cfg.accountId! })
31
-
32
- const pi = await payments.createIntent(collectionId, {
33
- appId: 'tap-to-donate',
34
- amount: 500, // £5.00
35
- currency: 'GBP',
36
- email: donorEmail, // Stripe's receipt
37
- reference: campaignId, // yours, kept on the payment
38
- metadata: { proofId }, // yours, up to 15 values
39
- })
40
-
41
- // <Elements stripe={stripePromise} options={{ clientSecret: pi.clientSecret }}>
42
- // <PaymentElement /> … await stripe.confirmPayment({ elements, redirect: 'if_required' })
43
- ```
44
-
45
- `createIntent` refuses with:
46
-
47
- | errorCode | When |
48
- |---|---|
49
- | `PAYMENTS_NOT_READY` (409) | The business hasn't connected Stripe, or hasn't finished Stripe's set-up. |
50
- | `APP_NOT_INSTALLED` (404) | The app isn't switched on in this collection. |
51
- | `INVALID_INPUT` (400) | Amount not a whole number of minor units (30 to 5,000,000), or currency not a 3-letter code. |
52
- | `PAYMENT_REFUSED` (400) | Stripe refused it; `errorText` is Stripe's own words (for example below its minimum). |
53
- | `SHOP_NOT_CONFIGURED` (503) | This server has no Stripe platform keys yet. |
54
-
55
- ### Apple Pay and Google Pay on your own domain
56
-
57
- They work on smartlinks.app as they are. On a site's own domain, register it once for the business's account:
58
-
59
- ```typescript
60
- await payments.admin.registerDomain(collectionId, 'donate.example.org') // → { applePay: 'active', … }
61
- ```
62
-
63
- ## Admin: the business's account
64
-
65
- ```typescript
66
- const s = await payments.admin.status(collectionId, { appIds: ['tap-to-donate', 'shop'] })
67
- // { connected, chargesEnabled, payoutsEnabled, detailsSubmitted, fees: [{ appId, percent }] }
68
-
69
- const { url } = await payments.admin.connect(collectionId, {
70
- returnUrl: location.href, // back here when done (or stopped): read status again
71
- refreshUrl: location.href, // the link ran out: make another
72
- })
73
- location.href = url
74
- ```
75
-
76
- `shop.admin.connect` does the same thing: there is one account per business, whichever app connects it.
77
-
78
- ### Reconciling an app's payments
79
-
80
- ```typescript
81
- let page = await payments.admin.intents(collectionId, { appId: 'tap-to-donate', since: '2026-12-01' })
82
- // page.data: [{ id, amount, status: 'succeeded', created, email, metadata }]
83
- while (page.hasMore) page = await payments.admin.intents(collectionId, { appId: 'tap-to-donate', after: page.next! })
84
- ```
85
-
86
- Recording a payment is still the app's job (for example an app record after `confirmPayment` succeeds);
87
- reconciling finds the ones a closed browser never recorded.
1
+ # Payments
2
+
3
+ A business connects **one** Stripe account, once, in **Studio → Payments** (Stripe Connect: Stripe's own
4
+ set-up pages, no keys to copy). Every app then takes money on that account through SmartLinks. Apps never
5
+ hold Stripe keys.
6
+
7
+ - **The business is the merchant of record**: its name on the card statement, its refunds and disputes, its
8
+ Stripe dashboard. SmartLinks never holds the money. SmartLinks may take a small fee per app (often none).
9
+ - **Money is in minor units** (pence, cents): `500` is £5.00.
10
+ - **Two ways to take a payment:**
11
+ - **Hosted checkout** for fixed prices the server knows: `shop.checkout` (docs/shop.md), memberships.
12
+ The server prices it and only Stripe's webhook marks it paid.
13
+ - **In-page payment** for pay-what-you-want moments (a donation, a tip): `payments.createIntent`, confirmed
14
+ in the page with Stripe.js (Payment Element, Apple Pay, Google Pay). The browser chooses the amount, so
15
+ don't use it for a fixed price.
16
+
17
+ ## In-page payment (React)
18
+
19
+ ```typescript
20
+ import { payments } from '@proveanything/smartlinks'
21
+ import { loadStripe } from '@stripe/stripe-js'
22
+ import { Elements, PaymentElement, useStripe, useElements } from '@stripe/react-stripe-js'
23
+
24
+ const cfg = await payments.config(collectionId)
25
+ if (!cfg.ready) {
26
+ // The business hasn't connected Stripe yet: say so, and point admins to Studio → Payments.
27
+ }
28
+
29
+ // The account id matters: the payment is made on the BUSINESS's account, not SmartLinks'.
30
+ const stripePromise = loadStripe(cfg.publishableKey!, { stripeAccount: cfg.accountId! })
31
+
32
+ const pi = await payments.createIntent(collectionId, {
33
+ appId: 'tap-to-donate',
34
+ amount: 500, // £5.00
35
+ currency: 'GBP',
36
+ email: donorEmail, // Stripe's receipt
37
+ reference: campaignId, // yours, kept on the payment
38
+ metadata: { proofId }, // yours, up to 15 values
39
+ })
40
+
41
+ // <Elements stripe={stripePromise} options={{ clientSecret: pi.clientSecret }}>
42
+ // <PaymentElement /> … await stripe.confirmPayment({ elements, redirect: 'if_required' })
43
+ ```
44
+
45
+ `createIntent` refuses with:
46
+
47
+ | errorCode | When |
48
+ |---|---|
49
+ | `PAYMENTS_NOT_READY` (409) | The business hasn't connected Stripe, or hasn't finished Stripe's set-up. |
50
+ | `APP_NOT_INSTALLED` (404) | The app isn't switched on in this collection. |
51
+ | `INVALID_INPUT` (400) | Amount not a whole number of minor units (30 to 5,000,000), or currency not a 3-letter code. |
52
+ | `PAYMENT_REFUSED` (400) | Stripe refused it; `errorText` is Stripe's own words (for example below its minimum). |
53
+ | `PAYMENTS_NOT_CONFIGURED` (503) | This server has no Stripe platform keys yet. |
54
+
55
+ ### Apple Pay and Google Pay on your own domain
56
+
57
+ They work on smartlinks.app as they are. On a site's own domain, register it once for the business's account:
58
+
59
+ ```typescript
60
+ await payments.admin.registerDomain(collectionId, 'donate.example.org') // → { applePay: 'active', … }
61
+ ```
62
+
63
+ ## Admin: the business's account
64
+
65
+ ```typescript
66
+ const s = await payments.admin.status(collectionId, { appIds: ['tap-to-donate', 'shop'] })
67
+ // { connected, chargesEnabled, payoutsEnabled, detailsSubmitted, fees: [{ appId, percent }] }
68
+
69
+ const { url } = await payments.admin.connect(collectionId, {
70
+ returnUrl: location.href, // back here when done (or stopped): read status again
71
+ refreshUrl: location.href, // the link ran out: make another
72
+ })
73
+ location.href = url
74
+ ```
75
+
76
+ `shop.admin.connect` does the same thing: there is one account per business, whichever app connects it.
77
+
78
+ ```typescript
79
+ await payments.admin.disconnect(collectionId) // → { connected: false, disconnectedAccountId }
80
+ ```
81
+
82
+ Disconnecting stops every app taking payments until an account is connected again. SmartLinks forgets the
83
+ account; the Stripe account stays the business's own, with its payments. Connecting again makes a new one.
84
+
85
+ ### Reconciling an app's payments
86
+
87
+ ```typescript
88
+ let page = await payments.admin.intents(collectionId, { appId: 'tap-to-donate', since: '2026-12-01' })
89
+ // page.data: [{ id, amount, status: 'succeeded', created, email, metadata }]
90
+ while (page.hasMore) page = await payments.admin.intents(collectionId, { appId: 'tap-to-donate', after: page.next! })
91
+ ```
92
+
93
+ Recording a payment is still the app's job (for example an app record after `confirmPayment` succeeds);
94
+ reconciling finds the ones a closed browser never recorded.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "2.2.7",
3
+ "version": "2.2.9",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",