UNPKG

@ztimson/momentum

Version:

Client library for momentum

153 lines 4.96 kB
import { AssetController } from './asset-controller'; import { Meta } from './core'; import { Momentum } from './momentum'; /** Credit-card information for payments */ export type Card = { /** Credit-card number */ number: number | string; /** Year card expires */ expYear: number | string; /** Month card expires */ expMonth: number | string; /** 3 digit security code */ csv: number | string; /** Additional details for anti-fraud */ details?: { /** Cardholder name */ name?: string; /** Billing address */ address?: { postal_code?: string; }; }; }; /** User financial status */ export type Finances = { /** Username */ readonly _id?: string; /** Account balance */ readonly balance: number; /** Account subscriptions */ readonly subscriptions: { /** Product ID */ readonly _id: string; /** Date subscription started */ readonly created: Date; /** Number of days the subscription lasts */ readonly interval: number; /** Date of next renewal, null if cancelled */ readonly renewal?: Date | null; }[]; }; /** Purchase options */ export type Transaction = Meta & { /** Purchased items */ readonly cart: { /** Product ID number, 'balance' for credit or null if custom */ readonly _id?: number | 'balance'; /** Product name or description */ readonly name: string; /** Number of units to purchase */ readonly quantity: number; /** Individual unit cost */ readonly cost: number; }[]; /** How was the Payment completed */ readonly complete?: string; /** Apply credit (Infinity to use all credit) */ readonly credit: number; /** Apply discount */ readonly discount?: { code?: string; type: 'fixed' | 'percent'; value: number; }; /** Receipt/Invoice number */ readonly invoiceNum?: string; /** Payment notes */ readonly notes?: string | null; /** Recipient username or information */ readonly recipient?: { /** Billing address */ readonly address?: string; /** Delivery email */ readonly email?: string; /** Receipt name */ readonly name?: string; /** Account name */ readonly username?: string; }; /** Whether the Payment/invoice has been refunded / canceled respectively */ readonly refunded?: boolean; /** Current status of Payment - null for self-checkout */ readonly status?: 'Invoice' | 'Cancelled' | 'Receipt' | 'Refunded'; /** Payment total */ readonly subtotal: number; /** Tax percentage as float */ readonly tax: number; /** Payment total (subtotal - discount - credit + tax) */ readonly total: number; /** Stripe Payment */ readonly tx?: any; }; /** Process payments */ export declare class Transactions extends AssetController<Transaction> { protected momentum: Momentum; /** Stripe object */ stripe?: any; constructor(momentum: Momentum); /** * Initialize stripe API * @return {Promise<any>} Returns stripe API * @private */ private initStripe; /** * Create a stripe client secret to complete Payment * @param {string} id Payment ID * @return {Promise<string>} Client secret * @private */ private getToken; /** * Process transaction programmatically * @param {string} id Transaction ID * @param {Card} card Credit card information * @return {Promise<any>} Stripe confirmation */ checkout(id: string, card: Card): Promise<any>; /** * Process transaction using Stripe form * @param {string} id Transaction ID * @param {string} element DOM element to inject form into * @return {Promise<() => Promise<any>>} Callback to submit form */ checkoutForm(id: string, element: string): Promise<() => Promise<any>>; /** * Complete transaction via Momentum's checkout page * @param {string} id Transaction ID * @param {string} host Host origin attempting to login * @return {Promise<string>} Translation ID on success */ checkoutRedirect(id: string, host?: string): Promise<string>; /** * Get URL to checkout page for transaction * @param {string} id Transaction ID * @returns {string} URL */ checkoutUrl(id: string): string; delete(key: string): Promise<number>; /** * Send recipient transaction receipt or invoice * @param {string} id Translation ID * @return {Promise<void>} Returns once complete */ notify(id: string): Promise<void>; /** * Refund a transaction * @param {string} key Asset primary key * @return {Promise<Transaction>} Returns on success */ refund(key: string): Promise<Transaction>; } //# sourceMappingURL=transactions.d.ts.map