payment added
This commit is contained in:
+10
-4
@@ -499,17 +499,23 @@ ALTER TABLE payments_session OWNER TO merms_panel;
|
||||
CREATE TABLE payments (
|
||||
id SERIAL,
|
||||
uid uuid DEFAULT uuid_generate_v4(),
|
||||
member_id INT REFERENCES members(id),
|
||||
option_name VARCHAR(100) REFERENCES subscription_options(option_name),
|
||||
description VARCHAR(100) NOT NULL,
|
||||
list_order INT DEFAULT 0,
|
||||
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()
|
||||
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
|
||||
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.subscription_session import SubscriptionSession
|
||||
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.api.integrations import StripeIntegration
|
||||
import json
|
||||
@@ -259,8 +260,13 @@ class SubscriptionsService(BaseService):
|
||||
"payment_uid": currentPaymentsession.uid,
|
||||
"member_id": currentPaymentsession.member_id,
|
||||
"option_name": currentPaymentsession.option_name,
|
||||
"amount": amount_subtotal,
|
||||
"option_type": "MAIN",
|
||||
"next_billing_days": 30
|
||||
}
|
||||
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
|
||||
response_data = {
|
||||
|
||||
@@ -26,16 +26,18 @@ from .subscription_options import SubscriptionOptions
|
||||
from .subscription_options_items import SubscriptionOptionsItems
|
||||
from .products_templates import ProductsTemplates
|
||||
from .payments_session import PaymentsSession
|
||||
from .payments import Payments
|
||||
|
||||
|
||||
|
||||
|
||||
__all__ = ['Members','Customer', 'Account', 'Products',
|
||||
|
||||
__all__ = ['Members', 'Account', 'Products',
|
||||
'MembersProducts', 'MembersActions', 'MembersPending', 'ProductsDetails',
|
||||
'ProvisionActions', 'MembersProductsRefresh','MembersProductsSettings',
|
||||
'PasswordReset','MembersProfile','SubscriptionOptions','SubscriptionOptionsItems',
|
||||
'ProductsTemplates','PaymentsSession',
|
||||
'ProductsTemplates','Payments','PaymentsSession']
|
||||
|
||||
'Loan', 'Transaction', 'Repayment',
|
||||
'LoanCharge', 'Offer', 'Charge', 'RACCheck', 'LoanRepaymentSchedule',
|
||||
'TransactionOffer', 'RepaymentsData', 'Salary']
|
||||
# 'Loan', 'Transaction', 'Repayment', 'Customer',
|
||||
# 'LoanCharge', 'Offer', 'Charge', 'RACCheck', 'LoanRepaymentSchedule',
|
||||
# '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.models.charge import Charge
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
|
||||
class Payments(db.Model):
|
||||
__tablename__ = 'payments'
|
||||
|
||||
@@ -16,48 +15,84 @@ class Payments(db.Model):
|
||||
)
|
||||
uid = db.Column(db.String(150), nullable=True)
|
||||
member_id = db.Column(db.Integer, nullable=False)
|
||||
product_id = db.Column(db.String(25), nullable=False)
|
||||
processor = db.Column(db.String(25), nullable=False)
|
||||
option_name = db.Column(db.String(100), 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)
|
||||
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
|
||||
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
|
||||
rac_check = cls(
|
||||
customer_id=customer_id,
|
||||
account_id=account_id,
|
||||
transaction_id=transaction_id,
|
||||
pay_data = cls(
|
||||
member_id=member_id,
|
||||
payment_uid=payment_uid,
|
||||
option_name=option_name,
|
||||
amount=amount,
|
||||
option_type=option_type,
|
||||
added=datetime.now(timezone.utc),
|
||||
updated=datetime.now(timezone.utc)
|
||||
sub_start=datetime.now(timezone.utc),
|
||||
next_billing = next_billing_date
|
||||
)
|
||||
|
||||
try:
|
||||
db.session.add(rac_check)
|
||||
db.session.add(pay_data)
|
||||
except IntegrityError as err:
|
||||
raise ValueError(f"Database integrity error: {err}")
|
||||
return rac_check
|
||||
return pay_data
|
||||
|
||||
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"offerId": self.id,
|
||||
"productId": self.product_id,
|
||||
"minAmount": self.min_amount,
|
||||
"maxAmount": self.max_amount,
|
||||
"tenor": self.tenor,
|
||||
"interest_rate": self.interest_rate,
|
||||
"management_rate": self.management_rate,
|
||||
"insurance_rate": self.insurance_rate,
|
||||
"vat_rate": self.vat_rate,
|
||||
"maxDailyLoans": self.max_daily_loans,
|
||||
"maxActiveLoans": self.max_active_loans,
|
||||
"maxLifeLoans": self.max_life_loans
|
||||
"id": self.id,
|
||||
"uid": self.uid,
|
||||
"member_id": self.member_id,
|
||||
"option_name": self.option_name,
|
||||
"option_type": self.option_type,
|
||||
"payment_uid": self.payment_uid,
|
||||
"amount": self.amount,
|
||||
"status": self.status,
|
||||
"added": self.added,
|
||||
"sub_start": self.sub_start,
|
||||
"next_billing": self.next_billing,
|
||||
"sub_stop": self.sub_stop
|
||||
|
||||
}
|
||||
|
||||
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