pay_stripe.py 文件源码

python
阅读 46 收藏 0 点赞 0 评论 0

项目:Tktr 作者: Intuity 项目源码 文件源码
def refund_stripe_charge (self, charge_id):
        all_methods = PROP.getProperty(self.request, PROP.PAYMENT_METHODS)
        method = [x for x in all_methods if x.__name__ == "stripe"]
        method = method[0] if len(method) > 0 else None
        if method == None:
            logging.exception(self.user.username + ": Could not refund %s because could not find stripe payment method" % charge_id)
            return False
        priv_api_key = method.settings[PROP.STRIPE_API_KEY].value
        try:
            stripe.api_key = priv_api_key
            refund = stripe.Refund.create(
                charge=charge_id,
                reason="duplicate"
            )
            if refund != None and "id" in refund:
                logging.info(self.user.username + ": Refunded charge %s with refund id %s" % (charge_id, refund["id"]))
                return True
            else:
                logging.error(self.user.username + ": Refund of charge %s may have failed" % charge_id)
                return False
        except Exception, e:
            logging.error(self.user.username + ": Exception was thrown during refund: %s" % e)
            return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号