def accounts_search(): """Gets an account's Recurly ID based on the provided 'account_code' """ client = recurly.Client(os.environ['RECURLY_KEY']) recurly_email = request.args.get('email') recurly_code = request.args.get('code') account_list = [] try: accounts = client.list_accounts(limit=1, email=recurly_email).items() for account in accounts: account_list.append({"account_email": account.email, "account_id": account.id, "account_code": account.code}) for account in account_list: if recurly_code == account['account_code']: # Log the account_id app.logger.info("Got account %s" % account['account_email']) # Store the ID in the session session['account_id'] = account['account_id'] # Redirect to /account return redirect(url_for('account_get')) except recurly.errors.NotFoundError as e: app.logger.error("accounts_search: not found error for %s" % recurly_email) error = 'No records found.' return render_template('error.html', error=error) except recurly.NetworkError as e: app.logger.error("account_search: network error for %s which was %s" %(recurly_email, e) ) error = "We had a what appears to be temporary problem finding your records. Please try again later." return render_template('error.html', error=error) # Catch-all if there's nothing above error = 'No records found.' return render_template('error.html', error=error)
def account_get(): """Gets a Recurly account by account_id""" client = recurly.Client(os.environ['RECURLY_KEY']) account_id = '' if 'account_id' in session: account_id = session.get('account_id') else: error = "We couldn't find your account information." return render_template('error.html', error=error) try: account = client.get_account(account_id) app.logger.info('Showing the billing update form to %s.' % account.email ) return render_template('account_update.html', account=account) except recurly.errors.NotFoundError as e: app.logger.error('account_get: not found error') error = "We couldn't find your account information." return render_template('error.html', error=error) except recurly.NetworkError as e: app.logger.error("account_get: network error for %s which was %s" %(account.email, e) ) error = "We had a what appears to be temporary problem finding your records. Please try again later." return render_template('error.html', error=error)
def account_update_billing(): """Updates account's billing info""" client = recurly.Client(os.environ['RECURLY_KEY']) account_id = session.get('account_id') token = request.form['recurly-token'] account = client.get_account(account_id) app.logger.info('Received a billing update form submission from %s' % account.email ) try: billing_update = {"token_id": token} billing = client.update_billing_info(account_id, billing_update) app.logger.info('Successfully updated billing info.') return render_template('account_update_success.html', billing=billing) except recurly.errors.TransactionError as e: app.logger.error("account_update_billing: transaction error for %s which was %s" %(account.email, e) ) error = "We had a problem completing the transaction: %s" % e return render_template('error.html', error=error) except recurly.errors.NotFoundError as e: app.logger.error('account_update_billing: not found error for %s' % account.email ) error = 'We had a problem locating your record.' return render_template('error.html', error=error) except recurly.NetworkError as e: app.logger.error("account_update_billing: network error for %s which was %s" %(account.email, e) ) error = "We had a what appears to be temporary problem finding your records. Please try again later." return render_template('error.html', error=error)
def client(self): if not hasattr(self, "_client"): self._client = recurly.Client(self.conn.api_token) return self._client
def post_fork(server, worker): client = recurly.Client(os.environ['RECURLY_KEY'])
import os # Import Flask and recurly client library from flask import Flask from flask import request from flask import Response from flask import redirect import recurly # We'll use uuid to generate unique account codes import uuid # Configure the recurly client with your api key client = recurly.Client(os.environ['RECURLY_API_KEY']) # Set your Recurly public key RECURLY_PUBLIC_KEY = os.environ['RECURLY_PUBLIC_KEY'] SUCCESS_URL = os.environ['SUCCESS_URL'] ERROR_URL = os.environ['ERROR_URL'] PUBLIC_DIR_PATH = os.getenv('PUBLIC_DIR_PATH', '../../public') app = Flask(__name__, static_folder=PUBLIC_DIR_PATH, static_url_path='') # GET route to show the list of options @app.route("/", methods=['GET']) def index(): return redirect('index.html')