def get_subscription_status(gocardless_subscription_id) -> str: status_on_error = "Unknown" payment_provider = PaymentProvider.query.first() client = gocardless_pro.Client( access_token=payment_provider.gocardless_access_token, environment=payment_provider.gocardless_environment) try: response = client.subscriptions.get(gocardless_subscription_id) return response.status if hasattr(response, "status") else status_on_error except Exception as e: logging.error(e) return status_on_error
def get_transactions(): """Return tuple list of transactions from SSOT""" from SSOT import SSOT payment_provider = PaymentProvider.query.first() access_token = payment_provider.gocardless_access_token gc_environment = payment_provider.gocardless_environment target_gateways = ({ "name": "GoCardless", "construct": { "access_token": access_token, "environment": gc_environment } }, ) try: SSOT = SSOT(target_gateways) transactions = SSOT.transactions except gocardless_pro.errors.InvalidApiUsageError as e: logging.error(e.type) logging.error(e.message) flash("Invalid GoCardless API token. Correct your GoCardless API key.") return redirect(url_for("admin.connect_gocardless_manually")) except ValueError as e: logging.error(e.message) if e.message == "No access_token provided": flash("You must connect your GoCardless account first.") return redirect(url_for("admin.connect_gocardless_manually")) else: raise return transactions
def transactions(): payment_provider = PaymentProvider.query.first() from SSOT import SSOT access_token = payment_provider.gocardless_access_token, target_gateways = ({"name": "GoCardless", "construct": access_token}, ) try: SSOT = SSOT(target_gateways) transactions = SSOT.transactions except gocardless_pro.errors.InvalidApiUsageError as e: logging.error(e.type) logging(e.message) flash("Invalid GoCardless API token. Correct your GoCardless API key.") return redirect(url_for("admin.connect_gocardless_manually")) except ValueError as e: logging.error(e.message) if e.message == "No access_token provided": flash("You must connect your GoCardless account first.") return redirect(url_for("admin.connect_gocardless_manually")) else: raise return render_template("admin/transactions.html", transactions=transactions)
def customers(): jamla = get_jamla() from SSOT import SSOT jamlaApp = Jamla() jamlaApp.load(jamla=jamla) target_gateways = () if jamlaApp.has_connected("gocardless"): access_token = jamla["payment_providers"]["gocardless"]["access_token"] gc_environment = jamla["payment_providers"]["gocardless"][ "environment"] target_gateways = target_gateways + ({ "name": "GoCardless", "construct": { "access_token": access_token, "environment": gc_environment } }, ) if jamlaApp.has_connected("stripe"): stripe_token = jamla["payment_providers"]["stripe"]["secret_key"] target_gateways = target_gateways + ({ "name": "Stripe", "construct": stripe_token }, ) try: SSOT = SSOT(target_gateways) partners = SSOT.partners except gocardless_pro.errors.InvalidApiUsageError as e: logging.error(e.type) logging.error(e.message) flash("Invalid GoCardless API token. Correct your GoCardless API key.") return redirect(url_for("admin.connect_gocardless_manually")) except ValueError as e: logging.error(e.message) if e.message == "No access_token provided": flash("You must connect your GoCardless account first.") return redirect(url_for("admin.connect_gocardless_manually")) else: raise return render_template("admin/customers.html", jamla=jamla, partners=partners)
def customers(): payment_provider = PaymentProvider.query.first() from SSOT import SSOT target_gateways = () if payment_provider.gocardless_active: access_token = payment_provider.gocardless_access_token, gc_environment = payment_provider.gocardless_environment, target_gateways = target_gateways + ({ "name": "GoCardless", "construct": { "access_token": access_token, "environment": gc_environment } }, ) if payment_provider.stripe_active: stripe_token = payment_provider.stripe_secret_key target_gateways = target_gateways + ({ "name": "Stripe", "construct": stripe_token }, ) try: SSOT = SSOT(target_gateways) partners = SSOT.partners except gocardless_pro.errors.InvalidApiUsageError as e: logging.error(e.type) logging.error(e.message) flash("Invalid GoCardless API token. Correct your GoCardless API key.") return redirect(url_for("admin.connect_gocardless_manually")) except ValueError as e: logging.error(e.message) if e.message == "No access_token provided": flash("You must connect your GoCardless account first.") return redirect(url_for("admin.connect_gocardless_manually")) else: raise return render_template("admin/customers.html", partners=partners)
def refresh_ssot(resource): """Refresh SSOT to fetch newest customers (aka partners) and transactions resource is either "customers" or "transactions" """ jamla = get_jamla() from SSOT import SSOT access_token = jamla["payment_providers"]["gocardless"]["access_token"] gc_environment = jamla["payment_providers"]["gocardless"]["environment"] target_gateways = ({ "name": "GoCardless", "construct": { "access_token": access_token, "environment": gc_environment } }, ) try: SSOT = SSOT(target_gateways, refresh=True) partners = SSOT.partners except gocardless_pro.errors.InvalidApiUsageError as e: logging.error(e.type) logging.error(e.message) flash("Invalid GoCardless API token. Correct your GoCardless API key.") return redirect(url_for("admin.connect_gocardless_manually")) except ValueError as e: logging.error(e.message) if e.message == "No access_token provided": flash("You must connect your GoCardless account first.") return redirect(url_for("admin.connect_gocardless_manually")) else: raise if resource == "customers": flash("Customers refreshed") return redirect(url_for('admin.customers')) if resource == "transactions": flash("Customers refreshed") return redirect(url_for('admin.transactions')) # Fallback flask("Refreshed customers & transactions") return redirect(url_for('admin.dashboard'))