fix: mark payment license as used after usage.

fix: fix system models with createdAt and updatedAt fields.
fix: reset password token expiration time.
This commit is contained in:
Ahmed Bouhuolia
2020-09-07 17:13:37 +02:00
parent d3870974c0
commit ffb0499280
24 changed files with 191 additions and 94 deletions

View File

@@ -42,7 +42,6 @@ export default class LicenseService {
});
}
/**
*
* @param {number} loop
@@ -52,7 +51,7 @@ export default class LicenseService {
*/
async generateLicenses(
loop = 1,
licensePeriod: numner,
licensePeriod: number,
periodInterval: string = 'days',
planId: number,
) {
@@ -67,7 +66,7 @@ export default class LicenseService {
/**
* Disables the given license id on the storage.
* @param {number} licenseId
* @param {number} licenseId
* @return {Promise}
*/
async disableLicense(licenseId: number) {

View File

@@ -1,14 +1,47 @@
import { License } from "@/system/models";
import PaymentMethod from '@/services/Payment/PaymentMethod';
import { Plan } from '@/system/models';
import { IPaymentMethod, ILicensePaymentModel } from '@/interfaces';
import { ILicensePaymentModel } from "@/interfaces";
import { PaymentInputInvalid, PaymentAmountInvalidWithPlan } from '@/exceptions';
export default class VocuherPaymentMethod extends PaymentMethod implements IPaymentMethod {
export default class LicensePaymentMethod extends PaymentMethod implements IPaymentMethod {
/**
* Payment subscription of organization via license code.
* @param {ILicensePaymentModel}
* @param {ILicensePaymentModel} licensePaymentModel -
*/
async payment(licensePaymentModel: ILicensePaymentModel) {
async payment(licensePaymentModel: ILicensePaymentModel, plan: Plan) {
const license = await this.getLicenseOrThrowInvalid(licensePaymentModel);
this.validatePaymentAmountWithPlan(license, plan);
// Mark the license code as used.
return License.markLicenseAsUsed(licensePaymentModel.licenseCode);
}
/**
* Validates the license code activation on the storage.
* @param {ILicensePaymentModel} licensePaymentModel -
*/
async getLicenseOrThrowInvalid(licensePaymentModel: ILicensePaymentModel) {
const foundLicense = await License.query()
.modify('filterActiveLicense')
.where('license_code', licensePaymentModel.licenseCode)
.first();
if (!foundLicense) {
throw new PaymentInputInvalid();
}
return foundLicense;
}
/**
* Validates the payment amount with given plan price.
* @param {License} license
* @param {Plan} plan
*/
validatePaymentAmountWithPlan(license: License, plan: Plan) {
if (license.planId !== plan.id) {
throw new PaymentAmountInvalidWithPlan();
}
}
}

View File

@@ -1,4 +1,5 @@
import { IPaymentMethod, IPaymentContext } from "@/interfaces";
import { Plan } from '@/system/models';
export default class PaymentContext<PaymentModel> implements IPaymentContext{
paymentMethod: IPaymentMethod;
@@ -15,7 +16,7 @@ export default class PaymentContext<PaymentModel> implements IPaymentContext{
*
* @param {<PaymentModel>} paymentModel
*/
makePayment(paymentModel: PaymentModel) {
this.paymentMethod.makePayment(paymentModel);
makePayment(paymentModel: PaymentModel, plan: Plan) {
return this.paymentMethod.payment(paymentModel, plan);
}
}