Skip to main content
Version: 2.x

Class: PostgresBillingStore

Defined in: javascript/src/billing/postgres/store.ts:153

Abstract billing store — provider-agnostic persistence layer for subscription lifecycle state.

Mirrors Python bursar/billing/store.py.

Extends​

Constructors​

Constructor​

new PostgresBillingStore(options): PostgresBillingStore

Defined in: javascript/src/billing/postgres/store.ts:169

Parameters​

options​

PostgresBillingStoreOptions

Returns​

PostgresBillingStore

Overrides​

BillingStore.constructor

Properties​

providerEnvironment​

readonly providerEnvironment: "live" | "test" | "sandbox"

Defined in: javascript/src/billing/postgres/store.ts:155

Exposed by environment-partitioned stores so composition can reject drift.

Overrides​

BillingStore.providerEnvironment

Methods​

claimAutoRechargeAttempt()​

claimAutoRechargeAttempt(input): Promise<BillingAutoRechargeAttempt | null>

Defined in: javascript/src/billing/postgres/store.ts:900

Parameters​

input​

AutoRechargeAttemptClaim

Returns​

Promise<BillingAutoRechargeAttempt | null>

Overrides​

BillingStore.claimAutoRechargeAttempt


claimBillingEvent()​

claimBillingEvent(provider, eventId, eventType, envelope?): Promise<BillingEventClaim>

Defined in: javascript/src/billing/postgres/store.ts:400

Parameters​

provider​

string

eventId​

string

eventType​

string

envelope?​

JsonObject

Returns​

Promise<BillingEventClaim>

Overrides​

BillingStore.claimBillingEvent


close()​

close(): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:195

Returns​

Promise<void>


completeBillingEvent()​

completeBillingEvent(provider, eventId, claimToken): Promise<boolean>

Defined in: javascript/src/billing/postgres/store.ts:440

Parameters​

provider​

string

eventId​

string

claimToken​

string

Returns​

Promise<boolean>

Overrides​

BillingStore.completeBillingEvent


computeTopupCredits()​

computeTopupCredits(amountMinor, topupConfig): Promise<Decimal>

Defined in: javascript/src/billing/postgres/store.ts:631

Parameters​

amountMinor​

number

topupConfig​

BillingTopupResult

Returns​

Promise<Decimal>

Overrides​

BillingStore.computeTopupCredits


countAutoRechargeAttempts()​

countAutoRechargeAttempts(userId, since): Promise<number>

Defined in: javascript/src/billing/postgres/store.ts:916

Parameters​

userId​

string

since​

string | Date

Returns​

Promise<number>

Overrides​

BillingStore.countAutoRechargeAttempts


createBillingCreditGrant()​

createBillingCreditGrant(input): Promise<string>

Defined in: javascript/src/billing/postgres/store.ts:663

Parameters​

input​

BillingCreditGrantCreate

Returns​

Promise<string>

Overrides​

BillingStore.createBillingCreditGrant


createBillingSubscriptionChange()​

createBillingSubscriptionChange(input): Promise<BillingSubscriptionChange>

Defined in: javascript/src/billing/postgres/store.ts:488

Parameters​

input​

BillingSubscriptionChangeInput

Returns​

Promise<BillingSubscriptionChange>

Overrides​

BillingStore.createBillingSubscriptionChange


createOrGetCheckoutIntent()​

createOrGetCheckoutIntent(input): Promise<CheckoutIntent>

Defined in: javascript/src/billing/postgres/store.ts:265

Parameters​

input​

CheckoutIntentCreate

Returns​

Promise<CheckoutIntent>

Overrides​

BillingStore.createOrGetCheckoutIntent


expireSubscriptionGracePeriod()​

expireSubscriptionGracePeriod(subjectId, subscriptionId, expectedGraceEndsAt, expiredAt, terminalPlanKey): Promise<boolean>

Defined in: javascript/src/billing/postgres/store.ts:546

Parameters​

subjectId​

string

subscriptionId​

string

expectedGraceEndsAt​

string

expiredAt​

string

terminalPlanKey​

string | null

Returns​

Promise<boolean>

Overrides​

BillingStore.expireSubscriptionGracePeriod


failBillingEvent()​

failBillingEvent(provider, eventId, claimToken, error?): Promise<boolean>

Defined in: javascript/src/billing/postgres/store.ts:448

Parameters​

provider​

string

eventId​

string

claimToken​

string

error?​

string

Returns​

Promise<boolean>

Overrides​

BillingStore.failBillingEvent


getActiveCatalogDocument()​

getActiveCatalogDocument(): Promise<JsonObject | null>

Defined in: javascript/src/billing/postgres/store.ts:853

Returns​

Promise<JsonObject | null>

Overrides​

BillingStore.getActiveCatalogDocument


getAutoRechargeProfile()​

getAutoRechargeProfile(userId): Promise<BillingAutoRechargeProfile | null>

Defined in: javascript/src/billing/postgres/store.ts:889

Parameters​

userId​

string

Returns​

Promise<BillingAutoRechargeProfile | null>

Overrides​

BillingStore.getAutoRechargeProfile


getBillingCreditGrantByPayment()​

getBillingCreditGrantByPayment(paymentId): Promise<string | null>

Defined in: javascript/src/billing/postgres/store.ts:694

Parameters​

paymentId​

string

Returns​

Promise<string | null>

Overrides​

BillingStore.getBillingCreditGrantByPayment


getBillingCustomer()​

getBillingCustomer(provider, providerCustomerId): Promise<string | null>

Defined in: javascript/src/billing/postgres/store.ts:475

Parameters​

provider​

string

providerCustomerId​

string

Returns​

Promise<string | null>

Overrides​

BillingStore.getBillingCustomer


getBillingCustomerByUserId()​

getBillingCustomerByUserId(userId, provider?): Promise<BillingCustomerRecord | null>

Defined in: javascript/src/billing/postgres/store.ts:920

Parameters​

userId​

string

provider?​

string | null

Returns​

Promise<BillingCustomerRecord | null>

Overrides​

BillingStore.getBillingCustomerByUserId


getBillingPayment()​

getBillingPayment(provider, providerPaymentId): Promise<BillingPaymentRecord | null>

Defined in: javascript/src/billing/postgres/store.ts:793

Parameters​

provider​

string

providerPaymentId​

string

Returns​

Promise<BillingPaymentRecord | null>

Overrides​

BillingStore.getBillingPayment


getBillingPreferences()​

getBillingPreferences(userId): Promise<BillingPreferences | null>

Defined in: javascript/src/billing/postgres/store.ts:881

Parameters​

userId​

string

Returns​

Promise<BillingPreferences | null>

Overrides​

BillingStore.getBillingPreferences


getBillingSubscription()​

getBillingSubscription(provider, providerSubscriptionId): Promise<BillingSubscriptionState | null>

Defined in: javascript/src/billing/postgres/store.ts:479

Parameters​

provider​

string

providerSubscriptionId​

string

Returns​

Promise<BillingSubscriptionState | null>

Overrides​

BillingStore.getBillingSubscription


getCheckoutIntent()​

getCheckoutIntent(id, subjectId): Promise<CheckoutIntent | null>

Defined in: javascript/src/billing/postgres/store.ts:314

Parameters​

id​

string

subjectId​

string

Returns​

Promise<CheckoutIntent | null>

Overrides​

BillingStore.getCheckoutIntent


getOpenBillingSubscriptionChange()​

getOpenBillingSubscriptionChange(provider, providerSubscriptionId): Promise<BillingSubscriptionChange | null>

Defined in: javascript/src/billing/postgres/store.ts:507

Parameters​

provider​

string

providerSubscriptionId​

string

Returns​

Promise<BillingSubscriptionChange | null>

Overrides​

BillingStore.getOpenBillingSubscriptionChange


getUserSubscription()​

getUserSubscription(userId, statuses?): Promise<BillingSubscriptionState | null>

Defined in: javascript/src/billing/postgres/store.ts:569

Parameters​

userId​

string

statuses?​

string[]

Returns​

Promise<BillingSubscriptionState | null>

Overrides​

BillingStore.getUserSubscription


getUserSubscriptions()​

getUserSubscriptions(userId): Promise<BillingSubscriptionState[]>

Defined in: javascript/src/billing/postgres/store.ts:578

Parameters​

userId​

string

Returns​

Promise<BillingSubscriptionState[]>

Overrides​

BillingStore.getUserSubscriptions


grantBillingCredit()​

grantBillingCredit(grantId, idempotencyKey): Promise<BillingCreditPostingResult>

Defined in: javascript/src/billing/postgres/store.ts:683

Parameters​

grantId​

string

idempotencyKey​

string

Returns​

Promise<BillingCreditPostingResult>

Overrides​

BillingStore.grantBillingCredit


listBillingInvoices()​

listBillingInvoices(userId): Promise<BillingInvoiceRecord[]>

Defined in: javascript/src/billing/postgres/store.ts:763

Parameters​

userId​

string

Returns​

Promise<BillingInvoiceRecord[]>

Overrides​

BillingStore.listBillingInvoices


listExpiredGraceSubscriptions()​

listExpiredGraceSubscriptions(now, limit?): Promise<BillingSubscriptionState[]>

Defined in: javascript/src/billing/postgres/store.ts:514

Parameters​

now​

string

limit?​

number = 100

Returns​

Promise<BillingSubscriptionState[]>

Overrides​

BillingStore.listExpiredGraceSubscriptions


postBillingRefund()​

postBillingRefund(refundId, grantId, amountMinor, idempotencyKey): Promise<BillingCreditPostingResult>

Defined in: javascript/src/billing/postgres/store.ts:705

Parameters​

refundId​

string

grantId​

string

amountMinor​

number

idempotencyKey​

string

Returns​

Promise<BillingCreditPostingResult>

Overrides​

BillingStore.postBillingRefund


pseudonymizeFinancialSubject()​

pseudonymizeFinancialSubject(userId): Promise<boolean>

Defined in: javascript/src/billing/postgres/store.ts:868

Parameters​

userId​

string

Returns​

Promise<boolean>

Overrides​

BillingStore.pseudonymizeFinancialSubject


reconcileSubscriptionEntitlement()​

reconcileSubscriptionEntitlement(subjectId, subscriptionId, billingEventId, expectedStatus, expectedProviderUpdatedAt, planAssignedAt, applyEntitlement, terminalPlanKey, reason): Promise<SubscriptionEntitlementOutcome>

Defined in: javascript/src/billing/postgres/store.ts:522

Parameters​

subjectId​

string

subscriptionId​

string

billingEventId​

string

expectedStatus​

BillingSubscriptionStatus

expectedProviderUpdatedAt​

string

planAssignedAt​

string | Date | null

applyEntitlement​

boolean

terminalPlanKey​

string | null

reason​

string

Returns​

Promise<SubscriptionEntitlementOutcome>

Overrides​

BillingStore.reconcileSubscriptionEntitlement


recordSubscriptionConflict()​

recordSubscriptionConflict(input): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:583

Parameters​

input​

BillingSubscriptionConflictCreate

Returns​

Promise<void>

Overrides​

BillingStore.recordSubscriptionConflict


resolveBillingOffer()​

resolveBillingOffer(provider, productId?, priceId?): Promise<BillingOfferResult | null>

Defined in: javascript/src/billing/postgres/store.ts:383

Parameters​

provider​

string

productId?​

string | null

priceId?​

string | null

Returns​

Promise<BillingOfferResult | null>

Overrides​

BillingStore.resolveBillingOffer


resolveBillingOfferByLookup()​

resolveBillingOfferByLookup(provider, lookupKey): Promise<BillingOfferResult | null>

Defined in: javascript/src/billing/postgres/store.ts:392

Parameters​

provider​

string

lookupKey​

string

Returns​

Promise<BillingOfferResult | null>

Overrides​

BillingStore.resolveBillingOfferByLookup


resolveCreditTopup()​

resolveCreditTopup(provider, productId?, priceId?): Promise<BillingTopupResult | null>

Defined in: javascript/src/billing/postgres/store.ts:614

Parameters​

provider​

string

productId?​

string | null

priceId?​

string | null

Returns​

Promise<BillingTopupResult | null>

Overrides​

BillingStore.resolveCreditTopup


resolveCreditTopupByLookup()​

resolveCreditTopupByLookup(provider, lookupKey): Promise<BillingTopupResult | null>

Defined in: javascript/src/billing/postgres/store.ts:623

Parameters​

provider​

string

lookupKey​

string

Returns​

Promise<BillingTopupResult | null>

Overrides​

BillingStore.resolveCreditTopupByLookup


updateAutoRechargeAttempt()​

updateAutoRechargeAttempt(input): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:906

Parameters​

input​

AutoRechargeAttemptUpdate

Returns​

Promise<void>

Overrides​

BillingStore.updateAutoRechargeAttempt


updateAutoRechargeAttemptByProviderPayment()​

updateAutoRechargeAttemptByProviderPayment(input): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:910

Parameters​

input​

AutoRechargeProviderPaymentUpdate

Returns​

Promise<void>

Overrides​

BillingStore.updateAutoRechargeAttemptByProviderPayment


updateBillingSubscriptionChange()​

updateBillingSubscriptionChange(id, update): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:562

Parameters​

id​

string

update​

BillingSubscriptionChangeUpdate

Returns​

Promise<void>

Overrides​

BillingStore.updateBillingSubscriptionChange


updateCheckoutIntent()​

updateCheckoutIntent(id, update): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:300

Parameters​

id​

string

update​

CheckoutIntentUpdate

Returns​

Promise<void>

Overrides​

BillingStore.updateCheckoutIntent


upsertAutoRechargeProfile()​

upsertAutoRechargeProfile(profile, options?): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:893

Parameters​

profile​

BillingAutoRechargeProfile

options?​
resetCooldown?​

boolean

Returns​

Promise<void>

Overrides​

BillingStore.upsertAutoRechargeProfile


upsertBillingCustomer()​

upsertBillingCustomer(provider, providerCustomerId, userId, email?): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:462

Parameters​

provider​

string

providerCustomerId​

string

userId​

string

email?​

string | null

Returns​

Promise<void>

Overrides​

BillingStore.upsertBillingCustomer


upsertBillingDispute()​

upsertBillingDispute(options): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:767

Parameters​

options​

BillingDisputeUpsert

Returns​

Promise<void>

Overrides​

BillingStore.upsertBillingDispute


upsertBillingInvoice()​

upsertBillingInvoice(options): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:733

Parameters​

options​

BillingInvoiceUpsert

Returns​

Promise<void>

Overrides​

BillingStore.upsertBillingInvoice


upsertBillingPayment()​

upsertBillingPayment(options): Promise<string>

Defined in: javascript/src/billing/postgres/store.ts:647

Parameters​

options​

BillingPaymentUpsert

Returns​

Promise<string>

Overrides​

BillingStore.upsertBillingPayment


upsertBillingPreferences()​

upsertBillingPreferences(prefs): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:885

Parameters​

prefs​

BillingPreferences

Returns​

Promise<void>

Overrides​

BillingStore.upsertBillingPreferences


upsertBillingRefund()​

upsertBillingRefund(options): Promise<string>

Defined in: javascript/src/billing/postgres/store.ts:718

Parameters​

options​

BillingRefundUpsert

Returns​

Promise<string>

Overrides​

BillingStore.upsertBillingRefund


upsertBillingSubscription()​

upsertBillingSubscription(state): Promise<void>

Defined in: javascript/src/billing/postgres/store.ts:471

Parameters​

state​

BillingSubscriptionState

Returns​

Promise<void>

Overrides​

BillingStore.upsertBillingSubscription