Permalink
Browse files

#25 USD to BRL conversion = (rate from Google) x 1.045

  • Loading branch information...
1 parent 205ce3b commit 6fddb6da5d6b77967872c6653cef2b6cfd251182 @tonylampada tonylampada committed Oct 22, 2012
View
@@ -19,7 +19,7 @@ git clone git://github.com/freedomsponsors/www.freedomsponsors.org.git
# 2.1 Install dependencies
- sudo pip install django splinter pygments misaka psycopg2 simplejson coverage
+ sudo pip install django splinter pygments misaka psycopg2 simplejson coverage python-dateutil
# Depending on your environment, psycopg2 installation with pip might fail.
# If that's your case, you might also wanna try.
@@ -4,6 +4,7 @@
from core.utils.paypal_adapter import generate_paypal_payment
from core.utils.frespo_utils import get_or_none
from core.models import Payment, Offer, Solution, PaymentPart
+from core.utils import google_calc_adapter
import logging
logger = logging.getLogger(__name__)
@@ -63,3 +64,7 @@ def process_ipn_return(paykey, status):
notify_payment_parties_paymentconfirmed(payment) #TODO Mover pro IPN
else:
logger.warn('received a ' + status + ' IPN confirmation')
+
+def usd_2_brl_convert_rate():
+ return google_calc_adapter.usd2brl() * 1.045
+
@@ -0,0 +1,7 @@
+import requests
+
+def usd2brl():
+ url = 'http://www.google.com/ig/calculator?hl=en&q=1USD%3D%3FBRL'
+ response = requests.get(url)
+ #sample response.content: '{lhs: "1 U.S. dollar",rhs: "2.02739826 Brazil reais",error: "",icc: true}'
+ return float(response.content.split('rhs:')[1].split(',')[0].split('"')[1].split(' ')[0])
@@ -56,5 +56,5 @@ def verify_ipn(data):
# If not verified
if not status == "VERIFIED":
return False
-
+
return True
@@ -2,16 +2,16 @@
from django.http import HttpResponse
from django.shortcuts import redirect, render_to_response
from django.template import RequestContext
-from core.utils.frespo_utils import get_or_none, dictOrEmpty
+from core.utils.frespo_utils import get_or_none, dictOrEmpty, twoplaces
from core.models import *
-from core.services import issue_services, watch_services
+from core.services import issue_services, watch_services, payment_services
+from decimal import Decimal
import logging
logger = logging.getLogger(__name__)
__author__ = 'tony'
-
@login_required
def addIssue(request):
try:
@@ -219,12 +219,13 @@ def payOfferForm(request, offer_id):
currency_symbol = "US$"
alert_brazil = False
if(offer.sponsor.getUserInfo().brazilianPaypal):
- convert_rate = 2
+ convert_rate = payment_services.usd_2_brl_convert_rate()
currency_symbol = "R$"
alert_brazil = True
if(solutions_done.count() > 0):
- shared_price = convert_rate* offer.price / solutions_done.count()
+ shared_price = convert_rate * float(offer.price) / solutions_done.count()
+ shared_price = twoplaces(Decimal(shared_price))
return render_to_response('core/pay_offer.html',
{'offer':offer,
@@ -4,12 +4,15 @@
from core_splinter_tests.tests import FrespoSplinterTestCase
from django.test import LiveServerTestCase
from helpers import testdata as td
+from django.utils.unittest import skipIf
+from frespo import env_settings
import traceback
__author__ = 'tony'
waitifbreak = 1
+@skipIf(env_settings.ENVIRONMENT != 'DEV', 'not supported in this environment')
class PaymentTests(FrespoSplinterTestCase):
# def onAppCreate(self):
# self.app.createGoogleSession(td.userDict1)
@@ -4,13 +4,13 @@
from splintertests_issues import FrespoSplinterTestCase
from django.utils.unittest import skipIf
from django.conf import settings
+from frespo import env_settings
waitifbreak = 1
__author__ = 'tony'
-@skipIf(True, 'not supported in this environment')
-# @skipIf(settings.SKIP_GOOGLE_TESTS, 'not supported in this environment')
+@skipIf(env_settings.ENVIRONMENT != 'DEV', 'not supported in this environment')
class AccountCreationTests(FrespoSplinterTestCase):
def needs_users(self):
return False
@@ -15,7 +15,6 @@ DEBUG = True
FAKE_EMAILS= True
FAKE_EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
#FAKE_EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
-SKIP_GOOGLE_TESTS = True
DATABASE_NAME = 'frespo'
DATABASE_USER = 'postgres'
@@ -16,8 +16,6 @@
DATABASE_USER = env_settings.DATABASE_USER
DATABASE_PASS = env_settings.DATABASE_PASS
-SKIP_GOOGLE_TESTS = env_settings.SKIP_GOOGLE_TESTS
-
TEMPLATE_DEBUG = DEBUG
MANAGERS = ADMINS
@@ -40,14 +40,14 @@ <h2>Pay US$ {{offer.price}} for issue - {{offer.issue.title}} </h2>
<!-- <tr>
<td> -->
- <div class="form-inline">
+ <div>
<div class="span2">
<input type="hidden" checked id="solutionId_{{forloop.counter0}}" name="solutionId_{{forloop.counter0}}" value="{{solution.id}}">
<input type="checkbox" class="sol_checkbox" checked id="check_{{forloop.counter0}}" name="check_{{forloop.counter0}}">
<img src="{{solution.programmer.gravatar_url_small}}"/> {{ solution.programmer.getUserInfo.screenName }}
</div>
- <div class="span2">
- <input type="text" id="pay_{{forloop.counter0}}" name="pay_{{forloop.counter0}}" class="span6 positive" value="{{shared_price}}" placeholder="{{currency_symbol}}">
+ <div class="span2 input-prepend">
+ <span class="add-on">{{currency_symbol}}</span><input type="text" id="pay_{{forloop.counter0}}" name="pay_{{forloop.counter0}}" class="span6 positive" value="{{shared_price}}">
</div>
<div class="span8"></div>
</div><br><br>

0 comments on commit 6fddb6d

Please sign in to comment.