示例#1
0
    def get_or_create_generic_product(self, app, secret=None):
        product_data = {
            'public_id': self.get_or_create_public_id(app),
        }

        log.info('Checking generic seller exists: {0}'.format(product_data))
        try:
            generic = self.generic.product.get_object_or_404(**product_data)
        except ObjectDoesNotExist:
            seller_uuid = get_uuid('seller')
            seller = self.generic.seller.post(data={'uuid': seller_uuid})

            log.info('Creating a new Generic Solitude '
                     'Seller {seller_uuid} for app {app}'.format(
                         seller_uuid=seller_uuid,
                         app=app,
                     ))

            product_data.update({
                'external_id': make_external_id(app),
                'seller': seller['resource_uri'],
                'secret': secret or generate_key(48),
                'access': ACCESS_PURCHASE,
            })
            generic = self.generic.product.post(data=product_data)

            log.info('Creating a new Generic Solitude Product '
                     '{public_id} for app {app}'.format(
                         public_id=product_data['public_id'],
                         app=app,
                     ))

        return generic
示例#2
0
def in_app_config(request, addon_id, addon, webapp=True):
    inapp = addon.premium_type in amo.ADDON_INAPPS
    if not inapp:
        messages.error(request,
                       _('Your app is not configured for in-app payments.'))
        return redirect(reverse('mkt.developers.apps.payments',
                                args=[addon.app_slug]))
    try:
        account = addon.app_payment_account
    except ObjectDoesNotExist:
        messages.error(request, _('No payment account for this app.'))
        return redirect(reverse('mkt.developers.apps.payments',
                                args=[addon.app_slug]))

    seller_config = get_seller_product(account)

    owner = acl.check_addon_ownership(request, addon)
    if request.method == 'POST':
        # Reset the in-app secret for the app.
        (client.api.generic
               .product(seller_config['resource_pk'])
               .patch(data={'secret': generate_key(48)}))
        messages.success(request, _('Changes successfully saved.'))
        return redirect(reverse('mkt.developers.apps.in_app_config',
                                args=[addon.app_slug]))

    return jingo.render(request, 'developers/payments/in-app-config.html',
                        {'addon': addon, 'owner': owner,
                         'seller_config': seller_config})
示例#3
0
def in_app_config(request, addon_id, addon, webapp=True):
    if not addon.has_payment_account():
        messages.error(request, _('No payment account for this app.'))
        return redirect(
            reverse('mkt.developers.apps.payments', args=[addon.app_slug]))

    # TODO: support multiple accounts.
    account = addon.single_pay_account()
    seller_config = get_seller_product(account)

    owner = acl.check_addon_ownership(request, addon)
    if request.method == 'POST':
        # Reset the in-app secret for the app.
        (client.api.generic.product(seller_config['resource_pk']).patch(
            data={'secret': generate_key(48)}))
        messages.success(request, _('Changes successfully saved.'))
        return redirect(
            reverse('mkt.developers.apps.in_app_config',
                    args=[addon.app_slug]))

    return render(request, 'developers/payments/in-app-config.html', {
        'addon': addon,
        'owner': owner,
        'seller_config': seller_config
    })
示例#4
0
    def product_create(self, account, app):
        secret = generate_key(48)
        generic = self.get_or_create_generic_product(app, secret=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_provider.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']
示例#5
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']
示例#6
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']
示例#7
0
    def setup_bango(cls, provider, addon, payment_account):
        secret = generate_key(48)
        external_id = webpay.make_ext_id(addon.pk)
        data = {
            'seller': uri_to_pk(payment_account.seller_uri),
            'external_id': external_id
        }
        try:
            generic_product = client.api.generic.product.get_object(**data)
        except ObjectDoesNotExist:
            generic_product = client.api.generic.product.post(
                data={
                    'seller': payment_account.seller_uri,
                    'secret': secret,
                    'external_id': external_id,
                    'public_id': str(uuid.uuid4()),
                    'access': ACCESS_PURCHASE,
                })

        product_uri = generic_product['resource_uri']
        if provider == 'bango':
            uri = cls._create_bango(product_uri, addon, payment_account,
                                    secret)
        else:
            uri = ''
        return uri
示例#8
0
def in_app_config(request, addon_id, addon, webapp=True):
    inapp = addon.premium_type in amo.ADDON_INAPPS
    if not inapp:
        messages.error(request,
                       _('Your app is not configured for in-app payments.'))
        return redirect(reverse('mkt.developers.apps.payments',
                                args=[addon.app_slug]))
    try:
        account = addon.app_payment_account
    except ObjectDoesNotExist:
        messages.error(request, _('No payment account for this app.'))
        return redirect(reverse('mkt.developers.apps.payments',
                                args=[addon.app_slug]))

    seller_config = get_seller_product(account)

    owner = acl.check_addon_ownership(request, addon)
    if request.method == 'POST':
        # Reset the in-app secret for the app.
        (client.api.generic
               .product(seller_config['resource_pk'])
               .patch(data={'secret': generate_key(48)}))
        messages.success(request, _('Changes successfully saved.'))
        return redirect(reverse('mkt.developers.apps.in_app_config',
                                args=[addon.app_slug]))

    return render(request, 'developers/payments/in-app-config.html',
                  {'addon': addon, 'owner': owner,
                   'seller_config': seller_config})
示例#9
0
    def create(cls, provider, addon, payment_account):
        """Parameters:

        - provider:
            The provider that the product is to be created for. (currently only
            `bango`)
        - addon:
            The app that the product is being created for.
        - payment_account:
            The PaymentAccount object to tie the app to.

        """
        secret = generate_key(48)
        generic_product = client.upsert(
            method='product',
            params={'seller': payment_account.seller_uri, 'secret': secret,
                    'external_id': addon.pk},
            lookup_by=['external_id'])
        product_uri = generic_product['resource_uri']

        if provider == 'bango':
            uri = cls._create_bango(
                product_uri, addon, payment_account, secret)
        else:
            uri = ''

        return cls.objects.create(addon=addon, provider=provider,
                                  set_price=addon.premium.price.price,
                                  account_uri=payment_account.uri,
                                  product_uri=uri)
示例#10
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']

        created = self.client.products.post(
            data={
                'external_id': generic['external_id'],
                'seller_id': uri_to_pk(account.uri),
                'name': unicode(app.name),
                'uuid': str(uuid.uuid4()),
            })
        return created['resource_uri']
示例#11
0
文件: providers.py 项目: cvan/zamboni
    def get_or_create_generic_product(self, app, secret=None):
        product_data = {"public_id": self.get_or_create_public_id(app)}

        log.info("Checking generic seller exists: {0}".format(product_data))
        try:
            generic = self.generic.product.get_object_or_404(**product_data)
        except ObjectDoesNotExist:
            seller_uuid = get_uuid("seller")
            seller = self.generic.seller.post(data={"uuid": seller_uuid})

            log.info(
                "Creating a new Generic Solitude "
                "Seller {seller_uuid} for app {app}".format(seller_uuid=seller_uuid, app=app)
            )

            product_data.update(
                {
                    "external_id": make_external_id(app),
                    "seller": seller["resource_uri"],
                    "secret": secret or generate_key(48),
                    "access": ACCESS_PURCHASE,
                }
            )
            generic = self.generic.product.post(data=product_data)

            log.info(
                "Creating a new Generic Solitude Product "
                "{public_id} for app {app}".format(public_id=product_data["public_id"], app=app)
            )

        return generic
示例#12
0
    def get_or_create_generic_product(self, app, secret=None):
        product_data = {
            'public_id': self.get_or_create_public_id(app),
        }

        log.info('Checking generic seller exists: {0}'.format(product_data))
        try:
            generic = self.generic.product.get_object_or_404(**product_data)
        except ObjectDoesNotExist:
            seller_uuid = get_uuid('seller')
            seller = self.generic.seller.post(data={'uuid': seller_uuid})

            log.info('Creating a new Generic Solitude '
                     'Seller {seller_uuid} for app {app}'.format(
                         seller_uuid=seller_uuid,
                         app=app,
                     ))

            product_data.update({
                'external_id': make_external_id(app),
                'seller': seller['resource_uri'],
                'secret': secret or generate_key(48),
                'access': ACCESS_PURCHASE,
            })
            generic = self.generic.product.post(data=product_data)

            log.info('Creating a new Generic Solitude Product '
                     '{public_id} for app {app}'.format(
                         public_id=product_data['public_id'],
                         app=app,
                     ))

        return generic
示例#13
0
文件: genkey.py 项目: jostw/zamboni
 def handle(self, *args, **options):
     if os.path.exists(options["dest"]):
         raise CommandError(
             "Key file already exists at %s; remove it " "first or specify a new path with --dest" % options["dest"]
         )
     with open(options["dest"], "wb") as fp:
         fp.write(generate_key(options["length"]))
     os.chmod(options["dest"], 0600)
     print "Wrote cryptography key: %s" % options["dest"]
示例#14
0
文件: genkey.py 项目: wangeek/zamboni
 def handle(self, *args, **options):
     if os.path.exists(options['dest']):
         raise CommandError('Key file already exists at %s; remove it '
                            'first or specify a new path with --dest' %
                            options['dest'])
     with open(options['dest'], 'wb') as fp:
         fp.write(generate_key(options['length']))
     os.chmod(options['dest'], 0600)
     print 'Wrote cryptography key: %s' % options['dest']
示例#15
0
 def handle(self, *args, **options):
     if os.path.exists(options['dest']):
         raise CommandError('Key file already exists at %s; remove it '
                            'first or specify a new path with --dest'
                            % options['dest'])
     with open(options['dest'], 'wb') as fp:
         fp.write(generate_key(options['length']))
     os.chmod(options['dest'], 0600)
     print 'Wrote in-app payment key: %s' % options['dest']
示例#16
0
 def create(cls, user):
     sel = SolitudeSeller.create(user)
     prod = client.post_product(data={
         'seller': sel.resource_uri, 'secret': generate_key(48),
         'external_id': str(uuid.uuid4()), 'public_id': str(uuid.uuid4())
     })
     log.info('User %s created an in-app payments dev key product=%s '
              'with %s' % (user, prod['resource_pk'], sel))
     return cls.objects.create(solitude_seller=sel,
                               seller_product_pk=prod['resource_pk'])
示例#17
0
    def generate_private_key(cls, max_tries=40):
        """Generate a random 43 character secret key."""

        for key in limited_keygen(lambda: generate_key(43), max_tries):
            cursor = connection.cursor()
            cursor.execute('select count(*) from addon_inapp where '
                           'private_key = AES_ENCRYPT(%s, %s) ',
                           [key, _get_key()])
            if cursor.fetchone()[0] == 0:
                return key
示例#18
0
    def generate_private_key(cls, max_tries=40):
        """Generate a random 43 character secret key."""

        timestamp, enc_key = _get_key()
        for key in limited_keygen(lambda: generate_key(43), max_tries):
            cursor = connection.cursor()
            cursor.execute('select count(*) from addon_inapp where '
                           'private_key = AES_ENCRYPT(%s, %s) ',
                           [key, enc_key])
            if cursor.fetchone()[0] == 0:
                return key
示例#19
0
 def create(cls, user):
     sel = SolitudeSeller.create(user)
     # Create a product key that can only be used for simulated purchases.
     prod = client.api.generic.product.post(data={
         'seller': sel.resource_uri, 'secret': generate_key(48),
         'external_id': str(uuid.uuid4()), 'public_id': str(uuid.uuid4()),
         'access': ACCESS_SIMULATE,
     })
     log.info(u'User %s created an in-app payments dev key product=%s '
              u'with %s' % (unicode(user), prod['resource_pk'], sel))
     return cls.objects.create(solitude_seller=sel,
                               seller_product_pk=prod['resource_pk'])
示例#20
0
 def create(cls, user):
     sel = SolitudeSeller.create(user)
     # Create a product key that can only be used for simulated purchases.
     prod = client.api.generic.product.post(data={
         'seller': sel.resource_uri, 'secret': generate_key(48),
         'external_id': str(uuid.uuid4()), 'public_id': str(uuid.uuid4()),
         'access': ACCESS_SIMULATE,
     })
     log.info('User %s created an in-app payments dev key product=%s '
              'with %s' % (user, prod['resource_pk'], sel))
     return cls.objects.create(solitude_seller=sel,
                               seller_product_pk=prod['resource_pk'])
示例#21
0
文件: models.py 项目: fwenzel/zamboni
 def create(cls, user):
     sel = SolitudeSeller.create(user)
     prod = client.post_product(
         data={
             "seller": sel.resource_uri,
             "secret": generate_key(48),
             "external_id": str(uuid.uuid4()),
             "public_id": str(uuid.uuid4()),
         }
     )
     log.info("User %s created an in-app payments dev key product=%s " "with %s" % (user, prod["resource_pk"], sel))
     return cls.objects.create(solitude_seller=sel, seller_product_pk=prod["resource_pk"])
示例#22
0
 def create(cls, user):
     sel = SolitudeSeller.create(user)
     # Create a product key that can only be used for simulated purchases.
     prod = client.api.generic.product.post(
         data={
             "seller": sel.resource_uri,
             "secret": generate_key(48),
             "external_id": str(uuid.uuid4()),
             "public_id": str(uuid.uuid4()),
             "access": ACCESS_SIMULATE,
         }
     )
     log.info("User %s created an in-app payments dev key product=%s " "with %s" % (user, prod["resource_pk"], sel))
     return cls.objects.create(solitude_seller=sel, seller_product_pk=prod["resource_pk"])
示例#23
0
文件: models.py 项目: fwenzel/zamboni
    def create(cls, provider, addon, payment_account):
        """Parameters:

        - provider:
            The provider that the product is to be created for. (currently only
            `bango`)
        - addon:
            The app that the product is being created for.
        - payment_account:
            The PaymentAccount object to tie the app to.

        """
        secret = generate_key(48)
        external_id = webpay.make_ext_id(addon.pk)
        data = {"seller": cls.uri_to_pk(payment_account.seller_uri), "external_id": external_id}
        # TODO: convert to curling and clean out a bunch of this code.
        res = client.get_product(filters=data)
        if res["meta"]["total_count"] > 1:
            # This probably means that Solitude
            # ignored one of our filter parameters.
            log.info("AddonPaymentAccount product result: %s" % res)
            raise ValueError("Multiple products returned for %s" % data)
        elif res["meta"]["total_count"] == 1:
            generic_product = res["objects"][0]
        else:
            generic_product = client.post_product(
                data={
                    "seller": payment_account.seller_uri,
                    "secret": secret,
                    "external_id": external_id,
                    "public_id": str(uuid.uuid4()),
                }
            )
        product_uri = generic_product["resource_uri"]

        if provider == "bango":
            uri = cls._create_bango(product_uri, addon, payment_account, secret)
        else:
            uri = ""

        return cls.objects.create(
            addon=addon,
            provider=provider,
            payment_account=payment_account,
            set_price=addon.addonpremium.price.price,
            account_uri=payment_account.uri,
            product_uri=uri,
        )
示例#24
0
def in_app_config(request, addon_id, addon, webapp=True):
    """
    Allows developers to get a key/secret for doing in-app payments.
    """
    config = get_inapp_config(addon)

    owner = acl.check_addon_ownership(request, addon)
    if request.method == "POST":
        # Reset the in-app secret for the app.
        (client.api.generic.product(config["resource_pk"]).patch(data={"secret": generate_key(48)}))
        messages.success(request, _("Changes successfully saved."))
        return redirect(reverse("mkt.developers.apps.in_app_config", args=[addon.app_slug]))

    return render(
        request, "developers/payments/in-app-config.html", {"addon": addon, "owner": owner, "seller_config": config}
    )
示例#25
0
def in_app_config(request, addon_id, addon, webapp=True):
    account = addon.app_payment_account
    seller_config = (client.api.generic
                           .product(account.uri_to_pk(account.product_uri))
                           .get_object_or_404())

    owner = acl.check_addon_ownership(request, addon)
    if request.method == 'POST':
        (client.api.generic
               .product(seller_config['resource_pk'])
               .patch(data={'secret':generate_key(48)}))
        messages.success(request, _('Changes successfully saved.'))
        return redirect(reverse('mkt.developers.apps.in_app_config',
                                args=[addon.app_slug]))

    return jingo.render(request, 'developers/payments/in-app-config.html',
                        {'addon': addon, 'seller_config': seller_config,
                         'account': account, 'owner': owner})
示例#26
0
    def create(cls, user, public_id=None, secret=None, access_type=None):
        if public_id is None:
            public_id = str(uuid.uuid4())
        if secret is None:
            secret = generate_key(48)
        if access_type is None:
            access_type = ACCESS_SIMULATE

        sel = SolitudeSeller.create(user)
        prod = client.api.generic.product.post(data={
            'seller': sel.resource_uri, 'secret': secret,
            'external_id': str(uuid.uuid4()), 'public_id': public_id,
            'access': access_type,
        })
        log.info(u'User %s created an in-app payments dev key product=%s '
                 u'with %s' % (unicode(user), prod['resource_pk'], sel))
        return cls.objects.create(solitude_seller=sel,
                                  seller_product_pk=prod['resource_pk'])
示例#27
0
    def product_create(self, account, app):
        secret = generate_key(48)
        generic = self.get_or_create_generic_product(app, secret=secret)

        exists = generic['seller_uuids']['reference']
        if exists:
            log.info('Reference product already exists: %s' % exists)
            return generic['resource_uri']

        data = {
            'seller_product': generic['resource_uri'],
            'seller_reference': account.uri,
            'name': unicode(app.name),
            'uuid': get_uuid('reference-product')
        }
        log.info('Creating Reference product: %s, %s' % (account.pk, app.pk))
        created = self.client.products.post(data=data)
        return created['resource_uri']
示例#28
0
文件: models.py 项目: zzdjk6/zamboni
    def create(cls, provider, addon, payment_account):
        """Parameters:

        - provider:
            The provider that the product is to be created for. (currently only
            `bango`)
        - addon:
            The app that the product is being created for.
        - payment_account:
            The PaymentAccount object to tie the app to.

        """
        secret = generate_key(48)
        external_id = webpay.make_ext_id(addon.pk)
        data = {
            'seller': uri_to_pk(payment_account.seller_uri),
            'external_id': external_id
        }
        try:
            generic_product = client.api.generic.product.get_object(**data)
        except ObjectDoesNotExist:
            generic_product = client.api.generic.product.post(
                data={
                    'seller': payment_account.seller_uri,
                    'secret': secret,
                    'external_id': external_id,
                    'public_id': str(uuid.uuid4()),
                    'access': ACCESS_PURCHASE,
                })

        product_uri = generic_product['resource_uri']

        if provider == 'bango':
            uri = cls._create_bango(product_uri, addon, payment_account,
                                    secret)
        else:
            uri = ''

        return cls.objects.create(addon=addon,
                                  provider=provider,
                                  payment_account=payment_account,
                                  set_price=addon.addonpremium.price.price,
                                  account_uri=payment_account.uri,
                                  product_uri=uri)
示例#29
0
def in_app_config(request, addon_id, addon, webapp=True):
    """
    Allows developers to get a key/secret for doing in-app payments.
    """
    config = get_inapp_config(addon)

    owner = acl.check_addon_ownership(request, addon)
    if request.method == 'POST':
        # Reset the in-app secret for the app.
        (client.api.generic
               .product(config['resource_pk'])
               .patch(data={'secret': generate_key(48)}))
        messages.success(request, _('Changes successfully saved.'))
        return redirect(reverse('mkt.developers.apps.in_app_config',
                                args=[addon.app_slug]))

    return render(request, 'developers/payments/in-app-config.html',
                  {'addon': addon, 'owner': owner,
                   'seller_config': config})
示例#30
0
def in_app_config(request, addon_id, addon, webapp=True):
    """
    Allows developers to get a key/secret for doing in-app payments.
    """
    config = get_inapp_config(addon)

    owner = acl.check_addon_ownership(request, addon)
    if request.method == 'POST':
        # Reset the in-app secret for the app.
        (client.api.generic
               .product(config['resource_pk'])
               .patch(data={'secret': generate_key(48)}))
        messages.success(request, _('Changes successfully saved.'))
        return redirect(reverse('mkt.developers.apps.in_app_config',
                                args=[addon.app_slug]))

    return render(request, 'developers/payments/in-app-config.html',
                  {'addon': addon, 'owner': owner,
                   'seller_config': config})
示例#31
0
文件: models.py 项目: atsay/zamboni
    def create(cls, provider, addon, payment_account):
        """Parameters:

        - provider:
            The provider that the product is to be created for. (currently only
            `bango`)
        - addon:
            The app that the product is being created for.
        - payment_account:
            The PaymentAccount object to tie the app to.

        """
        secret = generate_key(48)
        external_id = webpay.make_ext_id(addon.pk)
        data = {'seller_uri': payment_account.seller_uri,
                'external_id': external_id}
        res = client.get_product(filters=data)
        if res['meta']['total_count'] > 1:
            # This probably means that Solitude
            # ignored one of our filter parameters.
            log.info('AddonPaymentAccount product result: %s' % res)
            raise ValueError('Multiple products returned for %s' % data)
        elif res['meta']['total_count'] == 1:
            generic_product = res['objects'][0]
        else:
            generic_product = client.post_product(data={
                'seller': payment_account.seller_uri, 'secret': secret,
                'external_id': external_id
            })
        product_uri = generic_product['resource_uri']

        if provider == 'bango':
            uri = cls._create_bango(
                product_uri, addon, payment_account, secret)
        else:
            uri = ''

        return cls.objects.create(addon=addon, provider=provider,
                                  payment_account=payment_account,
                                  set_price=addon.addonpremium.price.price,
                                  account_uri=payment_account.uri,
                                  product_uri=uri)
示例#32
0
文件: models.py 项目: wangeek/zamboni
    def create(cls, user, public_id=None, secret=None, access_type=None):
        if public_id is None:
            public_id = str(uuid.uuid4())
        if secret is None:
            secret = generate_key(48)
        if access_type is None:
            access_type = ACCESS_SIMULATE

        sel = SolitudeSeller.create(user)
        prod = client.api.generic.product.post(
            data={
                'seller': sel.resource_uri,
                'secret': secret,
                'external_id': str(uuid.uuid4()),
                'public_id': public_id,
                'access': access_type,
            })
        log.info(u'User %s created an in-app payments dev key product=%s '
                 u'with %s' % (unicode(user), prod['resource_pk'], sel))
        return cls.objects.create(solitude_seller=sel,
                                  seller_product_pk=prod['resource_pk'])
示例#33
0
    def setup_bango(cls, provider, addon, payment_account):
        secret = generate_key(48)
        external_id = webpay.make_ext_id(addon.pk)
        data = {'seller': uri_to_pk(payment_account.seller_uri),
                'external_id': external_id}
        try:
            generic_product = client.api.generic.product.get_object(**data)
        except ObjectDoesNotExist:
            generic_product = client.api.generic.product.post(data={
                'seller': payment_account.seller_uri, 'secret': secret,
                'external_id': external_id, 'public_id': str(uuid.uuid4()),
                'access': ACCESS_PURCHASE,
            })

        product_uri = generic_product['resource_uri']
        if provider == 'bango':
            uri = cls._create_bango(
                product_uri, addon, payment_account, secret)
        else:
            uri = ''
        return uri
示例#34
0
文件: providers.py 项目: cvan/zamboni
    def product_create(self, account, app):
        secret = generate_key(48)
        generic = self.get_or_create_generic_product(app, secret=secret)

        exists = generic["seller_uuids"]["reference"]
        if exists:
            log.info("Reference product already exists: %s" % exists)
            return generic["resource_uri"]

        uuid = get_uuid("reference-product")
        data = {
            "seller_product": generic["resource_uri"],
            "seller_reference": account.uri,
            "name": unicode(app.name),
            "uuid": uuid,
        }
        log.info(
            "Creating Reference product: "
            "account {ac}, app {app}, uuid {uuid}".format(ac=account.pk, app=app.pk, uuid=uuid)
        )
        created = self.client.products.post(data=data)
        return created["resource_uri"]
示例#35
0
    def product_create(self, account, app):
        secret = generate_key(48)
        generic = self.get_or_create_generic_product(app, secret=secret)

        exists = generic['seller_uuids']['reference']
        if exists:
            log.info('Reference product already exists: %s' % exists)
            return generic['resource_uri']

        uuid = get_uuid('reference-product')
        data = {
            'seller_product': generic['resource_uri'],
            'seller_reference': account.uri,
            'name': unicode(app.name),
            'uuid': uuid
        }
        log.info('Creating Reference product: '
                 'account {ac}, app {app}, uuid {uuid}'.format(ac=account.pk,
                                                               app=app.pk,
                                                               uuid=uuid))
        created = self.client.products.post(data=data)
        return created['resource_uri']
示例#36
0
    def create(cls, provider, addon, payment_account):
        """Parameters:

        - provider:
            The provider that the product is to be created for. (currently only
            `bango`)
        - addon:
            The app that the product is being created for.
        - payment_account:
            The PaymentAccount object to tie the app to.

        """
        secret = generate_key(48)
        external_id = webpay.make_ext_id(addon.pk)
        data = {'seller': cls.uri_to_pk(payment_account.seller_uri),
                'external_id': external_id}
        try:
            generic_product = client.api.generic.product.get_object(**data)
        except ObjectDoesNotExist:
            generic_product = client.api.generic.product.post(data={
                'seller': payment_account.seller_uri, 'secret': secret,
                'external_id': external_id, 'public_id': str(uuid.uuid4()),
                'access': ACCESS_PURCHASE,
            })

        product_uri = generic_product['resource_uri']

        if provider == 'bango':
            uri = cls._create_bango(
                product_uri, addon, payment_account, secret)
        else:
            uri = ''

        return cls.objects.create(addon=addon, provider=provider,
                                  payment_account=payment_account,
                                  set_price=addon.addonpremium.price.price,
                                  account_uri=payment_account.uri,
                                  product_uri=uri)
示例#37
0
    def setup_bango(cls, provider, addon, payment_account):
        secret = generate_key(48)
        external_id = webpay.make_ext_id(addon.pk)
        data = {"seller": uri_to_pk(payment_account.seller_uri), "external_id": external_id}
        try:
            generic_product = client.api.generic.product.get_object(**data)
        except ObjectDoesNotExist:
            generic_product = client.api.generic.product.post(
                data={
                    "seller": payment_account.seller_uri,
                    "secret": secret,
                    "external_id": external_id,
                    "public_id": str(uuid.uuid4()),
                    "access": ACCESS_PURCHASE,
                }
            )

        product_uri = generic_product["resource_uri"]
        if provider == "bango":
            uri = cls._create_bango(product_uri, addon, payment_account, secret)
        else:
            uri = ""
        return uri
示例#38
0
def in_app_config(request, addon_id, addon, webapp=True):
    if not addon.has_payment_account():
        messages.error(request, _('No payment account for this app.'))
        return redirect(reverse('mkt.developers.apps.payments',
                                args=[addon.app_slug]))

    # TODO: support multiple accounts.
    account = addon.single_pay_account()
    seller_config = get_seller_product(account)

    owner = acl.check_addon_ownership(request, addon)
    if request.method == 'POST':
        # Reset the in-app secret for the app.
        (client.api.generic
               .product(seller_config['resource_pk'])
               .patch(data={'secret': generate_key(48)}))
        messages.success(request, _('Changes successfully saved.'))
        return redirect(reverse('mkt.developers.apps.in_app_config',
                                args=[addon.app_slug]))

    return render(request, 'developers/payments/in-app-config.html',
                  {'addon': addon, 'owner': owner,
                   'seller_config': seller_config})
示例#39
0
    def create(cls, user, public_id=None, secret=None, access_type=None):
        if public_id is None:
            public_id = str(uuid.uuid4())
        if secret is None:
            secret = generate_key(48)
        if access_type is None:
            access_type = ACCESS_SIMULATE

        sel = SolitudeSeller.create(user)
        prod = client.api.generic.product.post(
            data={
                "seller": sel.resource_uri,
                "secret": secret,
                "external_id": str(uuid.uuid4()),
                "public_id": public_id,
                "access": access_type,
            }
        )
        log.info(
            u"User %s created an in-app payments dev key product=%s "
            u"with %s" % (unicode(user), prod["resource_pk"], sel)
        )
        return cls.objects.create(solitude_seller=sel, seller_product_pk=prod["resource_pk"])
示例#40
0
 def reset(self):
     self._product().patch(data={'secret': generate_key(48)})
示例#41
0
def in_app_config(request, addon_id, addon, webapp=True):
    try:
        account = addon.app_payment_account
    except ObjectDoesNotExist:
        messages.error(request, _("No payment account for this app."))
        return redirect(reverse("mkt.developers.apps.payments", args=[addon.app_slug]))

    seller_config = get_seller_product(account)

    owner = acl.check_addon_ownership(request, addon)
    if request.method == "POST":
        # Reset the in-app secret for the app.
        (client.api.generic.product(seller_config["resource_pk"]).patch(data={"secret": generate_key(48)}))
        messages.success(request, _("Changes successfully saved."))
        return redirect(reverse("mkt.developers.apps.in_app_config", args=[addon.app_slug]))

    return render(
        request,
        "developers/payments/in-app-config.html",
        {"addon": addon, "owner": owner, "seller_config": seller_config},
    )
示例#42
0
 def product_create(self, account, app):
     secret = generate_key(48)
     created = self.generic_create(account, app, secret)
     # Note this is setting the generic product account,
     # not the specific product uri.
     return created['resource_uri']
示例#43
0
 def product_create(self, account, app):
     secret = generate_key(48)
     created = self.generic_create(account, app, secret)
     # Note this is setting the generic product account,
     # not the specific product uri.
     return created['resource_uri']
示例#44
0
 def reset(self):
     self._product().patch(data={'secret': generate_key(48)})