本文整理汇总了Python中pagseguro.PagSeguro.check_transaction方法的典型用法代码示例。如果您正苦于以下问题:Python PagSeguro.check_transaction方法的具体用法?Python PagSeguro.check_transaction怎么用?Python PagSeguro.check_transaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pagseguro.PagSeguro
的用法示例。
在下文中一共展示了PagSeguro.check_transaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PagSeguroProcessor
# 需要导入模块: from pagseguro import PagSeguro [as 别名]
# 或者: from pagseguro.PagSeguro import check_transaction [as 别名]
#.........这里部分代码省略.........
(
"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)
# TODO: get grossAmount to populate a payment with methods
try:
self.cart = Cart.objects.get(
reference_code=reference.replace(PREFIX, '')
)
self.cart.set_status(
self.STATUS_MAP.get(str(status), self.cart.status)
)
if transaction_code:
self.cart.transaction_code = transaction_code
msg = "Status changed to: %s" % self.cart.status
self.cart.addlog(msg)
return msg
except Exception as e:
msg = "Cart not found: {} - {}".format(reference, e)
logger.error(msg)
return msg
def confirmation(self): # redirect_url
context = {}
transaction_param = self.config.get(
'transaction_param',
self.pg.config.get('TRANSACTION_PARAM', 'transaction_id')
)
transaction_code = request.args.get(transaction_param)
if transaction_code:
context['transaction_code'] = transaction_code
response = self.pg.check_transaction(transaction_code)
logger.debug(response.xml)
reference = getattr(response, 'reference', None)
if not reference:
logger.error("no reference found")
return render_template('cart/simple_confirmation.html',
**context)
PREFIX = self.pg.config.get('REFERENCE_PREFIX', '') or ''
PREFIX = PREFIX.replace('%s', '')
status = getattr(response, 'status', None)
# TODO: get grossAmount to populate a payment with methods
try:
self.cart = Cart.objects.get(
reference_code=reference.replace(PREFIX, '')
)
self.cart.set_status(
self.STATUS_MAP.get(str(status), self.cart.status)
)
self.cart.transaction_code = transaction_code
msg = "Status changed to: %s" % self.cart.status
self.cart.addlog(msg)
context['cart'] = self.cart
logger.info("Cart updated")
return render_template('cart/confirmation.html', **context)
except Exception as e:
msg = "Cart not found: {} - {}".format(reference, e)
logger.error(msg)
return render_template('cart/simple_confirmation.html', **context)