import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import { RelateToOne } from "@entity-access/entity-access/dist/decorators/Relate.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import { StoreAccount } from "./StoreAccount.js"; import { JsonProperty } from "@entity-access/server-pages/dist/services/ModelService.js"; import Index from "@entity-access/entity-access/dist/decorators/Index.js"; import type StorePaymentAttempt from "./StorePaymentAttempt.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; const gatewayTypeArray = [ "paypal", "phone-pe", "stripe", "cashfree", "mock"] as const; export type gatewayType = typeof gatewayTypeArray[number]; /** * Reason this is a separate table is to isolate credentials. */ @Table("StorePaymentGateways") @Index({ name: "IX_StorePaymentGateway_Default", columns: [ { name: (x) => x.isGatewayActive, descending: true}, { name: (x) => x.isDefault, descending: true}, ], filter: (x) => x.isGatewayActive === true }) export default class StorePaymentGateway { @Column({ dataType: "BigInt", key: true}) @RelateToOne(StoreAccount, { property: (x) => x.storeAccount, inverseProperty: (x) => x.storePaymentGateway, foreignKeyConstraint: { name: "FC_StorePaymentGateway_Account", onDelete: "restrict" } }) accountID: number; @Column({ dataType: "Char", length: 50, nullable: true, enum: gatewayTypeArray }) paymentGateway: gatewayType; @Column({ dataType: "Boolean", default: () => true }) isGatewayActive: boolean; @Column({ dataType: "Boolean", default: () => false }) isDefault: boolean; @Column({ dataType: "Char", length: 400, nullable: true}) merchantID: string; @Column({ dataType: "Char", nullable: true}) url: string; @Column({ dataType:"Boolean", default: () => false}) sandbox: boolean; @Column({ dataType: "Char", nullable: true}) accessID: string; @Column({ dataType: "Char", nullable: true}) publicKey: string; @Column({ dataType: "Char", nullable: true}) clientID: string; @Column({ dataType: "Char", length: 50, nullable: true}) saltIndex: string; @Column({ dataType: "Char", length: 400, nullable: true}) encryptedSalt: string; @JsonProperty({}) salt: string; @JsonProperty({}) secret: string; @Column({ dataType: "Char", nullable: true}) encryptedSecret: string; @Column({ dataType: "Char", length: 20, nullable: true}) country: string; @Column({ dataType: "Char", length: 20, nullable: true}) currency: string; @Column({ dataType:"DateTime", default: () => Sql.date.now()}) dateCreated: DateTime; @Column({ dataType:"DateTime", default: () => Sql.date.now()}) dateUpdated: DateTime; storeAccount: StoreAccount; paymentAttempts: StorePaymentAttempt[]; }