@flopay/node 1.8.1 → 1.8.2
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 +10 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,12 +54,21 @@ const result = await flopay.checkout.sessions.create({
|
|
|
54
54
|
tagsData: { googleContainerId: 'GTM-XXXX' },
|
|
55
55
|
redirectParams: { email: 'user@example.com', mode: 'confirm' },
|
|
56
56
|
timeoutMs: 12000,
|
|
57
|
+
idempotencyKey: 'order-123-attempt-group',
|
|
57
58
|
});
|
|
58
59
|
|
|
59
60
|
// result = { status: 201, redirectUrl: 'https://checkout.example.com/secure?id=uuid&...' }
|
|
60
61
|
// result = { status: 204 } (payment method already on file)
|
|
61
62
|
```
|
|
62
63
|
|
|
64
|
+
Pass the same `idempotencyKey` when retrying one logical session creation after
|
|
65
|
+
an unknown outcome. `@flopay/node` sends a supplied non-whitespace key of at most
|
|
66
|
+
255 characters unchanged as `Idempotency-Key`; it does not generate a key or add
|
|
67
|
+
the header when the option is omitted. Empty, whitespace-only, overlong, and
|
|
68
|
+
Fetch-header-unsafe values are ignored without throwing or emitting a malformed
|
|
69
|
+
header. The Node SDK has no internal retry loop, so the server integration owns
|
|
70
|
+
retry timing and key reuse.
|
|
71
|
+
|
|
63
72
|
To authorise an eligible one-time card cart without capturing it, pass
|
|
64
73
|
`captureMethod: 'manual'` to `checkout.sessions.create`. Do not combine manual
|
|
65
74
|
capture with subscriptions; the SDK rejects that cart before making a request.
|
|
@@ -170,7 +179,7 @@ new FloPay(secretKey: string, options?: FloPayNodeOptions)
|
|
|
170
179
|
| Type | Description |
|
|
171
180
|
|------|-------------|
|
|
172
181
|
| `FloPayNodeOptions` | Constructor options |
|
|
173
|
-
| `CreateSessionParams` | Full session creation parameters (from `@flopay/shared`), including optional `captureMethod: 'automatic' \| 'manual'` |
|
|
182
|
+
| `CreateSessionParams` | Full session creation parameters (from `@flopay/shared`), including optional `captureMethod: 'automatic' \| 'manual'` and caller-managed `idempotencyKey` |
|
|
174
183
|
| `CheckoutSessionResult` | `{ status: 201, redirectUrl, nonce }` / `{ status: 204 }` / `{ status: number }` |
|
|
175
184
|
| `CheckoutSession` | Normalized session; `status` can be `authorized`, with `paymentId` and `authorizationExpiresAt`, for manual capture |
|
|
176
185
|
| `Customer` | `id`, `email`, `firstName?`, `lastName?` |
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var j=Object.create;var m=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var K=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var H=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},w=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of F(e))!q.call(r,o)&&o!==t&&m(r,o,{get:()=>e[o],enumerable:!(i=z(e,o))||i.enumerable});return r};var W=(r,e,t)=>(t=r!=null?j(K(r)):{},w(e||!r||!r.__esModule?m(t,"default",{value:r,enumerable:!0}):t,r)),$=r=>w(m({},"__esModule",{value:!0}),r);var G={};H(G,{FloPay:()=>d,STRIPE_API_VERSION:()=>g});module.exports=$(G);var s=require("@flopay/shared"),I=W(require("stripe"),1),g="2026-04-22.dahlia";function Y(r){for(let e of r){let t=e.charCodeAt(0);if(t<=8||t>=10&&t<=31||t===127)return!0}return!1}function B(r){if(!r||r.trim()===""||r.length>s.MAX_IDEMPOTENCY_KEY_LENGTH||Y(r))return!1;try{return new Headers({[s.IDEMPOTENCY_KEY_HEADER]:r}).get(s.IDEMPOTENCY_KEY_HEADER)===r}catch{return!1}}var d=class{constructor(e,t){if(!e)throw new s.FloPayError("A secret key is required to initialize the FloPay server SDK.","authentication_error");this.stripe=new I.default(t?.stripeSecretKey??e,{apiVersion:t?.apiVersion??g,appInfo:{name:"flopay-node",version:s.SDK_VERSION}}),this.checkout={sessions:{create:this.createSession.bind(this),retrieve:this.retrieveSession.bind(this),expire:this.expireSession.bind(this),listLineItems:this.listLineItems.bind(this)}},this.webhooks={constructEvent:this.constructWebhookEvent.bind(this)},this.customers={create:this.createCustomer.bind(this),retrieve:this.retrieveCustomer.bind(this),update:this.updateCustomer.bind(this)}}async createSession(e){let{billingApiUrl:t,checkoutBaseUrl:i,items:o=[],subscriptions:f=[],products:E,account:n,successUrl:N,cancelUrl:_,checkoutMode:R="confirm",captureMethod:l,couponCodes:U=[],tagsData:S,redirectParams:x={},timeoutMs:M=12e3,clientId:O,currency:T,utmMetadata:P,idempotencyKey:k}=e,p=E??(0,s.foldIntoProducts)(o,f);(0,s.assertCaptureMethodEligible)({captureMethod:l,products:p});let h=(0,s.resolveSessionCurrency)(T,o,f,p);if(!h)throw new s.FloPayError("currency is required: pass `currency` on the session, or include a `currency` on the first item/subscription/product.","validation_error",{code:"CurrencyRequired",param:"currency"});let c={clientId:O,checkoutVersion:s.SDK_VERSION,successUrl:N,cancelUrl:_,currency:h,checkoutMode:R,products:p.map(a=>(0,s.buildProductPayload)(a,h)),accountData:{userId:n.userId,firstName:n.firstName??null,lastName:n.lastName??null,email:n.email,country:n.country??null,gender:n.gender??null,city:n.city??null,state:n.state??null,zip:n.zip??null},couponCodes:U};l==="manual"&&(c.captureMethod=l),S&&(c.tagsData=S),P?.length&&(c.utmMetadata=P);let V=`${t.replace(/\/+$/,"")}/v1/checkouts/sessions`,b=new AbortController,A=setTimeout(()=>b.abort(),M),u,y;try{let a=await fetch(V,{method:"POST",headers:{"Content-Type":"application/json",...B(k)?{[s.IDEMPOTENCY_KEY_HEADER]:k}:{}},body:JSON.stringify(c),signal:b.signal});u=a.status;try{y=await a.json()}catch{}}finally{clearTimeout(A)}if(u===201){let a=y?.data?.uuid,v=y?.data?.nonce;if(!a)throw new Error("Checkout session created but no UUID was returned by the billing API");if(!v)throw new s.FloPayError("Checkout session created but no `nonce` was returned by the billing API. Upgrade the billing service to TeamFloPay/backend#640 or later.","api_error",{code:"MissingCheckoutSessionToken"});let C=new URL(`${i.replace(/\/+$/,"")}/secure`);C.searchParams.set("id",a);for(let[L,D]of Object.entries(x))C.searchParams.set(L,D);return{status:201,redirectUrl:C.toString(),nonce:v}}return u===204?{status:204}:{status:u}}normalizeStripeSession(e){let t={open:"open",complete:"complete",expired:"expired"};return{id:e.id,clientSecret:e.client_secret??"",mode:e.mode,status:t[e.status??"open"]??"open",amount:e.amount_total??0,currency:e.currency??"usd",metadata:e.metadata??{}}}async retrieveSession(e){let t=await this.stripe.checkout.sessions.retrieve(e);return this.normalizeStripeSession(t)}async expireSession(e){let t=await this.stripe.checkout.sessions.expire(e);return this.normalizeStripeSession(t)}async listLineItems(e){return(await this.stripe.checkout.sessions.listLineItems(e)).data.map(i=>({price:i.price?.id,quantity:i.quantity??1}))}constructWebhookEvent(e,t,i){let o=this.stripe.webhooks.constructEvent(e,t,i);return{id:o.id,type:o.type,data:o.data,created:o.created}}async createCustomer(e){let t=await this.stripe.customers.create({email:e.email,name:e.name,metadata:e.metadata});return{id:t.id,email:t.email??e.email,firstName:e.name?.split(" ")[0],lastName:e.name?.split(" ").slice(1).join(" ")}}async retrieveCustomer(e){let t=await this.stripe.customers.retrieve(e);if(t.deleted)throw new s.FloPayError(`Customer ${e} has been deleted`,"api_error",{code:"resource_missing"});return{id:t.id,email:t.email??"",firstName:t.name?.split(" ")[0],lastName:t.name?.split(" ").slice(1).join(" ")}}async updateCustomer(e,t){let i=await this.stripe.customers.update(e,{email:t.email,name:t.name,metadata:t.metadata});return{id:i.id,email:i.email??"",firstName:i.name?.split(" ")[0],lastName:i.name?.split(" ").slice(1).join(" ")}}};0&&(module.exports={FloPay,STRIPE_API_VERSION});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{assertCaptureMethodEligible as
|
|
1
|
+
import{assertCaptureMethodEligible as D,buildProductPayload as j,FloPayError as u,foldIntoProducts as z,IDEMPOTENCY_KEY_HEADER as y,MAX_IDEMPOTENCY_KEY_LENGTH as F,resolveSessionCurrency as K,SDK_VERSION as v}from"@flopay/shared";import q from"stripe";var w="2026-04-22.dahlia";function H(s){for(let e of s){let t=e.charCodeAt(0);if(t<=8||t>=10&&t<=31||t===127)return!0}return!1}function W(s){if(!s||s.trim()===""||s.length>F||H(s))return!1;try{return new Headers({[y]:s}).get(y)===s}catch{return!1}}var C=class{constructor(e,t){if(!e)throw new u("A secret key is required to initialize the FloPay server SDK.","authentication_error");this.stripe=new q(t?.stripeSecretKey??e,{apiVersion:t?.apiVersion??w,appInfo:{name:"flopay-node",version:v}}),this.checkout={sessions:{create:this.createSession.bind(this),retrieve:this.retrieveSession.bind(this),expire:this.expireSession.bind(this),listLineItems:this.listLineItems.bind(this)}},this.webhooks={constructEvent:this.constructWebhookEvent.bind(this)},this.customers={create:this.createCustomer.bind(this),retrieve:this.retrieveCustomer.bind(this),update:this.updateCustomer.bind(this)}}async createSession(e){let{billingApiUrl:t,checkoutBaseUrl:r,items:o=[],subscriptions:g=[],products:I,account:i,successUrl:E,cancelUrl:N,checkoutMode:_="confirm",captureMethod:m,couponCodes:R=[],tagsData:f,redirectParams:U={},timeoutMs:x=12e3,clientId:M,currency:O,utmMetadata:S,idempotencyKey:P}=e,d=I??z(o,g);D({captureMethod:m,products:d});let l=K(O,o,g,d);if(!l)throw new u("currency is required: pass `currency` on the session, or include a `currency` on the first item/subscription/product.","validation_error",{code:"CurrencyRequired",param:"currency"});let a={clientId:M,checkoutVersion:v,successUrl:E,cancelUrl:N,currency:l,checkoutMode:_,products:d.map(n=>j(n,l)),accountData:{userId:i.userId,firstName:i.firstName??null,lastName:i.lastName??null,email:i.email,country:i.country??null,gender:i.gender??null,city:i.city??null,state:i.state??null,zip:i.zip??null},couponCodes:R};m==="manual"&&(a.captureMethod=m),f&&(a.tagsData=f),S?.length&&(a.utmMetadata=S);let T=`${t.replace(/\/+$/,"")}/v1/checkouts/sessions`,k=new AbortController,V=setTimeout(()=>k.abort(),x),c,p;try{let n=await fetch(T,{method:"POST",headers:{"Content-Type":"application/json",...W(P)?{[y]:P}:{}},body:JSON.stringify(a),signal:k.signal});c=n.status;try{p=await n.json()}catch{}}finally{clearTimeout(V)}if(c===201){let n=p?.data?.uuid,b=p?.data?.nonce;if(!n)throw new Error("Checkout session created but no UUID was returned by the billing API");if(!b)throw new u("Checkout session created but no `nonce` was returned by the billing API. Upgrade the billing service to TeamFloPay/backend#640 or later.","api_error",{code:"MissingCheckoutSessionToken"});let h=new URL(`${r.replace(/\/+$/,"")}/secure`);h.searchParams.set("id",n);for(let[A,L]of Object.entries(U))h.searchParams.set(A,L);return{status:201,redirectUrl:h.toString(),nonce:b}}return c===204?{status:204}:{status:c}}normalizeStripeSession(e){let t={open:"open",complete:"complete",expired:"expired"};return{id:e.id,clientSecret:e.client_secret??"",mode:e.mode,status:t[e.status??"open"]??"open",amount:e.amount_total??0,currency:e.currency??"usd",metadata:e.metadata??{}}}async retrieveSession(e){let t=await this.stripe.checkout.sessions.retrieve(e);return this.normalizeStripeSession(t)}async expireSession(e){let t=await this.stripe.checkout.sessions.expire(e);return this.normalizeStripeSession(t)}async listLineItems(e){return(await this.stripe.checkout.sessions.listLineItems(e)).data.map(r=>({price:r.price?.id,quantity:r.quantity??1}))}constructWebhookEvent(e,t,r){let o=this.stripe.webhooks.constructEvent(e,t,r);return{id:o.id,type:o.type,data:o.data,created:o.created}}async createCustomer(e){let t=await this.stripe.customers.create({email:e.email,name:e.name,metadata:e.metadata});return{id:t.id,email:t.email??e.email,firstName:e.name?.split(" ")[0],lastName:e.name?.split(" ").slice(1).join(" ")}}async retrieveCustomer(e){let t=await this.stripe.customers.retrieve(e);if(t.deleted)throw new u(`Customer ${e} has been deleted`,"api_error",{code:"resource_missing"});return{id:t.id,email:t.email??"",firstName:t.name?.split(" ")[0],lastName:t.name?.split(" ").slice(1).join(" ")}}async updateCustomer(e,t){let r=await this.stripe.customers.update(e,{email:t.email,name:t.name,metadata:t.metadata});return{id:r.id,email:r.email??"",firstName:r.name?.split(" ")[0],lastName:r.name?.split(" ").slice(1).join(" ")}}};export{C as FloPay,w as STRIPE_API_VERSION};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flopay/node",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"stripe": "^22.2.1",
|
|
30
|
-
"@flopay/shared": "1.8.
|
|
30
|
+
"@flopay/shared": "1.8.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"tsup": "^8.3.0",
|