示例#1
0
def verify_payment(request):
    paramz = request.GET.get('trxref', 'None')
    user = request.user
    full_name = request.user.full_name
    email = request.user.email
    phone = request.user.phone_number
    print(paramz)
    pay_queryobj = Payment.objects.all().filter(reference=paramz)
    pay_instance = Payment.objects.all().filter(reference=paramz).first()
    details = Transaction.verify(reference=paramz)
    status = details['data']['status']
    if status == 'success':
        if pay_instance.product_type == '6 months':
            expiry_date = pay_instance.date_created + timedelta(days=184)
            pay_queryobj.update(paid=True, expiry_date=expiry_date)
            email = request.user.email
            current_user = Customuser.objects.filter(email=email)
            current_user.update(subscribed=True, expiry_date=expiry_date)
        elif pay_instance.product_type == '1 Year':
            expiry_date = pay_instance.date_created + timedelta(days=367)
            pay_queryobj.update(paid=True, expiry_date=expiry_date)
            email = request.user.email
            current_user = Customuser.objects.filter(email=email)
            current_user.update(subscribed=True, expiry_date=expiry_date)

    else:
        print(' payment not successful')

    return redirect('cbtexam')
示例#2
0
def verify_transaction(reference):
    resp = Transaction.verify(reference=reference)
    resp = json.load(resp)
    if resp['data']['status'] == "success":
        data = {"verify": True, "data": resp['customer']['metadata']['cart']}
        return data
    return {"verify": False}
示例#3
0
def verifyTransaction(request):
    status = False
    message = ''
    ref = request.POST.get('reference')
    response = Transaction.verify(reference=ref)
    if response['status']==True and response['data']['status'] != 'failed':
        auth_code = response['data']['authorization']['authorization_code']
        last_digit = response['data']['authorization']['last4']
        expiry_month = response['data']['authorization']['exp_month']
        card_exp_year = response['data']['authorization']['exp_year']
        card_bank = response['data']['authorization']['bank']
        card_account_name = response['data']['authorization']['account_name']
        card_first_name = response['data']['customer']['first_name']
        card_last_name = response['data']['customer']['last_name']
        card_email = response['data']['customer']['email']
        card_type = response['data']['authorization']['card_type']
        package = response['data']['metadata']['custom_fields']['package']
        
        card = Card(user=request.user, card_auth=auth_code, card_last_digit=last_digit, card_exp_month=expiry_month,card_exp_year=card_exp_year,
                 card_bank=card_bank, card_account_name=card_account_name, card_first_name=card_first_name, 
                 card_last_name=card_last_name, card_email=card_email, card_type=card_type) 
        card.save()
        package = Package.objects.get(id=int(package))
        subscription = Subscription(user=request.user, is_active=True, package_subscribed=package, has_expired=False)
        subscription.save()
        status = True
        message = 'Transaction Successful'
    else:
        status = False
        message = response['message']
   
    return JsonResponse({'status':status, 'message': message})
示例#4
0
def verify_payment(request):
    mm = marketing_member(request)
    ref = request.session['ref_no']
    response_dict = Transaction.verify(reference=ref)
    data = response_dict.get('data')
    print 'status', data['status']

    if data['status'] == 'success':
        status = "Approved"
        user = request.session['user']
        amount = request.session['amount']
        all_cost = CostCalcSettings.objects.get(marketer=mm, country="Nigeria")
        dollarNairaRate = all_cost.dollar_exchange_rate
        user.useraccount.credit_amount_D += (float(amount) /
                                             float(dollarNairaRate))
        user.useraccount.credit_amount_N += amount
        user.useraccount.save()
    else:
        status = data['status']
    bank_record = MarketerPayment.objects.get(ref_no=ref)
    bank_record.status = status
    bank_record.message = data['gateway_response']
    bank_record.save()
    messages.success(request, "You have sucessfully funded your VEI Wallet.")
    del request.session['ref_no']
    del request.session['user']
    del request.session['amount']
    return redirect('wallet:wallet')
示例#5
0
def mainPay(request):
    print "i got here"
    rp = request.POST
    print 'rp', rp
    email = request.user.email
    random_ref = purchase_ref()
    request.session['ref_no'] = random_ref
    request.session['user'] = request.user
    amount = rp.get('paystack_amount')
    print amount
    request.session['amount'] = amount
    url = 'payments:verify_payment'
    callback_url = request.build_absolute_uri(reverse(url))
    print "callback-url", callback_url
    response = Transaction.initialize(reference=random_ref,
                                      amount=(float(amount) * 100.0),
                                      email=request.user.email,
                                      callback_url=callback_url)
    # print 'response:', response
    data = response.get('data')
    # print "data:", data
    authorization_code = data['access_code']
    print "access_code", authorization_code
    url = data['authorization_url']
    # print 'url', url

    payment = Payments.objects.create(user=request.user,
                                      amount=amount,
                                      status="Pending",
                                      date_created=timezone.now(),
                                      payment_ref=random_ref)

    return redirect(url)
示例#6
0
 def verify_transcation(self, reference):
     """
     Verifies transaction
     :param reference: unique transaction reference to be verified
     :returns: Status of Transation Success
     :rtype: bool
     """
     return Transaction.verify(reference=reference)['status']
    def test_list(self):
        with mock.patch('paystackapi.transaction.Transaction.list') as \
                mock_list:
                mock_list.return_value = {
                    'status': True
                }

                response = Transaction.list()
                self.assertTrue(response['status'])
    def test_totals(self):
        with mock.patch('paystackapi.transaction.Transaction.totals') as \
                mock_totals:
                mock_totals.return_value = {
                    'status': True
                }

                response = Transaction.totals()
                self.assertTrue(response['status'])
    def test_verify(self):
        with mock.patch('paystackapi.transaction.Transaction.verify') as \
                mock_verify:
                mock_verify.return_value = {
                    'status': True
                }

                response = Transaction.verify('reference')
                self.assertTrue(response['status'])
示例#10
0
def verify_payment(request):
    ref = request.session['ref_no']
    response_dict = Transaction.verify(reference=ref)
    data = response_dict.get('data')
    print 'status', data['status']

    if data['status'] == 'success':
        status = "Approved"
        user = request.session['user']
        amount = request.session['amount']

        order_items = OrderItem.objects.filter(
            user_obj=request.user.useraccount, ordered=False, deleted=False)
        new_package = Packages.objects.create(user=request.user.useraccount)
        new_package.tracking_number = randomNumber(8)
        new_package.total_amount = request.session['total_amount']
        new_package.shipping_destination = request.session['country']
        new_package.shippingCost = request.session['shippingCost']
        new_package.subTotal = request.session['subTotal']
        new_package.payment_status = "Paid"
        new_package.save()

        for item in order_items:

            item.ordered = True
            item.status = "Paid"
            item.package = new_package
            item.save()

            stock_item = Item.objects.get(pk=item.item_id)
            if stock_item.quantity <= 0:
                stock_item.quantity = 0
            else:
                stock_item.quantity_left -= item.quantity
                stock_item.quantity_sold += item.quantity
            stock_item.save()

        bank_record = Payments.objects.get(payment_ref=ref)
        bank_record.status = status
        bank_record.packageID = new_package.tracking_number
        bank_record.save()
        messages.success(request,
                         "You have sucessfully paid for this package.")

    else:
        status = data['status']
        messages.success(request,
                         "You have not sucessfully paid for this package.")

    del request.session['country']
    del request.session['shippingCost']
    del request.session['subTotal']
    del request.session['ref_no']
    del request.session['total_amount']

    return redirect('general:homepage')
示例#11
0
def payement(request):
    if request.method == 'POST':
        refrence = request.POST.get('refrence')
        email = request.POST.get('email')
        amount = int(float(request.POST.get('amount')))
        response = Transaction.initialize(reference=refrence,
                                          amount=amount,
                                          email=email)
        return JsonResponse(response, status=200, safe=False)
    return JsonResponse({'error': 'could not add item to cart'}, status=400)
    def test_charge_token(self):
        with mock.patch('paystackapi.transaction.Transaction.charge_token') as \
                mock_charge_token:
                mock_charge_token.return_value = {
                    'status': True
                }

                response = Transaction.charge_token(
                    'getupall', 'token'
                    'email', 'amount')
                self.assertTrue(response['status'])
示例#13
0
    def test_verify(self):
        httpretty.register_uri(
            httpretty.GET,
            "https://api.paystack.co/transaction/verify/reference",
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.verify('reference')
        self.assertTrue(response['status'])
    def test_charge(self):
        with mock.patch('paystackapi.transaction.Transaction.charge') as \
                mock_charge:
                mock_charge.return_value = {
                    'status': True
                }

                response = Transaction.charge(
                    'getupall', 'authorization_code'
                    'email', 'amount')
                self.assertTrue(response['status'])
    def test_totals(self):
        httpretty.register_uri(
            httpretty.GET,
            "https://api.paystack.co/transaction/totals",
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.totals()
        self.assertTrue(response['status'])
    def test_verify(self):
        httpretty.register_uri(
            httpretty.GET,
            "https://api.paystack.co/transaction/verify/reference",
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.verify('reference')
        self.assertTrue(response['status'])
示例#17
0
    def test_totals(self):
        httpretty.register_uri(
            httpretty.GET,
            "https://api.paystack.co/transaction/totals",
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.totals()
        self.assertTrue(response['status'])
示例#18
0
    def test_totals(self):
        httpretty.register_uri(
            httpretty.GET,
            self.endpoint_url("/transaction/totals"),
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.totals()
        self.assertTrue(response['status'])
示例#19
0
 def check_transaction(self):
     if self.transaction_type == False:
         response = Transfer.verify(reference=self.code)
         if response['status']:
             if response['data']['status'] == "success":
                 return True
     elif self.transaction_type == True:
         response = Transaction.verify(reference=self.code)
         if response['status']:
             if response['data']['status'] == "success":
                 return True
     #parse check data to give result, true, false, pending
     return False
示例#20
0
    def test_initialize(self):
        httpretty.register_uri(
            httpretty.GET,
            "https://api.paystack.co/transaction/initialize",
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.initialize(reference='getupall',
                                          amount=12000,
                                          email='*****@*****.**')
        self.assertTrue(response['status'])
    def test_charge_token(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://api.paystack.co/transaction/charge_token",
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.charge_token(
            reference='getupall', token='token',
            email='email', amount=100000)
        self.assertTrue(response['status'])
    def test_initialize(self):
        httpretty.register_uri(
            httpretty.GET,
            "https://api.paystack.co/transaction/initialize",
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.initialize(
            reference='getupall', amount=12000,
            email='*****@*****.**')
        self.assertTrue(response['status'])
示例#23
0
    def test_initialize(self):
        httpretty.register_uri(
            httpretty.POST,
            self.endpoint_url("/transaction/initialize"),
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.initialize(reference='getupall',
                                          amount=12000,
                                          email='*****@*****.**')
        self.assertTrue(response['status'])
示例#24
0
    def test_charge(self):
        httpretty.register_uri(
            httpretty.POST,
            self.endpoint_url("/transaction/charge_authorization"),
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.charge(reference='getupall',
                                      authorization_code='authorization_code',
                                      email='email',
                                      amount='amount')
        self.assertTrue(response['status'])
示例#25
0
    def test_charge_token(self):
        httpretty.register_uri(
            httpretty.POST,
            "https://api.paystack.co/transaction/charge_token",
            content_type='text/json',
            body='{"status": true, "contributors": true}',
            status=201,
        )

        response = Transaction.charge_token(reference='getupall',
                                            token='token',
                                            email='email',
                                            amount=100000)
        self.assertTrue(response['status'])
示例#26
0
def verify_transaction():
    reference = request.form.get("reference")
    response = Transaction.verify(reference=reference)
    if response["status"]:
        return jsonify({
            "success": True,
            "message": response["message"],
            "data": response["data"]
        }), 200
    else:
        return jsonify({
            "success": False,
            "message": response["message"],
        }), 400
示例#27
0
def get_transactions():
    response = Transaction.list()
    if response["status"]:
        return jsonify({
            "success": True,
            "total": response["meta"]["total"],
            "total_volume": response["meta"]["total_volume"],
            "message": response["message"],
            "transactions": response["data"]
        }), 200
    else:
        return jsonify({
            "success": False,
            "message": response["message"],
        }), 400
示例#28
0
def new_transaction(email, price, cart):
    # start transaction and get payment url
    # reference = request.args.get("reference")
    # gets args from the checkout endpoint
    amount = price
    response = Transaction.initialize(amount=amount,
                                      email=email,
                                      callback_url="localhost:5000",
                                      metadata=cart)
    response = json.load(response)
    if response["status"]:
        payment_url = response['data']["authorization_url"]
        return True, payment_url
    else:
        return False, ""
示例#29
0
    def post(self, request, *args, **kwargs):
        response = request.data.get('response',None)
        userID = request.data.get('userID', None)

        reference = response["reference"]
        status = response["status"]

        if reference is not None and status == "success":
            verify_response = Transaction.verify(reference=f"{reference}")
            
            user = User.objects.get(pk=userID)
            reference = verify_response["data"]["reference"]
            auth_code = verify_response["data"]["authorization"]["authorization_code"]
            card_bin = verify_response["data"]["authorization"]["bin"]
            last_4 = verify_response["data"]["authorization"]["last4"]
            expiry_month = verify_response["data"]["authorization"]["exp_month"]
            expiry_year = verify_response["data"]["authorization"]["exp_year"]
            card_type = verify_response["data"]["authorization"]["card_type"]
            bank = verify_response["data"]["authorization"]["bank"]
            first_name = verify_response["data"]["customer"]["first_name"]
            last_name = verify_response["data"]["customer"]["last_name"]
            email = verify_response["data"]["customer"]["email"]
            
            card = Card(
                user = user, 
                reference = reference, 
                auth_code = auth_code, 
                card_bin = card_bin, 
                last_4 = last_4,
                expiry_month = expiry_month,
                expiry_year = expiry_year,
                card_type = card_type,
                bank = bank,
                first_name = first_name,
                last_name = last_name,
                email = email
            )

            card_qs = Card.objects.filter(user = user)
            
            if card_qs.exists():
                return Response({"message": "You already have a registered card"}, status=HTTP_400_BAD_REQUEST)
            else:
                card.save()
                return Response(status=HTTP_201_CREATED)

        return Response(status=HTTP_200_OK)
    def test_initialize(self):
        with mock.patch('paystackapi.transaction.Transaction.initialize') \
                as mock_initialize:
                mock_initialize.return_value = {
                    'status': True, 'message': 'Authorization URL created',
                    'data': {
                        'authorization_url': 'https://standard.paystackapi.co/pay/xam1uq26de',
                        'access_code': 'xam1uq26de',
                        'reference': 'getupall'
                    }
                }

                response = Transaction.initialize(
                    'getupall', 12000,
                    '*****@*****.**',
                    'daily')
                self.assertTrue(response['status'])
示例#31
0
def new_transaction():
    reference = request.form.get("reference")
    amount = request.form.get("amount")
    email = request.form.get("email")
    response = Transaction.initialize(reference=reference,
                                      amount=amount,
                                      email=email)
    if response["status"]:
        return jsonify({
            "success": True,
            "payment_url": response["data"]["authorization_url"],
            "reference": response["data"]["reference"],
            "message": response["message"]
        }), 200
    else:
        return jsonify({
            "success": False,
            "message": response["message"],
        }), 400
示例#32
0
def verify_payment(request):
    try:
        ref = request.session['ref_no']
    except:
        pass
        return redirect('wallet:wallet')
    response_dict = Transaction.verify(reference=ref)
    data = response_dict.get('data')
    print 'status', data['status']
    if data['status'] == 'success':
        status = "Successful"
    else:
        status = data['status']
    bank_record = Bank.objects.get(ref_no=ref)
    bank_record.status = status
    bank_record.message = data['gateway_response']
    bank_record.save()
    del request.session['ref_no']
    return redirect('wallet:wallet')
示例#33
0
def payment_process(request):
    order_id = request.session.get("order_id")
    order = get_object_or_404(Order, id=order_id)
    paystack_key = paystack_public_key

    if request.method == "POST":
        transaction = Transaction.initialize(
            reference=f"ANGALABIRI_REF_ORDER_{order_id}",
            email=order.email,
            amount="{:.2f}".format(order.get_total_cost()) * 100,
        )
        if transaction.is_success:
            order.paid = True
            order.transaction_id = transaction.id
            order.save()
            return redirect('shop:payment-done')
        else:
            return redirect('shop:payment-failed')
    return render(request, 'shop/billing/payment.html', {'order': order, 'paystack_key': paystack_key})
示例#34
0
def subscribe_full(request):
    amount = '170000'
    user = request.user
    full_name = request.user.full_name
    email = request.user.email
    phone = request.user.phone_number

    response = Transaction.initialize(amount=amount, email=email)

    ref = response['data']['reference']
    print(full_name)
    create_pay_instance = Payment.objects.create(customers_name=full_name,
                                                 customers_email=email,
                                                 customers_phone=phone,
                                                 product_type='1 Year',
                                                 reference=ref,
                                                 amount='1700')

    a_url = response['data']['authorization_url']
    return redirect(a_url)
示例#35
0
def initiate_charge_card(request, **kwargs):
    if request.method == "POST":
        markup_percentage, markup_min_charge, is_nigerian_card = get_markup_charge(
            request)
        txn_desc = kwargs['txn_desc']
        txn_ref = kwargs['txn_ref']
        request.session['txn_ref'] = txn_ref
        actual_amount_D = round(kwargs.get('actual_amount', 0), 2)
        request.session['actual_amount_D'] = actual_amount_D
        print 'markup_percentage, markup_min_charge: ', markup_percentage, markup_min_charge
        markup_charge_D = round(
            (float(actual_amount_D) * markup_percentage) + markup_min_charge,
            2)
        if is_nigerian_card:
            max_markup_charge_D = 5
            if markup_charge_D > max_markup_charge_D:
                markup_charge_D = max_markup_charge_D
            amount_D = round(actual_amount_D + markup_charge_D, 2)
            cost_calc = marketingmember_costcalc(request, 'Nigeria')
            amount_N = format(amount_D * float(cost_calc.dollar_exchange_rate),
                              '.2f')
            amountz = amount_D * float(cost_calc.dollar_exchange_rate) * 100
        print "going to paystack to charge card"
        email = request.user.email
        url = 'general:verifyPayment'
        callback_url = request.build_absolute_uri(reverse(url))
        print "callback-url", callback_url
        response = Transaction.initialize(reference=txn_ref,
                                          amount=amountz,
                                          email=email,
                                          callback_url=callback_url)
        print 'response:', response
        data = response.get('data')
        print "data:", data
        authorization_code = data['access_code']
        print "access_code", authorization_code
        url = data['authorization_url']
        print 'url', url
    return redirect(url)
示例#36
0
def verify_payment(request):
    print "rG", request.GET
    ref = request.session['txn_ref']
    response_dict = Transaction.verify(reference=ref)
    data = response_dict.get('data')
    print "data", data
    print "response_dict", response_dict
    amount = data['amount']
    status = data['status']
    response = data['gateway_response']
    print amount, status, response
    # jejepay     = update_jejepay_obj(ref,ref,response)
    # jejepay.amount = amount
    # jejepay.save()
    go_to_url = request.session['dest_namespace_1']
    if go_to_url == None:
        go_to_url = request.session['dest_namespace_2']
        del request.session['dest_namespace_2']
    print "go url:", go_to_url
    del request.session['dest_namespace_1']
    #messages.info(request, response)
    return redirect(
        request.build_absolute_uri(
            reverse(go_to_url) + '?jejepay_ref=' + ref + '&resp=' + status))
示例#37
0
def demo_task(message):
    users = User.objects.all()
    has_subscription = False

    for user in users:
        #get active subscription
        try:
            active = Subscription.objects.get(user=user.id,
                                              is_active=True,
                                              has_expired=False)
            if active:
                start_date = active.start_date
                from datetime import datetime
                diff = datetime.now().date() - start_date
                date_diff = diff.days
                if active.package_subscribed is 4:
                    if date_diff >= 15:
                        active.has_expired = True
                        is_active = False
                        active.save()
                    else:
                        has_subscription = True

                elif active.package_subscribed is not 4:
                    if date_diff >= 30:
                        active.has_expired = True
                        is_active = False
                        active.save()
                    else:
                        has_subscription = True

        except Subscription.DoesNotExist:
            pass

        if not has_subscription:
            latest_plan = Subscription.objects.filter(
                user=user.id).order_by('-id')[:1]
            package = None
            for plan in latest_plan:
                package = plan.package_subscribed

            #Get users card
            users_card = Card.objects.filter(user=user.id)
            for card in users_card:

                from paystackapi.transaction import Transaction
                import uuid
                reference = get_random_string(length=20)
                print(reference)
                response = Transaction.charge(
                    reference=reference,
                    authorization_code=card.card_auth,
                    email=card.card_email,
                    amount=int(package.amount) * 100)
                print(response)

                if response['status'] == True and response['data'][
                        'status'] != 'failed':
                    subscription = Subscription(user=user,
                                                is_active=True,
                                                package_subscribed=package,
                                                has_expired=False)
                    subscription.save()
                    break
示例#38
0
def main(request):
    try:
        useraccount = UserAccount.objects.get(user=request.user)
        if not useraccount.profile_updated:
            messages.info(request,
                          'Please Update your profile to top up your wallet')
            return redirect('general:profile')
    except Exception as e:
        print "e", e
        messages.info(request,
                      'Please Update your profile to top up your wallet')
        return redirect('general:profile')
    if request.method == "POST":
        bot_catcher = request.POST.get('bot_catcher')
        # print "bot_catcher",bot_catcher
        payment_method = request.POST.get('payment-method')
        if bot_catcher != "botty":
            return redirect(reverse('general:homepage'))

        try:
            value = int(request.POST.get('amount'))
        except:
            messages.info(request, 'Invalid amount entered')
            return redirect('wallet:wallet')
        if payment_method == "bank":
            # print a
            random_ref = purchase_ref()
            bank_record = Bank.objects.create(
                user=request.user,
                txn_type="Add",
                amount=value,
                ref_no=random_ref,
                created_at=timezone.now,
                date_created=timezone.now().date(),
                bank="BANK DEPOSIT",
                message="Wallet Top up Via Bank Deposit")
            bank_record.save()
            print bank_record
            payment = Bank.objects.filter(user=request.user)
            return render(request, 'general_snippets/bank_details.html', {
                'ref': random_ref,
                'wallet': payment
            })
        if value > 20000:
            messages.info(
                request,
                'You have exceeded the Top up Limit, Pls enter an amount less than 20,000'
            )
            return redirect('wallet:wallet')
        # print "value", value
        amount = value * 100
        # print "amount", amount
        email = request.user.email

        #secret_key = 'sk_test_9fe140b2bf798accdc2aade269cac47bc2de7ecc'
        random_ref = purchase_ref()
        request.session['ref_no'] = random_ref
        url = 'wallet:verify_payment'
        callback_url = request.build_absolute_uri(reverse(url))
        # print "callback-url", callback_url
        response = Transaction.initialize(reference=random_ref,
                                          amount=amount,
                                          email=email,
                                          callback_url=callback_url)
        # print 'response:', response
        data = response.get('data')
        # print "data:", data
        authorization_code = data['access_code']
        # print "access_code", authorization_code
        url = data['authorization_url']
        # print 'url', url
        bank_record = Bank.objects.create(user=request.user,
                                          txn_type="Add",
                                          amount=value,
                                          ref_no=random_ref,
                                          created_at=timezone.now,
                                          date_created=timezone.now().date())
        bank_record.save()
        return redirect(url)
        # response = Transaction.charge(reference=random_ref,
        #                       authorization_code=authorization_code,
        #                       email=email,
        #                       amount=amount)
        # response_dict = Transaction.verify(reference=random_ref)
        # print "response_dict", response_dict
        #test_email = email
        #test_amount = amount
        #plan = 'Basic'
        # client = TransactionResource(secret_key, random_ref)
        # response = client.initialize(amount,email)
        # print"response",response
        # client.authorize() # Will open a browser window for client to enter card details
        # verify = client.verify() # Verify client credentials
        # print "verify", verify
        # print type(verify)
        # ref = verify.get('data')
        # print ref

        #client.charge(None,amount,email,random_ref)
        #print client.charge() # Charge an already exsiting client
    return render(request, 'wallet/topup.html')
示例#39
0
def mainPay(request):
    marketer = marketing_member(request)
    print "i got here"
    rp = request.POST
    print 'rp', rp
    if request.method == "POST":
        bot_catcher = request.POST.get('bot_catcher')
        print "bot_catcher", bot_catcher
        payment_method = request.POST.get('payment-method')
        if bot_catcher != "botty":
            return redirect(reverse('general:homepage'))
        try:
            value = int(request.POST.get('amount'))
        except:
            messages.info(request, 'Invalid amount entered')
            # return redirect('wallet:wallet')
            return redirect
        if payment_method == "bank":
            # print a
            random_ref = purchase_ref()

            bank_payment = MarketerPayment.objects.create(
                user=request.user.useraccount,
                payment_channel="Bank Payment",
                purchase_type_2="Add",
                created_at=timezone.now(),
                message="Vei Wallet Fund",
                amount=amount,
                ref_no=random_ref,
                marketer=marketer,
                bank=None,
                teller_no=random_ref)

            payment = MarketerPayment.objects.filter(
                user=request.user.useraccount)
            return redirect('wallet:wallet')
        # if value > 9999:
        #     messages.info(request, 'You have exceeded the Top up Limit, Pls enter an amount less than 10,000')
        #     return redirect('wallet:wallet')
        # print "value", value
        amount = value
        # print "amount", amount
        email = request.user.email

        #secret_key = 'sk_test_9fe140b2bf798accdc2aade269cac47bc2de7ecc'
        random_ref = purchase_ref()
        request.session['ref_no'] = random_ref
        request.session['user'] = request.user
        request.session['amount'] = amount
        url = 'wallet:verify_payment'
        callback_url = request.build_absolute_uri(reverse(url))
        print "callback-url", callback_url
        response = Transaction.initialize(reference=random_ref,
                                          amount=float(amount * 100),
                                          email=email,
                                          callback_url=callback_url)
        # print 'response:', response
        data = response.get('data')
        # print "data:", data
        authorization_code = data['access_code']
        # print "access_code", authorization_code
        url = data['authorization_url']
        # print 'url', url
        payment = MarketerPayment.objects.create(
            user=request.user.useraccount,
            payment_channel="Card Payment",
            purchase_type_2="Add",
            created_at=timezone.now(),
            message="Paystack Vei Wallet Fund",
            purchase_type_3="veiwallet",
            amount=amount,
            ref_no=random_ref,
            marketer=marketer,
            bank=None,
            teller_no=random_ref)

        user_acc = request.user.useraccount

        return redirect(url)

    return render(request, 'volkmann/vei_wallet.html')