@proveanything/smartlinks 2.2.7 → 2.2.8
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/dist/docs/API_SUMMARY.md +1 -1
- package/dist/docs/i18n.md +15 -9
- package/dist/docs/overview.md +487 -487
- package/dist/docs/payments.md +87 -87
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/API_SUMMARY.md +1 -1
- package/docs/i18n.md +15 -9
- package/docs/overview.md +487 -487
- package/docs/payments.md +87 -87
- package/package.json +87 -87
package/docs/payments.md
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
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
|
-
| `
|
|
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
|
+
### 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.
|
package/package.json
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@proveanything/smartlinks",
|
|
3
|
-
"version": "2.2.
|
|
4
|
-
"description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js",
|
|
12
|
-
"default": "./dist/index.js"
|
|
13
|
-
},
|
|
14
|
-
"./testing": {
|
|
15
|
-
"types": "./dist/testing/index.d.ts",
|
|
16
|
-
"import": "./dist/testing/index.js",
|
|
17
|
-
"default": "./dist/testing/index.js"
|
|
18
|
-
},
|
|
19
|
-
"./*": {
|
|
20
|
-
"types": "./dist/*.d.ts",
|
|
21
|
-
"import": "./dist/*.js",
|
|
22
|
-
"default": "./dist/*.js"
|
|
23
|
-
},
|
|
24
|
-
"./baseline.css": "./dist/baseline.css",
|
|
25
|
-
"./baseline.classes.json": "./dist/baseline.classes.json",
|
|
26
|
-
"./theme.css": "./dist/theme.css",
|
|
27
|
-
"./theme-boot.js": "./dist/theme-boot.js",
|
|
28
|
-
"./package.json": "./package.json"
|
|
29
|
-
},
|
|
30
|
-
"bin": {
|
|
31
|
-
"smartlinks-register-release": "scripts/register-release.mjs",
|
|
32
|
-
"smartlinks-publish": "scripts/publish.mjs",
|
|
33
|
-
"smartlinks-doctor": "scripts/doctor.mjs",
|
|
34
|
-
"smartlinks-headless": "scripts/headless-check.mjs"
|
|
35
|
-
},
|
|
36
|
-
"files": [
|
|
37
|
-
"dist/",
|
|
38
|
-
"docs/",
|
|
39
|
-
"scripts/register-release.mjs",
|
|
40
|
-
"scripts/publish.mjs",
|
|
41
|
-
"scripts/doctor.mjs",
|
|
42
|
-
"scripts/headless-check.mjs",
|
|
43
|
-
"scripts/lib/",
|
|
44
|
-
"openapi.yaml",
|
|
45
|
-
"README.md"
|
|
46
|
-
],
|
|
47
|
-
"scripts": {
|
|
48
|
-
"test": "node test/run.cjs",
|
|
49
|
-
"build": "node scripts/write-version.mjs && tsc && node scripts/fix-esm-extensions.mjs && node generate-api-summary.cjs && node generate-openapi.cjs && node scripts/copy-docs-to-dist.cjs && node scripts/build-baseline.mjs",
|
|
50
|
-
"docs": "typedoc",
|
|
51
|
-
"docs:summary": "node generate-api-summary.cjs",
|
|
52
|
-
"docs:openapi": "node generate-openapi.cjs",
|
|
53
|
-
"docs:openapi:lint": "npx --yes @redocly/cli@latest lint openapi.yaml",
|
|
54
|
-
"docs:openapi:check": "node generate-openapi.cjs && npx --yes @redocly/cli@latest lint openapi.yaml",
|
|
55
|
-
"build:docs": "tsc build-docs.ts --outDir dist && node dist/build-docs.js",
|
|
56
|
-
"prepublishOnly": "npm run build"
|
|
57
|
-
},
|
|
58
|
-
"keywords": [
|
|
59
|
-
"smartlinks",
|
|
60
|
-
"api",
|
|
61
|
-
"authentication",
|
|
62
|
-
"traceability",
|
|
63
|
-
"blockchain",
|
|
64
|
-
"typescript",
|
|
65
|
-
"sdk"
|
|
66
|
-
],
|
|
67
|
-
"author": "Glenn Shoosmith",
|
|
68
|
-
"license": "MIT",
|
|
69
|
-
"publishConfig": {
|
|
70
|
-
"access": "public"
|
|
71
|
-
},
|
|
72
|
-
"dependencies": {
|
|
73
|
-
"cross-fetch": "^3.1.5",
|
|
74
|
-
"es-module-lexer": "^1.7.0"
|
|
75
|
-
},
|
|
76
|
-
"devDependencies": {
|
|
77
|
-
"ts-node": "^10.9.1",
|
|
78
|
-
"typedoc": "^0.25.13",
|
|
79
|
-
"typedoc-plugin-markdown": "^3.17.1",
|
|
80
|
-
"typescript": "^4.9.0"
|
|
81
|
-
},
|
|
82
|
-
"repository": {
|
|
83
|
-
"type": "git",
|
|
84
|
-
"url": "https://github.com/Prove-Anything/smartlinks.git"
|
|
85
|
-
},
|
|
86
|
-
"homepage": "https://smartlinks.app"
|
|
87
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@proveanything/smartlinks",
|
|
3
|
+
"version": "2.2.8",
|
|
4
|
+
"description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./testing": {
|
|
15
|
+
"types": "./dist/testing/index.d.ts",
|
|
16
|
+
"import": "./dist/testing/index.js",
|
|
17
|
+
"default": "./dist/testing/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./*": {
|
|
20
|
+
"types": "./dist/*.d.ts",
|
|
21
|
+
"import": "./dist/*.js",
|
|
22
|
+
"default": "./dist/*.js"
|
|
23
|
+
},
|
|
24
|
+
"./baseline.css": "./dist/baseline.css",
|
|
25
|
+
"./baseline.classes.json": "./dist/baseline.classes.json",
|
|
26
|
+
"./theme.css": "./dist/theme.css",
|
|
27
|
+
"./theme-boot.js": "./dist/theme-boot.js",
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"bin": {
|
|
31
|
+
"smartlinks-register-release": "scripts/register-release.mjs",
|
|
32
|
+
"smartlinks-publish": "scripts/publish.mjs",
|
|
33
|
+
"smartlinks-doctor": "scripts/doctor.mjs",
|
|
34
|
+
"smartlinks-headless": "scripts/headless-check.mjs"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist/",
|
|
38
|
+
"docs/",
|
|
39
|
+
"scripts/register-release.mjs",
|
|
40
|
+
"scripts/publish.mjs",
|
|
41
|
+
"scripts/doctor.mjs",
|
|
42
|
+
"scripts/headless-check.mjs",
|
|
43
|
+
"scripts/lib/",
|
|
44
|
+
"openapi.yaml",
|
|
45
|
+
"README.md"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"test": "node test/run.cjs",
|
|
49
|
+
"build": "node scripts/write-version.mjs && tsc && node scripts/fix-esm-extensions.mjs && node generate-api-summary.cjs && node generate-openapi.cjs && node scripts/copy-docs-to-dist.cjs && node scripts/build-baseline.mjs",
|
|
50
|
+
"docs": "typedoc",
|
|
51
|
+
"docs:summary": "node generate-api-summary.cjs",
|
|
52
|
+
"docs:openapi": "node generate-openapi.cjs",
|
|
53
|
+
"docs:openapi:lint": "npx --yes @redocly/cli@latest lint openapi.yaml",
|
|
54
|
+
"docs:openapi:check": "node generate-openapi.cjs && npx --yes @redocly/cli@latest lint openapi.yaml",
|
|
55
|
+
"build:docs": "tsc build-docs.ts --outDir dist && node dist/build-docs.js",
|
|
56
|
+
"prepublishOnly": "npm run build"
|
|
57
|
+
},
|
|
58
|
+
"keywords": [
|
|
59
|
+
"smartlinks",
|
|
60
|
+
"api",
|
|
61
|
+
"authentication",
|
|
62
|
+
"traceability",
|
|
63
|
+
"blockchain",
|
|
64
|
+
"typescript",
|
|
65
|
+
"sdk"
|
|
66
|
+
],
|
|
67
|
+
"author": "Glenn Shoosmith",
|
|
68
|
+
"license": "MIT",
|
|
69
|
+
"publishConfig": {
|
|
70
|
+
"access": "public"
|
|
71
|
+
},
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"cross-fetch": "^3.1.5",
|
|
74
|
+
"es-module-lexer": "^1.7.0"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"ts-node": "^10.9.1",
|
|
78
|
+
"typedoc": "^0.25.13",
|
|
79
|
+
"typedoc-plugin-markdown": "^3.17.1",
|
|
80
|
+
"typescript": "^4.9.0"
|
|
81
|
+
},
|
|
82
|
+
"repository": {
|
|
83
|
+
"type": "git",
|
|
84
|
+
"url": "https://github.com/Prove-Anything/smartlinks.git"
|
|
85
|
+
},
|
|
86
|
+
"homepage": "https://smartlinks.app"
|
|
87
|
+
}
|