feat: integrate Stripe payment to invoices

This commit is contained in:
Ahmed Bouhuolia
2024-09-18 19:24:01 +02:00
parent df706d2573
commit 4665f529e6
24 changed files with 540 additions and 80 deletions

View File

@@ -1,6 +1,7 @@
import { Model } from 'objection';
import TenantModel from 'models/TenantModel';
export class PaymentIntegration extends Model {
export class PaymentIntegration extends TenantModel {
static get tableName() {
return 'payment_integrations';
}
@@ -12,7 +13,7 @@ export class PaymentIntegration extends Model {
static get jsonSchema() {
return {
type: 'object',
required: ['service', 'enable'],
required: ['name', 'service', 'enable'],
properties: {
id: { type: 'integer' },
service: { type: 'string' },

View File

@@ -414,8 +414,8 @@ export default class SaleInvoice extends mixin(TenantModel, [
const Document = require('models/Document');
const { MatchedBankTransaction } = require('models/MatchedBankTransaction');
const {
TransactionPaymentService,
} = require('models/TransactionPaymentService');
TransactionPaymentServiceEntry,
} = require('models/TransactionPaymentServiceEntry');
return {
/**
@@ -577,14 +577,17 @@ export default class SaleInvoice extends mixin(TenantModel, [
},
/**
* Sale invoice may belongs to payment methods.
* Sale invoice may belongs to payment methods entries.
*/
paymentMethods: {
relation: Model.HasManyRelation,
modelClass: TransactionPaymentService,
modelClass: TransactionPaymentServiceEntry,
join: {
from: 'sales_invoices.id',
to: 'transactions_payment_services.referenceId',
to: 'transactions_payment_methods.referenceId',
},
beforeInsert: (model) => {
model.referenceType = 'SaleInvoice';
},
filter: (query) => {
query.where('reference_type', 'SaleInvoice');

View File

@@ -1,23 +1,25 @@
import { Model, mixin } from 'objection';
import TenantModel from 'models/TenantModel';
export class TransactionPaymentService extends TenantModel {
export class TransactionPaymentServiceEntry extends TenantModel {
/**
* Table name
*/
static get tableName() {
return 'transactions_payment_services';
return 'transactions_payment_methods';
}
/**
* Json schema of the model.
*/
static get jsonSchema() {
return {
type: 'object',
required: ['service', 'enable'],
required: ['paymentIntegrationId'],
properties: {
id: { type: 'integer' },
reference_id: { type: 'integer' },
reference_type: { type: 'string' },
service: { type: 'string' },
referenceId: { type: 'integer' },
referenceType: { type: 'string' },
paymentIntegrationId: { type: 'integer' },
enable: { type: 'boolean' },
options: { type: 'object' },
},