payment added
This commit is contained in:
+10
-4
@@ -499,17 +499,23 @@ ALTER TABLE payments_session OWNER TO merms_panel;
|
|||||||
CREATE TABLE payments (
|
CREATE TABLE payments (
|
||||||
id SERIAL,
|
id SERIAL,
|
||||||
uid uuid DEFAULT uuid_generate_v4(),
|
uid uuid DEFAULT uuid_generate_v4(),
|
||||||
|
member_id INT REFERENCES members(id),
|
||||||
option_name VARCHAR(100) REFERENCES subscription_options(option_name),
|
option_name VARCHAR(100) REFERENCES subscription_options(option_name),
|
||||||
description VARCHAR(100) NOT NULL,
|
option_type VARCHAR(25),
|
||||||
list_order INT DEFAULT 0,
|
payment_uid VARCHAR(100) UNIQUE NOT NULL,
|
||||||
|
amount INT DEFAULT 0,
|
||||||
status INT DEFAULT 1,
|
status INT DEFAULT 1,
|
||||||
added timestamp without time zone DEFAULT now()
|
added timestamp without time zone DEFAULT now(),
|
||||||
|
sub_start timestamp without time zone,
|
||||||
|
next_billing timestamp without time zone,
|
||||||
|
sub_stop timestamp without time zone
|
||||||
);
|
);
|
||||||
ALTER TABLE ONLY payments
|
ALTER TABLE ONLY payments
|
||||||
ADD CONSTRAINT payments_id_key UNIQUE (id);
|
ADD CONSTRAINT payments_id_key UNIQUE (id);
|
||||||
|
|
||||||
|
ALTER TABLE payments OWNER TO merms_panel;
|
||||||
|
|
||||||
|
{'payment_uid': UUID('360b8829-45e0-4419-bcf0-18f4087f14b9'), 'member_id': 1, 'option_name': 'STATRTER001'}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ from app.api.helpers.response_helper import ResponseHelper
|
|||||||
from app.api.schemas.user import UserSchema
|
from app.api.schemas.user import UserSchema
|
||||||
from app.api.schemas.subscription_session import SubscriptionSession
|
from app.api.schemas.subscription_session import SubscriptionSession
|
||||||
from marshmallow import ValidationError
|
from marshmallow import ValidationError
|
||||||
from app.models import Members, MembersProducts, SubscriptionOptions, SubscriptionOptionsItems, PaymentsSession
|
from app.models import Members, MembersProducts, SubscriptionOptions, SubscriptionOptionsItems, PaymentsSession, \
|
||||||
|
Payments
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.api.integrations import StripeIntegration
|
from app.api.integrations import StripeIntegration
|
||||||
import json
|
import json
|
||||||
@@ -259,8 +260,13 @@ class SubscriptionsService(BaseService):
|
|||||||
"payment_uid": currentPaymentsession.uid,
|
"payment_uid": currentPaymentsession.uid,
|
||||||
"member_id": currentPaymentsession.member_id,
|
"member_id": currentPaymentsession.member_id,
|
||||||
"option_name": currentPaymentsession.option_name,
|
"option_name": currentPaymentsession.option_name,
|
||||||
|
"amount": amount_subtotal,
|
||||||
|
"option_type": "MAIN",
|
||||||
|
"next_billing_days": 30
|
||||||
}
|
}
|
||||||
logger.info(f"HOOK payment_data ==>>>> {payment_data}")
|
logger.info(f"HOOK payment_data ==>>>> {payment_data}")
|
||||||
|
paymentAddResult = Payments.add_payment(payment_data.member_id, payment_data.payment_uid, payment_data.option_name,
|
||||||
|
payment_data.amount, payment_data.option_type, payment_data.next_billing_days)
|
||||||
|
|
||||||
# Simulate processing
|
# Simulate processing
|
||||||
response_data = {
|
response_data = {
|
||||||
|
|||||||
@@ -26,16 +26,18 @@ from .subscription_options import SubscriptionOptions
|
|||||||
from .subscription_options_items import SubscriptionOptionsItems
|
from .subscription_options_items import SubscriptionOptionsItems
|
||||||
from .products_templates import ProductsTemplates
|
from .products_templates import ProductsTemplates
|
||||||
from .payments_session import PaymentsSession
|
from .payments_session import PaymentsSession
|
||||||
|
from .payments import Payments
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['Members','Customer', 'Account', 'Products',
|
|
||||||
|
__all__ = ['Members', 'Account', 'Products',
|
||||||
'MembersProducts', 'MembersActions', 'MembersPending', 'ProductsDetails',
|
'MembersProducts', 'MembersActions', 'MembersPending', 'ProductsDetails',
|
||||||
'ProvisionActions', 'MembersProductsRefresh','MembersProductsSettings',
|
'ProvisionActions', 'MembersProductsRefresh','MembersProductsSettings',
|
||||||
'PasswordReset','MembersProfile','SubscriptionOptions','SubscriptionOptionsItems',
|
'PasswordReset','MembersProfile','SubscriptionOptions','SubscriptionOptionsItems',
|
||||||
'ProductsTemplates','PaymentsSession',
|
'ProductsTemplates','Payments','PaymentsSession']
|
||||||
|
|
||||||
'Loan', 'Transaction', 'Repayment',
|
# 'Loan', 'Transaction', 'Repayment', 'Customer',
|
||||||
'LoanCharge', 'Offer', 'Charge', 'RACCheck', 'LoanRepaymentSchedule',
|
# 'LoanCharge', 'Offer', 'Charge', 'RACCheck', 'LoanRepaymentSchedule',
|
||||||
'TransactionOffer', 'RepaymentsData', 'Salary']
|
# 'TransactionOffer', 'RepaymentsData', 'Salary'
|
||||||
+61
-26
@@ -1,11 +1,10 @@
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone, timedelta
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.models.charge import Charge
|
from app.models.charge import Charge
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
|
|
||||||
class Payments(db.Model):
|
class Payments(db.Model):
|
||||||
__tablename__ = 'payments'
|
__tablename__ = 'payments'
|
||||||
|
|
||||||
@@ -16,48 +15,84 @@ class Payments(db.Model):
|
|||||||
)
|
)
|
||||||
uid = db.Column(db.String(150), nullable=True)
|
uid = db.Column(db.String(150), nullable=True)
|
||||||
member_id = db.Column(db.Integer, nullable=False)
|
member_id = db.Column(db.Integer, nullable=False)
|
||||||
product_id = db.Column(db.String(25), nullable=False)
|
option_name = db.Column(db.String(100), nullable=False)
|
||||||
processor = db.Column(db.String(25), nullable=False)
|
option_type = db.Column(db.String(25), nullable=False)
|
||||||
|
payment_uid = db.Column(db.String(100), nullable=False)
|
||||||
|
amount = db.Column(db.Integer, nullable=True, default=0)
|
||||||
status = db.Column(db.Integer, nullable=True, default=1)
|
status = db.Column(db.Integer, nullable=True, default=1)
|
||||||
added = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
added = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||||
updated = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
sub_start = db.Column(db.DateTime(timezone=True))
|
||||||
|
next_billing = db.Column(db.DateTime(timezone=True))
|
||||||
|
sub_stop = db.Column(db.DateTime(timezone=True))
|
||||||
|
|
||||||
|
'''
|
||||||
|
"payment_uid": currentPaymentsession.uid,
|
||||||
|
"member_id": currentPaymentsession.member_id,
|
||||||
|
"option_name": currentPaymentsession.option_name,
|
||||||
|
"amount": amount_subtotal,
|
||||||
|
"option_type": "MAIN"
|
||||||
|
'''
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_payment(cls, customer_id, account_id, transaction_id, data=None):
|
def add_payment(cls, member_id, payment_uid, option_name,amount, option_type, next_billing_days=30):
|
||||||
|
|
||||||
|
# Get the current date and time
|
||||||
|
current_date = datetime.now()
|
||||||
|
|
||||||
|
# Calculate the date "next_billing_days" days from now
|
||||||
|
next_billing_date = current_date + timedelta(days=next_billing_days)
|
||||||
|
|
||||||
# Save the response
|
# Save the response
|
||||||
rac_check = cls(
|
pay_data = cls(
|
||||||
customer_id=customer_id,
|
member_id=member_id,
|
||||||
account_id=account_id,
|
payment_uid=payment_uid,
|
||||||
transaction_id=transaction_id,
|
option_name=option_name,
|
||||||
|
amount=amount,
|
||||||
|
option_type=option_type,
|
||||||
added=datetime.now(timezone.utc),
|
added=datetime.now(timezone.utc),
|
||||||
updated=datetime.now(timezone.utc)
|
sub_start=datetime.now(timezone.utc),
|
||||||
|
next_billing = next_billing_date
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
db.session.add(rac_check)
|
db.session.add(pay_data)
|
||||||
except IntegrityError as err:
|
except IntegrityError as err:
|
||||||
raise ValueError(f"Database integrity error: {err}")
|
raise ValueError(f"Database integrity error: {err}")
|
||||||
return rac_check
|
return pay_data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return {
|
return {
|
||||||
"offerId": self.id,
|
"id": self.id,
|
||||||
"productId": self.product_id,
|
"uid": self.uid,
|
||||||
"minAmount": self.min_amount,
|
"member_id": self.member_id,
|
||||||
"maxAmount": self.max_amount,
|
"option_name": self.option_name,
|
||||||
"tenor": self.tenor,
|
"option_type": self.option_type,
|
||||||
"interest_rate": self.interest_rate,
|
"payment_uid": self.payment_uid,
|
||||||
"management_rate": self.management_rate,
|
"amount": self.amount,
|
||||||
"insurance_rate": self.insurance_rate,
|
"status": self.status,
|
||||||
"vat_rate": self.vat_rate,
|
"added": self.added,
|
||||||
"maxDailyLoans": self.max_daily_loans,
|
"sub_start": self.sub_start,
|
||||||
"maxActiveLoans": self.max_active_loans,
|
"next_billing": self.next_billing,
|
||||||
"maxLifeLoans": self.max_life_loans
|
"sub_stop": self.sub_stop
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<LoanOffer {self.id}>'
|
return f'<Payments {self.id}>'
|
||||||
|
|
||||||
|
'''
|
||||||
|
id SERIAL,
|
||||||
|
uid uuid DEFAULT uuid_generate_v4(),
|
||||||
|
member_id INT REFERENCES members(id),
|
||||||
|
option_name VARCHAR(100) REFERENCES subscription_options(option_name),
|
||||||
|
option_type VARCHAR(25),
|
||||||
|
payment_uid VARCHAR(100) UNIQUE NOT NULL,
|
||||||
|
amount INT DEFAULT 0,
|
||||||
|
status INT DEFAULT 1,
|
||||||
|
added timestamp without time zone DEFAULT now(),
|
||||||
|
sub_start timestamp without time zone,
|
||||||
|
next_billing timestamp without time zone,
|
||||||
|
sub_stop timestamp without time zone
|
||||||
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user