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')
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')
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})
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}
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_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'])
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')
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 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
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
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 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')
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))