feat: implement plan upgrade logic with prorated pricing and MercadoPago integration
This commit is contained in:
@@ -22,6 +22,7 @@ export class PlanPaymentsAdapterMongoose implements IPlanPaymentsAdapter {
|
||||
status: { type: String, required: true },
|
||||
transactionId: { type: String, required: false },
|
||||
});
|
||||
this.schema.index({ transactionId: 1 }, { unique: true, sparse: true });
|
||||
|
||||
this.planPaymentList = model<IPlanPaymentDocument>("PlanPayment", this.schema);
|
||||
}
|
||||
@@ -33,4 +34,16 @@ export class PlanPaymentsAdapterMongoose implements IPlanPaymentsAdapter {
|
||||
public async create(data: CreatePlanPaymentParams): Promise<IPlanPayment> {
|
||||
return this.planPaymentList.create(data);
|
||||
}
|
||||
|
||||
public async createIfMissingByTransactionId(data: CreatePlanPaymentParams): Promise<IPlanPayment> {
|
||||
if (!data.transactionId) {
|
||||
return this.create(data);
|
||||
}
|
||||
|
||||
return this.planPaymentList.findOneAndUpdate(
|
||||
{ transactionId: data.transactionId },
|
||||
{ $setOnInsert: data },
|
||||
{ new: true, upsert: true, setDefaultsOnInsert: true }
|
||||
).exec();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user