我在我的项目中集成了Stripe,只要所有信用卡详细信息都很好,我的应用就完美无缺。但是,我没有集成但错误消息处理,我有点问题,以了解它是如何工作的。我对Ajax并不熟悉,也许存在问题。查看reference API,然后单击Python,这对我来说看起来不像Python代码,我不知道如何处理错误消息处理,因为它在那里解释
任何人都可以帮我解决所附的代码吗?我也很感兴趣,我需要研究和学习,以便更好地理解在API参考中用Python编写的内容。
def stripe_charge(self, transaction_profile, **kwargs):
try:
c = stripe.Charge.create(
amount=kwargs['total']*100,
currency='eur',
description=kwargs['order_id'],
receipt_email=transaction_profile.email,
source=kwargs['token'],
)
new_charge_obj = self.model(
transaction_profile = transaction_profile,
stripe_id = c.id,
paid = c.paid,
refunded = c.refunded,
outcome = c.outcome,
outcome_type = c.outcome['type'],
seller_message = c.outcome.get('seller_message'),
risk_level = c.outcome.get('risk_level'),
)
new_charge_obj.save()
except stripe.error.CardError as e:
# Since it's a decline, stripe.error.CardError will be caught
body = e.json_body
err = body.get('error', {})
# print "Status is: %s" % e.http_status
# print "Type is: %s" % err.get('type')
# print "Code is: %s" % err.get('code')
# # param is '' in this case
# print "Param is: %s" % err.get('param')
# print "Message is: %s" % err.get('message')
return False, e
return new_charge_obj.paid, new_charge_obj.seller_message
答案 0 :(得分:1)
您可以使用django中包含的消息模块。
import django.contrib.messages
# usage
messages.error(request, "Something bad happened")