SHARE
TWEET

Untitled

a guest May 15th, 2019 121 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import braintree
  2. from flask import Flask, render_template, send_from_directory, request
  3.  
  4. try:
  5.     from ConfigParser import SafeConfigParser
  6. except ImportError:
  7.     from configparser import SafeConfigParser
  8.  
  9. app = Flask(__name__)
  10.  
  11. parser = SafeConfigParser()
  12. parser.read('secrets.ini')
  13. MERCHANTID = parser.get('braintree', 'MERCHANTID')
  14. PUBLICKEY = parser.get('braintree', 'PUBLICKEY')
  15. PRIVATEKEY = parser.get('braintree', 'PRIVATEKEY')
  16.  
  17. braintree.Configuration.configure(braintree.Environment.Sandbox,
  18.                                   merchant_id=MERCHANTID,
  19.                                   public_key=PUBLICKEY,
  20.                                   private_key=PRIVATEKEY)
  21.  
  22. @app.route("/")
  23. def index():
  24.     # Generate client token for the dropin ui
  25.     client_token = braintree.ClientToken.generate({})
  26.  
  27.     return render_template('index.html', token=client_token)
  28.  
  29. @app.route("/proc", methods=['GET', 'POST'])
  30. def proc():
  31.     # result = braintree.Transaction.sale({
  32.     #     "amount": request.form["amount"],
  33.     #     "payment_method_nonce": request.form["payment_method_nonce"]
  34.     # })
  35.     # print(result)
  36.     result = braintree.Customer.create({
  37.     "credit_card": {
  38.         "number": "4111111111111111",
  39.         "expiration_date": "12/16"
  40.     }
  41.     })
  42.  
  43.     result = braintree.Subscription.create({
  44.     "payment_method_token": result.customer.credit_cards[0].token,
  45.     "plan_id": "upwork_sub"
  46.     })
  47.     print(result)
  48.     return render_template('proc.html', result=result, request=request.form)
  49.  
  50. if __name__ == "__main__":
  51.     app.run(host='0.0.0.0')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top