Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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"
        }
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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