Hi
I apologise in advance if this is a little rudimentary.
I want to use Python to act as the back end server to process stripe payments from an iPhone app. I have been following an example online that uses the Stripe Python libraries to process the 'test' payment. The problem I'm having is the script in the example works as a CGI file. I have been trying to convert it to a Flask app, but with no success. I do not want it to return a user interface. My iPhone app keeps getting the following error: 'failure Expected status code in (200-299), got 500'. I have not been able to find and figure out a solution.
Here is the original script for the CGI file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Here is what I have so far trying to convert it to a Flask app:
import sys
import json
import stripe
from flask import Flask
application = Flask(__name__)
@application.route('/', methods=["POST"])
def payments_test():
stripe.api_key = 'your-private-key-goes-here'
json_data = sys.stdin.read()
json_dict = json.loads(json_data)
stripeAmount = json_dict['stripeAmount']
stripeCurrency = json_dict['stripeCurrency']
stripeToken = json_dict['stripeToken']
stripeDescription = json_dict['stripeDescription']
json_response = stripe.Charge.create(amount=stripeAmount, currency=stripeCurrency, card=stripeToken, description=stripeDescription)
return json_response
Any help will be greatly appreciated.