medusa-bonuses-plugin
Version:
medusa-bonuses-plugin is a Medusa plugin that adds bonus program to Medusa ecommerce stores.
96 lines (95 loc) • 4.35 kB
TypeScript
import { Order, TransactionBaseService, FindConfig, CartService, DiscountService, Cart, CustomerService, UserService } from "@medusajs/medusa";
import { EntityManager, Repository } from "typeorm";
import { BonusAccount } from "../models/bonus-account";
import { BonusSettings } from "../models/bonus-settings";
import { BonusTransaction, BonusTransactionType, OrderRelationType } from "../models/bonus-transaction";
type InjectedDependencies = {
manager: EntityManager;
bonusAccountRepository: Repository<BonusAccount>;
bonusTransactionRepository: Repository<BonusTransaction>;
bonusSettingsRepository: Repository<BonusSettings>;
userService: UserService;
cartService: CartService;
discountService: DiscountService;
customerService: CustomerService;
};
declare class BonusService extends TransactionBaseService {
protected readonly bonusAccountRepository_: Repository<BonusAccount>;
protected readonly bonusTransactionRepository_: Repository<BonusTransaction>;
protected readonly bonusSettingsRepository_: Repository<BonusSettings>;
protected readonly userService_: UserService;
protected readonly cartService_: CartService;
protected readonly discountService_: DiscountService;
protected readonly customerService_: CustomerService;
constructor(container: InjectedDependencies);
getSettings(): Promise<BonusSettings>;
updateSettings(data: {
default_percentage?: number;
metadata?: Record<string, unknown>;
}): Promise<BonusSettings>;
getBonusAccount(customerId: string, config?: FindConfig<BonusAccount>): Promise<BonusAccount>;
createBonusAccount(customerId: string, data?: {
metadata?: Record<string, unknown>;
}): Promise<BonusAccount>;
updateBonusAccount(customerId: string, update: {
balance?: number;
custom_percentage?: number | null;
custom_percentage_ends_at?: Date | null;
metadata?: Record<string, unknown>;
}): Promise<BonusAccount>;
adjustBonusBalance(customerId: string, balance: number, metadata: {
reason?: string;
adjusted_by: string;
}): Promise<BonusAccount>;
setCustomerBonusPercentage(customerId: string, percentage: number, options?: {
ends_at?: Date;
metadata?: Record<string, unknown>;
}): Promise<BonusAccount>;
removeCustomerBonusPercentage(customerId: string): Promise<BonusAccount>;
getCurrentBonusPercentage(customerId: string): Promise<number>;
createTransaction(data: {
customer_id: string;
amount: number;
type: BonusTransactionType;
order_id?: string;
order_relation_type?: OrderRelationType;
order_amount?: number;
earning_percentage?: number;
created_by?: string;
note?: string;
metadata?: Record<string, unknown>;
}): Promise<BonusTransaction>;
addOrderEarning(orderId: string, customerId: string, amount: number): Promise<void>;
spendOnOrder(orderId: string, customerId: string, amount: number): Promise<void>;
isEligibleForBonus(order: Order): Promise<boolean>;
isEligibleForBonusPayment(cart: Cart): Promise<boolean>;
calculateOrderBonus(order: Order): Promise<number>;
getTransactionHistory(customerId: string, options?: {
type?: BonusTransactionType[];
limit?: number;
offset?: number;
order?: "ASC" | "DESC";
fromDate?: Date;
toDate?: Date;
}): Promise<{
transactions: BonusTransaction[];
count: number;
}>;
getOrderRelatedTransactions(orderId: string): Promise<{
earnings?: BonusTransaction;
spendings?: BonusTransaction;
}>;
reserveBonus(customerId: string, amount: number, referenceId: string): Promise<BonusTransaction>;
cancelReservation(customerId: string, referenceId: string): Promise<void>;
applyBonusToCart(customerId: string, cartId: string, requestedAmount?: number): Promise<{
applied: boolean;
appliedAmount: number;
discountCode?: string;
}>;
createBonusDiscount(cartId: string, bonusAmount: number, customerId: string): Promise<string>;
activateBonusTransfer(customerId: string, transferCode: string, transferData: {
amount: number;
source?: string;
}): Promise<BonusAccount>;
}
export default BonusService;