@proveanything/smartlinks 2.2.6 → 2.2.7

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.
@@ -0,0 +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
+ | `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.
package/openapi.yaml CHANGED
@@ -36239,6 +36239,180 @@ components:
36239
36239
  enum:
36240
36240
  - sales
36241
36241
  - purchase
36242
+ PaymentsPublicConfig:
36243
+ type: object
36244
+ properties:
36245
+ ready:
36246
+ type: boolean
36247
+ publishableKey:
36248
+ type: string
36249
+ accountId:
36250
+ type: string
36251
+ required:
36252
+ - ready
36253
+ - publishableKey
36254
+ - accountId
36255
+ PaymentIntentInput:
36256
+ type: object
36257
+ properties:
36258
+ appId:
36259
+ type: string
36260
+ amount:
36261
+ type: number
36262
+ currency:
36263
+ type: string
36264
+ email:
36265
+ type: string
36266
+ description:
36267
+ type: string
36268
+ reference:
36269
+ type: string
36270
+ metadata:
36271
+ type: object
36272
+ additionalProperties:
36273
+ type: object
36274
+ additionalProperties: true
36275
+ cardOnly:
36276
+ type: boolean
36277
+ idempotencyKey:
36278
+ type: string
36279
+ required:
36280
+ - appId
36281
+ - amount
36282
+ - currency
36283
+ PaymentIntentResult:
36284
+ type: object
36285
+ properties:
36286
+ paymentIntentId:
36287
+ type: string
36288
+ clientSecret:
36289
+ type: string
36290
+ publishableKey:
36291
+ type: string
36292
+ accountId:
36293
+ type: string
36294
+ amount:
36295
+ type: number
36296
+ currency:
36297
+ type: string
36298
+ fee:
36299
+ type: number
36300
+ required:
36301
+ - paymentIntentId
36302
+ - clientSecret
36303
+ - publishableKey
36304
+ - accountId
36305
+ - amount
36306
+ - currency
36307
+ - fee
36308
+ PaymentsStatus:
36309
+ type: object
36310
+ properties:
36311
+ connected:
36312
+ type: boolean
36313
+ accountId:
36314
+ type: string
36315
+ chargesEnabled:
36316
+ type: boolean
36317
+ detailsSubmitted:
36318
+ type: boolean
36319
+ payoutsEnabled:
36320
+ type: boolean
36321
+ platformReady:
36322
+ type: boolean
36323
+ publishableKeySet:
36324
+ type: boolean
36325
+ fees:
36326
+ type: array
36327
+ items:
36328
+ type: object
36329
+ additionalProperties: true
36330
+ required:
36331
+ - connected
36332
+ - platformReady
36333
+ - publishableKeySet
36334
+ - fees
36335
+ PaymentsConnectInput:
36336
+ type: object
36337
+ properties:
36338
+ returnUrl:
36339
+ type: string
36340
+ refreshUrl:
36341
+ type: string
36342
+ country:
36343
+ type: string
36344
+ required:
36345
+ - returnUrl
36346
+ - refreshUrl
36347
+ PaymentRecord:
36348
+ type: object
36349
+ properties:
36350
+ id:
36351
+ type: string
36352
+ amount:
36353
+ type: number
36354
+ amountReceived:
36355
+ type: number
36356
+ currency:
36357
+ type: string
36358
+ status:
36359
+ type: string
36360
+ created:
36361
+ type: string
36362
+ email:
36363
+ type: string
36364
+ metadata:
36365
+ type: object
36366
+ additionalProperties:
36367
+ type: string
36368
+ required:
36369
+ - id
36370
+ - amount
36371
+ - amountReceived
36372
+ - currency
36373
+ - status
36374
+ - created
36375
+ - email
36376
+ - metadata
36377
+ PaymentListParams:
36378
+ type: object
36379
+ properties:
36380
+ appId:
36381
+ type: string
36382
+ since:
36383
+ type: string
36384
+ limit:
36385
+ type: number
36386
+ after:
36387
+ type: string
36388
+ PaymentList:
36389
+ type: object
36390
+ properties:
36391
+ data:
36392
+ type: array
36393
+ items:
36394
+ $ref: "#/components/schemas/PaymentRecord"
36395
+ hasMore:
36396
+ type: boolean
36397
+ next:
36398
+ type: string
36399
+ required:
36400
+ - data
36401
+ - hasMore
36402
+ - next
36403
+ PaymentDomainResult:
36404
+ type: object
36405
+ properties:
36406
+ domain:
36407
+ type: string
36408
+ applePay:
36409
+ type: string
36410
+ googlePay:
36411
+ type: string
36412
+ required:
36413
+ - domain
36414
+ - applePay
36415
+ - googlePay
36242
36416
  ProductKey:
36243
36417
  type: object
36244
36418
  properties:
package/package.json CHANGED
@@ -1,87 +1,87 @@
1
- {
2
- "name": "@proveanything/smartlinks",
3
- "version": "2.2.6",
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.7",
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
+ }