trying to get country info
This commit is contained in:
@@ -235,7 +235,8 @@
|
|||||||
|
|
||||||
<h2>BrainTree Experimental Corner</h2>
|
<h2>BrainTree Experimental Corner</h2>
|
||||||
|
|
||||||
<form id="payment-form" method="post" action="/rowers/checkouts">
|
<form id="payment-form" method="post" action="/rowers/checkouts"
|
||||||
|
autocomplete="off">
|
||||||
<section>
|
<section>
|
||||||
<label for="amount">
|
<label for="amount">
|
||||||
<span class="input-label">Amount</span>
|
<span class="input-label">Amount</span>
|
||||||
|
|||||||
@@ -1045,9 +1045,24 @@ def payments_view(request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# add code to store customer_id
|
# 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({
|
client_token = gateway.client_token.generate({
|
||||||
"customer_id": r.id,
|
"customer_id": r.customer_id,
|
||||||
})
|
})
|
||||||
|
|
||||||
return render(request,
|
return render(request,
|
||||||
@@ -1082,6 +1097,9 @@ def checkouts_view(request):
|
|||||||
amount = form.cleaned_data['amount']
|
amount = form.cleaned_data['amount']
|
||||||
amount = str(amount)
|
amount = str(amount)
|
||||||
|
|
||||||
|
#for testing
|
||||||
|
#nonce_from_the_client = 'fake-processor-declined-visa-none'
|
||||||
|
|
||||||
result = gateway.transaction.sale({
|
result = gateway.transaction.sale({
|
||||||
"amount": amount,
|
"amount": amount,
|
||||||
"payment_method_nonce": nonce_from_the_client,
|
"payment_method_nonce": nonce_from_the_client,
|
||||||
@@ -1091,6 +1109,21 @@ def checkouts_view(request):
|
|||||||
})
|
})
|
||||||
if result.is_success:
|
if result.is_success:
|
||||||
transaction = result.transaction
|
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
|
amount = transaction.amount
|
||||||
messages.info(request,
|
messages.info(request,
|
||||||
"We have successfully received your payment of {amount} Euro".format(
|
"We have successfully received your payment of {amount} Euro".format(
|
||||||
|
|||||||
Reference in New Issue
Block a user