Ejemplo n.º 1
0
def handleVerification():

    amount = None
    ref = None

    if request.method == 'POST':
        amount = request.json.get('amount')
        ref = request.json.get('ref')

    print(request.get_json())

    if ref == None or amount == None:
        return jsonify({
            "status":
            "failed",
            "msg":
            "Bad request some fields are missing from request body"
        }), 400

    rave = FlutterWave()

    verify = rave.verifyPayment(ref, amount)

    if verify == True:
        return jsonify({
            'msg': "amount charged match provided amount",
            'status': 'success'
        }), 200
    else:
        return jsonify({
            'msg': "amount charged  does not match provided amount",
            'status': 'success'
        }), 200
Ejemplo n.º 2
0
def handleOTP():
    
    otp = None
    ref = None
    amount = None
    userId = None
    wallet = None

    if request.method == 'POST':
        otp = request.json.get('otp')
        ref = request.json.get('ref')
        userId = request.json.get('userId')
        amount = request.json.get('amount')
    print(request.get_json())
    if otp == None or ref == None or userId == None or amount == None:
        return jsonify({"status": "failed", "msg": "Bad request some fields are missing from request body"}), 400

    rave = FlutterWave()

    res = rave.validatePayment(ref,otp)

    if 'data' in res['data'] and res['status'] == "success" and res['data']['data']['responsecode'] == '00':
        verify = rave.verifyPayment(res['data']['tx']['txRef'],amount)

        if verify:
            try:
                wallet = Wallets.objects(user=userId).first()

                if wallet:
                    wallet.update(
                        inc__amount=amount,
                        set__paymentRef=res['data']['data']['transactionreference']
                    )
                    wallet.save()
                    wallet.reload()
                else:
                    wallet = Wallets(user=userId, paymentRef=res['data']['data']['transactionreference'], amount=amount)
                    wallet.save()
                    wallet.reload()

                transaction = Transactions(
                    user=wallet.user,
                    wallet=wallet.pk,
                    amount=amount,
                    reference=wallet.paymentRef,
                    operation="deposit"
                )
                transaction.save()

                return jsonify({"status": "ok", "wallet": wallet, 'msg': 'Wallet funded successfully'}), 201
            except Exception as e:
                print(e)
                res = rave.refund(ref)
                return jsonify({"status": "failed", "wallet": wallet, 'msg': 'something happened cannot fund wallet'}), 500
        else:
            return jsonify({"status": "failed", "wallet": wallet, 'msg': 'Charge amount does not match enter amount'}), 402

    else:
        return jsonify({"status": "failed", "wallet": wallet, 'msg': res['data']['data']['responsemessage']}), 402