本文整理汇总了Python中mkt.webpay.webpay_jwt.get_product_jwt函数的典型用法代码示例。如果您正苦于以下问题:Python get_product_jwt函数的具体用法?Python get_product_jwt怎么用?Python get_product_jwt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_product_jwt函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: debug
def debug(request, addon):
if not settings.DEBUG:
raise http.Http404
context = {
'app': addon,
'inapps': [],
'urls': {'es': '%s/apps/webapp/%s' % (settings.ES_URLS[0], addon.pk)},
}
if addon.is_premium():
contribution = Contribution.objects.create(addon=addon)
context['app_jwt'] = get_product_jwt(
WebAppProduct(addon),
contribution,
)['webpayJWT']
for inapp in addon.inappproduct_set.all():
contribution = Contribution.objects.create(
addon=addon,
inapp_product=inapp,
)
context['inapps'].append({
'inapp': inapp,
'jwt': get_product_jwt(
InAppProduct(inapp),
contribution,
)['webpayJWT'],
})
return render(request, 'developers/debug.html', context)
示例2: post
def post(self, request, *args, **kwargs):
form = PrepareInAppForm(request.DATA)
if not form.is_valid():
app_pay_cef.log(
request._request,
'Preparing InApp JWT Failed',
'preparing_inapp_jwt_failed',
'Preparing InApp JWT Failed error: {0}'.format(form.errors),
severity=3
)
return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
inapp = form.cleaned_data['inapp']
app_pay_cef.log(
request._request,
'Preparing InApp JWT',
'preparing_inapp_jwt',
'Preparing InApp JWT for: {0}'.format(inapp.pk), severity=3
)
token = get_product_jwt(
InAppProduct(inapp),
client_data=ClientData.get_or_create(request._request),
lang=request._request.LANG,
source=request._request.REQUEST.get('src', ''),
)
return Response(token, status=status.HTTP_201_CREATED)
示例3: prepare_pay
def prepare_pay(request, addon):
if addon.is_premium() and addon.has_purchased(request.user):
log.info('Already purchased: %d' % addon.pk)
raise AlreadyPurchased
app_pay_cef.log(request, 'Preparing JWT', 'preparing_jwt',
'Preparing JWT for: %s' % (addon.pk), severity=3)
log.debug('Starting purchase of app: {0} by user: {1}'.format(
addon.pk, request.user))
contribution = Contribution.objects.create(
addon_id=addon.pk,
amount=addon.get_price(region=request.REGION.id),
paykey=None,
price_tier=addon.premium.price,
source=request.REQUEST.get('src', ''),
source_locale=request.LANG,
type=amo.CONTRIB_PENDING,
user=request.user,
uuid=str(uuid.uuid4()),
)
log.debug('Storing contrib for uuid: {0}'.format(contribution.uuid))
return get_product_jwt(WebAppProduct(addon), contribution)
示例4: debug
def debug(request, addon):
if not settings.DEBUG:
raise http.Http404
context = {"app": addon, "inapps": [], "urls": {"es": "%s/apps/webapp/%s" % (settings.ES_URLS[0], addon.pk)}}
if addon.is_premium():
contribution = Contribution.objects.create(addon=addon)
context["app_jwt"] = get_product_jwt(WebAppProduct(addon), contribution)["webpayJWT"]
for inapp in addon.inappproduct_set.all():
contribution = Contribution.objects.create(addon=addon, inapp_product=inapp)
context["inapps"].append(
{"inapp": inapp, "jwt": get_product_jwt(InAppProduct(inapp), contribution)["webpayJWT"]}
)
return render(request, "developers/debug.html", context)
示例5: setUp
def setUp(self):
super(TestInAppProduct, self).setUp()
self.contribution = Contribution.objects.create(
user=self.user,
addon=self.addon,
)
self.product = InAppProduct(self.inapp)
self.token = get_product_jwt(self.product, self.contribution)
示例6: setUp
def setUp(self):
super(TestWebAppProduct, self).setUp()
self.product = WebAppProduct(self.addon)
self.token = get_product_jwt(
self.product,
region=regions.US,
user=self.user,
)
self.contribution = Contribution.objects.get()
示例7: post
def post(self, request, *args, **kwargs):
form = PrepareInAppForm(request.DATA)
if not form.is_valid():
app_pay_cef.log(
request._request,
'Preparing InApp JWT Failed',
'preparing_inapp_jwt_failed',
'Preparing InApp JWT Failed error: {0}'.format(form.errors),
severity=3
)
return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
inapp = form.cleaned_data['inapp']
app_pay_cef.log(
request._request,
'Preparing InApp JWT',
'preparing_inapp_jwt',
'Preparing InApp JWT for: {0}'.format(inapp.pk), severity=3
)
log.debug('Starting purchase of in app: {0}'.format(inapp.pk))
contribution = Contribution.objects.create(
addon_id=inapp.webapp and inapp.webapp.pk,
inapp_product=inapp,
# In-App payments are unauthenticated so we have no user
# and therefore can't determine a meaningful region.
amount=None,
paykey=None,
price_tier=inapp.price,
source=request._request.REQUEST.get('src', ''),
source_locale=request._request.LANG,
type=amo.CONTRIB_PENDING,
user=None,
uuid=str(uuid.uuid4()),
)
log.info('Storing contrib for uuid: {0}'.format(contribution.uuid))
if inapp.simulate:
log.info('Preparing in-app JWT simulation for {i}'
.format(i=inapp))
product = SimulatedInAppProduct(inapp)
else:
log.info('Preparing in-app JWT for {i}'.format(i=inapp))
product = InAppProduct(inapp)
token = get_product_jwt(product, contribution)
return Response(token, status=status.HTTP_201_CREATED)
示例8: post
def post(self, request, *args, **kwargs):
form = PrepareWebAppForm(request.DATA)
if not form.is_valid():
return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
app = form.cleaned_data['app']
region = getattr(request, 'REGION', None)
if region:
enabled_regions = app.get_price_region_ids()
region_can_purchase = region.id in enabled_regions
restofworld_can_purchase = RESTOFWORLD.id in enabled_regions
if not region_can_purchase and not restofworld_can_purchase:
log.info('Region {0} is not in {1}; '
'restofworld purchases are inactive'
.format(region.id, enabled_regions))
return Response(
{'reason': 'Payments are restricted for this region'},
status=status.HTTP_403_FORBIDDEN)
if app.is_premium() and app.has_purchased(request._request.user):
log.info('Already purchased: {0}'.format(app.pk))
return Response({'reason': u'Already purchased app.'},
status=status.HTTP_409_CONFLICT)
app_pay_cef.log(request._request, 'Preparing JWT', 'preparing_jwt',
'Preparing JWT for: {0}'.format(app.pk), severity=3)
log.debug('Starting purchase of app: {0} by user: {1}'.format(
app.pk, request._request.user))
contribution = Contribution.objects.create(
addon_id=app.pk,
amount=app.get_price(region=request._request.REGION.id),
paykey=None,
price_tier=app.premium.price,
source=request._request.REQUEST.get('src', ''),
source_locale=request._request.LANG,
type=mkt.CONTRIB_PENDING,
user=request._request.user,
uuid=str(uuid.uuid4()),
)
log.debug('Storing contrib for uuid: {0}'.format(contribution.uuid))
token = get_product_jwt(WebAppProduct(app), contribution)
return Response(token, status=status.HTTP_201_CREATED)
示例9: prepare_pay
def prepare_pay(request, addon):
if addon.is_premium() and addon.has_purchased(request.amo_user):
log.info('Already purchased: %d' % addon.pk)
raise AlreadyPurchased
app_pay_cef.log(request, 'Preparing JWT', 'preparing_jwt',
'Preparing JWT for: %s' % (addon.pk), severity=3)
return get_product_jwt(
WebAppProduct(addon),
user=request.amo_user,
region=request.REGION,
source=request.REQUEST.get('src', ''),
lang=request.LANG,
client_data=ClientData.get_or_create(request),
)
示例10: debug
def debug(request, addon):
if not settings.DEBUG:
raise http.Http404
data = {
'urls': {'es': '%s/apps/webapp/%s' % (settings.ES_URLS[0], addon.pk)},
'pay_request': ''
}
if addon.is_premium():
data['pay_request'] = get_product_jwt(
WebAppProduct(addon),
user=request.amo_user,
region=request.REGION,
source=request.REQUEST.get('src', ''),
lang=request.LANG
)['webpayJWT']
return render(request, 'developers/debug.html',
{'app': addon, 'data': data})
示例11: _prepare_pay
def _prepare_pay(request, webapp):
app_pay_cef.log(request, 'Preparing JWT', 'preparing_jwt',
'Preparing JWT for: %s' % (webapp.pk), severity=3)
log.debug('Starting purchase of app: {0} by user: {1}'.format(
webapp.pk, request.user))
contribution = Contribution.objects.create(
webapp_id=webapp.pk,
amount=webapp.get_price(region=request.REGION.id),
paykey=None,
price_tier=webapp.premium.price,
source=request.GET.get('src', ''),
source_locale=request.LANG,
type=mkt.CONTRIB_PENDING,
user=request.user,
uuid=str(uuid.uuid4()),
)
log.debug('Storing contrib for uuid: {0}'.format(contribution.uuid))
return get_product_jwt(WebAppProduct(webapp), contribution)
示例12: decode_token
def decode_token(self):
token = get_product_jwt(self.product, self.contribution)
return jwt.decode(str(token['webpayJWT']), verify=False)