Esempio n. 1
0
    def __init__(self, order_payment):
        super(FlutterwaveBasePaymentAdapter, self).__init__(order_payment)
        options = {'debug': True}

        if properties.LIVE_PAYMENTS_ENABLED:
            options = {'debug': False, 'env': 'production'}

        self.flw = Flutterwave(self.credentials['api_key'],
                               self.credentials['merchant_key'], options)
Esempio n. 2
0
class TestMisc(unittest.TestCase):

    global flw
    global ip
    global cardBin6
    global country

    flw = Flutterwave("tk_NabYp2XjZ6G9WwdFruzK", "tk_tdyrSMQo8a",
                      {"debug": True})

    ref = "{}{}".format("12345ref", time.time())[0:18]
    ip = "41.58.202.50"
    cardBin6 = "484250"
    country = "NG"

    def test1Ip(self):
        print("\n---------###-- Flutterwave IP Check --###------------")
        r = flw.ip.check(ip, country)
        d = json.loads(r.text)

        self.assertEqual(d["data"]["responsecode"], "00")
        print("{}".format(r.text))

    def test2Bin(self):
        print("\n---------###-- Flutterwave Card BIN Check --###------------")
        r = flw.bin.check(cardBin6, country)
        d = json.loads(r.text)

        self.assertEqual(d["data"]["responseCode"], "00")
        print("{}".format(r.text))

    def test2Bin(self):
        print("\n---------###-- Flutterwave Get Bank List --###------------")
        r = flw.bank.list()
        d = json.loads(r.text)

        # self.assertEqual(d["data"]["responseCode"], "00")
        print("{}".format(r.text))

    def testEncryptDecrypt(self):
        print(
            "\n---------###-- Utilities : Encrypt and Decrypt --###------------"
        )
        print(">>> Plain")
        plain = "I got encrypted, then reversed."
        encrypted = flw.util.encryptData(plain)
        print(">>> Encrypted")
        decrypted = flw.util.decryptData(encrypted)
        print(">>> Decrypted")
        print(decrypted)
Esempio n. 3
0
class TestBvn(unittest.TestCase):

    global flw
    global bvn
    global verifyUsing
    global otp
    global transactionReference
    global country


    flw = Flutterwave("tk_NabYp2XjZ6G9WwdFruzK", "tk_tdyrSMQo8a", {"debug": True})

    verifyUsing = "SMS"
    bvn = "12345678901"
    otp = "12345"
    country = "NG"





    def test1Bvn(self):
        print "\n---------###-- Flutterwave BVN verify --###------------"
        r = flw.bvn.verify(bvn, verifyUsing, country)
        d = json.loads(r.text)

        global transactionReference
        transactionReference = d["data"]["transactionReference"]

        # self.assertEqual(d["data"]["responseCode"], "00")
        print "{}".format(r.text)


    def test2ResendOtp(self):
        print "\n---------###-- Flutterwave BVN resendotp --###------------"
        r = flw.bvn.resendOtp(verifyUsing, transactionReference, country)
        d = json.loads(r.text)

        # self.assertEqual(d["data"]["responseCode"], "00")
        print "{}".format(r.text)

    
    def test3BvnValidate(self):
        print "\n---------###-- Flutterwave BVN validate --###------------"
        r = flw.bvn.validate(bvn, otp, transactionReference, country)
        d = json.loads(r.text)

        # self.assertEqual(d["data"]["responseCode"], "00")
        print "{}".format(r.text)
Esempio n. 4
0
def resend_OTP(request):

    flw = Flutterwave(FLUTTER_TEST_API_KEY, FLUTTER_MERCHANT_KEY, {'debug': True})

    data = request.session['data']
    name_string = data['name'][0]
    verify_using = data['verifyUsing'][0]
    country = data['country'][0]

    try:
        to_save = Info.objects.get(name=name_string)
        transaction_reference = to_save.transactionReference

        resend = flw.bvn.resendOtp(verify_using, transaction_reference, country)
        json_dict = json.loads(resend.text)

        if json_dict['status'] == 'success':
            return HttpResponseRedirect(reverse('flutter:results'))

    except Exception, e:
        ErrorLogHelper.log_error(e, 'resend_OTP')
Esempio n. 5
0
def results(request):

    flw = Flutterwave(FLUTTER_TEST_API_KEY, FLUTTER_MERCHANT_KEY, {'debug': True})
    data = request.session['data']
    name_string = data['name'][0]
    bvn = data['bvn'][0]
    verify_using = data['verifyUsing'][0]
    country = data['country'][0]

    rar = flw.bvn.verify(bvn, verify_using, country)
    json_dict = json.loads(rar.text)

    if json_dict['data']['responseCode'] != 'B01':

        try:
            transaction_reference = json_dict['data']['transactionReference']
            to_save = Info.objects.get(name=name_string)
            to_save.transactionReference = transaction_reference
            to_save.save(update_fields=['transactionReference'])

        except Exception, e:
            ErrorLogHelper.log_error(e, 'results_view')
        
        return HttpResponseRedirect(reverse('flutter:enter_otp' ))
Esempio n. 6
0
class TestCards(unittest.TestCase):

    global flw
    global validateOption
    global authModel
    global cardNumber
    global cvv
    global expiryMonth
    global expiryYear
    global bvn
    global amount
    global currency
    global customerID
    global narration
    global responseUrl
    global otp
    global otpTransactionIdentifier
    global cardToken
    global transactionRef
    global authorizeID
    global country
    global pin
    global ref


    flw = Flutterwave("tk_NabYp2XjZ6G9WwdFruzK", "tk_tdyrSMQo8a", {"debug": True})

    ref = "{}{}".format("cust", time.time())[0:18]
    validateOption = "SMS"
    authModel = "BVN"
    cardNumber = "4842508225502547"
    cvv = "136"
    expiryMonth = "10"
    expiryYear = "18"
    bvn = "12345678901"
    amount = "100"
    currency = "NGN"
    customerID = ref
    narration = "sample card purchase"
    responseUrl = "http://127.0.0.1/your_callback_url"
    otp = "12345"
    country = "NG"
    pin = "1234"


    def test1CardTokenize(self):
        print "\n---------###-- Flutterwave Card Tokenize --###------------"
        data = {
            "validateOption": validateOption,
            "authModel": authModel,
            "cardNumber": cardNumber,
            "cvv": cvv,
            "expiryMonth": expiryMonth,
            "expiryYear": expiryYear,
            "bvn": bvn,
            "country": country
        }

        r = flw.card.tokenize(data)
        d = json.loads(r.text)

        global otpTransactionIdentifier
        otpTransactionIdentifier = d["data"]["otptransactionidentifier"]
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)

    
    def test2CardValidate(self):
        print "\n---------###-- Flutterwave Card Validate Tokenize --###------------"
        data = {
            "otp": otp,
            "otpTransactionIdentifier": otpTransactionIdentifier,
            "country": country
        }

        r = flw.card.validate(data)
        d = json.loads(r.text)

        global cardToken
        cardToken = d["data"]["responsetoken"]
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)


    def test3CardCharge(self):
        print "\n---------###-- Flutterwave Card Charge --###------------"
        data = {
            "amount": amount,
            "authModel": authModel,
            "cardNumber": cardNumber,
            "cvv": cvv,
            "expiryMonth": expiryMonth,
            "expiryYear": expiryYear,
            "bvn": bvn,
            "currency": currency,
            "customerID": customerID,
            "narration": narration,
            "responseUrl": responseUrl,
            "currency": currency,
            "country": country
        }

        r = flw.card.charge(data)
        d = json.loads(r.text)

        global otpTransactionIdentifier
        otpTransactionIdentifier = d["data"]["otptransactionidentifier"]
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)

    
    def test4CardValidate(self):
        print "\n---------###-- Flutterwave Card Validate Charge --###------------"
        data = {
            "otp": otp,
            "otpTransactionIdentifier": otpTransactionIdentifier,
            "country": country
        }

        r = flw.card.validate(data)
        d = json.loads(r.text)
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)


    def test5ChargeWithToken(self):
        print "\n---------###-- Flutterwave Card Charge with Token --###------------"
        data = {
            "amount": amount,
            "cardToken": cardToken,
            "customerID": customerID,
            "narration": narration,
            "currency": currency,
            "country": country
        }

        r = flw.card.chargeWithToken(data)
        d = json.loads(r.text)

        global transactionRef
        transactionRef = d["data"]["transactionreference"]
        
        self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)


    def test6VerifyCharge(self):
        print "\n---------###-- Flutterwave Verify Card Charge --###------------"

        r = flw.card.verifyCharge(transactionRef, country)
        d = json.loads(r.text)
        
        self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)


    def test7CardPreauth(self):
        print "\n---------###-- Flutterwave Card Preauth 1 --###------------"
        data = {
            "amount": amount,
            "currency": currency,
            "cardToken": cardToken,
            "country": country
        }

        r = flw.card.preauth(data)
        d = json.loads(r.text)

        global authorizeID
        global transactionRef
        authorizeID = d["data"]["authorizeId"]
        transactionRef = d["data"]["transactionreference"]
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)


    def test8CardCapture(self):
        print "\n---------###-- Flutterwave Card Capture 1 --###------------"
        data = {
            "amount": amount,
            "currency": currency,
            "transactionRef": transactionRef,
            "authorizeID": authorizeID,
            "country": country
        }

        r = flw.card.capture(data)
        d = json.loads(r.text)
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)


    def test9CardPreauth(self):
        print "\n---------###-- Flutterwave Card Preauth 2 --###------------"
        data = {
            "amount": amount,
            "currency": currency,
            "cardToken": cardToken,
            "country": country
        }

        r = flw.card.preauth(data)
        d = json.loads(r.text)

        global authorizeID
        global transactionRef
        otpTransactionIdentifier = d["data"]["authorizeId"]
        otpTransactionIdentifier = d["data"]["transactionreference"]
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)


    def test91CardVoid(self):
        print "\n---------###-- Flutterwave Card Void 2 --###------------"
        data = {
            "amount": amount,
            "currency": currency,
            "transactionRef": transactionRef,
            "authorizeID": authorizeID,
            "country": country
        }

        r = flw.card.void(data)
        d = json.loads(r.text)
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)

    def test92CardRefund(self):
        print "\n---------###-- Flutterwave Card Refund --###------------"
        data = {
            "amount": amount,
            "currency": currency,
            "transactionRef": transactionRef,
            "authorizeID": authorizeID,
            "country": country
        }

        r = flw.card.refund(data)
        d = json.loads(r.text)
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)

    
    def test93CardBalanceEnquiry(self):
        print "\n---------###-- Flutterwave Card Balance Enquiry --###------------"
        data = {
            "cardNumber": cardNumber,
            "cvv": cvv,
            "expiryMonth": expiryMonth,
            "expiryYear": expiryYear,
            "pin": pin,
            "transactionRef": ref,
            "country": country
        }

        r = flw.card.balanceEnquiry(data)
        d = json.loads(r.text)

        global otpTransactionIdentifier
        otpTransactionIdentifier = d["data"]["otpref"]
        global transactionRef
        transactionRef = d['data']['transactionref']
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)


    def test94CardRefund(self):
        print "\n---------###-- Flutterwave Validate Card Balance Enquiry --###------------"
        data = {
            "otp": otp,
            "otpTransactionIdentifier": otpTransactionIdentifier,
            "transactionRef": transactionRef,
            "country": country
        }

        r = flw.card.validateBalanceEnquiry(data)
        d = json.loads(r.text)
        
        # self.assertEqual(d["data"]["responsecode"], "00")
        print "{}".format(r.text)        
Esempio n. 7
0
from flutterwave import Flutterwave
import unittest

print Flutterwave
test = Flutterwave("tk_NabYp2XjZ6G9WwdFruzK", "tk_tdyrSMQo8a")
print test


class TestStringMethods(unittest.TestCase):
    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')


#
def testip(ip):
    r = test.ip.check(ip)
    print "{} {}".format(r.status_code, r.text, r.json)


# "484250"
def testBin(cardBin):
    r = test.bin.check(cardBin)
    print "{} {}".format(r.status_code, r.text, r.json)


# "22171877153", "SMS"
def testbvn(bvn, verifyUsing):
    r = test.bvn.verify(bvn, verifyUsing)
    print "{} {}".format(r.status_code, r.text, r.json)

Esempio n. 8
0
def initialize_flw(api_key, merchant_key):
    flw = Flutterwave(api_key, merchant_key, {"debug": False})
    return flw
Esempio n. 9
0
class TestDisburse(unittest.TestCase):

    global flw
    global amount
    global ref
    global relatedRef
    global bankCode
    global narration
    global debitAccount
    global creditAccount
    global recipientName
    global senderName
    global country
    global currency
    global accountToken
    global otpType1
    global otp1
    global otpType2
    global otp2

    flw = Flutterwave("tk_NabYp2XjZ6G9WwdFruzK", "tk_tdyrSMQo8a",
                      {"debug": True})

    ref = "{}{}".format("12345ref", time.time())[0:18]
    amount = "100"
    bankCode = "058"
    narration = "sample disburse"
    debitAccount = "0690000000"
    creditAccount = "0921318712"
    recipientName = "test receiver"
    senderName = "test app"
    country = "NG"
    currency = "NGN"
    accountToken = ""
    otpType1 = "PHONE_OTP"
    otp1 = "12345"
    otpType2 = "ACCOUNT_DEBIT"
    otp2 = "1.00"

    def test1LinkAccount(self):
        print("\n---------###-- Flutterwave Link Account --###------------")

        r = flw.disburse.linkAccount(debitAccount, country)
        print("{}".format(r.text))
        d = json.loads(r.text)

        global relatedRef
        relatedRef = d["data"]["uniquereference"]

        self.assertEqual(d["data"]["responsecode"], "00")

    def test2ValidateLinkAccount(self):
        print(
            "\n---------###-- Flutterwave Validate Link Account S1 --###------------"
        )

        r = flw.disburse.validateLinkAccount(relatedRef, otpType1, otp1,
                                             country)
        print("{}".format(r.text))
        d = json.loads(r.text)

        self.assertEqual(d["data"]["responsecode"], "00")

    def test3ValidateLinkAccount(self):
        print(
            "\n---------###-- Flutterwave Validate Link Account S2 --###------------"
        )

        r = flw.disburse.validateLinkAccount(relatedRef, otpType2, otp2,
                                             country)
        print("{}".format(r.text))
        d = json.loads(r.text)

        global accountToken
        accountToken = d["data"]["accounttoken"]

        self.assertEqual(d["data"]["responsecode"], "00")

    def test4GetLinkedAccounts(self):
        print(
            "\n---------###-- Flutterwave Get Linked Accounts --###------------"
        )

        r = flw.disburse.getLinkedAccounts(country)
        print("{}".format(r.text))
        d = json.loads(r.text)

        self.assertEqual(d["data"]["responsecode"], "00")

    def test5DisburseSend(self):
        print("\n---------###-- Flutterwave Disburse send --###------------")
        data = {
            "amount": amount,
            "accountToken": accountToken,
            "ref": ref,
            "bankCode": bankCode,
            "narration": narration,
            "creditAccount": creditAccount,
            "recipientName": recipientName,
            "senderName": senderName,
            "country": country,
            "currency": currency
        }
        r = flw.disburse.send(data)
        print("{}".format(r.text))
        d = json.loads(r.text)

        self.assertEqual(d["data"]["responsecode"], "00")
Esempio n. 10
0
def enter_OTP(request):

    flw = Flutterwave(FLUTTER_TEST_API_KEY, FLUTTER_MERCHANT_KEY, {'debug': True})
    data = request.session['data']
    name_string = data['name'][0]
    bvn = data['bvn'][0]
    country = data['country'][0]

    try:
        to_save = Info.objects.get(name=name_string)
        transaction_reference = to_save.transactionReference

        if request.method == 'POST':
            otp = request.POST['OTP']
            r = flw.bvn.validate(bvn, otp, transaction_reference, country)
            json_dict = json.loads(r.text)
            # r = {
            # 'data': {
            #     'firstName':'Ope',
            #     'lastName':'Onikute',
            #     'phoneNumber':'08155718567',
            #     'enrollmentBank':'044',
            #     'bvn':'11111111111',
            #     'responseMessage':'Completed successfully',
            # },
            # 'status':'success'
            # }

            if json_dict['status'] == 'success':
                status = 'success'

                if json_dict['data']['firstName'] is not None and json_dict['data']['lastName'] is not None:

                    status = 'Thankyou for using flutterbvn!'
                    name = json_dict['data']['firstName'] + ' ' + json_dict['data']['lastName']
                    phone_number = json_dict['data']['phoneNumber']
                    sortcode = json_dict['data']['enrollmentBank']
                    bvn_no = json_dict['data']['bvn']

                else:
                    status = 'Something went wrong. Please try again.'
                    name = 'Sample name'
                    phone_number = '081XXXXXXXXX'
                    sortcode = 'XXXX'
                    bvn_no = 'XXXXXXXXXXX'

                context = {
                    'status': status,
                    'name': name,
                    'phone_number': phone_number,
                    'sortcode': sortcode,
                    'bvn_no': bvn_no,
                }

                return render(request, 'flutter/results.html', context)

            else:
                request.session.flush()
                status = 'failed'
                context = {
                    'status': status,
                }
                return render(request, 'flutter/results.html', context)

    except Exception, e:

        ErrorLogHelper.log_error(e, 'enter_otp')

        request.session.flush()
        status = 'failed'
        context = {
            'status': status,
        }
        return render(request, 'flutter/results.html', context)
Esempio n. 11
0
class TestAccounts(unittest.TestCase):

    global flw
    global ref
    global amount
    global narration
    global debitAccount
    global transactionReference
    global otp
    global token
    global country
    global bankcode

    flw = Flutterwave("tk_NabYp2XjZ6G9WwdFruzK", "tk_tdyrSMQo8a", {"debug": True})

    ref = "{}{}".format("12345ref", time.time())[0:18]
    amount = "100"
    narration = "sample purchase"
    debitAccount = "0690000000"
    otp = "12345"
    country = "NG"
    bankcode = "044"


    # def test1AccountTokenize(self):
    #     print "\n---------###-- Flutterwave Account Tokenize --###------------"
    #     r = flw.account.tokenize(debitAccount, country)
    #     d = json.loads(r.text)

    #     global transactionReference
    #     transactionReference = d["data"]["transactionReference"]

    #     # self.assertEqual(d["data"]["responseCode"], "00")
    #     print "{}".format(r.text)
        

    # def test2AccountValidate(self):
    #     print "\n---------###-- Flutterwave Account Tokenize Validate --###------------"
    #     data = {
    #         "amount": amount,
    #         "ref": transactionReference,
    #         "otp": otp,
    #         "accountNumber": debitAccount,
    #         "narration": narration,
    #         "country": country
    #     }
    #     r = flw.account.validate(data)
    #     d = json.loads(r.text)

    #     global token
    #     token = d["data"]["accountToken"]
        
    #     # self.assertEqual(d["data"]["responsecode"], "00")
    #     print "{}".format(r.text)


    # def test3AccountCharge(self):
    #     print "\n---------###-- Flutterwave Account Charge --###------------"
    #     data = {
    #         "amount": amount,
    #         "token": token,
    #         "narration": narration,
    #         "country": country
    #     }

    #     r = flw.account.charge(data)
    #     d = json.loads(r.text)
        
    #     # self.assertEqual(d["data"]["responseCode"], "00")
    #     print "{}".format(r.text)


    # def test4AccountLookup(self):
    #     print "\n---------###-- Flutterwave Account Lookup --###------------"
    #     data = {
    #         "destBankCode": bankcode,
    #         "recipientAccount": debitAccount,
    #         "country": country
    #     }

    #     r = flw.account.lookup(data)
    #     d = json.loads(r.text)
        
    #     # self.assertEqual(d["data"]["responseCode"], "00")
    #     print "{}".format(r.text)


    def test5ChargeAny(self):
        print "\n---------###-- Flutterwave ChargeAny --###------------"
        data = {
            "narration": narration,
            "accountNumber": "0043480060",
            "bankCode": "058",
            "passcode":"123456789012",
            "amount": amount,
            "currency": "NGN",
            "firstName": "john",
            "lastName": "yemi",
            "email": "*****@*****.**",
            "transactionRef": "{}{}".format("12345ref", time.time())[0:18],
            "country": country
        }

        r = flw.account.chargeAny(data)
        d = json.loads(r.text)

        global transactionReference
        transactionReference = d["data"]["transactionreference"]
        
        # self.assertEqual(d["data"]["responseCode"], "00")
        print "{}".format(r.text)


    def test6ValidateChargeAnyRef(self):
        print "\n---------###-- Flutterwave Validate ChargeAny --###------------"
        data = {
            "transactionRef": transactionReference,
            "otp": otp,
            "country": country
        }

        r = flw.account.validateChargeAnyRef(data)
        d = json.loads(r.text)
        
        # self.assertEqual(d["data"]["responseCode"], "00")
        print "{}".format(r.text)
Esempio n. 12
0
from flask import Flask, abort, flash, redirect, render_template, request, url_for
from flutterwave import Flutterwave
import json
flw = Flutterwave("tk_WKidq81NCpnoyeu5vZHU", "tk_pPXQd5L0Th", {"debug": True})
app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def pay():
    err = None

    if request.method == 'POST':
        email = request.form['email']
        cardno = request.form['cardno']
        cvv = request.form['cvv']
        expmonth = request.form['expyear']
        expyear = request.form['expyear']
        data = {
            "amount": "100",
            "authModel": "NOAUTH",
            "cardNumber": cardno,
            "cvv": cvv,
            "expiryMonth": expmonth,
            "expiryYear": expyear[2:],
            "currency": "NGN",
            "country": "NG",
            "customerID": email,
            "narration": "donation"
        }

        r = flw.card.charge(data)
Esempio n. 13
0
class TestAch(unittest.TestCase):

    global flw
    global institutionId
    global institutionUsername
    global institutionPassword
    global institutionPin
    global institutionType
    global country
    global email

    flw = Flutterwave("tk_NabYp2XjZ6G9WwdFruzK", "tk_tdyrSMQo8a",
                      {"debug": True})

    institutionId = ""
    country = "NG"
    email = "*****@*****.**"
    institutionPin = "1"
    institutionType = "wells"
    institutionPassword = "******"
    institutionUsername = "******"

    def test1List(self):
        print "\n---------###-- Flutterwave ACH List Institutions --###------------"

        r = flw.ach.listInstitutions(country)
        d = json.loads(r.text)

        global institutionId
        institutionId = d["data"]["institutions"][0]['id']
        global institutionUsername
        #institutionUsername = d["data"]["institutions"][0]['credentials']['username']
        global institutionPassword
        #institutionPassword = d["data"]["institutions"][0]['credentials']['password']
        global institutionPin
        #institutionPin = d["data"]["institutions"][0]['credentials']['pin']
        global institutionType
        #institutionType = d["data"]["institutions"][0]['type']

        # self.assertEqual(d["data"]["responseCode"], "00")
        print "{}".format(r.text)

    def test2Detail(self):
        print "\n---------###-- Flutterwave ACH Get Institution --###------------"
        r = flw.ach.getInstitution(institutionId, country)
        d = json.loads(r.text)

        # self.assertEqual(d["data"]["responseCode"], "00")
        print "{}".format(r.text)

    def test3AddUser(self):
        print "\n---------###-- Flutterwave ACH Add User --###------------"

        payload = {
            "username": institutionUsername,
            "password": institutionPassword,
            "email": email,
            "institutionType": institutionType,
            "country": country
        }

        r = flw.ach.addUser(payload)
        d = json.loads(r.text)

        # self.assertEqual(d["data"]["responseCode"], "00")
        print "{}".format(r.text)