def start_pay(transaction_uuid, notes, **kw): """ Work with Solitude to begin a Bango payment. This puts the transaction in a state where it's ready to be fulfilled by Bango. """ # Because this is called from views, we get a new transaction every # time. If you re-use this task, you'd want to add some checking about the # transaction state. pay = notes['pay_request'] try: seller_uuid = get_seller_uuid(notes['issuer_key'], pay['request'].get('productData', '')) # Ask the marketplace for a valid price point. prices = mkt_client.get_price(pay['request']['pricePoint']) # Set up the product for sale. bill_id, seller_product = client.configure_product_for_billing( transaction_uuid, seller_uuid, pay['request']['id'], pay['request']['name'], # app/product name absolutify(reverse('bango.success')), absolutify(reverse('bango.error')), prices['prices'] ) client.slumber.generic.transaction(transaction_uuid).patch({ 'notes': json.dumps(notes), 'uid_pay': bill_id, 'status': constants.STATUS_PENDING }) except Exception, exc: log.exception('while configuring for payment') etype, val, tb = sys.exc_info() raise exc, None, tb
def start_pay(transaction_uuid, notes, **kw): """ Work with Solitude to begin a Bango payment. This puts the transaction in a state where it's ready to be fulfilled by Bango. """ # Because this is called from views, we get a new transaction every # time. If you re-use this task, you'd want to add some checking about the # transaction state. pay = notes["pay_request"] try: seller_uuid = get_seller_uuid(notes["issuer_key"], pay["request"].get("productData", "")) # Ask the marketplace for a valid price point. prices = mkt_client.get_price(pay["request"]["pricePoint"]) # Set up the product for sale. bill_id, seller_product = client.configure_product_for_billing( transaction_uuid, seller_uuid, pay["request"]["id"], pay["request"]["name"], # app/product name absolutify(reverse("bango.success")), absolutify(reverse("bango.error")), prices["prices"], ) trans_pk = client.slumber.generic.transaction.get_object(uuid=transaction_uuid)["resource_pk"] client.slumber.generic.transaction(trans_pk).patch( {"notes": json.dumps(notes), "uid_pay": bill_id, "status": constants.STATUS_PENDING} ) except Exception, exc: log.exception("while configuring for payment") etype, val, tb = sys.exc_info() raise exc, None, tb
def test_has_bango(self, slumber): slumber.generic.seller.get_object.return_value = self.seller slumber.bango.billing.post.return_value = { 'billingConfigurationId': 'bar' } slumber.bango.product.get_object.return_value = {'resource_uri': 'foo'} eq_(client.configure_product_for_billing(*range(0, 8)), ('bar', 'foo'))
def test_no_bango(self, slumber): slumber.generic.seller.get_object.return_value = self.seller slumber.bango.billing.post.return_value = { 'billingConfigurationId': 'bar' } slumber.bango.product.get_object.side_effect = ObjectDoesNotExist eq_(client.configure_product_for_billing(*range(0, 8)), ('bar', 'foo'))
def start_pay(transaction_uuid, notes, user_uuid, **kw): """ Work with Solitude to begin a Bango payment. This puts the transaction in a state where it's ready to be fulfilled by Bango. """ try: # This task is fired from multiple locations. This checks first to # see if it already ran. trans = (client.slumber.generic.transaction .get_object(uuid=transaction_uuid)) if trans['status'] in (constants.STATUS_RECEIVED, constants.STATUS_PENDING): log.info('trans %s (status=%r) already configured: ' 'skipping configure payments step' % (transaction_uuid, trans['status'])) return except ObjectDoesNotExist: pass pay = notes['pay_request'] try: seller_uuid = get_seller_uuid(notes['issuer_key'], pay['request'].get('productData', '')) # Ask the marketplace for a valid price point. prices = mkt_client.get_price(pay['request']['pricePoint']) log.debug('pricePoint=%s prices=%s' % (pay['request']['pricePoint'], prices['prices'])) try: icon_url = (get_icon_url(pay['request']) if settings.USE_PRODUCT_ICONS else None) except: log.exception('Calling get_icon_url') icon_url = None log.info('icon URL for %s: %s' % (transaction_uuid, icon_url)) # Set up the product for sale. bill_id, seller_product = client.configure_product_for_billing( transaction_uuid, seller_uuid, pay['request']['id'], pay['request']['name'], # app/product name absolutify(reverse('bango.success')), absolutify(reverse('bango.error')), prices['prices'], icon_url, user_uuid ) trans_pk = client.slumber.generic.transaction.get_object( uuid=transaction_uuid)['resource_pk'] client.slumber.generic.transaction(trans_pk).patch({ 'notes': json.dumps(notes), 'uid_pay': bill_id, 'status': constants.STATUS_PENDING }) except Exception, exc: log.exception('while configuring for payment') etype, val, tb = sys.exc_info() raise exc, None, tb
def test_has_bango(self, slumber): slumber.generic.seller.get_object_or_404.return_value = self.seller slumber.bango.billing.post.return_value = { 'billingConfigurationId': 'bar'} slumber.bango.product.get_object.return_value = { 'resource_uri': 'foo'} eq_(client.configure_product_for_billing(*range(0, 8)), ('bar', 'foo'))
def test_no_bango(self, slumber): slumber.generic.seller.get_object_or_404.return_value = self.seller slumber.bango.billing.post.return_value = { 'billingConfigurationId': 'bar'} slumber.bango.product.get_object_or_404.side_effect = ( ObjectDoesNotExist) eq_(client.configure_product_for_billing(*range(0, 8)), ('bar', 'foo'))
def start_pay(transaction_uuid, notes, user_uuid, **kw): """ Work with Solitude to begin a Bango payment. This puts the transaction in a state where it's ready to be fulfilled by Bango. """ pay = notes['pay_request'] product_data = urlparse.parse_qs(pay['request'].get('productData', '')) try: seller_uuid = get_seller_uuid(notes['issuer_key'], product_data) try: application_size = int(product_data['application_size'][0]) except (KeyError, ValueError): application_size = None # Ask the marketplace for a valid price point. prices = mkt_client.get_price(pay['request']['pricePoint']) log.debug('pricePoint=%s prices=%s' % (pay['request']['pricePoint'], prices['prices'])) try: icon_url = (get_icon_url(pay['request']) if settings.USE_PRODUCT_ICONS else None) except: log.exception('Calling get_icon_url') icon_url = None log.info('icon URL for %s: %s' % (transaction_uuid, icon_url)) # Set up the product for sale. bill_id, seller_id = client.configure_product_for_billing( transaction_uuid, seller_uuid, pay['request']['id'], pay['request']['name'], # app/product name absolutify(reverse('bango.success')), absolutify(reverse('bango.error')), prices['prices'], icon_url, user_uuid, application_size, ) trans_pk = client.slumber.generic.transaction.get_object( uuid=transaction_uuid)['resource_pk'] client.slumber.generic.transaction(trans_pk).patch({ 'notes': json.dumps(notes), 'uid_pay': bill_id, 'status': constants.STATUS_PENDING }) except Exception, exc: log.exception('while configuring for payment') etype, val, tb = sys.exc_info() raise exc, None, tb
def start_pay(transaction_uuid, notes, user_uuid, **kw): """ Work with Solitude to begin a Bango payment. This puts the transaction in a state where it's ready to be fulfilled by Bango. """ key = notes['issuer_key'] pay = notes['pay_request'] product_data = urlparse.parse_qs(pay['request'].get('productData', '')) try: seller_uuid = get_seller_uuid(key, product_data) try: application_size = int(product_data['application_size'][0]) except (KeyError, ValueError): application_size = None # Ask the marketplace for a valid price point. prices = mkt_client.get_price(pay['request']['pricePoint']) log.debug('pricePoint=%s prices=%s' % (pay['request']['pricePoint'], prices['prices'])) try: icon_url = (get_icon_url(pay['request']) if settings.USE_PRODUCT_ICONS else None) except: log.exception('Calling get_icon_url') icon_url = None log.info('icon URL for %s: %s' % (transaction_uuid, icon_url)) # Set up the product for sale. bill_id, seller_id = client.configure_product_for_billing( transaction_uuid, seller_uuid, pay['request']['id'], pay['request']['name'], # app/product name absolutify(reverse('bango.success')), absolutify(reverse('bango.error')), prices['prices'], icon_url, user_uuid, application_size, source='marketplace' if is_marketplace(key) else 'other' ) trans_pk = client.slumber.generic.transaction.get_object( uuid=transaction_uuid)['resource_pk'] client.slumber.generic.transaction(trans_pk).patch({ 'notes': json.dumps(notes), 'uid_pay': bill_id, 'status': constants.STATUS_PENDING }) except Exception, exc: log.exception('while configuring for payment') etype, val, tb = sys.exc_info() raise exc, None, tb
def start_pay(transaction_uuid, notes, **kw): """ Work with Solitude to begin a Bango payment. This puts the transaction in a state where it's ready to be fulfilled by Bango. """ # Because this is called from views, we get a new transaction every # time. If you re-use this task, you'd want to add some checking about the # transaction state. pay_request = notes['pay_request'] iss = Issuer.objects.get(pk=notes['issuer']) if notes['issuer'] else None try: seller_uuid = get_effective_issuer_key(iss, notes['issuer_key']) if seller_uuid == settings.KEY: # The issuer of the JWT is Firefox Marketplace. # This is a special case where we need to find the # actual Solitude/Bango seller_uuid to associate the # product to the right account. prod_data = pay_request['request'].get('productData', '') try: seller_uuid = urlparse.parse_qs(prod_data)['seller_uuid'][0] except KeyError: raise ValueError('Marketplace %r did not put a seller_uuid ' 'in productData: %r' % (settings.KEY, prod_data)) log.info('Using real seller_uuid %r for Marketplace %r ' 'app payment' % (seller_uuid, settings.KEY)) # Ask the marketplace for a valid price point. prices = mkt_client.get_price(pay_request['request']['pricePoint']) # Set up the product for sale. bill_id, seller_product = client.configure_product_for_billing( transaction_uuid, seller_uuid, pay_request['request']['id'], pay_request['request']['name'], # app/product name absolutify(reverse('bango.success')), absolutify(reverse('bango.error')), prices['prices'] ) client.slumber.generic.transaction(transaction_uuid).patch({ 'notes': json.dumps(notes), 'uid_pay': bill_id, 'status': constants.STATUS_PENDING }) except Exception, exc: log.exception('while configuring for payment') etype, val, tb = sys.exc_info() raise exc, None, tb
def start_pay(transaction_uuid, notes, **kw): """ Work with Solitude to begin a Bango payment. This puts the transaction in a state where it's ready to be fulfilled by Bango. """ # Because this is called from views, we get a new transaction every # time. If you re-use this task, you'd want to add some checking about the # transaction state. pay = notes['pay_request'] try: seller_uuid = get_seller_uuid(notes['issuer_key'], pay['request'].get('productData', '')) # Ask the marketplace for a valid price point. prices = mkt_client.get_price(pay['request']['pricePoint']) try: icon_url = (get_icon_url(pay['request']) if settings.USE_PRODUCT_ICONS else None) except: log.exception('Calling get_icon_url') icon_url = None log.info('icon URL for %s: %s' % (transaction_uuid, icon_url)) # Set up the product for sale. bill_id, seller_product = client.configure_product_for_billing( transaction_uuid, seller_uuid, pay['request']['id'], pay['request']['name'], # app/product name absolutify(reverse('bango.success')), absolutify(reverse('bango.error')), prices['prices'], icon_url, ) trans_pk = client.slumber.generic.transaction.get_object( uuid=transaction_uuid)['resource_pk'] client.slumber.generic.transaction(trans_pk).patch({ 'notes': json.dumps(notes), 'uid_pay': bill_id, 'status': constants.STATUS_PENDING }) except Exception, exc: log.exception('while configuring for payment') etype, val, tb = sys.exc_info() raise exc, None, tb
def test_no_seller(self, slumber): slumber.generic.seller.get_object.side_effect = ObjectDoesNotExist with self.assertRaises(SellerNotConfigured): client.configure_product_for_billing(*range(0, 10))
def test_has_bango(self, slumber): slumber.generic.seller.get_object.return_value = self.seller slumber.bango.billing.post.return_value = {"billingConfigurationId": "bar"} slumber.bango.product.get_object.return_value = {"resource_uri": "foo"} eq_(client.configure_product_for_billing(*range(0, 9)), ("bar", "foo"))
def test_no_bango(self, slumber): slumber.generic.seller.get_object.return_value = self.seller slumber.bango.billing.post.return_value = {"billingConfigurationId": "bar"} slumber.bango.product.get_object.side_effect = ObjectDoesNotExist eq_(client.configure_product_for_billing(*range(0, 9)), ("bar", "foo"))