当前位置: 首页>>代码示例>>Python>>正文


Python Notification.eventCode方法代码示例

本文整理汇总了Python中models.Notification.eventCode方法的典型用法代码示例。如果您正苦于以下问题:Python Notification.eventCode方法的具体用法?Python Notification.eventCode怎么用?Python Notification.eventCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Notification的用法示例。


在下文中一共展示了Notification.eventCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_raw_adyen_notification

# 需要导入模块: from models import Notification [as 别名]
# 或者: from models.Notification import eventCode [as 别名]
def process_raw_adyen_notification(raw, POST):
	# Process a single raw Adyen notification. Must *not* be called in
	# a transactional context, as it manages it's own.

	# Now open a transaction for actually processing what we get
	with transaction.commit_on_success():
		# Set it to confirmed - if we were unable to process the RAW one,
		# this will be rolled back by the transaction, and that's the only
		# thing that htis flag means. Anything else is handled by the
		# regular notification.
		raw.confirmed = True
		raw.save()

		# Have we already seen this notification before?
		notlist = list(Notification.objects.filter(pspReference=POST['pspReference'], eventCode=POST['eventCode'], merchantAccountCode=POST['merchantAccountCode']))
		if len(notlist) == 1:
			# Found it before!
			notification = notlist[0]

			# According to Adyen integration manual, the only case when
			# we need to process this is when it goes from
			# success=False -> success=True.
			if not notification.success and POST['success'] == 'true':
				# We'll implement this one later, but for now trigger a
				# manual email so we don't loose things.
				send_simple_mail(settings.INVOICE_SENDER_EMAIL,
								 settings.ADYEN_NOTIFICATION_RECEIVER,
								 'Received adyen notification type %s that went from failure to success!' % notification.eventCode,
							 "An Adyen notification that went from failure to success has been received.\nThe system doesn't know how to handle this yet, so you'll need to go take a manual look!\n",
							 )
				AdyenLog(pspReference=notification.pspReference, message='Received success->fail notification of type %s, unhandled' % notification.eventCode, error=True).save()
			else:
				AdyenLog(pspReference=notification.pspReference, message='Received duplicate %s notification' % notification.eventCode).save()
				# Don't actually do any processing here either
		else:
			# Not found, so create
			notification = Notification()
			notification.rawnotification = raw
			notification.eventDate = POST['eventDate']
			notification.eventCode = POST['eventCode']
			notification.live = (POST['live'] == 'true')
			notification.success = (POST['success'] == 'true')
			notification.pspReference = POST['pspReference']
			notification.originalReference = POST['originalReference']
			notification.merchantReference = POST['merchantReference']
			notification.merchantAccountCode = POST['merchantAccountCode']
			notification.paymentMethod = POST['paymentMethod']
			notification.reason = POST['reason']
			try:
				notification.amount = int(POST['value'])/100 # We only deal in whole euros
			except:
				# Invalid amount, set to -1
				AdyenLog(pspReference=notification.pspReference, message='Received invalid amount %s' % POST['value'], error=True).save()
				notification.amount = -1
			if POST['currency'] != settings.CURRENCY_ABBREV:
				# For some reason, *report* notifications specifically get delivered with
				# a hard-coded value of EUR, even though they have no currency inside them.
				if notification.eventCode != 'REPORT_AVAILABLE':
					AdyenLog(pspReference=notification.pspReference, message='Received invalid currency %s' % POST['currency'], error=True).save()
					notification.amount = -2

			# Save this unconfirmed for now
			notification.save()

			# Process this notification, which includes flagging invoices
			# as paid.
			process_one_notification(notification)

			# Log the fact that we received it
			AdyenLog(pspReference=notification.pspReference, message='Processed %s notification for %s' % (notification.eventCode, notification.merchantReference)).save()

	# Return that we've consumed the report outside the transaction, in
	# the unlikely event that the COMMIT is what failed
	return True
开发者ID:louiseGrandjonc,项目名称:pgeu-website,代码行数:76,代码来源:util.py


注:本文中的models.Notification.eventCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。