Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

pull in price tiers, partial, add in api (bug 812511) #15

Merged
merged 1 commit into from

1 participant

@andymckay
Owner

No description provided.

@andymckay andymckay merged commit 123ecb8 into mozilla:master

1 check passed

Details default Jenkins build 'marketplace_webpay_github' #130 has succeeded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
0  lib/marketplace/__init__.py
No changes.
View
13 lib/marketplace/api.py
@@ -0,0 +1,13 @@
+from django.conf import settings
+
+from ..utils import SlumberWrapper
+
+
+class MarketplaceAPI(SlumberWrapper):
+ errors = {}
+
+ def get_price(self, tier):
+ return self.slumber.api.webpay.prices(id=tier).get()
+
+
+client = MarketplaceAPI(settings.MARKETPLACE_URL or 'http://example.com')
View
24 lib/marketplace/tests.py
@@ -0,0 +1,24 @@
+from django.test import TestCase
+
+import mock
+from nose.tools import eq_
+
+from lib.marketplace.api import client
+
+
+sample_price = {
+ u'name': u'Tier 0',
+ u'prices': [{u'amount': u'1.00', u'currency': u'USD'},
+ {u'amount': u'3.00', u'currency': u'JPY'}],
+ u'resource_uri': u'/api/webpay/prices/1/'
+}
+
+@mock.patch('lib.marketplace.api.client.slumber')
+class SolitudeAPITest(TestCase):
+
+ def test_get_prices(self, slumber):
+ sample = mock.Mock()
+ sample.get.return_value = sample_price
+ slumber.api.webpay.prices.return_value = sample
+ prices = client.get_price(1)
+ eq_(prices['name'], sample_price['name'])
View
31 lib/solitude/api.py
@@ -1,11 +1,9 @@
-import json
import logging
from django.conf import settings
-from slumber import API
-from slumber.exceptions import HttpClientError
+from ..utils import SlumberWrapper
from .errors import ERROR_STRINGS
@@ -17,14 +15,12 @@ class SellerNotConfigured(Exception):
"""The seller has not yet been configued for the payment."""
-class SolitudeAPI(object):
+class SolitudeAPI(SlumberWrapper):
"""A solitude API client.
:param url: URL of the solitude endpoint.
"""
-
- def __init__(self, url):
- self.slumber = API(url)
+ errors = ERROR_STRINGS
def _buyer_from_response(self, res):
buyer = {}
@@ -40,23 +36,6 @@ def _buyer_from_response(self, res):
buyer['uuid'] = res['uuid']
return buyer
- def parse_res(self, res):
- if res == '':
- return {}
- if isinstance(res, (str, unicode)):
- return json.loads(res)
- return res
-
- def safe_run(self, command, *args, **kwargs):
- try:
- res = command(*args, **kwargs)
- except HttpClientError as e:
- res = self.parse_res(e.response.content)
- for key, value in res.iteritems():
- res[key] = [ERROR_STRINGS[v] for v in value]
- return {'errors': res}
- return res
-
def buyer_has_pin(self, uuid):
"""Returns True if the existing buyer has a PIN.
@@ -180,7 +159,8 @@ def configure_product_for_billing(self, webpay_trans_id,
% (webpay_trans_id, bill_id))
return bill_id
- def create_product(self, external_id, product_name, currency, amount, seller):
+ def create_product(self, external_id, product_name, currency, amount,
+ seller):
"""
Creates a product and a Bango ID on the fly in solitude.
"""
@@ -213,7 +193,6 @@ def create_product(self, external_id, product_name, currency, amount, seller):
return bango['resource_uri']
-
if getattr(settings, 'SOLITUDE_URL', False):
client = SolitudeAPI(settings.SOLITUDE_URL)
else:
View
30 lib/utils.py
@@ -0,0 +1,30 @@
+import json
+
+from slumber import API
+from slumber.exceptions import HttpClientError
+
+
+class SlumberWrapper(object):
+ """
+ A wrapper around the Slumber API.
+ """
+
+ def __init__(self, url):
+ self.slumber = API(url)
+
+ def parse_res(self, res):
+ if res == '':
+ return {}
+ if isinstance(res, (str, unicode)):
+ return json.loads(res)
+ return res
+
+ def safe_run(self, command, *args, **kwargs):
+ try:
+ res = command(*args, **kwargs)
+ except HttpClientError as e:
+ res = self.parse_res(e.response.content)
+ for key, value in res.iteritems():
+ res[key] = [self.errors[v] for v in value]
+ return {'errors': res}
+ return res
View
3  webpay/settings/base.py
@@ -200,3 +200,6 @@
# This is the URL for the bango payment screen.
# It will receive one string substitution: the billing configuration ID.
BANGO_PAY_URL = 'http://mozilla.test.bango.org/mozpayments/?bcid=%s'
+
+# This is the URL to the marketplace.
+MARKETPLACE_URL = None
Something went wrong with that request. Please try again.