Skip to content

basalt / subscriptions/src / StripeBillingGateway

Class: StripeBillingGateway ​

Defined in: subscriptions/src/drivers/stripe.ts:69

Stripe billing gateway targeting the Stripe REST API directly — no stripe SDK dependency. HTTP goes through an injectable fetch; webhook signatures are verified with node:crypto using Stripe's documented scheme.

Implements ​

Constructors ​

Constructor ​

> new StripeBillingGateway(options): StripeBillingGateway

Defined in: subscriptions/src/drivers/stripe.ts:78

Parameters ​

options ​

StripeGatewayOptions

Returns ​

StripeBillingGateway

Properties ​

name ​

> readonly name: "stripe" = 'stripe'

Defined in: subscriptions/src/drivers/stripe.ts:70

Implementation of ​

BillingGateway.name


signatureHeader ​

> readonly signatureHeader: "stripe-signature" = 'stripe-signature'

Defined in: subscriptions/src/drivers/stripe.ts:71

Request header(s) carrying this gateway's webhook signature, lower-case (e.g. 'stripe-signature', 'paddle-signature', 'x-signature'). billingWebhookRoute reads the first one present. Omitted: the route falls back to stripe-signature / x-billing-signature.

Implementation of ​

BillingGateway.signatureHeader

Methods ​

cancelSubscription() ​

> cancelSubscription(gatewayRef, options): Promise<void>

Defined in: subscriptions/src/drivers/stripe.ts:106

Parameters ​

gatewayRef ​

string

options ​
atPeriodEnd ​

boolean

Returns ​

Promise<void>

Implementation of ​

BillingGateway.cancelSubscription


createCheckoutSession() ​

> createCheckoutSession(input): Promise<{ id: string; url: string; }>

Defined in: subscriptions/src/drivers/stripe.ts:116

Hosted Checkout session — returns a URL to redirect the customer to.

Parameters ​

input ​

CheckoutInput

Returns ​

Promise<{ id: string; url: string; }>

Implementation of ​

BillingGateway.createCheckoutSession


createPortalSession() ​

> createPortalSession(input): Promise<{ url: string; }>

Defined in: subscriptions/src/drivers/stripe.ts:137

Customer Portal session — returns a URL for self-service billing.

Parameters ​

input ​

PortalInput

Returns ​

Promise<{ url: string; }>

Implementation of ​

BillingGateway.createPortalSession


createSubscription() ​

> createSubscription(input): Promise<{ gatewayRef: string; }>

Defined in: subscriptions/src/drivers/stripe.ts:88

Parameters ​

input ​

CreateSubscriptionInput

Returns ​

Promise<{ gatewayRef: string; }>

Implementation of ​

BillingGateway.createSubscription


resumeSubscription() ​

> resumeSubscription(gatewayRef): Promise<void>

Defined in: subscriptions/src/drivers/stripe.ts:146

Withdraws a cancellation scheduled with cancelSubscription(ref, { atPeriodEnd: true }), so the gateway keeps renewing. Required by Subscriptions.resume() for a gateway-backed subscription.

Parameters ​

gatewayRef ​

string

Returns ​

Promise<void>

Implementation of ​

BillingGateway.resumeSubscription


swapSubscription() ​

> swapSubscription(gatewayRef, input): Promise<void>

Defined in: subscriptions/src/drivers/stripe.ts:152

Changes the plan on an existing subscription, applying proration.

Parameters ​

gatewayRef ​

string

input ​

SwapInput

Returns ​

Promise<void>

Implementation of ​

BillingGateway.swapSubscription


verifyWebhook() ​

> verifyWebhook(rawBody, signature): WebhookEvent | null

Defined in: subscriptions/src/drivers/stripe.ts:170

Verifies the signature and translates the payload. Throws WebhookInvalidError on a bad signature. Returns null for a verified event the gateway doesn't map to a domain event (gateways emit many event types we don't act on).

Parameters ​

rawBody ​

string

signature ​

string | undefined

Returns ​

WebhookEvent | null

Implementation of ​

BillingGateway.verifyWebhook

Released under the MIT License.