本文整理汇总了Python中lib.solitude.api.ProviderHelper.is_callback_token_valid方法的典型用法代码示例。如果您正苦于以下问题:Python ProviderHelper.is_callback_token_valid方法的具体用法?Python ProviderHelper.is_callback_token_valid怎么用?Python ProviderHelper.is_callback_token_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.solitude.api.ProviderHelper
的用法示例。
在下文中一共展示了ProviderHelper.is_callback_token_valid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _callback_url
# 需要导入模块: from lib.solitude.api import ProviderHelper [as 别名]
# 或者: from lib.solitude.api.ProviderHelper import is_callback_token_valid [as 别名]
def _callback_url(request, is_success):
status = is_success and 'success' or 'error'
signed_notice = request.POST['signed_notice']
statsd.incr('purchase.payment_{0}_callback.received'.format(status))
# This is currently only used by Bango and Zippy.
# Future providers should probably get added to the notification
# abstraction in provider/views.py
provider = ProviderHelper(settings.PAYMENT_PROVIDER)
if provider.is_callback_token_valid(signed_notice):
statsd.incr('purchase.payment_{0}_callback.ok'.format(status))
log.info('Callback {0} token was valid.'.format(status))
querystring = http.QueryDict(signed_notice)
if 'ext_transaction_id' in querystring:
ext_transaction_id = querystring['ext_transaction_id']
if is_success:
tasks.payment_notify.delay(ext_transaction_id)
else:
tasks.chargeback_notify.delay(ext_transaction_id)
return http.HttpResponse(status=204)
else:
statsd.incr('purchase.payment_{0}_callback.incomplete'
''.format(status))
log.error('Callback {0} token was incomplete: '
'{1}'.format(status, querystring))
else:
statsd.incr('purchase.payment_{0}_callback.fail'.format(status))
log.error('Callback {0} token was invalid: '
'{1}'.format(status, signed_notice))
return http.HttpResponseBadRequest()
示例2: TestReferenceProvider
# 需要导入模块: from lib.solitude.api import ProviderHelper [as 别名]
# 或者: from lib.solitude.api.ProviderHelper import is_callback_token_valid [as 别名]
#.........这里部分代码省略.........
def test_with_new_prod(self):
name = 'Magic Unicorn'
new_product_uuid = 'new-product'
self.slumber.generic.buyer.get_object_or_404.return_value = {
'resource_uri': self.buyer_uri,
}
(self.slumber.generic.product.get_object_or_404
.side_effect) = ObjectDoesNotExist
self.slumber.generic.product.post.return_value = {
'access': 1,
'public_id': '6597288d-7bce-409b-a35b-772acfe04b1e',
'external_id': self.product_uuid,
'seller': self.seller_uri,
'resource_uri': self.product_uri,
}
self.slumber.provider.reference.transactions.post.return_value = {
'token': 'zippy-trans-token',
}
seller_ref_uri = '/reference/seller/1'
(self.slumber.provider.reference.sellers.get_object_or_404
.return_value) = {
'resource_uri': seller_ref_uri
}
seller_prod_uri = '/reference/product/1'
self.slumber.provider.reference.products.post.return_value = {
'reference': {
'uuid': new_product_uuid
},
'resource_uri': seller_prod_uri
}
(self.slumber.provider.reference.products
.side_effect) = ObjectDoesNotExist
result = self.configure(seller_uuid=self.seller_uuid,
product_uuid=self.product_uuid,
product_name=name)
eq_(result[0], 'zippy-trans-token')
kw = self.slumber.provider.reference.products.post.call_args[0][0]
eq_(kw['name'], name)
eq_(kw['seller_reference'], seller_ref_uri)
eq_(kw['seller_product'], self.product_uri)
assert 'uuid' in kw, kw
kw = self.slumber.provider.reference.transactions.post.call_args[0][0]
eq_(kw['product_id'], new_product_uuid)
eq_(kw['product_image_url'], '/todo/icons')
assert kw['success_url'].endswith('/provider/reference/success'), (
'Unexpected: {0}'.format(kw['success_url']))
assert kw['error_url'].endswith('/provider/reference/error'), (
'Unexpected: {0}'.format(kw['error_url']))
self.slumber.generic.transaction.post.assert_called_with({
'amount': '0.99',
'carrier': 'USA_TMOBILE',
'currency': 'EUR',
'provider': constants.PROVIDER_REFERENCE,
'region': '123',
'buyer': self.buyer_uri,
'seller': self.seller_uri,
'seller_product': self.product_uri,
'source': 'unknown',
'status': constants.STATUS_PENDING,
'type': constants.TYPE_PAYMENT,
'uuid': 'trans-xyz',
})
def test_callback_validation_success(self):
self.slumber.provider.reference.notices.post.return_value = {
'result': 'OK',
}
self.slumber.provider.reference.transactions.post.return_value = {
'token': 'zippy-trans-token',
}
self.configure(seller_uuid='seller-xyz', product_uuid='app-xyz')
is_valid = self.provider.is_callback_token_valid({'foo': 'bar'})
eq_(is_valid, True)
eq_(self.slumber.provider.reference.notices.post.call_args[0][0],
{'qs': {'foo': 'bar'}})
def test_callback_validation_failure(self):
self.slumber.provider.reference.notices.post.return_value = {
'result': 'FAIL',
'reason': 'signature mismatch',
}
self.slumber.provider.reference.transactions.post.return_value = {
'token': 'zippy-trans-token',
}
self.configure(seller_uuid='seller-xyz', product_uuid='app-xyz')
is_valid = self.provider.is_callback_token_valid({'foo': 'bar'})
eq_(is_valid, False)
示例3: TestReferenceProvider
# 需要导入模块: from lib.solitude.api import ProviderHelper [as 别名]
# 或者: from lib.solitude.api.ProviderHelper import is_callback_token_valid [as 别名]
#.........这里部分代码省略.........
eq_(seller_uuid, seller_uuid)
assert pay_url.endswith('tx={t}'.format(t=trans_id)), (
'Unexpected: {url}'.format(url=pay_url))
kw = self.slumber.provider.reference.products\
.get_object_or_404.call_args[1]
eq_(kw['external_id'], product_uuid)
eq_(kw['seller_id'], seller_uuid)
def test_with_new_prod(self):
new_product_id = 66
product_uuid = 'app-xyz'
seller_uuid = 'seller-xyz'
self.set_mocks({
'generic.product': {
'side_effect': ObjectDoesNotExist,
},
'provider.reference.transactions': {
'method': 'post',
'return': {
'token': 'zippy-trans-token',
}
},
'provider.reference.products': {
'side_effect': ObjectDoesNotExist,
},
'provider.reference.sellers': {
'return': {
'resource_pk': seller_uuid,
}
}},
seller_uuid=seller_uuid
)
self.slumber.provider.reference.products.post.return_value = {
'resource_pk': new_product_id,
}
result = self.configure(seller_uuid=seller_uuid,
product_uuid=product_uuid)
eq_(result[0], 'zippy-trans-token')
kw = self.slumber.provider.reference.products.post.call_args[0][0]
eq_(kw['external_id'], product_uuid)
eq_(kw['seller_id'], seller_uuid)
kw = self.slumber.provider.reference.transactions.post.call_args[0][0]
eq_(kw['product_id'], new_product_id)
eq_(kw['product_image_url'], '/todo/icons')
assert kw['success_url'].endswith('/provider/reference/success'), (
'Unexpected: {0}'.format(kw['success_url']))
assert kw['error_url'].endswith('/provider/reference/error'), (
'Unexpected: {0}'.format(kw['error_url']))
def test_callback_validation_success(self):
self.set_mocks({
'provider.reference.notices': {
'method': 'post',
'return': {
'result': 'OK',
}
},
'provider.reference.transactions': {
'method': 'post',
'return': {
'token': 'zippy-trans-token',
}
}},
product_uuid='XYZ'
)
self.configure(seller_uuid='seller-xyz', product_uuid='app-xyz')
is_valid = self.provider.is_callback_token_valid({'foo': 'bar'})
eq_(is_valid, True)
eq_(self.slumber.provider.reference.notices.post.call_args[0][0],
{'qs': {'foo': 'bar'}})
def test_callback_validation_failure(self):
self.set_mocks({
'provider.reference.notices': {
'method': 'post',
'return': {
'result': 'FAIL',
'reason': 'signature mismatch',
}
},
'provider.reference.transactions': {
'method': 'post',
'return': {
'token': 'zippy-trans-token',
}
}},
product_uuid='XYZ'
)
self.configure(seller_uuid='seller-xyz', product_uuid='app-xyz')
is_valid = self.provider.is_callback_token_valid({'foo': 'bar'})
eq_(is_valid, False)