UNPKG

@lomray/microservice-payment-stripe

Version:

Stripe payment microservice based on NodeJS & inverted json.

93 lines (92 loc) 3.73 kB
import StripeSdk from 'stripe'; import TransactionRole from "../../constants/transaction-role.js"; import ITax from "../../interfaces/tax.js"; import ITaxes from "../../interfaces/taxes.js"; import { IPaymentIntentParams } from "../payment-gateway/stripe.js"; interface IGetPaymentIntentTaxParams { processingTransactionAmountUnit: number; paymentMethodId: string; entityId: string; feesPayer: TransactionRole; } interface IGetStripeFeeAndProcessingAmountParams { amountUnit: number; feesPayer: TransactionRole; } interface IPaymentIntentTax extends Pick<ITaxes, 'autoCalculateFeeUnit'> { tax: ITax; createTaxTransactionFeeUnit: number; } interface IGetPaymentIntentFeesParams extends Pick<IPaymentIntentParams, 'applicationPaymentPercent' | 'feesPayer' | 'additionalFeesPercent' | 'extraReceiverRevenuePercent'> { entityUnitCost: number; shouldEstimateTax?: boolean; withStripeFee?: boolean; } interface IPaymentIntentFees { stripeUnitFee: number; platformUnitFee: number; userUnitAmount: number; receiverUnitRevenue: number; receiverAdditionalFee: number; senderAdditionalFee: number; extraReceiverUnitRevenue: number; estimatedTaxUnit?: number; estimatedTaxPercent?: number; } /** * Stripe calculation service */ declare class Calculation { /** * Returns receiver payment amount * @description NOTES: How much end user will get after fees from transaction * 1. Stable unit - stable amount that payment provider charges * 2. Payment percent - payment provider fee percent for single transaction * Fees calculation: * 1. User pays fee * totalAmount = 106$, receiverReceiver = 100, taxFee = 3, platformFee = 3 * 2. Receiver pays fees * totalAmount = 100$, receiverReceiver = 94, taxFee = 3, platformFee = 3 */ /** * Returns receiver payment amount * @description NOTES: How much end user will get after fees from transaction * 1. Stable unit - stable amount that payment provider charges * 2. Payment percent - payment provider fee percent for single transaction * Fees calculation: * 1. User pays fee * totalAmount = 106$, receiverReceiver = 100, taxFee = 3, platformFee = 3 * 2. Receiver pays fees * totalAmount = 100$, receiverReceiver = 94, taxFee = 3, platformFee = 3 */ static getPaymentIntentFees({ entityUnitCost, additionalFeesPercent, feesPayer, applicationPaymentPercent, extraReceiverRevenuePercent, shouldEstimateTax, withStripeFee, }: IGetPaymentIntentFeesParams): Promise<IPaymentIntentFees>; /** * Returns Stripe fee */ /** * Returns Stripe fee */ static getStripeFeeAndProcessingAmount({ amountUnit, feesPayer, }: IGetStripeFeeAndProcessingAmountParams): Promise<{ stripeFeeUnit: number; processingAmountUnit: number; }>; /** * Returns payment intent tax */ /** * Returns payment intent tax */ static getPaymentIntentTax(sdk: StripeSdk, { processingTransactionAmountUnit, entityId, paymentMethodId, feesPayer, }: IGetPaymentIntentTaxParams): Promise<IPaymentIntentTax>; /** * Compute transaction tax * @description NOTE: Customer SHOULD HAVE address details - at least postal code * One this api call cost is $0.05 - DO NOT ALLOW user call this method in depth */ /** * Compute transaction tax * @description NOTE: Customer SHOULD HAVE address details - at least postal code * One this api call cost is $0.05 - DO NOT ALLOW user call this method in depth */ private static computePaymentIntentTax; } export { Calculation as default, IGetPaymentIntentFeesParams, IPaymentIntentFees };