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
评论列表
文章目录