@stacksjs/payments 0.75.159 → 0.75.161
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/connect/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { manageConnectedAccount } from './account';
|
|
2
2
|
import { manageConnectWebhook } from './webhook';
|
|
3
3
|
import { manageDestinationCharge } from './charge';
|
|
4
|
+
import { manageDestinationSubscription } from './subscription';
|
|
4
5
|
import { managePayout } from './payout';
|
|
5
6
|
import { manageTransfer } from './transfer';
|
|
6
7
|
/**
|
|
@@ -14,6 +15,9 @@ export declare const connect: {
|
|
|
14
15
|
retrieveAccount: typeof manageConnectedAccount.retrieveConnectedAccount;
|
|
15
16
|
destinationCharge: typeof manageDestinationCharge.destinationCharge;
|
|
16
17
|
applicationFeeFor: typeof manageDestinationCharge.applicationFeeFor;
|
|
18
|
+
subscriptionCheckout: typeof manageDestinationSubscription.checkout;
|
|
19
|
+
subscriptionFeePercent: typeof manageDestinationSubscription.feePercentFor;
|
|
20
|
+
subscriptionDestination: typeof manageDestinationSubscription.destinationOf;
|
|
17
21
|
createTransfer: typeof manageTransfer.createTransfer;
|
|
18
22
|
reverseTransfer: typeof manageTransfer.reverseTransfer;
|
|
19
23
|
listTransfers: typeof manageTransfer.listTransfers;
|
|
@@ -28,6 +32,7 @@ export declare const connect: {
|
|
|
28
32
|
getConnectedAccountId: typeof manageConnectWebhook.getConnectedAccountId;
|
|
29
33
|
account: typeof manageConnectedAccount;
|
|
30
34
|
charge: typeof manageDestinationCharge;
|
|
35
|
+
subscription: typeof manageDestinationSubscription;
|
|
31
36
|
transfer: typeof manageTransfer;
|
|
32
37
|
payout: typeof managePayout
|
|
33
38
|
};
|
|
@@ -45,5 +50,6 @@ export declare const connect: {
|
|
|
45
50
|
export * from './account';
|
|
46
51
|
export * from './charge';
|
|
47
52
|
export * from './payout';
|
|
53
|
+
export * from './subscription';
|
|
48
54
|
export * from './transfer';
|
|
49
55
|
export * from './webhook';
|
package/dist/connect/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./account";export*from"./charge";export*from"./payout";export*from"./transfer";export*from"./webhook";import{manageConnectedAccount}from"./account";import{manageDestinationCharge}from"./charge";import{managePayout}from"./payout";import{manageTransfer}from"./transfer";import{manageConnectWebhook}from"./webhook";export const connect={createAccount:manageConnectedAccount.createConnectedAccount,createTestAccount:manageConnectedAccount.createTestConnectedAccount,onboardingLink:manageConnectedAccount.accountOnboardingLink,accountStatus:manageConnectedAccount.accountStatus,retrieveAccount:manageConnectedAccount.retrieveConnectedAccount,destinationCharge:manageDestinationCharge.destinationCharge,applicationFeeFor:manageDestinationCharge.applicationFeeFor,createTransfer:manageTransfer.createTransfer,reverseTransfer:manageTransfer.reverseTransfer,listTransfers:manageTransfer.listTransfers,retrieveTransfer:manageTransfer.retrieveTransfer,listPayouts:managePayout.listPayouts,retrievePayout:managePayout.retrievePayout,accountBalance:managePayout.accountBalance,onAccount:manageConnectWebhook.onAccount,onPayout:manageConnectWebhook.onPayout,getAccount:manageConnectWebhook.getAccount,getPayout:manageConnectWebhook.getPayout,getConnectedAccountId:manageConnectWebhook.getConnectedAccountId,account:manageConnectedAccount,charge:manageDestinationCharge,transfer:manageTransfer,payout:managePayout};
|
|
1
|
+
export*from"./account";export*from"./charge";export*from"./payout";export*from"./subscription";export*from"./transfer";export*from"./webhook";import{manageConnectedAccount}from"./account";import{manageDestinationCharge}from"./charge";import{managePayout}from"./payout";import{manageDestinationSubscription}from"./subscription";import{manageTransfer}from"./transfer";import{manageConnectWebhook}from"./webhook";export const connect={createAccount:manageConnectedAccount.createConnectedAccount,createTestAccount:manageConnectedAccount.createTestConnectedAccount,onboardingLink:manageConnectedAccount.accountOnboardingLink,accountStatus:manageConnectedAccount.accountStatus,retrieveAccount:manageConnectedAccount.retrieveConnectedAccount,destinationCharge:manageDestinationCharge.destinationCharge,applicationFeeFor:manageDestinationCharge.applicationFeeFor,subscriptionCheckout:manageDestinationSubscription.checkout,subscriptionFeePercent:manageDestinationSubscription.feePercentFor,subscriptionDestination:manageDestinationSubscription.destinationOf,createTransfer:manageTransfer.createTransfer,reverseTransfer:manageTransfer.reverseTransfer,listTransfers:manageTransfer.listTransfers,retrieveTransfer:manageTransfer.retrieveTransfer,listPayouts:managePayout.listPayouts,retrievePayout:managePayout.retrievePayout,accountBalance:managePayout.accountBalance,onAccount:manageConnectWebhook.onAccount,onPayout:manageConnectWebhook.onPayout,getAccount:manageConnectWebhook.getAccount,getPayout:manageConnectWebhook.getPayout,getConnectedAccountId:manageConnectWebhook.getConnectedAccountId,account:manageConnectedAccount,charge:manageDestinationCharge,subscription:manageDestinationSubscription,transfer:manageTransfer,payout:managePayout};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { UserModel } from '@stacksjs/orm';
|
|
2
|
+
import type Stripe from 'stripe';
|
|
3
|
+
export declare const manageDestinationSubscription: ManageDestinationSubscription;
|
|
4
|
+
/** A recurring price defined at checkout rather than in the catalog. */
|
|
5
|
+
export declare interface InlineRecurringPrice {
|
|
6
|
+
amount: number
|
|
7
|
+
currency: string
|
|
8
|
+
interval: SubscriptionInterval
|
|
9
|
+
intervalCount?: number
|
|
10
|
+
productName: string
|
|
11
|
+
productDescription?: string
|
|
12
|
+
}
|
|
13
|
+
export declare interface DestinationSubscriptionCheckoutOptions {
|
|
14
|
+
destination: string
|
|
15
|
+
price: string | InlineRecurringPrice
|
|
16
|
+
quantity?: number
|
|
17
|
+
trialDays?: number
|
|
18
|
+
platformFeePercent?: number
|
|
19
|
+
onBehalfOf?: boolean
|
|
20
|
+
metadata?: Record<string, string>
|
|
21
|
+
clientReferenceId?: string
|
|
22
|
+
customer?: string
|
|
23
|
+
successUrl: string
|
|
24
|
+
cancelUrl: string
|
|
25
|
+
sessionParams?: Partial<Stripe.Checkout.SessionCreateParams>
|
|
26
|
+
}
|
|
27
|
+
export declare interface ManageDestinationSubscription {
|
|
28
|
+
feePercentFor: (options?: { platformFeePercent?: number }) => number | undefined
|
|
29
|
+
subscriptionData: (destination: string, options?: Pick<DestinationSubscriptionCheckoutOptions, 'trialDays' | 'platformFeePercent' | 'onBehalfOf' | 'metadata'>) => Stripe.Checkout.SessionCreateParams.SubscriptionData
|
|
30
|
+
lineItem: (price: string | InlineRecurringPrice, quantity?: number) => Stripe.Checkout.SessionCreateParams.LineItem
|
|
31
|
+
checkout: (user: UserModel, options: DestinationSubscriptionCheckoutOptions) => Promise<Stripe.Response<Stripe.Checkout.Session>>
|
|
32
|
+
destinationOf: (subscription: { transfer_data?: { destination?: string | { id?: string } | null } | null }) => string | null
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Destination subscriptions: a merchant's recurring price, billed by the
|
|
36
|
+
* platform and settled to the merchant's connected account.
|
|
37
|
+
*
|
|
38
|
+
* The subscription, its customer and its invoices live on the platform, the
|
|
39
|
+
* same as a destination charge, so one webhook endpoint sees every renewal,
|
|
40
|
+
* failed payment and cancellation, and refunds and disputes stay with the
|
|
41
|
+
* platform. Each paid invoice transfers to `transfer_data.destination`, less
|
|
42
|
+
* `application_fee_percent` (a percentage, unlike a one-off charge's fee
|
|
43
|
+
* amount, because Stripe applies it to every invoice whatever its total:
|
|
44
|
+
* prorations, a coupon's discount, a trial's zero).
|
|
45
|
+
*
|
|
46
|
+
* Cancel, resume and read these with `manageSubscription` like any other
|
|
47
|
+
* platform subscription; nothing about them needs the connected account's
|
|
48
|
+
* credentials.
|
|
49
|
+
*/
|
|
50
|
+
/** Billing periods Stripe accepts for a recurring price. */
|
|
51
|
+
export type SubscriptionInterval = 'day' | 'week' | 'month' | 'year';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{config}from"@stacksjs/config";import{manageCheckout}from"../billable/checkout";import{manageCustomer}from"../billable/customer";import{requireAccountId}from"./account";const INTERVALS=["day","week","month","year"];function configuredFeePercent(){return(config||{}).payment?.connect?.platformFeePercent}export const manageDestinationSubscription=(()=>{function feePercentFor(options={}){const percent=options.platformFeePercent??configuredFeePercent();if(percent==null)return;if(!Number.isFinite(percent)||percent<0||percent>100)throw Error(`[payments/connect] platformFeePercent must be between 0 and 100, got ${percent}`);if(Math.round(percent*100)!==percent*100)throw Error(`[payments/connect] platformFeePercent takes at most two decimal places, got ${percent}`);return percent>0?percent:void 0}function subscriptionData(destination,options={}){requireAccountId(destination,"destinationSubscription");if(options.trialDays!=null&&(!Number.isInteger(options.trialDays)||options.trialDays<1||options.trialDays>730))throw Error(`[payments/connect] trialDays must be a whole number from 1 to 730, got ${options.trialDays}`);const fee=feePercentFor({platformFeePercent:options.platformFeePercent});return{transfer_data:{destination},...fee!=null?{application_fee_percent:fee}:{},...options.onBehalfOf?{on_behalf_of:destination}:{},...options.trialDays?{trial_period_days:options.trialDays}:{},...options.metadata?{metadata:options.metadata}:{}}}function lineItem(price,quantity=1){if(!Number.isInteger(quantity)||quantity<1)throw Error(`[payments/connect] quantity must be a positive whole number, got ${quantity}`);if(typeof price==="string"){if(!price.startsWith("price_"))throw Error(`[payments/connect] a catalog price id starts with "price_", got "${price}"`);return{price,quantity}}if(!Number.isInteger(price.amount)||price.amount<=0)throw Error("[payments/connect] a recurring price needs a positive amount in minor units");if(!INTERVALS.includes(price.interval))throw Error(`[payments/connect] interval must be one of ${INTERVALS.join(", ")}, got ${price.interval}`);const intervalCount=price.intervalCount??1;if(!Number.isInteger(intervalCount)||intervalCount<1)throw Error(`[payments/connect] intervalCount must be a positive whole number, got ${intervalCount}`);if(!price.productName?.trim())throw Error("[payments/connect] a recurring price needs a productName");return{quantity,price_data:{currency:price.currency.toLowerCase(),unit_amount:price.amount,recurring:{interval:price.interval,...intervalCount!==1?{interval_count:intervalCount}:{}},product_data:{name:price.productName.slice(0,250),...price.productDescription?{description:price.productDescription.slice(0,500)}:{}}}}}async function checkout(user,options){const customer=options.customer??(await manageCustomer.createOrGetStripeUser(user,{})).id;return await manageCheckout.create(user,{mode:"subscription",customer,line_items:[lineItem(options.price,options.quantity)],subscription_data:subscriptionData(options.destination,options),success_url:options.successUrl,cancel_url:options.cancelUrl,...options.clientReferenceId?{client_reference_id:options.clientReferenceId}:{},...options.metadata?{metadata:options.metadata}:{},...options.sessionParams})}function destinationOf(subscription){const destination=subscription.transfer_data?.destination;if(!destination)return null;return(typeof destination==="string"?destination:destination.id)||null}return{feePercentFor,subscriptionData,lineItem,checkout,destinationOf}})();
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/payments",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.161",
|
|
6
6
|
"description": "The Stacks payments package. Currently supporting Stripe.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"prepublishOnly": "bun run build"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@stacksjs/config": "0.75.
|
|
64
|
-
"@stacksjs/database": "0.75.
|
|
65
|
-
"@stacksjs/error-handling": "0.75.
|
|
66
|
-
"@stacksjs/logging": "0.75.
|
|
67
|
-
"@stacksjs/orm": "0.75.
|
|
68
|
-
"@stacksjs/types": "0.75.
|
|
63
|
+
"@stacksjs/config": "0.75.161",
|
|
64
|
+
"@stacksjs/database": "0.75.161",
|
|
65
|
+
"@stacksjs/error-handling": "0.75.161",
|
|
66
|
+
"@stacksjs/logging": "0.75.161",
|
|
67
|
+
"@stacksjs/orm": "0.75.161",
|
|
68
|
+
"@stacksjs/types": "0.75.161"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@stripe/stripe-js": "^10.0.0",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@stacksjs/utils": "0.75.
|
|
83
|
+
"@stacksjs/utils": "0.75.161",
|
|
84
84
|
"@stripe/stripe-js": "^10.0.0",
|
|
85
85
|
"better-dx": "^0.2.24",
|
|
86
86
|
"stripe": "23.0.0"
|