Beispiel #1
0
    def update_payment_status(self):
        try:
            db = get_db()
            db_transaction = (db.query(Transaction).filter_by(
                order_id=self.order.id).first())

            db_transaction.status = self.payment_data.get("status")

            db_payment = (db.query(Payment).filter_by(
                id=db_transaction.payment_id).first())
            db_order = db.query(Order).filter_by(
                id=db_transaction.order_id).first()
            db_payment.processed = True
            db_payment.processed_at = datetime.now()
            db_payment.gateway_id = self.payment_data.get("gateway_id")
            db_order.payment_id = self.payment_data.get("gateway_id")

            db_payment.token = self.payment_data.get("token")
            db_payment.authorization = self.payment_data.get(
                "authorization_code")
            db_payment.status = self.payment_data.get("status")
            db.add(db_transaction)
            db.add(db_payment)
            db.add(db_order)
            db.commit()
            db.refresh(db_transaction)
            db.refresh(db_payment)
            db.refresh(db_order)
        except Exception as e:
            logger.error(e)
            raise e
Beispiel #2
0
 def __init__(self, user_id, cart, order, affiliate, payment_id):
     self.db = get_db()
     self.user_id = user_id
     self.cart = cart
     self.order = order
     self.affiliate = affiliate
     self.payment_id = payment_id
Beispiel #3
0
 def create_order_items(self, db_order, cart):
     db = get_db()
     db_item = OrderItems(
         order_id=db_order,
         product_id=cart.get("product_id"),
         quantity=cart.get("qty"),
     )
     db.add(db_item)
     db.commit()
Beispiel #4
0
 def create_order(self):
     db = get_db()
     db_order = Order(
         customer_id=self.user_id,
         order_date=datetime.now(),
         order_status="pending",
     )
     db.add(db_order)
     db.commit()
     return OrderFullResponse.from_orm(db_order)
Beispiel #5
0
 def create_credit(self):
     db = get_db()
     db_config = CreditCardFeeConfig(
         active_date=datetime.now(),
         fee=Decimal(self.config_data.fee),
         min_installment_with_fee=self.config_data.min_installment,
         mx_installments=self.config_data.max_installment,
     )
     db.add(db_config)
     db.commit()
     return db_config
Beispiel #6
0
 def __init__(self, user_id, _payment_method, _installments, _total_amount):
     self.user_id = user_id
     self._total_amount = _total_amount
     self._payment_method = _payment_method
     self._installments = _installments
     self.db = get_db()
Beispiel #7
0
 def __init__(self, item):
     self.db = get_db()
     self.item = item
Beispiel #8
0
def rollback():
    db = get_db()
    db.rollback()
Beispiel #9
0
 def __init__(self, _product_id):
     self.db = get_db()
     self._product_id = _product_id