示例#1
0
    def product_create(self, account, app):
        secret = generate_key(48)
        generic = self.generic_create(account, app, secret)

        # These just pass straight through to zippy to create the product
        # and don't create any intermediate objects in solitude.
        #
        # Until bug 948240 is fixed, we have to do this, again.
        try:
            created = self.client.products.get(
                external_id=generic['external_id'],
                seller_id=uri_to_pk(account.uri))
        except HttpClientError:
            created = []

        if len(created) > 1:
            raise ValueError('Zippy returned more than one resource.')

        elif len(created) == 1:
            return created[0]['resource_uri']

        # Note that until zippy get some persistence, this will just
        # throw a 409 if the seller doesn't exist.
        created = self.client.products.post(data={
            'external_id': generic['external_id'],
            'seller_id': uri_to_pk(account.uri),
            'name': unicode(app.name),
        })
        return created['resource_uri']
示例#2
0
def get_seller_product(account):
    """
    Get the solitude seller_product for a payment account object.
    """
    bango_product = client.api.bango.product(uri_to_pk(account.product_uri)).get_object_or_404()
    # TODO(Kumar): we can optimize this by storing the seller_product
    # when we create it in developers/models.py or allowing solitude
    # to filter on both fields.
    return client.api.generic.product(uri_to_pk(bango_product["seller_product"])).get_object_or_404()
示例#3
0
    def product_create(self, account, app):
        secret = generate_key(48)
        generic = self.generic_create(account, app, secret)
        product_uri = generic['resource_uri']
        data = {'seller_product': uri_to_pk(product_uri)}

        # There are specific models in solitude for Bango details.
        # These are SellerBango and SellerProductBango that store Bango
        # details such as the Bango Number.
        #
        # Solitude calls Bango to set up whatever it needs.
        try:
            res = self.client.product.get_object_or_404(**data)
        except ObjectDoesNotExist:
            # The product does not exist in Solitude so create it.
            res = self.client.product.post(data={
                'seller_bango': account.uri,
                'seller_product': product_uri,
                'name': unicode(app.name),
                'packageId': account.account_id,
                'categoryId': 1,
                'secret': secret
            })

        return res['resource_uri']
示例#4
0
 def account_retrieve(self, account):
     data = {'account_name': account.name}
     package_data = (self.client.package(uri_to_pk(account.uri))
                     .get(data={'full': True}))
     data.update((k, v) for k, v in package_data.get('full').items() if
                 k in self.package_values)
     return data
def get_generic_product(app):
    if app.app_payment_accounts.exists():
        for account in app.app_payment_accounts.all():
            print (
                'Looking up public_id for app '
                '{app} using account {account}'
            ).format(
                app=app,
                account=account.payment_account.seller_uri)
            try:
                generic_product = Provider.generic.product.get_object(
                    seller=uri_to_pk(account.payment_account.seller_uri),
                    external_id=make_external_id(app))
                print (
                    'Found generic product {product} for '
                    'app {app} using account {account}'
                ).format(
                    product=generic_product['public_id'],
                    app=app,
                    account=account)
                return generic_product
            except ObjectDoesNotExist:
                pass
            except MultipleObjectsReturned:
                print 'Found multiple generic products for app {app}'.format(
                    app=app)
        print 'Unable to find a generic product for app {app}'.format(app=app)
示例#6
0
 def test_show_secret(self, solitude):
     self.set_mocks(solitude)
     resp = self.client.get(self.url)
     eq_(resp.content, 'shhh!')
     pk = uri_to_pk(self.account.product_uri)
     solitude.api.bango.product.assert_called_with(pk)
     solitude.api.generic.product.assert_called_with('prod-pk')
def get_generic_product(app):
    if app.app_payment_accounts.exists():
        account = app.app_payment_accounts.all()[:1].get()
        generic_product = Provider.generic.product.get_object(
            seller=uri_to_pk(account.payment_account.seller_uri),
            external_id=make_external_id(app),
        )
        return generic_product
示例#8
0
def get_generic_product(app):
    if app.app_payment_accounts.exists():
        account = app.app_payment_accounts.all()[:1].get()
        generic_product = Provider.generic.product.get_object(
            seller=uri_to_pk(account.payment_account.seller_uri),
            external_id=make_external_id(app),
        )
        return generic_product
示例#9
0
    def generic_create(self, account, app, secret):
        # This sets the product up in solitude.
        external_id = webpay.make_ext_id(app.pk)
        data = {'seller': uri_to_pk(account.seller_uri),
                'external_id': external_id}

        # Create the generic product.
        try:
            generic = self.generic.product.get_object_or_404(**data)
        except ObjectDoesNotExist:
            generic = self.generic.product.post(data={
                'seller': account.seller_uri, 'secret': secret,
                'external_id': external_id, 'public_id': str(uuid.uuid4()),
                'access': ACCESS_PURCHASE,
            })

        return generic
示例#10
0
    def generic_create(self, account, app, secret):
        # This sets the product up in solitude.
        external_id = WebAppProduct(app).external_id()
        data = {'seller': uri_to_pk(account.seller_uri),
                'external_id': external_id}

        # Create the generic product.
        try:
            generic = self.generic.product.get_object_or_404(**data)
        except ObjectDoesNotExist:
            generic = self.generic.product.post(data={
                'seller': account.seller_uri, 'secret': secret,
                'external_id': external_id, 'public_id': str(uuid.uuid4()),
                'access': ACCESS_PURCHASE,
            })

        return generic
示例#11
0
    def generic_create(self, account, app, secret):
        # This sets the product up in solitude.
        external_id = WebAppProduct(app).external_id()
        data = {"seller": uri_to_pk(account.seller_uri), "external_id": external_id}

        # Create the generic product.
        try:
            generic = self.generic.product.get_object_or_404(**data)
        except ObjectDoesNotExist:
            generic = self.generic.product.post(
                data={
                    "seller": account.seller_uri,
                    "secret": secret,
                    "external_id": external_id,
                    "public_id": str(uuid.uuid4()),
                    "access": ACCESS_PURCHASE,
                }
            )

        return generic
def get_generic_product(app):
    if app.app_payment_accounts.exists():
        for account in app.app_payment_accounts.all():
            print(
                'Looking up public_id for app '
                '{app} using account {account}').format(
                    app=app, account=account.payment_account.seller_uri)
            try:
                generic_product = Provider.generic.product.get_object(
                    seller=uri_to_pk(account.payment_account.seller_uri),
                    external_id=make_external_id(app))
                print(
                    'Found generic product {product} for '
                    'app {app} using account {account}').format(
                        product=generic_product['public_id'],
                        app=app,
                        account=account)
                return generic_product
            except ObjectDoesNotExist:
                pass
            except MultipleObjectsReturned:
                print 'Found multiple generic products for app {app}'.format(
                    app=app)
        print 'Unable to find a generic product for app {app}'.format(app=app)
示例#13
0
文件: providers.py 项目: cvan/zamboni
 def account_retrieve(self, account):
     data = {"account_name": account.name}
     package_data = self.client.package(uri_to_pk(account.uri)).get(data={"full": True})
     data.update((k, v) for k, v in package_data.get("full").items() if k in self.package_values)
     return data