@fonderie/client 0.13.0 → 0.15.0

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.
@@ -192,8 +192,12 @@ new BillingClient(http: HttpClient, tokens: TokenStore): BillingClient
192
192
  .getWallet(opts?: IReadOptions | undefined): Promise<IApiResponse<IWalletResult>>
193
193
  .setWalletPreferences(input: IWalletPreferencesInput): Promise<IApiResponse<IWalletResult>>
194
194
  .createWalletCheckout(input: IWalletCheckoutInput): Promise<IApiResponse<ICheckoutUrlResult>>
195
+ .purchaseWalletPack(input: IWalletPurchaseInput): Promise<IApiResponse<IWalletPurchaseResult>>
195
196
  .getWalletTransactions(opts?: (IReadOptions & { cursor?: string; limit?: number; }) | undefined): Promise<IApiResponse<IWalletTransactionsResult>>
196
197
  .getPaymentMethod(opts?: IReadOptions | undefined): Promise<IApiResponse<IPaymentMethodResult>>
198
+ .setupPaymentMethod(): Promise<IApiResponse<ISetupIntentResult>>
199
+ .savePaymentMethod(input: ISavePaymentMethodInput): Promise<IApiResponse<IPaymentMethodResult>>
200
+ .removePaymentMethod(): Promise<IApiResponse<IPaymentMethodResult>>
197
201
  .listInvoices(opts?: IReadOptions | undefined): Promise<IApiResponse<IInvoicesResult>>
198
202
 
199
203
  interface IConfigAdminClientOptions {
@@ -1011,6 +1015,20 @@ interface IWalletDTO {
1011
1015
  grantedExpiresAt?: string | null;
1012
1016
  }
1013
1017
 
1018
+ interface IWalletPurchaseInput {
1019
+ packId: string;
1020
+ idempotencyKey: string;
1021
+ }
1022
+
1023
+ interface IWalletPurchaseResult {
1024
+ status: 'credited' | 'checkout_required' | 'declined' | 'processing';
1025
+ balance?: string;
1026
+ currency?: string;
1027
+ credits?: string;
1028
+ duplicate?: boolean;
1029
+ reason?: 'no_saved_card' | 'authentication_required';
1030
+ }
1031
+
1014
1032
  interface IWalletResult {
1015
1033
  wallet: IWalletDTO;
1016
1034
  }
package/dist/index.cjs CHANGED
@@ -545,6 +545,21 @@ var BillingClient = class {
545
545
  workspaceId: this.workspaceId
546
546
  });
547
547
  }
548
+ // Buy a credit pack in-app by charging the saved card — no redirect. Inspect
549
+ // `result.status`: 'credited' (done — refresh the wallet), 'checkout_required'
550
+ // (no saved card or the card needs 3-D Secure → fall back to
551
+ // createWalletCheckout), 'declined', or 'processing' (indeterminate — retry
552
+ // with the SAME idempotencyKey). Generate one idempotencyKey per attempt and
553
+ // reuse it on retry so a double-submit can't double-charge.
554
+ purchaseWalletPack(input) {
555
+ return this.http.request({
556
+ method: "POST",
557
+ path: "/billing/wallet/purchase",
558
+ body: input,
559
+ token: this.tokens.get(),
560
+ workspaceId: this.workspaceId
561
+ });
562
+ }
548
563
  // The wallet ledger, newest first — every credit/debit with a running
549
564
  // balanceAfter. Cursor-paginated: pass the previous result's `nextCursor`.
550
565
  getWalletTransactions(opts) {
@@ -572,6 +587,37 @@ var BillingClient = class {
572
587
  bust: opts?.bust
573
588
  });
574
589
  }
590
+ // Begin in-app card entry — returns a SetupIntent client secret for the
591
+ // provider's embedded card element (Stripe Payment Element); the user never
592
+ // leaves the site. 501 when the provider has no in-app card support.
593
+ setupPaymentMethod() {
594
+ return this.http.request({
595
+ method: "POST",
596
+ path: "/billing/payment-method/setup",
597
+ token: this.tokens.get(),
598
+ workspaceId: this.workspaceId
599
+ });
600
+ }
601
+ // Save the card after the client confirms the SetupIntent: makes it the
602
+ // default and records it. 422 when the card isn't attached to this customer.
603
+ savePaymentMethod(input) {
604
+ return this.http.request({
605
+ method: "PUT",
606
+ path: "/billing/payment-method",
607
+ body: input,
608
+ token: this.tokens.get(),
609
+ workspaceId: this.workspaceId
610
+ });
611
+ }
612
+ // Remove the saved card (detach at the provider + clear the record).
613
+ removePaymentMethod() {
614
+ return this.http.request({
615
+ method: "DELETE",
616
+ path: "/billing/payment-method",
617
+ token: this.tokens.get(),
618
+ workspaceId: this.workspaceId
619
+ });
620
+ }
575
621
  // The customer's invoices, newest first — each links out to the hosted
576
622
  // invoice / PDF. 501 when the provider can't list them.
577
623
  listInvoices(opts) {