Пример #1
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
Пример #2
0
    def test_prepare_pay(self):
        from mkt.purchase.webpay import make_ext_id

        data = self.post(self.prepare_pay)
        cn = Contribution.objects.get()
        eq_(cn.type, amo.CONTRIB_PENDING)
        eq_(cn.user, self.user)
        eq_(cn.price_tier, self.price)

        data = jwt.decode(data["webpayJWT"].encode("ascii"), verify=False)
        eq_(data["typ"], settings.APP_PURCHASE_TYP)
        eq_(data["aud"], settings.APP_PURCHASE_AUD)
        req = data["request"]
        eq_(req["pricePoint"], self.price.name)
        eq_(req["id"], make_ext_id(self.addon.pk))
        eq_(req["name"], unicode(self.addon.name))
        eq_(req["description"], unicode(self.addon.description))
        eq_(req["postbackURL"], absolutify(reverse("webpay.postback")))
        eq_(req["chargebackURL"], absolutify(reverse("webpay.chargeback")))
        eq_(req["icons"]["512"], absolutify(self.addon.get_icon_url(512)))
        pd = urlparse.parse_qs(req["productData"])
        eq_(pd["contrib_uuid"][0], cn.uuid)
        eq_(pd["seller_uuid"][0], self.seller.uuid)
        eq_(pd["addon_id"][0], str(self.addon.pk))
        eq_(pd["application_size"][0], "388096")
Пример #3
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}
        # 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,
        )
Пример #4
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
Пример #5
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': 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)
Пример #6
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_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)
Пример #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 test_prepare_pay(self):
        from mkt.purchase.webpay import make_ext_id
        data = self.post(self.prepare_pay)
        cn = Contribution.objects.get()
        eq_(cn.type, amo.CONTRIB_PENDING)
        eq_(cn.user, self.user)
        eq_(cn.price_tier, self.price)

        data = jwt.decode(data['webpayJWT'].encode('ascii'), verify=False)
        eq_(data['typ'], settings.APP_PURCHASE_TYP)
        eq_(data['aud'], settings.APP_PURCHASE_AUD)
        req = data['request']
        eq_(req['pricePoint'], self.price.pk)
        eq_(req['id'], make_ext_id(self.addon.pk))
        eq_(req['name'], unicode(self.addon.name))
        eq_(req['description'], unicode(self.addon.summary))
        eq_(req['postbackURL'], absolutify(reverse('webpay.postback')))
        eq_(req['chargebackURL'], absolutify(reverse('webpay.chargeback')))
        pd = urlparse.parse_qs(req['productData'])
        eq_(pd['contrib_uuid'][0], cn.uuid)
        eq_(pd['seller_uuid'][0], self.seller.uuid)
        eq_(pd['addon_id'][0], str(self.addon.pk))
Пример #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 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)
Пример #11
0
    def test_prepare_pay(self):
        from mkt.purchase.webpay import make_ext_id
        data = self.post(self.prepare_pay)
        cn = Contribution.objects.get()
        eq_(cn.type, amo.CONTRIB_PENDING)
        eq_(cn.user, self.user)
        eq_(cn.price_tier, self.price)

        data = jwt.decode(data['webpayJWT'].encode('ascii'), verify=False)
        eq_(data['typ'], settings.APP_PURCHASE_TYP)
        eq_(data['aud'], settings.APP_PURCHASE_AUD)
        req = data['request']
        eq_(req['pricePoint'], self.price.name)
        eq_(req['id'], make_ext_id(self.addon.pk))
        eq_(req['name'], unicode(self.addon.name))
        eq_(req['description'], unicode(self.addon.summary))
        eq_(req['postbackURL'], absolutify(reverse('webpay.postback')))
        eq_(req['chargebackURL'], absolutify(reverse('webpay.chargeback')))
        eq_(req['icons']['512'], absolutify(self.addon.get_icon_url(512)))
        pd = urlparse.parse_qs(req['productData'])
        eq_(pd['contrib_uuid'][0], cn.uuid)
        eq_(pd['seller_uuid'][0], self.seller.uuid)
        eq_(pd['addon_id'][0], str(self.addon.pk))
Пример #12
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