@proveanything/smartlinks 2.2.10 → 2.2.12

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
@@ -82,6 +82,23 @@ await payments.admin.disconnect(collectionId) // → { connected: false, discon
82
82
  Disconnecting stops every app taking payments until an account is connected again. SmartLinks forgets the
83
83
  account; the Stripe account stays the business's own, with its payments. Connecting again makes a new one.
84
84
 
85
+ ### Asking someone else to set it up
86
+
87
+ Often the person with the business's Stripe login isn't the one in Studio: the finance team, or the client
88
+ a business was built for. Email them a link instead of giving them a login:
89
+
90
+ ```typescript
91
+ await payments.admin.requestSetup(collectionId, { email: 'finance@example.org', name: 'Sam', note: 'For the donations page' })
92
+ // status(…).setupRequest → { email, status: 'pending' | 'expired' | 'done' | 'cancelled' | 'reported', stripeAccountName, … }
93
+ await payments.admin.cancelSetupRequest(collectionId) // the link stops working
94
+ ```
95
+
96
+ SmartLinks sends the email. Its link opens a SmartLinks page that only starts Stripe's set-up for this
97
+ business, with no login. It works for 7 days, and a new request replaces it. It can't be used once payments
98
+ are set up, and `requestSetup` is refused then (409 `ALREADY_CONNECTED`): disconnect first. The admin who
99
+ sent it is emailed when it's done, naming the Stripe account now taking the money, or if the person says
100
+ they weren't expecting it (which cancels it).
101
+
85
102
  ### Reconciling an app's payments
86
103
 
87
104
  ```typescript
@@ -90,5 +107,36 @@ let page = await payments.admin.intents(collectionId, { appId: 'tap-to-donate',
90
107
  while (page.hasMore) page = await payments.admin.intents(collectionId, { appId: 'tap-to-donate', after: page.next! })
91
108
  ```
92
109
 
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.
110
+ ### Payment records: what Stripe says happened
111
+
112
+ SmartLinks keeps every in-page payment's true state for you, from Stripe's own events, never from the
113
+ payer's browser: one **app record of type `payment`** per payment, in your app (visibility admin,
114
+ `customId` = the Stripe payment id). Its `status` follows the money:
115
+
116
+ | status | meaning |
117
+ |---|---|
118
+ | `paid` | taken |
119
+ | `partially_refunded` / `refunded` | refunded in part / in full (from Stripe's dashboard or anywhere else) |
120
+ | `disputed` / `dispute_lost` | the payer's bank is disputing it / the dispute was lost (a won dispute goes back to `paid`) |
121
+
122
+ ```typescript
123
+ import { app, type AppPaymentRecordData } from '@proveanything/smartlinks'
124
+
125
+ const page = await app.records.list(collectionId, 'tap-to-donate', { recordType: 'payment' }, true)
126
+ for (const r of page.data) {
127
+ const p = r.data as AppPaymentRecordData // amounts in pence: p.amount, p.amountRefunded, p.fee
128
+ console.log(r.status, p.paymentIntentId, p.amount - p.amountRefunded, p.metadata.campaignId)
129
+ }
130
+ // one payment: { recordType: 'payment', customId: paymentIntentId }
131
+ ```
132
+
133
+ Keep `paymentIntentId` (from `createIntent`) on your own record (a donation, a ticket) and read its status
134
+ from the payment record. A payment with no record of yours (the page closed before you saved it) still has
135
+ its payment record: show it, so nothing is missed. Totals should use `amount - amountRefunded`.
136
+
137
+ Payments made before payment records existed, or whose events never arrived, are brought in with:
138
+
139
+ ```typescript
140
+ let r = await payments.admin.sync(collectionId, { appId: 'tap-to-donate' }) // → { checked, saved, hasMore, next }
141
+ while (r.hasMore) r = await payments.admin.sync(collectionId, { appId: 'tap-to-donate', after: r.next! })
142
+ ```
package/openapi.yaml CHANGED
@@ -36561,6 +36561,8 @@ components:
36561
36561
  type: boolean
36562
36562
  accountId:
36563
36563
  type: string
36564
+ name:
36565
+ type: string
36564
36566
  chargesEnabled:
36565
36567
  type: boolean
36566
36568
  detailsSubmitted:
@@ -36576,11 +36578,70 @@ components:
36576
36578
  items:
36577
36579
  type: object
36578
36580
  additionalProperties: true
36581
+ setupRequest:
36582
+ $ref: "#/components/schemas/PaymentSetupRequest"
36579
36583
  required:
36580
36584
  - connected
36581
36585
  - platformReady
36582
36586
  - publishableKeySet
36583
36587
  - fees
36588
+ PaymentSetupRequest:
36589
+ type: object
36590
+ properties:
36591
+ id:
36592
+ type: string
36593
+ email:
36594
+ type: string
36595
+ name:
36596
+ type: string
36597
+ note:
36598
+ type: string
36599
+ sentByEmail:
36600
+ type: string
36601
+ sentByName:
36602
+ type: string
36603
+ sentAt:
36604
+ type: string
36605
+ expiresAt:
36606
+ type: string
36607
+ status:
36608
+ type: string
36609
+ enum:
36610
+ - pending
36611
+ - expired
36612
+ - done
36613
+ - cancelled
36614
+ - reported
36615
+ startedAt:
36616
+ type: string
36617
+ finishedAt:
36618
+ type: string
36619
+ stripeAccountName:
36620
+ type: string
36621
+ required:
36622
+ - id
36623
+ - email
36624
+ - name
36625
+ - note
36626
+ - sentByEmail
36627
+ - sentByName
36628
+ - sentAt
36629
+ - expiresAt
36630
+ - status
36631
+ - startedAt
36632
+ - finishedAt
36633
+ - stripeAccountName
36634
+ PaymentSetupRequestInput:
36635
+ type: object
36636
+ properties:
36637
+ email:
36638
+ type: string
36639
+ name:
36640
+ type: string
36641
+ note:
36642
+ type: string
36643
+ required:
36644
+ - email
36584
36645
  PaymentsConnectInput:
36585
36646
  type: object
36586
36647
  properties:
@@ -36649,6 +36710,70 @@ components:
36649
36710
  - data
36650
36711
  - hasMore
36651
36712
  - next
36713
+ PaymentSyncInput:
36714
+ type: object
36715
+ properties:
36716
+ appId:
36717
+ type: string
36718
+ since:
36719
+ type: string
36720
+ after:
36721
+ type: string
36722
+ PaymentSyncResult:
36723
+ type: object
36724
+ properties:
36725
+ checked:
36726
+ type: number
36727
+ saved:
36728
+ type: number
36729
+ hasMore:
36730
+ type: boolean
36731
+ next:
36732
+ type: string
36733
+ required:
36734
+ - checked
36735
+ - saved
36736
+ - hasMore
36737
+ - next
36738
+ AppPaymentRecordData:
36739
+ type: object
36740
+ properties:
36741
+ paymentIntentId:
36742
+ type: string
36743
+ amount:
36744
+ type: number
36745
+ currency:
36746
+ type: string
36747
+ amountRefunded:
36748
+ type: number
36749
+ fee:
36750
+ type: number
36751
+ email:
36752
+ type: string
36753
+ reference:
36754
+ type: string
36755
+ metadata:
36756
+ type: object
36757
+ additionalProperties:
36758
+ type: string
36759
+ paidAt:
36760
+ type: string
36761
+ refundedAt:
36762
+ type: string
36763
+ dispute:
36764
+ type: object
36765
+ additionalProperties: true
36766
+ required:
36767
+ - paymentIntentId
36768
+ - amount
36769
+ - currency
36770
+ - amountRefunded
36771
+ - fee
36772
+ - email
36773
+ - reference
36774
+ - metadata
36775
+ - paidAt
36776
+ - refundedAt
36652
36777
  PaymentDomainResult:
36653
36778
  type: object
36654
36779
  properties:
@@ -36662,6 +36787,14 @@ components:
36662
36787
  - domain
36663
36788
  - applePay
36664
36789
  - googlePay
36790
+ AppPaymentStatus:
36791
+ type: string
36792
+ enum:
36793
+ - paid
36794
+ - partially_refunded
36795
+ - refunded
36796
+ - disputed
36797
+ - dispute_lost
36665
36798
  ProductKey:
36666
36799
  type: object
36667
36800
  properties:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "2.2.10",
3
+ "version": "2.2.12",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",