import type { PerxConfig } from './config'; import { AxiosInstance } from 'axios'; import { PerxRewardsResponse, TokenResponse, PerxVouchersResponse, PerxVoucher, PerxLoyalty, PerxCustomer, PerxTransaction, PerxTransactionReqeust, PerxLoyaltyTransactionRequest, PerxLoyaltyTransaction, PerxLoyaltyTransactionsHistoryResponse, PerxRewardSearchResultResponse, PerxCategoriesResultResponse, PerxVoucherState, PerxRewardReservation, PerxLoyaltyTransactionRequestUserAccount, PerxLoyaltyTransactionReservationRequest, PerxInvoiceRequest, PerxInvoiceCreationResponse, BearerTokenResponse, MerchantInfo, PerxRewardResponse, PerxVoucherResponse, PerxMerchant, PerxMerchantsResponse, PerxCampaign, PerxCampaignsResponse } from './models'; export interface PerxVoucherScope { size: number; page: number; sortBy: 'issued_date' | 'valid_to'; order: 'asc' | 'desc'; state: PerxVoucherState; type: 'active' | 'all' | 'expired' | 'gifted' | 'redeemed' | 'redemption_in_progress'; } export interface PerxRewardScope { /** * Page's sequence start with 1 *NOT* 0. */ page: number; /** * How much should Perx retrieve per page */ pageSize: number; /** * Category's Name * * !warning: This is not exact match search! */ categoryNamePrefix: string; /** * mapped to: `filter_for_catalogs` * !warning: from manualy testing The API doesn't support multiple value */ catalogId: string; /** * mapped to: `filter_for_brands` * !warning: from manualy testing The API doesn't support multiple vlaue */ brandId: string; /** * tagIds to apply against */ tagIds: string[]; /** * translated to: `filter_by_points_balance` // undefined or none */ filterByPointsBalance: boolean; /** * translated to: `filter_for_merchants` * !warning: from manualy testing The API doesn't support multiple value */ filterForMerchants: string; /** * Sorting */ sortBy: 'name' | 'id' | 'updated_at' | 'begins_at' | 'ends_at'; /** * sortBy's order */ order: 'asc' | 'desc'; } export interface IPerxAuthService { /** * Issue the token by assuming role of user (customer). * * @param userIdentifier */ getUserToken(userIdentifier: string): Promise; /** * Issue the application's token */ getApplicationToken(): Promise; /** * * @param merchantIdentifier */ getMerchantBearerToken(merchantIdentifier: string): Promise; } export interface IPerxUserService { /** * Get single reward by id * * @param userToken * @param rewardId */ getReward(userToken: string, rewardId: number): Promise; /** * List rewards for specific user * * @param userToken * @param scope */ getRewards(userToken: string, scope: Partial): Promise; /** * Search rewards for that matched the keyword * * @param userToken * @param keyword keyword to search * @param page start with 1 * @param size page size to load results */ searchRewards(userToken: string, keyword: string, page: number, size: number): Promise; /** * Reserve reward for particular user * * This API can be commit and release by saving the id generated `ReservationId`, and use it to corresponding APIs * * @param userToken * @param rewardId */ reserveReward(userToken: string, rewardId: string): Promise; /** * Reserve reward for particular user * * This API can be commit and release by saving the id generated `ReservationId`, and use the corresponding APIs * * @param userToken * @param rewardId * @param timeoutInMs */ reserveReward(userToken: string, rewardId: string, timeoutInMs: number): Promise; /** * Release reward's reservation with its id. * * Reservation ID is generated from reserveReward() API * * @param userToken * @param reservationId */ releaseRewardReservation(userToken: string, reservationId: string): Promise; /** * Confirm reward's reservation with its id. * * Reservation ID is generated from reserveReward() API * * @param userToken * @param reservationId */ confirmRewardReservation(userToken: string, reservationId: string): Promise; /** * Issue a voucher from particular reward for specific user * * @param userToken * @param rewardId */ issueVoucher(userToken: string, rewardId: number | string): Promise; /** * Get single voucher by Id * * @param userToken * @param voucherId */ getVoucher(userToken: string, voucherId: number): Promise; /** * List vouchers for specific users * * @param userToken * @param scope */ getVouchers(userToken: string, scope: Partial): Promise; /** * Redeem the voucher with specific voucherId and pass confirm boolean flag * * For 2 phase action * if confirm flag = false, to reserve * if confirm flag = true, to confirm * * For single shot * if confirm flag = undefined, to confirm right away * * @param userToken * @param voucherId * @param confirm * @returns */ redeemVoucher(userToken: string, voucherId: number | string): Promise; redeemVoucher(userToken: string, voucherId: number | string, confirm: boolean): Promise; /** * Query perx loyalty points */ getLoyaltyProgram(userToken: string, loyaltyProgramId: string | number): Promise; /** * Query perx loyalty list */ getLoyaltyPrograms(userToken: string): Promise; /** * Fetch specific perx's customer * * @param userToken * @param customerId */ getCustomer(userToken: string, customerId: string | number): Promise; /** * Fetch myself as customer * * @param userToken */ getMe(userToken: string): Promise; /** * List all existing categories * * @param userToken * @param parentId list categories with specific parentId null to list all. */ getCategories(userToken: string, parentId: number | null, page: number, size: number): Promise; /** * Fetch customer's transaction history from Perx's service * * @param userToken * @param page start with 1 * @param perPage desinate the page size */ queryLoyaltyTransactionsHistory(userToken: string, page: number, perPage: number, transactionReference?: string): Promise; /** * Query all merchants from Perx * @param {boolean} favorite * @param {number} perPage * @returns */ listAllMerchants(userToken: string, page: number, perPage: number, favorite: boolean | undefined): Promise; /** * Query merchants by merchant id from Perx * @param {number} merchantId * @param {boolean} favorite * @returns */ getMerchant(userToken: string, merchantId: number): Promise; /** * Execute custom trigger on Perx with specific user. * * This API is fire & forget API. No response is provided. * However invalid key will be responsed with Axios error (400 Bad Request) * * @param userToken * @param perxCustomTriggerId */ performCustomTrigger(userToken: string, perxCustomTriggerId: string): Promise; /** * Query all campaign from Perx * @param userToken * @param page * @param perPage * @param campaignType */ listAllCampaign(userToken: string, page: number, perPage: number, campaignType: string | undefined): Promise; /** * Query campaign by campaign id from Perx * @param userToken * @param campaignId */ getCampaign(userToken: string, campaignId: number): Promise; } export interface IPerxPosService { /** * @param userToken * @param voucherId */ posReleaseReservedVoucher(applicationToken: string, voucherId: number | string): Promise; /** * POS operation, create invoice based on given request. * * @param applicationToken * @param request */ posCreateInvoice(applicationToken: string, request: PerxInvoiceRequest): Promise; /** * Burn/Earn loyalty transaction (See static methods of `PerxLoyaltyTransactionRequest`) * construct the request to make Burn/Earn transaction. * * @param applicationToken * @param request */ submitLoyaltyTransaction(applicationToken: string, request: PerxLoyaltyTransactionRequest): Promise; /** * Reserve amount of Loyalty points to be confirm * * @param applicationToken * @param request */ reserveLoyaltyPoints(applicationToken: string, request: PerxLoyaltyTransactionReservationRequest): Promise; /** * Reserve amount of Loyalty points to be confirm * * @param applicationToken * @param request * @param loyaltyTransactionId that holding the value to release */ releaseLoyaltyPoints(applicationToken: string, account: PerxLoyaltyTransactionRequestUserAccount, transactionId: string): Promise; /** * Submit new transaction to perx service via POS Access. * * An Amount Transaction should be submitted here. * * @param transaction */ submitTransaction(applicationToken: string, transaction: PerxTransactionReqeust): Promise; /** * get customer detail via POS Access. * * @param userId */ getCustomerDetail(applicationToken: string, userId: number): Promise; /** * Create merchant object via POS Access. * * @param applicationToken * @param username * @param email * @param merchantAccountId */ createMerchantInfo(applicationToken: string, username: string, email: string, merchantAccountId: number): Promise; } export declare type IPerxService = IPerxAuthService & IPerxUserService & IPerxPosService & { clone(lang: string): IPerxService; }; export declare class PerxService implements IPerxService { readonly config: PerxConfig; readonly debug: ((axios: AxiosInstance) => void) | 'request' | 'response' | 'all' | 'none'; private axios; clone(lang: string): PerxService; /** * Create perx service * * @param config */ constructor(config: PerxConfig, debug?: ((axios: AxiosInstance) => void) | 'request' | 'response' | 'all' | 'none'); /** * Find and create the userToken * * @param userIdentifier */ getUserToken(userIdentifier: string): Promise; getMerchantBearerToken(merchantIdentifier: string): Promise; getCustomerDetail(applicationToken: string, userId: number): Promise; getApplicationToken(): Promise; getReward(userToken: string, rewardId: number): Promise; getRewards(userToken: string, scope: Partial): Promise; issueVoucher(userToken: string, rewardId: number | string): Promise; getVoucher(userToken: string, voucherId: number): Promise; getVouchers(userToken: string, scope: Partial): Promise; reserveReward(userToken: string, rewardId: string, timeoutInMs?: number): Promise; releaseRewardReservation(userToken: string, reservationId: string): Promise; confirmRewardReservation(userToken: string, reservationId: string): Promise; redeemVoucher(userToken: string, voucherId: string | number, confirm?: boolean | undefined): Promise; posReleaseReservedVoucher(applicationToken: string, voucherId: string | number): Promise; /** * According to Perx's response, this API doesn't response any payload. * * This API is fire & forget. * * @param userToken * @param perxCustomTriggerId * @returns nothing */ performCustomTrigger(userToken: string, perxCustomTriggerId: string): Promise; getLoyaltyProgram(userToken: string, loyaltyProgramId: string | number): Promise; getLoyaltyPrograms(userToken: string): Promise; getMe(userToken: string): Promise; getCustomer(userToken: string, customerId?: string | number): Promise; submitTransaction(applicationToken: string, transaction: PerxTransactionReqeust): Promise; submitLoyaltyTransaction(applicationToken: string, request: PerxLoyaltyTransactionRequest): Promise; reserveLoyaltyPoints(applicationToken: string, request: PerxLoyaltyTransactionReservationRequest): Promise; releaseLoyaltyPoints(applicationToken: string, account: PerxLoyaltyTransactionRequestUserAccount, transactionId: string): Promise; posCreateInvoice(applicationToken: string, request: PerxInvoiceRequest): Promise; searchRewards(userToken: string, keyword: string, page: number, size: number): Promise; getCategories(userToken: string, parentId: number | null, page: number, size: number): Promise; queryLoyaltyTransactionsHistory(userToken: string, page: number, perPage: number, transactionReference?: string): Promise; listAllMerchants(userToken: string, page: number, perPage: number, favorite?: boolean | undefined): Promise; getMerchant(userToken: string, merchantId: number): Promise; createMerchantInfo(applicationToken: string, username: string, email: string, merchantAccountId: number): Promise; private static fromRewardsScopeToQueryParams; listAllCampaign(userToken: string, page: number, perPage: number, campaignType?: string | undefined): Promise; getCampaign(userToken: string, campaignId: number): Promise; }