@vulog/aima-billing
Version:
Invoice management, credits, wallets, and refunds.
269 lines (268 loc) • 8.37 kB
text/typescript
import { Client } from "@vulog/aima-client";
import { UUID } from "crypto";
import { PatchAction } from "@vulog/aima-core";
//#region src/types.d.ts
type ChargeProductInfo = {
productId: string;
serviceId?: string;
amount: number;
userId: string;
entityId: string;
subscriptionId?: string;
productNotes?: string;
originId?: string;
chargeProductRequestId?: string;
additionalInfo?: {
manualPayment?: boolean;
};
};
type ManualPayment = {
requiresActionReturnUrl: string;
online?: boolean;
scope: 'RENTAL' | 'DEPOSIT';
};
type Invoice = {
id: string;
sequence: number;
refundSequence?: number;
userId: string;
pricingId?: string;
tripId?: string;
invoiceDate: string;
updateDate: string;
fleetId: string;
invoiceYear: number;
invoicesStatus: 'PENDING' | 'PAID' | 'REFUSED' | 'ERROR' | 'REFUNDED' | 'CANCELLED' | 'PENDING_EXTERNAL_PAYMENT' | 'PENDING_MANUAL_PAYMENT' | 'PENDING_AUTHENTICATION' | 'MOP_MISSING';
amount: number;
productId?: string;
currency: string;
serviceId?: string;
tokenId?: string;
entityId: string;
amountPayWithSystemCredit?: number;
attempts: number;
pspName?: string;
pspReference: string;
withTaxRefundAmount: number;
isRefunded?: boolean;
paymentInProgress: boolean;
subscriptionId?: string;
paymentDate?: string;
externalPaymentRequesterId?: string;
externalPaymentNotes?: string;
isPaidExternally?: boolean;
refundInProgress?: boolean;
originId?: string;
originRole?: string;
pspIdempotency: string;
paidExternally?: boolean;
refunded?: boolean;
productTaxIncluded?: boolean;
pspReferencePreAuth?: string;
amountPreAuth?: number;
preAuthEnabled?: boolean;
[key: string]: any;
};
type Credit = {
initialAmount: number;
validityStartDate: string;
validityEndDate: string;
notes: string;
discountCategory: 'CREDITS' | 'PERCENTAGE';
oneTimeUsage: boolean;
id: UUID;
availableAmount: number;
usedAmount: number;
originId: UUID;
entityId: UUID;
creditAlreadyUsed: boolean;
updateDate: string;
type: 'LOCAL' | 'GLOBAL' | 'PERIODIC';
usage: 'TRIP' | 'REGISTRATION' | 'PRODUCTS' | 'ALL';
[key: string]: any;
};
type Receipt = {
id: string;
pspName: string;
pspReference: string;
pspPublishableKey: string;
amount: number;
currency: string;
date: string;
status: string;
paymentMethodType: string;
paymentMethodPspReference: string;
paymentIntentPspReference: string;
number: number;
code: string;
declineCode: string;
pspClientSecret: string;
reason: string;
note: string;
nextAction: {
nextActionRedirectUrl: {
url: string;
method: string;
data: {
[key: string]: unknown;
};
};
type: string;
};
metadatas: {
[key: string]: unknown;
};
};
type RefundableAmount = {
invoiceId: string;
fleetId: string;
refundableAmount: number;
currency: string;
refundablePaymentReceipts: Receipt[];
refundedPaymentReceipts: Receipt[];
};
/** Billing line item returned by the trip invoices endpoint (nested in Billing array). */
type TripBillingItem = {
trip?: unknown;
product?: unknown;
vehiculeModelName?: string;
vehiculePlate?: string;
modelId?: string;
userId?: string;
withoutTaxAmountForDriving?: number;
withoutTaxAmountForStopover?: number;
withoutTaxAmountForBooking?: number;
withoutTaxForOvermileage?: number;
withoutTaxAmountForStartZoneFee?: number;
withoutTaxAmountForEndZoneFee?: number;
withoutTaxAmountForCancellationFee?: number;
withoutTaxAmountForScheduleTripFee?: number;
withoutTaxAmountForTripSystemCredit?: number;
withoutTaxAmountForBillingGroupDiscount?: number | null;
withTaxAmountForDriving?: number;
withTaxAmountForStopover?: number;
withTaxAmountForBooking?: number;
withTaxForOvermileage?: number;
withTaxAmountForStartZoneFee?: number;
withTaxAmountForEndZoneFee?: number;
withTaxAmountForCancellationFee?: number;
withTaxAmountForScheduleTripFee?: number;
withTaxAmountForTripSystemCredit?: number;
withTaxAmountForBillingGroupDiscount?: number;
withoutTaxInitialTotalAmount?: number;
withTaxInitialTotalAmount?: number;
taxInitialTotalAmount?: number;
paymentMethodType?: string;
walletId?: string | null;
totalTaxAmount?: number;
totalWithTax?: number;
totalWithoutTax?: number;
taxRate?: number;
taxName?: string;
withoutTaxAmountRideCost?: number;
withTaxAmountRideCost?: number;
taxAmountRideCost?: number;
products?: unknown[];
taxesPerRate?: unknown;
serviceId?: string | null;
profileId?: string | null;
profileType?: string | null;
profileName?: string | null;
withoutTaxUnlockFee?: number;
withTaxUnlockFee?: number;
taxUnlockFee?: number;
withTaxRefundAmount?: number | null;
isRefunded?: boolean;
cityName?: string | null;
cityId?: string | null;
tripBillingBreakdown?: unknown;
pricingId?: string;
netJourney?: number;
taxJourney?: number;
grossJourney?: number;
durationJourney?: number;
taxRemainingToBePaid?: number;
grossRemainingToBePaid?: number;
netRemainingToBePaid?: number;
overriddenTripInfo?: unknown;
interrupted?: boolean;
interruptedReason?: string | null;
invoice?: unknown;
distanceUnit?: string;
isTaxIncluded?: boolean;
[key: string]: unknown;
};
/** Response shape of GET .../trips/:tripId/invoices */
type InvoicesByTripIdResponse = {
balance: number;
userId: string;
entityId: string;
Billing: TripBillingItem[];
};
type Wallet = {
initialAmount: number;
validityStartDate: string;
validityEndDate: string;
notes: string;
discountCategory: string;
oneTimeUsage: boolean;
id: string;
availableAmount: number;
usedAmount: number;
originId: string;
entityId: string;
creditAlreadyUsed: boolean;
updateDate: string;
type: string;
usage: string;
};
//#endregion
//#region src/chargeProduct.d.ts
declare const chargeProduct: (client: Client, info: ChargeProductInfo) => Promise<Invoice>;
//#endregion
//#region src/getUserCreditsByEntityId.d.ts
declare const getUserCreditsByEntityId: (client: Client, id: string) => Promise<Credit>;
//#endregion
//#region src/addCredits.d.ts
interface Payload$1 extends Omit<Credit, 'id' | 'availableAmount' | 'usedAmount' | 'originId' | 'creditAlreadyUsed' | 'updateDate'> {}
declare const addCredits: (client: Client, payload: Payload$1) => Promise<Credit>;
//#endregion
//#region src/getInvoiceById.d.ts
declare const getInvoiceById: (client: Client, id: string) => Promise<Invoice>;
//#endregion
//#region src/getInvoicePdf.d.ts
declare const getInvoicePdf: (client: Client, invoiceId: string) => Promise<ArrayBuffer | null>;
//#endregion
//#region src/getInvoicesByTripId.d.ts
declare const getInvoicesByTripId: (client: Client, tripId: string) => Promise<InvoicesByTripIdResponse>;
//#endregion
//#region src/getRefundableAmount.d.ts
declare const getRefundableAmount: (client: Client, invoiceId: string) => Promise<RefundableAmount>;
//#endregion
//#region src/refund.d.ts
interface Payload {
invoiceId: string;
amount?: number;
note?: string | null;
paymentIntentPspReference?: string;
}
declare const refund: (client: Client, payload: Payload) => Promise<void>;
//#endregion
//#region src/getWalletsByEntity.d.ts
declare const getWalletsByEntity: (client: Client, entityId: string) => Promise<Wallet[]>;
//#endregion
//#region src/updateWallet.d.ts
declare const paths: readonly ["/availableAmount", "/percentage"];
type Paths = (typeof paths)[number];
declare const updateWallet: (client: Client, walletId: string, actions: PatchAction<Paths>[]) => Promise<void>;
//#endregion
//#region src/payInvoice.d.ts
declare const payInvoice: (client: Client, invoiceId: string, manualPayment: ManualPayment) => Promise<Invoice>;
//#endregion
//#region src/retry-payment.d.ts
/**
* Retry an invoices payment stuck in REFUSED and ERROR status, move the status to PENDING or PENDING_MANUAL_PAYMENT
*/
declare const retryPayment: (client: Client, invoiceId: string) => Promise<Invoice>;
//#endregion
export { ChargeProductInfo, Credit, Invoice, InvoicesByTripIdResponse, ManualPayment, Paths, Receipt, RefundableAmount, TripBillingItem, Wallet, addCredits, chargeProduct, getInvoiceById, getInvoicePdf, getInvoicesByTripId, getRefundableAmount, getUserCreditsByEntityId, getWalletsByEntity, payInvoice, refund, retryPayment, updateWallet };