本文整理汇总了Python中pagseguro.PagSeguro.check_notification方法的典型用法代码示例。如果您正苦于以下问题:Python PagSeguro.check_notification方法的具体用法?Python PagSeguro.check_notification怎么用?Python PagSeguro.check_notification使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pagseguro.PagSeguro
的用法示例。
在下文中一共展示了PagSeguro.check_notification方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pagseguro_notification
# 需要导入模块: from pagseguro import PagSeguro [as 别名]
# 或者: from pagseguro.PagSeguro import check_notification [as 别名]
def pagseguro_notification(request):
notification_code = request.POST.get('notificationCode', None)
if notification_code:
pg = PagSeguro(
email=settings.PAGSEGURO_EMAIL, token=settings.PAGSEGURO_TOKEN,
config={'sandbox': settings.PAGSEGURO_SANDBOX}
)
notification_data = pg.check_notification(notification_code)
status = notification_data.status
reference = notification_data.reference
try:
order = Order.objects.get(pk=reference)
except Order.DoesNotExist:
pass
else:
order.pagseguro_update_status(status)
return HttpResponse('OK')
示例2: notification_view
# 需要导入模块: from pagseguro import PagSeguro [as 别名]
# 或者: from pagseguro.PagSeguro import check_notification [as 别名]
def notification_view(request):
notification_code = request.POST['notificationCode']
pg = PagSeguro(email=app.config['EMAIL'], token=app.config['TOKEN'])
pg.check_notification(notification_code)
示例3: PagSeguroProcessor
# 需要导入模块: from pagseguro import PagSeguro [as 别名]
# 或者: from pagseguro.PagSeguro import check_notification [as 别名]
class PagSeguroProcessor(BaseProcessor):
STATUS_MAP = {
"1": "checked_out",
"2": "analysing",
"3": "confirmed",
"4": "completed",
"5": "refunding",
"6": "refunded",
"7": "cancelled"
}
def __init__(self, cart, *args, **kwargs):
self.cart = cart
self.config = kwargs.get('config')
self._record = kwargs.get('_record')
if not isinstance(self.config, dict):
raise ValueError("Config must be a dict")
email = self.config.get('email')
token = self.config.get('token')
self.pg = PagSeguro(email=email, token=token)
self.cart and self.cart.addlog(
"PagSeguro initialized {}".format(self.__dict__)
)
def validate(self, *args, **kwargs):
self.pg.sender = self.cart.sender_data
self.pg.shipping = self.cart.shipping_data
self.pg.reference = self.cart.get_uid()
extra_costs = self.cart.get_extra_costs()
if extra_costs:
self.pg.extra_amount = "%.2f" % extra_costs
self.pg.items = [
{
"id": item.get_uid(),
"description": item.title[:100],
"amount": "%.2f" % item.unity_plus_extra,
"weight": item.weight,
"quantity": int(item.quantity or 1)
}
for item in self.cart.items if item.total >= 0
]
if hasattr(self.cart, 'redirect_url'):
self.pg.redirect_url = self.cart.redirect_url
else:
self.pg.redirect_url = self.config.get('redirect_url')
if hasattr(self.cart, 'notification_url'):
self.pg.notification_url = self.cart.notification_url
else:
self.pg.notification_url = self.config.get('notification_url')
self.cart.addlog("pagSeguro validated {}".format(self.pg.data))
return True # all data is valid
def process(self, *args, **kwargs):
kwargs.update(self._record.config)
kwargs.update(self.cart.config)
response = self.pg.checkout(**kwargs)
self.cart.addlog(
(
"lib checkout data:{pg.data}\n"
" code:{r.code} url:{r.payment_url}\n"
" errors: {r.errors}\n"
" xml: {r.xml}\n"
).format(
pg=self.pg, r=response
)
)
if not response.errors:
self.cart.checkout_code = response.code
#self.cart.status = 'checked_out' # should set on redirect url
self.cart.addlog("PagSeguro processed! {}".format(response.code))
return redirect(response.payment_url)
else:
self.cart.addlog(
'PagSeguro error processing {}'.format(
response.errors
)
)
return render_template("cart/checkout_error.html",
response=response, cart=self.cart)
def notification(self):
code = request.form.get('notificationCode')
if not code:
return "notification code not found"
response = self.pg.check_notification(code)
reference = getattr(response, 'reference', None)
if not reference:
return "reference not found"
PREFIX = self.pg.config.get('REFERENCE_PREFIX', '') or ''
PREFIX = PREFIX.replace('%s', '')
status = getattr(response, 'status', None)
transaction_code = getattr(response, 'code', None)
#.........这里部分代码省略.........