feat: Payment system with voucher cards.

feat: Design with inversion dependency injection architecture.
feat: Prettier http middleware.
feat: Re-write items categories with preferred accounts.
This commit is contained in:
Ahmed Bouhuolia
2020-08-27 20:39:55 +02:00
parent e23b8d9947
commit e4270dc039
63 changed files with 2567 additions and 462 deletions

View File

@@ -0,0 +1,36 @@
import { Service } from 'typedi';
import { Plan, Tenant, Voucher } from '@/system/models';
import Subscription from '@/services/Subscription/Subscription';
import VocuherPaymentMethod from '@/services/Payment/VoucherPaymentMethod';
import PaymentContext from '@/services/Payment';
@Service()
export default class SubscriptionService {
/**
* Handles the payment process via voucher code and than subscribe to
* the given tenant.
*
* @param {number} tenantId
* @param {String} planSlug
* @param {string} voucherCode
*
* @return {Promise}
*/
async subscriptionViaVoucher(
tenantId: number,
planSlug: string,
voucherCode: string,
subscriptionSlug: string = 'main',
) {
const plan = await Plan.query().findOne('slug', planSlug);
const tenant = await Tenant.query().findById(tenantId);
const voucherModel = await Voucher.query().findOne('voucher_code', voucherCode);
const paymentViaVoucher = new VocuherPaymentMethod();
const paymentContext = new PaymentContext(paymentViaVoucher);
const subscription = new Subscription(paymentContext);
return subscription.subscribe(tenant, plan, voucherModel, subscriptionSlug);
}
}