@lomray/microservice-payment-stripe
Version:
Stripe payment microservice based on NodeJS & inverted json.
204 lines (203 loc) • 5.31 kB
TypeScript
import StripeSdk from 'stripe';
import { Stripe as StripeTypes } from "stripe";
import { EntityManager, Repository } from 'typeorm';
import CouponDuration from "../../constants/coupon-duration.js";
import TransactionStatus from "../../constants/transaction-status.js";
import TransactionType from "../../constants/transaction-type.js";
import BankAccount from "../../entities/bank-account.js";
import Card from "../../entities/card.js";
import Cart from "../../entities/cart.js";
import Coupon from "../../entities/coupon.js";
import Customer from "../../entities/customer.js";
import Dispute from "../../entities/dispute.js";
import EvidenceDetails from "../../entities/evidence-details.js";
import Payout from "../../entities/payout.js";
import Price from "../../entities/price.js";
import Product from "../../entities/product.js";
import Refund from "../../entities/refund.js";
import Transaction from "../../entities/transaction.js";
import { IParams as ITransactionEntityParams } from "../../entities/transaction.js";
interface ICardParams {
userId: string;
token?: string;
expired?: string;
digits?: string;
cvc?: string;
}
interface IBankAccountParams {
userId: string;
lastDigits: string;
holderName?: string | null;
bankName?: string | null;
bankAccountId?: string;
}
interface IPriceParams {
productId: string;
userId: string;
currency: string;
unitAmount: number;
}
interface ITransactionParams {
status: TransactionStatus;
amount: number;
userId: string;
title?: string;
bankAccountId?: string;
productId?: string;
cardId?: string;
entityId?: string;
type?: TransactionType;
tax?: number;
fee?: number;
params?: ITransactionEntityParams;
}
interface IProductParams {
entityId: string;
userId: string;
}
interface ICouponParams {
duration: CouponDuration;
products: string[];
userId?: string;
name?: string;
maxRedemptions?: number;
durationInMonths?: number;
amountOff?: number;
percentOff?: number;
}
/**
* Abstract class for payment gateway
*/
declare abstract class Abstract {
/**
* @protected
*/
protected readonly customerRepository: Repository<Customer>;
/**
* @protected
*/
protected readonly productRepository: Repository<Product>;
/**
* @protected
*/
protected readonly cardRepository: Repository<Card>;
/**
* @protected
*/
protected readonly bankAccountRepository: Repository<BankAccount>;
/**
* @protected
*/
protected readonly priceRepository: Repository<Price>;
/**
* @protected
*/
protected readonly cartRepository: Repository<Cart>;
/**
* @protected
*/
protected readonly transactionRepository: Repository<Transaction>;
/**
* @protected
*/
protected readonly disputeRepository: Repository<Dispute>;
/**
* @protected
*/
protected readonly evidenceDetailsRepository: Repository<EvidenceDetails>;
/**
* @protected
*/
protected readonly refundRepository: Repository<Refund>;
/**
* @protected
*/
protected readonly couponRepository: Repository<Coupon>;
/**
* @protected
*/
protected readonly payoutRepository: Repository<Payout>;
/**
* @protected
*/
protected readonly manager: EntityManager;
/**
* @protected
*/
protected readonly sdk: StripeSdk;
/**
* @protected
*/
protected readonly methods: string[];
/**
* @constructor
*/
/**
* @constructor
*/
constructor(manager: EntityManager, apiKey: string, stripeConfig: StripeTypes.StripeConfig, methods: string[]);
/**
* Add new card
*/
/**
* Add new card
*/
abstract addCard(params: ICardParams): Promise<Card>;
/**
* Add new bank account
*/
/**
* Add new bank account
*/
abstract addBankAccount(params: IBankAccountParams): Promise<BankAccount>;
/**
* Create new transaction
*/
/**
* Create new transaction
*/
createTransaction(params: ITransactionParams, transactionId?: string): Promise<Transaction>;
/**
* Create new customer
*/
/**
* Create new customer
*/
createCustomer(userId: string, customerId?: string): Promise<Customer>;
/**
* Create new product
*/
/**
* Create new product
*/
createProduct(params: IProductParams, productId?: string): Promise<Product>;
/**
* Create new price
*/
/**
* Create new price
*/
createPrice(params: IPriceParams, priceId?: string): Promise<Price>;
/**
* Get transaction by transactionId
*/
/**
* Get transaction by transactionId
*/
getTransactionById(transactionId: string): Promise<Transaction>;
/**
* Get the customer
*/
/**
* Get the customer
*/
protected getCustomer(userId: string): Promise<Customer>;
/**
* Create coupon
*/
/**
* Create coupon
*/
protected createCoupon(params: ICouponParams, couponId: string): Promise<Coupon>;
}
export { Abstract as default, ICardParams, IBankAccountParams, IPriceParams, ITransactionParams, IProductParams, ICouponParams };