trying to get country info
This commit is contained in:
@@ -1045,9 +1045,24 @@ def payments_view(request):
|
||||
)
|
||||
|
||||
# add code to store customer_id
|
||||
if not r.customer_id:
|
||||
result = gateway.customer.create(
|
||||
{
|
||||
'first_name':r.user.first_name,
|
||||
'last_name':r.user.last_name,
|
||||
'email':r.user.email,
|
||||
})
|
||||
|
||||
if not result.is_success:
|
||||
messages.error(request,'Failed to create customer. Please try again later')
|
||||
return render(request,
|
||||
"payments.html")
|
||||
else:
|
||||
r.customer_id = result.customer.id
|
||||
r.save()
|
||||
|
||||
client_token = gateway.client_token.generate({
|
||||
"customer_id": r.id,
|
||||
"customer_id": r.customer_id,
|
||||
})
|
||||
|
||||
return render(request,
|
||||
@@ -1081,6 +1096,9 @@ def checkouts_view(request):
|
||||
nonce_from_the_client = form.cleaned_data['payment_method_nonce']
|
||||
amount = form.cleaned_data['amount']
|
||||
amount = str(amount)
|
||||
|
||||
#for testing
|
||||
#nonce_from_the_client = 'fake-processor-declined-visa-none'
|
||||
|
||||
result = gateway.transaction.sale({
|
||||
"amount": amount,
|
||||
@@ -1091,6 +1109,21 @@ def checkouts_view(request):
|
||||
})
|
||||
if result.is_success:
|
||||
transaction = result.transaction
|
||||
if transaction.payment_instrument_type == "credit_card":
|
||||
country = transaction.credit_card_details.country_of_issuance
|
||||
if country == 'Unknown':
|
||||
bin = transaction.credit_card_details.bin
|
||||
url = "https://lookup.binlist.net/"+str(bin)
|
||||
headers = {
|
||||
'Accept-Version':'3',
|
||||
}
|
||||
binresult = requests.get(url,headers=headers)
|
||||
print binresult.status_code
|
||||
if binresult.status_code == 200:
|
||||
js = binresult.json()
|
||||
country = js['country']['name']
|
||||
|
||||
print country
|
||||
amount = transaction.amount
|
||||
messages.info(request,
|
||||
"We have successfully received your payment of {amount} Euro".format(
|
||||
|
||||
Reference in New Issue
Block a user