Skip to content
This repository has been archived by the owner on Jan 25, 2018. It is now read-only.

Commit

Permalink
add in event notification endpoints (bug 866939)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy McKay committed Jun 6, 2013
1 parent 5807f7d commit 53a6ecc
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 8 deletions.
13 changes: 10 additions & 3 deletions docs/topics/setup.rst
Expand Up @@ -70,8 +70,6 @@ settings::
SITE_URL = 'http://your.solitude.instance/'
STATSD_CLIENT = 'django_statsd.clients.null'

PAYPAL_USE_SANDBOX = True

Solitude requires some keys on the file system. For each key in `base.py`,
copy into `local.py` and point to a file that makes sense for your install. For
example::
Expand Down Expand Up @@ -106,7 +104,7 @@ To actually talk to PayPal you'll need to setup the following settings. These
are the settings for the Sandbox, meaning you can test Solitude without using
real money::


PAYPAL_USE_SANDBOX = True
PAYPAL_APP_ID = 'the.app.id.from.paypal'
PAYPAL_AUTH = {'USER': 'the.paypal.user',
'PASSWORD': 'the.paypal.password',
Expand Down Expand Up @@ -151,6 +149,15 @@ you'll have need to setup the following::
BANGO_AUTH = {'USER': 'the.bango.username',
'PASSWORD': 'the.bango.password'}

Solitude receives calls from Bango. Bango needs to know a URL and a
username and password for them. Example::

BANGO_BASIC_AUTH = {'USER': 'a.username',
'PASSWORD': 'a.password'}
BANGO_NOTIFICATION_URL = 'https://your.site/notification'

These are passed to Bango each time a package is created.

Running Locally
~~~~~~~~~~~~~~~

Expand Down
9 changes: 8 additions & 1 deletion lib/bango/forms.py
Expand Up @@ -51,13 +51,20 @@ class PackageForm(forms.Form):
countryIso = forms.CharField()
currencyIso = forms.CharField()
homePageURL = forms.CharField(required=False)
eventNotificationURL = forms.CharField(required=False)

seller = URLField(to='lib.sellers.resources.SellerResource')

@property
def bango_data(self):
result = self.cleaned_data.copy()
del result['seller']
if settings.BANGO_NOTIFICATION_URL:
result.update({
'eventNotificationURL': settings.BANGO_NOTIFICATION_URL,
'eventNotificationUsername': settings.BANGO_BASIC_AUTH['USER'],
'eventNotificationPassword':
settings.BANGO_BASIC_AUTH['PASSWORD'],
})
return result


Expand Down
20 changes: 18 additions & 2 deletions lib/bango/tests/test_forms.py
Expand Up @@ -7,8 +7,8 @@

from ..forms import (CreateBankDetailsForm,
CreateBillingConfigurationForm as BillingForm, EventForm,
PriceForm, VatNumberForm)
from .samples import (event_notification, good_bank_details,
PackageForm, PriceForm, VatNumberForm)
from .samples import (event_notification, good_address, good_bank_details,
good_billing_request)
from lib.sellers.models import Seller, SellerProduct
from lib.transactions import constants
Expand Down Expand Up @@ -80,6 +80,22 @@ def test_iterate(self, clean):
ok_(price.is_valid())


@mock.patch('lib.bango.forms.URLField.clean')
class TestPackage(APITest):

def test_no_auth(self, clean):
form = PackageForm(good_address)
ok_(form.is_valid())
ok_(not 'eventNotificationURL' in form.bango_data)

def test_auth(self, clean):
with self.settings(BANGO_NOTIFICATION_URL='http://f.com',
BANGO_BASIC_AUTH={'USER': 'u', 'PASSWORD': 'p'}):
form = PackageForm(good_address)
ok_(form.is_valid())
eq_(form.bango_data['eventNotificationURL'], 'http://f.com')


class TestVat(APITest):

def test_delete(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/bango/tests/test_resources.py
Expand Up @@ -100,7 +100,7 @@ def test_create(self):
def good_data(self):
post = samples.good_address.copy()
post['seller'] = ('/generic/seller/%s/' %
Seller.objects.create(uuid=self.uuid).pk)
Seller.objects.get_or_create(uuid=self.uuid)[0].pk)
return post

@mock.patch.object(ClientMock, 'mock_results')
Expand Down
13 changes: 13 additions & 0 deletions settings_test.py
@@ -1,5 +1,9 @@
# test_utils picks this file up for testing.
import atexit
import os
import shutil
from tempfile import gettempdir

from solitude.settings.base import *

filename = os.path.join(os.path.dirname(__file__), 'sample.key')
Expand Down Expand Up @@ -53,3 +57,12 @@
SITE_URL = 'http://localhost/'

SEND_USER_ID_TO_BANGO = True

# Suds keeps a cache of the WSDL around, so after completing the test run,
# lets remove that so it doesn't affect the next test run.
def _cleanup():
target = os.path.join(gettempdir(), 'suds')
if os.path.exists(target):
shutil.rmtree(target)

atexit.register(_cleanup)
4 changes: 4 additions & 0 deletions solitude/settings/base.py
Expand Up @@ -207,6 +207,10 @@
# These are the credentials for Bango calling us.
BANGO_BASIC_AUTH = {'USER': '', 'PASSWORD': ''}

# The URL that Bango will send notifications too. If this is not set, the
# notification URL will not be set.
BANGO_NOTIFICATION_URL = ''

# Anything less than this USD price will be considerd a micro
# payment. Purchases at these prices cannot be made with credit cards.
BANGO_MAX_MICRO_AMOUNT = Decimal('0.99')
Expand Down
6 changes: 5 additions & 1 deletion solitude/settings/sites/dev/db.py
Expand Up @@ -48,6 +48,10 @@
PAYPAL_URL_WHITELIST = ('https://marketplace-dev.allizom.org',)

BANGO_PROXY = private.BANGO_PROXY
SITE_URL = 'https://payments-dev.allizom.org'
BANGO_NOTIFICATION_URL = (
'https://marketplace-dev.allizom.org/mozpay/bango/notification')
# BANGO_BASIC_AUTH = private.BANGO_BASIC_AUTH

BANGO_FAKE_REFUNDS = True

SITE_URL = 'https://payments-dev.allizom.org'
4 changes: 4 additions & 0 deletions solitude/settings/sites/prod/db.py
Expand Up @@ -47,4 +47,8 @@

BANGO_ENV = 'prod'
BANGO_PROXY = private.BANGO_PROXY
BANGO_NOTIFICATION_URL = (
'https://marketplace.firefox.com/mozpay/bango/notification')
# BANGO_BASIC_AUTH = private.BANGO_BASIC_AUTH

SITE_URL = 'https://payments.firefox.com'
4 changes: 4 additions & 0 deletions solitude/settings/sites/stage/db.py
Expand Up @@ -47,4 +47,8 @@

BANGO_ENV = 'prod'
BANGO_PROXY = private.BANGO_PROXY
BANGO_NOTIFICATION_URL = (
'https://marketplace.allizom.org/mozpay/bango/notification')
# BANGO_BASIC_AUTH = private.BANGO_BASIC_AUTH

SITE_URL = 'https://payments.allizom.org'

0 comments on commit 53a6ecc

Please sign in to comment.