-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApplePaySwagServer.py
43 lines (35 loc) · 1.23 KB
/
ApplePaySwagServer.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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_4HKKLEaGa6YweA50gknGDYEf"
#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
pass
#5
return "Success!"
if __name__ == '__main__':
# Set as 0.0.0.0 to be accessible outside your local machine
app.run(debug=True, host= '0.0.0.0')