@fabriktor/fx 0.0.131 → 0.0.132
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PaymentEntityTypeBill, PaymentEntityTypePayroll, type Bill, type Payroll, PSPPaymentStatusPending, PSPPaymentStatusPartial, PSPPaymentStatusFull, type CreditLedgerEntry, type Payment, type PmtAccount, type PmtBankAccount, type PmtCard, type PmtCustomer, type PmtPublicSession, type PmtRefund } from "@fabriktor/schema";
|
|
1
|
+
import { PaymentEntityTypeBill, PaymentEntityTypePayroll, type Bill, type Payroll, PSPPaymentStatusPending, PSPPaymentStatusPartial, PSPPaymentStatusFull, type CreditLedgerEntry, type Payment, type PmtAccount, type PmtBankAccount, type PmtCard, type PmtCustomer, type PmtPublicSession, type PmtRefund, type SortStripeBalanceResult } from "@fabriktor/schema";
|
|
2
2
|
import { type PaymentsOperator, type BillableOperator, type PayrollsOperator } from "@fabriktor/client";
|
|
3
3
|
import { type SearchOptions, type OwnerSearchOptions, type SearchPage } from "../core/search.js";
|
|
4
4
|
import { EventBus } from "../core/events.js";
|
|
@@ -149,6 +149,11 @@ export type GetPmtAccountAccessOptions = {
|
|
|
149
149
|
owner_id: string;
|
|
150
150
|
signal?: AbortSignal;
|
|
151
151
|
};
|
|
152
|
+
export type GetPayoutBalanceOptions = GetPmtAccountAccessOptions;
|
|
153
|
+
export type PayoutBalance = {
|
|
154
|
+
access: PmtAccountAccess;
|
|
155
|
+
balance: SortStripeBalanceResult | null;
|
|
156
|
+
};
|
|
152
157
|
export declare function isPmtAccountReady(account: PmtAccount | null): boolean;
|
|
153
158
|
export declare function currentPmtAccount(accounts: readonly PmtAccount[]): PmtAccount | null;
|
|
154
159
|
export declare function pmtAccountAccess(account: PmtAccount | null): PmtAccountAccess;
|
|
@@ -200,6 +205,7 @@ export interface PaymentsFXOperator {
|
|
|
200
205
|
replacePmtAccount(opts: ReplacePmtAccountOptions): Promise<PmtAccount>;
|
|
201
206
|
searchPmtAccounts(opts: SearchPmtAccountsOptions): Promise<SearchPmtAccountsPage>;
|
|
202
207
|
getPmtAccountAccess(opts: GetPmtAccountAccessOptions): Promise<PmtAccountAccess>;
|
|
208
|
+
getPayoutBalance(opts: GetPayoutBalanceOptions): Promise<PayoutBalance>;
|
|
203
209
|
createPmtBankAccount(opts: CreatePmtBankAccountOptions): Promise<PmtBankAccount>;
|
|
204
210
|
replacePmtBankAccount(opts: ReplacePmtBankAccountOptions): Promise<PmtBankAccount>;
|
|
205
211
|
searchPmtBankAccounts(opts: SearchPmtBankAccountsOptions): Promise<SearchPmtBankAccountsPage>;
|
|
@@ -247,6 +253,7 @@ export declare class PaymentsFX implements PaymentsFXOperator {
|
|
|
247
253
|
replacePmtAccount(opts: ReplacePmtAccountOptions): Promise<PmtAccount>;
|
|
248
254
|
searchPmtAccounts(opts: SearchPmtAccountsOptions): Promise<SearchPmtAccountsPage>;
|
|
249
255
|
getPmtAccountAccess(opts: GetPmtAccountAccessOptions): Promise<PmtAccountAccess>;
|
|
256
|
+
getPayoutBalance(opts: GetPayoutBalanceOptions): Promise<PayoutBalance>;
|
|
250
257
|
createPmtBankAccount(opts: CreatePmtBankAccountOptions): Promise<PmtBankAccount>;
|
|
251
258
|
replacePmtBankAccount(opts: ReplacePmtBankAccountOptions): Promise<PmtBankAccount>;
|
|
252
259
|
searchPmtBankAccounts(opts: SearchPmtBankAccountsOptions): Promise<SearchPmtBankAccountsPage>;
|
|
@@ -14,6 +14,7 @@ const publicAmountPattern = /^\d+$/;
|
|
|
14
14
|
const resourcePayment = "payment";
|
|
15
15
|
const resourcePmtAccount = "pmt_account";
|
|
16
16
|
const resourcePmtAccountOnboarding = "pmt_account_onboarding";
|
|
17
|
+
const resourcePayoutBalance = "payout_balance";
|
|
17
18
|
const resourcePmtBankAccount = "pmt_bank_account";
|
|
18
19
|
const resourcePmtCard = "pmt_card";
|
|
19
20
|
const resourcePmtRefund = "pmt_refund";
|
|
@@ -37,6 +38,7 @@ const msgCreatedPaymentIDMissing = "Created payment response did not contain an
|
|
|
37
38
|
const msgPaymentMissing = "Payment could not be resolved after the mutation.";
|
|
38
39
|
const msgCreatedPmtAccountIDMissing = "Created payment account response did not contain an ID.";
|
|
39
40
|
const msgPmtAccountMissing = "Payment account could not be resolved after the mutation.";
|
|
41
|
+
const msgPayoutBalanceMissing = "Payout balance response is incomplete.";
|
|
40
42
|
const msgPmtAccountOnboardingIDMissing = "Payment account onboarding requires a valid account ID.";
|
|
41
43
|
const msgPmtAccountOnboardingLinkMissing = "Payment account onboarding did not return a link.";
|
|
42
44
|
const msgCreatedPmtBankAccountIDMissing = "Created payment bank account response did not contain an ID.";
|
|
@@ -502,6 +504,31 @@ export class PaymentsFX {
|
|
|
502
504
|
page = out.next_page;
|
|
503
505
|
}
|
|
504
506
|
}
|
|
507
|
+
async getPayoutBalance(opts) {
|
|
508
|
+
const access = await this.getPmtAccountAccess(opts);
|
|
509
|
+
opts.signal?.throwIfAborted();
|
|
510
|
+
const accountID = resolvedID(access.account?.psp_id);
|
|
511
|
+
if (accountID === undefined) {
|
|
512
|
+
return { access, balance: null };
|
|
513
|
+
}
|
|
514
|
+
// Outstanding funds remain visible when the account needs updated onboarding.
|
|
515
|
+
const out = await this.payments.balance({ psp_account_id: accountID }, { signal: opts.signal });
|
|
516
|
+
opts.signal?.throwIfAborted();
|
|
517
|
+
if (!out?.value) {
|
|
518
|
+
throw errResolveFailed({
|
|
519
|
+
resource: resourcePayoutBalance,
|
|
520
|
+
msg: msgPayoutBalanceMissing,
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
return {
|
|
524
|
+
access,
|
|
525
|
+
balance: {
|
|
526
|
+
available: out.value.available ?? [],
|
|
527
|
+
pending: out.value.pending ?? [],
|
|
528
|
+
instant_available: out.value.instant_available ?? [],
|
|
529
|
+
},
|
|
530
|
+
};
|
|
531
|
+
}
|
|
505
532
|
async createPmtBankAccount(opts) {
|
|
506
533
|
const out = await this.payments.insertOnePmtBankAccount(opts);
|
|
507
534
|
const id = requiredOperationID(out, msgCreatedPmtBankAccountIDMissing);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabriktor/fx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.132",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"typescript": "^6.0.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@fabriktor/client": "0.0.
|
|
20
|
+
"@fabriktor/client": "0.0.93",
|
|
21
21
|
"@fabriktor/fx": "0.0.94",
|
|
22
22
|
"@fabriktor/schema": "0.0.66"
|
|
23
23
|
}
|