问题
I am new to Flask and will appreciate little help with stripe payments. I currently can "Send" data to stripe with simple view and it communicates with stripe site as it shows payment charged against the subscription plan. But I need to "receive" signal from stripe so I can capture the event and take action as needed. For that I would appreciated if according to the following view someone help me to figure it out. Following view is to charge customer and now I need to retrieve expiration from stripe end.
@app.route('/charged', methods=['POST'])
def charge():
# Amount in cents
amount = 9900
# customer
customer = stripe.Customer.create(
email='testing@gmail.com',
source=request.form['stripeToken']
)
try:
charge = stripe.Charge.create(
customer=customer.id,
capture='true',
amount=amount,
currency='usd',
description='standard',
)
data="$" + str(float(amount) / 100) + " " + charge.currency.upper()
except stripe.error.CardError as e:
# The card has been declined
body = e.json_body
err = body['error']
print
"Status is: %s" % e.http_status
print
"Type is: %s" % err['type']
print
"Code is: %s" % err['code']
print
"Message is: %s" % err['message']
return render_template('/charge.html', data=data)
HTML Template:
<form action="/charged" method="post">
<div class="form-group">
<label for="email">Amount is $99.00 USD </label>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="{{ key }}"
data-description="Standard Package"
data-name="Demo Site"
data-amount="9900"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto">
</script>
</div>
</form>
I will really appreciate if someone can give me just one example of receiving the expiration date of the package from stripe or any other event.
来源:https://stackoverflow.com/questions/42256026/receiving-a-webhook-event-for-stripe-in-flask