我正在尝试实施Apple Pay,但是当通过POST请求发送JSON时,我会收到此响应;
TypeError:视图函数未返回有效响应。该函数返回None或不返回return语句结束
有时我还会收到此错误;
AttributeError:“模块”对象没有属性“ CardError”
这是我要发送的Json;
{
"stripeToken": "tok_1CnVhKJfdfthSF864bdMLBsK",
"description": "product",
"amount": 525
}
这是python服务器;
import stripe
from flask import Flask
from flask import request
from flask import json
app = Flask(__name__)
#1
@app.route('/pay', methods=['POST'])
def pay():
#2
# Set this to your Stripe secret key (use your test key!)
stripe.api_key = "sk_test_SECRETKEY"
#3
# Parse the request as JSON
json = request.get_json(force=True)
# Get the credit card details
token = json['stripeToken']
amount = json['amount']
description = json['description']
# Create the charge on Stripe's servers - this will charge the user's card
try:
#4
charge = stripe.Charge.create(
amount=amount,
currency="usd",
card=token,
description=description
)
except stripe.CardError, e:
# The card has been declined
return "Failure"
#5
return "Success!"
if __name__ == '__main__':
# Set as 0.0.0.0 to be accessible outside your local machine
app.run(debug=True, host= 'SERVER_IP_ADDRESS')