def create(id):
    image = Images.get_by_id(id)
    payment_amount = request.form.get('amount')
    result = transact({
        'amount':
        request.form['amount'],
        'payment_method_nonce':
        request.form['payment_method_nonce'],
        'options': {
            "submit_for_settlement": True
        }
    })

    if result.is_success or result.transaction:

        new_payment = Payments(image_id=image.id,
                               donor=current_user.id,
                               payment_amount=payment_amount).save()
        return redirect(
            url_for('payments.show_checkout',
                    transaction_id=result.transaction.id,
                    id=image))

    else:
        for x in result.errors.deep_errors:
            flash('Error')
        return redirect(url_for('payments.index', id=id))
示例#2
0
    def post(self) -> Response:
        body = request.get_json()
        id = body['id']
        payment = Payments.objects(transactionID=id)

        if len(payment) > 0:
            Payments.objects(transactionID=id).update(set__status='False')

            res = jsonify({
                "data": payment,
                "message": "success",
                "status": 200
            })
            res.status_code = 200
            return res
        else:
            res = jsonify({"data": "null", "message": "error", "status": 204})
            res.status_code = 204
            return res
示例#3
0
    def put(self) -> Response:

        body = request.get_json()
        reportID = body['reportID']
        bill = Payments.objects(reportID=reportID)
        if len(bill) > 0:
            Payments.objects(reportID=reportID).update(
                set__status="ชำระเงินสำเร็จ",
                set__update_at=str(datetime.utcnow()))
            response = jsonify({
                "data": bill,
                "message": "success",
                "status": 200
            })
            response.status_code = 200
            return response
        else:
            response = jsonify({
                "data": None,
                "message": "bill is not",
                "status": 204
            })
            response.status_code = 204
            return response
示例#4
0
 def get(self) -> Response:
     bill = Payments.objects()
     if len(bill) > 0:
         response = jsonify({
             "data": bill,
             "message": "success",
             "status": 200
         })
         response.status_code = 200
         return response
     else:
         response = jsonify({
             "data": None,
             "message": "document bill is null",
             "status": 204
         })
         response.status_code = 204
         return response
示例#5
0
 def get(self) -> Response:
     reportID = request.args.get('reportID')
     print(reportID)
     bill = Payments.objects(reportID=reportID)
     report = Reports.objects(reportID=reportID)
     data = {'bill': bill, 'report': report}
     print(report)
     if len(bill) > 0:
         response = jsonify({
             "data": data,
             "message": "success",
             "status": 200
         })
         response.status_code = 200
         return response
     else:
         response = jsonify({
             "data": None,
             "message": "error",
             "status": 204
         })
         response.status_code = 204
         return response
示例#6
0
    def post(self) -> Response:
        body = request.get_json()
        transaction = body['transactionID']
        pipline = [{
            "$match": {
                "_id": transaction
            }
        }, {
            "$lookup": {
                'from': 'guests',
                'localField': 'guestID',
                'foreignField': '_id',
                'as': 'guest'
            }
        }, {
            "$lookup": {
                'from': 'rooms',
                'localField': 'roomID',
                'foreignField': '_id',
                'as': 'room'
            }
        }]
        x = Transactions.objects.aggregate(pipline)
        y = list(x)
        local = list(y)

        if local[0]['status'] == 'False':
            guest = local[0]['guest']
            room = local[0]['room']

            key = uuid.uuid4().int
            checkIN = str(local[0]['check_in']).format("%Y-%m-%d")
            checkOUT = body['check_out']
            days = days_between(checkIN, checkOUT)

            price = days * int(room[0]['price'])

            data = {
                'transactionID': transaction,
                'room': room[0],
                'roomID': room[0]["_id"],
                'roomType': room[0]["_id"],
                'roomID': room[0]["_id"],
                'roomID': room[0]["_id"],
                'price': price,
                'guest': {
                    'name': guest[0]['name'],
                    'tel': guest[0]['tel']
                },
                'check_in': checkIN,
                'check_out': checkOUT
            }

            Transactions.objects(transactionID=transaction).update(
                set__status="True",
                set__check_out=checkOUT,
                set__total_bill=str(price),
            )
            data_payment = {
                'paymentID': str(key)[0:5],
                'transactionID': transaction,
                'guestID': guest[0]['_id'],
                'room_price': room[0]['price'],
                'total_bill': price,
                'status': 'False'
            }

            try:
                payment = Payments(**data_payment)
                payment.save()

                Rooms.objects(roomID=room[0]['_id']).update(
                    set__room_status='True')

                res = jsonify({
                    "data": [None],
                    "message": "success",
                    "status": 200
                })
                res.status_code = 200
                return res
            except NotUniqueError:
                res = jsonify({
                    "data": "null",
                    "message": "error",
                    "status": 400
                })
                res.status_code = 400
                return res
        else:
            res = jsonify({"data": "null", "message": "error", "status": 400})
            res.status_code = 400
            return res
 def total_payments(self):
     from models.payments import Payments
     total_payments = Payments.select(
         fn.SUM(Payments.amount)).where(Payments.image_id == self.id)
示例#8
0
    def post(self) -> Response:
        body = request.get_json()
        reportID = body['reportID']
        check_bill = Payments.objects(reportID=reportID)
        print(check_bill)
        if len(check_bill) <= 0:
            calMed = calculatorMed(reportID)
            if len(calMed) > 0:
                med_sum_price = 0
                for i in calMed:
                    med_sum_price = med_sum_price + i[0]['sum_price']

                print(med_sum_price)
            else:
                med_sum_price = 0

            calOrder = orderCal(reportID)
            order_sum_price = 0
            if len(calOrder) > 0:
                order_sum_price = 0
                for j in calOrder:
                    order_sum_price = order_sum_price + j[0]['price']

                print(order_sum_price)
            else:
                order_sum_price = 0

            key = uuid.uuid4().int
            data = {
                'paymentID': str(key)[0:6],
                'reportID': reportID,
                'objOrder': calOrder,
                'objMed': calMed,
                'status': "รอชำระเงิน",
                'price': int(order_sum_price + med_sum_price),
                'create_at': datetime.utcnow(),
                'update_at': datetime.utcnow()
            }
            try:
                Payments(**data).save()
                response = jsonify(data)
                response = jsonify({
                    "data": data,
                    "message": "success",
                    "status": 201
                })
                response.status_code = 201
                return response

            except NotUniqueError:
                response = jsonify({
                    "data": None,
                    "message": "error",
                    "status": 400
                })
                response.status_code = 400
                return response

        else:
            response = jsonify({
                "data": body,
                "message": "ReportID does not exist",
                "status": 204
            })
            response.status_code = 204
            return response