vr-models 1.0.46 → 1.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,9 +4,9 @@ import type { DevicePaymentPlan } from "./devicePaymentPlan.models";
|
|
|
4
4
|
import type { Transaction } from "./transaction.models";
|
|
5
5
|
import type { IdempotencyRecord } from "./idempotencyRecord.models";
|
|
6
6
|
export type PaymentProvider = "mtn_momo" | "airtel_money";
|
|
7
|
-
export type PaymentStatus = "
|
|
7
|
+
export type PaymentStatus = "PENDING" | "SUCCESSFUL" | "FAILED";
|
|
8
8
|
export declare const PAYMENT_PROVIDER: readonly ["mtn_momo", "airtel_money"];
|
|
9
|
-
export declare const PAYMENT_STATUS: readonly ["
|
|
9
|
+
export declare const PAYMENT_STATUS: readonly ["PENDING", "SUCCESSFUL", "FAILED"];
|
|
10
10
|
export interface PaymentAttributes {
|
|
11
11
|
id: string;
|
|
12
12
|
userId: string;
|
|
@@ -4,7 +4,7 @@ exports.Payment = exports.PAYMENT_STATUS = exports.PAYMENT_PROVIDER = void 0;
|
|
|
4
4
|
const vr_migrations_1 = require("vr-migrations");
|
|
5
5
|
// TYPES AS CONSTANTS
|
|
6
6
|
exports.PAYMENT_PROVIDER = ["mtn_momo", "airtel_money"];
|
|
7
|
-
exports.PAYMENT_STATUS = ["
|
|
7
|
+
exports.PAYMENT_STATUS = ["PENDING", "SUCCESSFUL", "FAILED"];
|
|
8
8
|
class Payment extends vr_migrations_1.Model {
|
|
9
9
|
// Static initialization method
|
|
10
10
|
static initialize(sequelize) {
|
|
@@ -29,9 +29,9 @@ class Payment extends vr_migrations_1.Model {
|
|
|
29
29
|
},
|
|
30
30
|
providerReference: { type: vr_migrations_1.DataTypes.STRING, allowNull: true },
|
|
31
31
|
status: {
|
|
32
|
-
type: vr_migrations_1.DataTypes.ENUM("
|
|
32
|
+
type: vr_migrations_1.DataTypes.ENUM("PENDING", "SUCCESSFUL", "FAILED"),
|
|
33
33
|
allowNull: false,
|
|
34
|
-
defaultValue: "
|
|
34
|
+
defaultValue: "PENDING",
|
|
35
35
|
},
|
|
36
36
|
metadata: {
|
|
37
37
|
type: vr_migrations_1.DataTypes.JSONB,
|
|
@@ -46,7 +46,7 @@ class Payment extends vr_migrations_1.Model {
|
|
|
46
46
|
modelName: "Payment",
|
|
47
47
|
hooks: {
|
|
48
48
|
beforeUpdate: (payment) => {
|
|
49
|
-
if (payment.status === "
|
|
49
|
+
if (payment.status === "SUCCESSFUL" && !payment.providerReference) {
|
|
50
50
|
throw new Error("providerReference is required for successful payments");
|
|
51
51
|
}
|
|
52
52
|
},
|
|
@@ -82,7 +82,7 @@ class Payment extends vr_migrations_1.Model {
|
|
|
82
82
|
}
|
|
83
83
|
// Custom instance methods
|
|
84
84
|
async markAsSucceeded(providerReference, metadata) {
|
|
85
|
-
this.status = "
|
|
85
|
+
this.status = "SUCCESSFUL";
|
|
86
86
|
this.providerReference = providerReference;
|
|
87
87
|
if (metadata) {
|
|
88
88
|
this.metadata = { ...this.metadata, ...metadata };
|
|
@@ -90,7 +90,7 @@ class Payment extends vr_migrations_1.Model {
|
|
|
90
90
|
await this.save();
|
|
91
91
|
}
|
|
92
92
|
async markAsFailed(reason, metadata) {
|
|
93
|
-
this.status = "
|
|
93
|
+
this.status = "FAILED";
|
|
94
94
|
const failureMetadata = {
|
|
95
95
|
failureReason: reason,
|
|
96
96
|
failedAt: new Date().toISOString(),
|
|
@@ -107,13 +107,13 @@ class Payment extends vr_migrations_1.Model {
|
|
|
107
107
|
await this.save();
|
|
108
108
|
}
|
|
109
109
|
isSuccessful() {
|
|
110
|
-
return this.status === "
|
|
110
|
+
return this.status === "SUCCESSFUL";
|
|
111
111
|
}
|
|
112
112
|
isPending() {
|
|
113
|
-
return this.status === "
|
|
113
|
+
return this.status === "PENDING";
|
|
114
114
|
}
|
|
115
115
|
isFailed() {
|
|
116
|
-
return this.status === "
|
|
116
|
+
return this.status === "FAILED";
|
|
117
117
|
}
|
|
118
118
|
getProviderDisplayName() {
|
|
119
119
|
switch (this.provider) {
|