better-auth-solana-payments 0.2.0 → 0.3.1

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/README.md CHANGED
@@ -8,7 +8,7 @@ One-time Solana payment integration for [Better Auth](https://www.better-auth.co
8
8
  pnpm add better-auth better-auth-solana-payments solana-payments
9
9
  ```
10
10
 
11
- Requires Node.js 22 or later and solana-payments 1.x.
11
+ Requires Node.js 22.22.2 or later and solana-payments 1.x.
12
12
 
13
13
  Existing installations must add the fulfillment fields before upgrading. For the default SQLite table and column names, see `migrations/0.2.0-sqlite.sql`; custom schemas must generate the equivalent Better Auth migration. Back up the database, verify paid-row fulfillment state, then deploy.
14
14
 
@@ -66,8 +66,8 @@ const verified = await authClient.payment.verify({
66
66
  reference: created.data!.reference,
67
67
  });
68
68
 
69
- if (verified.data?.status === "paid") {
70
- // Grant the entitlement only after server-side verification reports a paid payment.
69
+ if (verified.data?.status === "paid" && verified.data.fulfillmentStatus === "completed") {
70
+ // Grant the entitlement only after server-side verification and fulfillment complete.
71
71
  }
72
72
 
73
73
  const payment = await authClient.payment.get({
@@ -119,3 +119,71 @@ adapter, a generated `BETTER_AUTH_SECRET`, and a dedicated RPC provider.
119
119
  Generate/apply your Better Auth schema migration before upgrading. Add `fulfillmentStatus` (default `pending`), nullable `fulfillmentToken`, and nullable `fulfillmentClaimedAt` to `solanaPayment`. Backfill previously paid rows to `completed` before accepting requests, so historical payments are not fulfilled again.
120
120
 
121
121
  Payment settlement and fulfillment are separate: verification persists `paid`, then claims a database lease before invoking `onPaymentComplete`. Failed callbacks return an error and leave fulfillment pending; retry verification to recover, including after a restart. A crashed worker's claim becomes recoverable after five minutes. Callbacks must be idempotent by payment reference, since a crash after an external side effect can cause a retry. Responses expose `fulfillmentStatus`; grant access only when it is `completed`.
122
+
123
+ ## Settlement and operational edge cases
124
+
125
+ ### Confirmation depth
126
+
127
+ The SDK verifier requires at least `confirmed`, even if its client is configured with
128
+ `processed`. Configure `commitment: "finalized"` when your application needs the strongest
129
+ settlement state before fulfillment; a merely confirmed transaction then remains unaccepted.
130
+ This is a commitment policy, not a configurable number of confirmations. Failed execution
131
+ is rejected regardless of commitment. See [Solana's commitment definitions](https://solana.com/docs/rpc#configuring-state-commitment).
132
+
133
+ Show an awaiting-confirmation state and retry server verification with bounded backoff for
134
+ an unsettled transfer or RPC failure. `PAYMENT_MISMATCH` alone does not distinguish an
135
+ unconfirmed transfer, absent transfer, wrong token/network, or a provider error. A browser
136
+ wallet success notification is not settlement proof. Grant an entitlement only when the
137
+ response has both `status === "paid"` and `fulfillmentStatus === "completed"`.
138
+
139
+ Choose the commitment before accepting payments and keep it consistent: an already-paid
140
+ intent retries fulfillment without re-verifying the chain, so changing the client to
141
+ `finalized` does not upgrade previously recorded confirmed payments automatically.
142
+
143
+ ### Duplicate verification and callbacks
144
+
145
+ Repeated browser verification calls share the stored payment. A conditional database claim
146
+ allows one active fulfillment callback; completed fulfillment is not called again. Callback
147
+ failure releases the claim for retry, and a crashed claim can be recovered after five minutes.
148
+ This does not guarantee exactly-once external side effects: a crash after issuing an email,
149
+ granting access, or updating another service can happen before completion is persisted.
150
+
151
+ Make `onPaymentComplete` idempotent using the payment reference as a durable business key.
152
+ Use a unique entitlement/fulfillment record and a transaction or outbox where possible;
153
+ pass the same reference as an external service's idempotency key. Retry verification after
154
+ a transient failure, including after a restart. The fulfillment migration and a persistent
155
+ adapter are required; an in-memory adapter cannot coordinate separate workers.
156
+
157
+ ### Refunds
158
+
159
+ This read-only plugin has no refund endpoint and no `refunded` payment status. A refund is a
160
+ separate authorized on-chain transfer, not a rollback of the settled transaction. Keep the
161
+ original paid record as settlement evidence. An application refund ledger should record the
162
+ payment reference, approved amount, token mint, cluster, destination, refund signature and
163
+ confirmation state, and reconcile retries idempotently before sending again.
164
+
165
+ Verify the refund destination through your application's authenticated review flow; do not
166
+ trust a browser-supplied address or infer the payer from an arbitrary transaction account.
167
+ Use a separate controlled signing service/manual process. Mark a refund complete only after
168
+ its chosen confirmation policy succeeds, then apply the application's entitlement policy.
169
+ The plugin neither signs refunds nor automatically revokes access.
170
+
171
+ ### Right token, wrong network
172
+
173
+ Token symbols are labels; the asset is identified by its cluster and mint address. Verification
174
+ uses the server's configured RPC endpoint and token, and does not search other networks. A
175
+ transfer on another Solana cluster, or USDT sent through another chain, does not settle this
176
+ intent. The mainnet `SOLANA_USDT` preset is not a devnet token. See [Solana clusters](https://solana.com/docs/references/clusters).
177
+
178
+ Show the required network and mint before payment, check the wallet's network where possible,
179
+ and keep the RPC/cluster/mint configuration fixed for outstanding intents. If verification
180
+ cannot find a matching transfer, leave access unfulfilled; the intent remains pending until
181
+ expiry. Do not switch the production verifier to another network or manually mark the intent
182
+ paid to make the transaction appear to match.
183
+
184
+ Collect the transaction signature, actual network, mint and recipient for a support case,
185
+ and independently verify them on that network. A missing result is not proof that funds were
186
+ never sent. Explain that recovery depends on control of the recipient on the actual network;
187
+ this plugin cannot bridge, reverse or recover those funds. If a reviewed recovery/refund is
188
+ possible, track it separately and ask the customer to create a new intent on the required
189
+ network. Never request a wallet seed phrase or private key.
package/dist/client.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as solanaPayments } from "./index-6unaaVQL.mjs";
1
+ import { t as solanaPayments } from "./index-DRaH60lh.mjs";
2
2
  import { BetterFetch, BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
3
3
  import { BetterAuthClientPlugin } from "better-auth/client";
4
4
  //#region src/client.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;YAMY,YAAY,GAAG,UAAU,iCAAiC;EAAY;IAC9E,IACA,oBAAoB;iBAEP;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX;EACA;EACA,WAAW;EACX;;iBAGe;EACf,SAAS,UAAU,2CACjB;IACE;IACA,WAAW;IACX;KAEF,UAAU,MACP,QAAQ,YAAY,uBAAuB;EAChD,SAAS,UAAU,2CACjB;IAAQ;IAAmB;KAC3B,UAAU,MACP,QAAQ,YAAY,uBAAuB;EAChD,MAAM,UAAU,2CACd;IAAQ;IAAmB;KAC3B,UAAU,MACP,QAAQ,YAAY,uBAAuB;;iBAGjC;EACf,SAAS;;;YAIC;IACR,SAAS;;;;YAKD;IACR,gBAAgB,kBAAkB;;;KAIjC,qCAAqC,KACxC;EAGA;EACA,oBAAoB,kBAAkB;EACtC,aACE,QAAQ,aACR,iBACA,qBACG;;qBAGM,4BAA2B"}
1
+ {"version":3,"file":"client.d.mts","names":["solanaPaymentsServer"],"sources":["../src/client.ts"],"mappings":";;;;YAMY,YAAY,GAAG,UAAU,iCAAiC;EAAY;IAC9E,IACA,oBAAoB;iBAEP;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX;EACA;EACA,WAAW;EACX;;iBAGe;EACf,SAAS,UAAU,2CACjB;IACE;IACA,WAAW;IACX;KAEF,UAAU,MACP,QAAQ,YAAY,uBAAuB;EAChD,SAAS,UAAU,2CACjB;IAAQ;IAAmB;KAC3B,UAAU,MACP,QAAQ,YAAY,uBAAuB;EAChD,MAAM,UAAU,2CACd;IAAQ;IAAmB;KAC3B,UAAU,MACP,QAAQ,YAAY,uBAAuB;;iBAGjC;EACf,SAAS;;;YAIC;IACR,SAAS;;;;YAKD;IACR,gBAAgB,kBAAkB;;;KAIjC,qCAAqC,KACxC;EAGA;EACA,oBAAoB,kBAAkBA;EACtC,aACE,QAAQ,aACR,iBACA,qBACG;;qBAGM,4BAA2B"}
package/dist/client.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-Cmtbh3PR.mjs";
1
+ import { t as PACKAGE_VERSION } from "./version-AvRh2hcs.mjs";
2
2
  //#region src/client.ts
3
3
  const solanaPaymentsClient = () => ({
4
4
  id: "solanaPayments",
@@ -45,7 +45,7 @@ interface SolanaPaymentsOptions {
45
45
  }
46
46
  //#endregion
47
47
  //#region src/version.d.ts
48
- declare const PACKAGE_VERSION = "0.2.0";
48
+ declare const PACKAGE_VERSION = "0.3.1";
49
49
  //#endregion
50
50
  //#region src/store.d.ts
51
51
  type Adapter = {
@@ -248,4 +248,4 @@ declare function solanaPayments(input: SolanaPaymentsOptions): {
248
248
  };
249
249
  //#endregion
250
250
  export { SolanaPaymentStore as a, PACKAGE_VERSION as c, SolanaPaymentsOptions as d, getSchema as f, MarkPaidResult as i, SolanaPayment as l, CreateSolanaPaymentInput as n, SolanaPaymentStoreContext as o, solanaPaymentsPluginSchema as p, MarkPaidInput as r, createSolanaPaymentStore as s, solanaPayments as t, SolanaPaymentStatus as u };
251
- //# sourceMappingURL=index-6unaaVQL.d.mts.map
251
+ //# sourceMappingURL=index-DRaH60lh.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-DRaH60lh.d.mts","names":["_$__types_ts0.SolanaPaymentStatus"],"sources":["../src/schema.ts","../src/types.d.ts","../src/version.ts","../src/store.ts","../src/index.ts"],"mappings":";;;;KAIK,sBAAsB;EAGvB,QAAQ,kQAkBN;;KA6BM,6BAA6B;cAC5B,4BAA4B;iBAEzB,UACd,SAAS,KAAK,mCACb;;;KCxDS;UACK;EACb;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA,uBAAuB;EACvB,WAAW;EACX;;EAEA;EACA;EACA,WAAW;EACX,WAAW;;UAEE;EACb,QAAQ;EACR,WAAW;EACX;EACA,qBAAqB,SAAS,eAAe,SAAS,2BAA2B;EACjF;IACI;;EAEJ,SAAS,kBAAkB;;;;cClClB;;;KCMR;EACH,OAAO,GAAG;IAAS;IAAe,MAAM,KAAK;MAAa,QAAQ;EAClE,QAAQ,GAAG;IAAS;IAAe,OAAO;MAAgB,QAAQ;EAClE,OAAO,GAAG;IAAS;IAAe,QAAQ,QAAQ;IAAI,OAAO;MAAgB,QAAQ;;KAElF;EAAgB;EAAe;;UAEnB;EACf,SAAS;EACT;IAAY;MAAS;;;EACrB;EACA;;KAGU,2BAA2B,KACrC;UAIe;EACf;EACA;;UAGe;EACf,SAAS;EACT;;UAGe;EACf,eAAe;EACf,OAAO,OAAO,2BAA2B,QAAQ;EACjD,SAAS,aAAa,QAAQ;EAC9B,gBAAgB,oBAAoB,QAAQ;EAC5C,SAAS,mBAAmB,QAAQ,gBAAgB,QAAQ;EAC5D,uBAAuB,mBAAmB,QAAQ,gBAAgB,QAAQ;EAC1E,iBAAiB,oBAAoB,QAAQ;EAC7C,kBACE,mBACA,eACA,qBACC,QAAQ;EACX,YAAY,oBAAoB,QAAQ;;iBAG1B,yBAAyB,SAAS,4BAA4B;;;iBCzB9D,eAAe,OAAO;;;;;;;;;;;;;;;;;;;YAuBi4D;YAA6C;;;;;;;;;YAAyN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAtQ;YAA6C;;;;;;;;;YAAyN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAtQ;YAA6C;;;;;;;;;YAAyN"}
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as SolanaPaymentStore, c as PACKAGE_VERSION, d as SolanaPaymentsOptions, f as getSchema, i as MarkPaidResult, l as SolanaPayment, n as CreateSolanaPaymentInput, o as SolanaPaymentStoreContext, p as solanaPaymentsPluginSchema, r as MarkPaidInput, s as createSolanaPaymentStore, t as solanaPayments, u as SolanaPaymentStatus } from "./index-6unaaVQL.mjs";
1
+ import { a as SolanaPaymentStore, c as PACKAGE_VERSION, d as SolanaPaymentsOptions, f as getSchema, i as MarkPaidResult, l as SolanaPayment, n as CreateSolanaPaymentInput, o as SolanaPaymentStoreContext, p as solanaPaymentsPluginSchema, r as MarkPaidInput, s as createSolanaPaymentStore, t as solanaPayments, u as SolanaPaymentStatus } from "./index-DRaH60lh.mjs";
2
2
  export { type CreateSolanaPaymentInput, type MarkPaidInput, type MarkPaidResult, PACKAGE_VERSION, type SolanaPayment, type SolanaPaymentStatus, type SolanaPaymentStore, type SolanaPaymentStoreContext, type SolanaPaymentsOptions, createSolanaPaymentStore, getSchema, solanaPayments, solanaPaymentsPluginSchema };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PACKAGE_VERSION } from "./version-Cmtbh3PR.mjs";
1
+ import { t as PACKAGE_VERSION } from "./version-AvRh2hcs.mjs";
2
2
  import { defineErrorCodes } from "better-auth";
3
3
  import { randomBytes, randomUUID } from "node:crypto";
4
4
  import { APIError, createAuthEndpoint, getSessionFromCtx, originCheckMiddleware, sessionMiddleware } from "better-auth/api";
@@ -0,0 +1,6 @@
1
+ //#region src/version.ts
2
+ const PACKAGE_VERSION = "0.3.1";
3
+ //#endregion
4
+ export { PACKAGE_VERSION as t };
5
+
6
+ //# sourceMappingURL=version-AvRh2hcs.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version-AvRh2hcs.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["export const PACKAGE_VERSION = \"0.3.1\"; // x-release-please-version\n"],"mappings":";AAAA,MAAa,kBAAkB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-auth-solana-payments",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "One-time Solana payment integration for Better Auth",
5
5
  "keywords": [
6
6
  "better-auth",
@@ -41,24 +41,22 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
- "better-call": "1.3.8",
45
- "defu": "^6.1.7",
46
- "zod": "^4.6.2"
44
+ "zod": "^4.6.5"
47
45
  },
48
46
  "devDependencies": {
49
47
  "@arethetypeswrong/cli": "^0.18.5",
50
- "@better-fetch/fetch": "1.3.1",
51
- "@types/node": "^24.13.4",
52
- "better-auth": "1.6.31",
53
- "publint": "^0.3.24",
54
- "typescript": "^6.0.3",
55
- "vite": "npm:@voidzero-dev/vite-plus-core@0.3.1",
56
- "vite-plus": "0.3.1"
48
+ "@better-fetch/fetch": "1.3.2",
49
+ "@types/node": "^22.20.5",
50
+ "better-auth": "1.7.7",
51
+ "publint": "^0.3.25",
52
+ "typescript": "npm:@typescript/typescript6@6.0.2",
53
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.1.0",
54
+ "vite-plus": "1.1.0"
57
55
  },
58
56
  "peerDependencies": {
59
57
  "@better-fetch/fetch": "^1.3.1",
60
58
  "better-auth": "^1.6.25",
61
- "solana-payments": "^1.0.0"
59
+ "solana-payments": "^1.0.2"
62
60
  },
63
61
  "engines": {
64
62
  "node": ">=22.0.0"
@@ -68,7 +66,7 @@
68
66
  "dev": "vp pack --watch",
69
67
  "test": "vp test run",
70
68
  "lint": "vp lint src test",
71
- "typecheck": "tsc -p tsconfig.json --noEmit",
69
+ "typecheck": "tsc6 -p tsconfig.json --noEmit",
72
70
  "check": "vp check",
73
71
  "lint:package": "publint run --strict",
74
72
  "lint:types": "attw --profile esm-only --pack ."
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-6unaaVQL.d.mts","names":[],"sources":["../src/schema.ts","../src/types.d.ts","../src/version.ts","../src/store.ts","../src/index.ts"],"mappings":";;;;KAIK,sBAAsB;EAGvB,QAAQ,kQAkBN;;KA6BM,6BAA6B;cAC5B,4BAA4B;iBAEzB,UACd,SAAS,KAAK,mCACb;;;KCxDS;UACK;EACb;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA,uBAAuB;EACvB,WAAW;EACX;;EAEA;EACA;EACA,WAAW;EACX,WAAW;;UAEE;EACb,QAAQ;EACR,WAAW;EACX;EACA,qBAAqB,SAAS,eAAe,SAAS,2BAA2B;EACjF;IACI;;EAEJ,SAAS,kBAAkB;;;;cClClB;;;KCMR;EACH,OAAO,GAAG;IAAS;IAAe,MAAM,KAAK;MAAa,QAAQ;EAClE,QAAQ,GAAG;IAAS;IAAe,OAAO;MAAgB,QAAQ;EAClE,OAAO,GAAG;IAAS;IAAe,QAAQ,QAAQ;IAAI,OAAO;MAAgB,QAAQ;;KAElF;EAAgB;EAAe;;UAEnB;EACf,SAAS;EACT;IAAY;MAAS;;;EACrB;EACA;;KAGU,2BAA2B,KACrC;UAIe;EACf;EACA;;UAGe;EACf,SAAS;EACT;;UAGe;EACf,eAAe;EACf,OAAO,OAAO,2BAA2B,QAAQ;EACjD,SAAS,aAAa,QAAQ;EAC9B,gBAAgB,oBAAoB,QAAQ;EAC5C,SAAS,mBAAmB,QAAQ,gBAAgB,QAAQ;EAC5D,uBAAuB,mBAAmB,QAAQ,gBAAgB,QAAQ;EAC1E,iBAAiB,oBAAoB,QAAQ;EAC7C,kBACE,mBACA,eACA,qBACC,QAAQ;EACX,YAAY,oBAAoB,QAAQ;;iBAG1B,yBAAyB,SAAS,4BAA4B;;;iBCzB9D,eAAe,OAAO;;;;;;;;;;;;;;;;;;;YAuBi4D;YAA6C;;;;;;;;;YAAyN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAtQ;YAA6C;;;;;;;;;YAAyN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAtQ;YAA6C;;;;;;;;;YAAyN"}
@@ -1,6 +0,0 @@
1
- //#region src/version.ts
2
- const PACKAGE_VERSION = "0.2.0";
3
- //#endregion
4
- export { PACKAGE_VERSION as t };
5
-
6
- //# sourceMappingURL=version-Cmtbh3PR.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version-Cmtbh3PR.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["export const PACKAGE_VERSION = \"0.2.0\"; // x-release-please-version\n"],"mappings":";AAAA,MAAa,kBAAkB"}