def post(cls): user_id = get_jwt_identity() value = ItemModel.sum_cart_by_user_id(user_id) if value and value != 0: quantity = ItemModel.count_cart_by_user_id(user_id) payment = PaymentModel(user_id, value, quantity, insert_timestamp()) payment.save_to_db() ItemModel.update_user_id(user_id) return {"message": "Payment ACCEPTED"}, 200 else: return {"message": "No Items in Cart!"}, 401
def find_all(cls, user, payment_id): from models.payment import PaymentModel records = cls.query.filter_by(payment_id=payment_id).all() if records and PaymentModel.find_by_id(payment_id, user): return records
def post(self): # Get user id user_id = get_jwt_identity() user = UserModel.find_user_with_id(user_id) # Get the order id from request arguments = self.parse_args() order_id = arguments["orderId"] # Capture the order response = self.paypal_handler.capture_order(order_id) token_id = response["reference_id"] # Check if status is completed if self.paypal_handler.is_completed(response): # Get the token pack with id token_pack = PaymentModel.find_by_id(token_id) # Increase user's token tokens = token_pack.amount user.increase_tokens(tokens) else: return { "message": "Purchase is not completed" }, 500 # Respond with captured data return { "message": "Successfully purchased more tokens" }
def find_by_id(cls, _id, user): from models.payment import PaymentModel record = cls.query.filter_by(id=_id).first() if record: if PaymentModel.find_by_id(record.payment_id, user): return record
def post(self, booking_id): user_from_token = get_jwt_identity() current_user = UsersModel.query.filter_by( email=user_from_token).first() fullname = request.json['fullname'] method_of_pay = request.json['method_of_pay'] phoneNum = request.json['phoneNum'] booking_amount = request.json['total_price'] id = booking_id booking = BookingModel.query.get(id) created_at = str(datetime.now()) if booking_amount == '': booking_amount = booking.price new_trans = PaymentModel(user_id=current_user.id, booking_id=booking_id, package_id=None, amount=booking_amount, phoneNum=phoneNum, fullname=fullname, method_of_pay=method_of_pay, created_at=created_at) db.session.add(new_trans) db.session.commit() return { "message": "Successfully Transcation Thank You for Using Services" } else: new_trans = PaymentModel(user_id=current_user.id, booking_id=booking_id, package_id=None, amount=booking_amount, phoneNum=phoneNum, fullname=fullname, method_of_pay=method_of_pay, created_at=created_at) db.session.add(new_trans) db.session.commit() return { "message": "Successfully Transcation Thank You for Using Services" }
def post(self): # db.session.begin(subtransactions=True) try: data = MenuOrderResource.parser.parse_args() if data['payment_type'] == "CD": payment = PaymentModel(data['payment_type'], "COD", data['amount'], data['amount_payable'], data['amount_tax'], data['amount_menu'], data['amount_discount'], data['amount_wallet']) try: # payment.save_to_db() db.session.add(payment) db.session.flush() # db.session.commit() except: return { 'data': { "status": False, "message": "Paymnet False" } }, 500 # payment_id = payment.id order_id = MenuOrderModel.getOrderNumber() order = MenuOrderModel(order_id, data['user_id'], payment.id, data['address_id'], data['promo_code'], data['special_note_required'], data['ratings'], 0) try: # order.save_to_db() db.session.add(order) db.session.flush() # db.session.commit() except: return { 'data': { "status": False, "message": "Order Failed" } }, 500 o_id = order.id menu = json.loads(data['menu']) for m in menu: print str(m) # m = json.loads(me) mmodel = MenuOrderItemModel(o_id, m['menu_id'], m['menu_qty'], m['menu_amount'], m['menu_choice']) try: # mmodel.save_to_db() db.session.add(mmodel) db.session.flush() # db.session.commit() except: return { 'data': { "status": False, "message": "Menu Item Save Failed" } }, 500 db.session.commit() push_service = FCMNotification( api_key= "AAAABnCMzP4:APA91bHf4jst14Er5BrZMC9fOVVRGtMUVkPF7VYUI8t3BWbReJJbH_KYui8TIjITnTGZTq8HoKRPztnBsSXAD07m-JA1Tv1Wf6-I4P8gy3coaeMzJpG2K2alBF9iOHJQjbtQhjXuxzFo" ) # Your api-key can be gotten from: https://console.firebase.google.com/project/<project-name>/settings/cloudmessaging firebase = pyrebase.initialize_app(config) dbfirebase = firebase.database() user = UsersModel.find_by_id(int(data['user_id'])) address = UsersAddressModel.find_by_id(int(data['address_id'])) data = { "user_id": data['user_id'], "status": "0", "order": order.json(), "payment": payment.json(), "menu": menu, "user": user.json(), "address": address.json(), "datetime": str(datetime.datetime.now(pytz.timezone('Asia/Calcutta'))) } dbfirebase.child("orders").child(str(order_id)).set(data) admin = AdminModel.find_by_username("admin") print admin.fcmtoken registration_id = admin.fcmtoken message_title = "New Order" message_body = "A new Food order has arrived..!! Confirm the order " push_service.notify_single_device( registration_id=registration_id, message_title=message_title, message_body=message_body) return { 'data': { "status": True, "payment": payment.json(), "order": order.json(), "menu": menu } } # except: # db.session.rollback() finally: db.session.close()
def get(cls, id: int): payment = PaymentModel.find_by_id(id) if order: return payment_schema.dump(payment), 200 return {"message": gettext("order_not_found")}, 404