私はFlaskのシンプルなフォームを作成し、Stripe.comでプランを作成しました。私は開発モードでプランニングに加入することができ、ストライプの支払いを反映します。ストリープサイトとリアルタイムで同期して、プランの有効期限やその他のイベントを取得する必要があります。この目的のために、ストライプIDを取得してデータベースに保存するコールバック関数を作成する必要があることを理解しています。セッションよりもデータベースに保存したいと思っています。コールバックルートを作成し、JSON APIからデータベースに値を保存する方法をアドバイスしてください。以下は私の購読するコードです。私は期限切れや他のイベントを表示する必要があります。ストライプフラスコのリクエスト/レスポンス方法
def yearly_charged():
#Need to save customer stripe ID to DB model
amount = 1450
customer = stripe.Customer.create(
email='[email protected]',
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('/profile/charge.html', data=data, charge=charge)
テンプレート:
<form action="/charged" method="post">
<div class="form-group">
<label for="email">Amount is 14.95 USD </label>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="{{ key }}"
data-description="Yearly recurring billing"
data-name="yearly"
data-amount="1495"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto">
</script>
</div>
</form>
モデル:
class Students(db.Model):
__tablename__='students'
.......
student_strip_id = db.Column(db.String(45))
.......
は、私は、DBに保存する適切な方法で応答を取得する方法を設定することができますので、以下の機能を考案する手助けが必要です。
@app.route('/oauth/callback/, methods=['POST'])
# This is where I guess I have to define callback function to get API data
return redirect('/')
ここでの目的は、フラスコモデルに保存するようにストライプID、有効期限イベントやストライプのAPIオブジェクトから他のサブスクリプションの通知を抽出することです。
は、あなたが大きな助けてきた、ありがとうございました。 –