def etl(conn_id): logging.info('Getting Chargebee Configuration from Data Warehouse') conf = get_chargebee_config(conn_id) for elem in conf: sitename, api_key, module = elem table = f'''w0_chargebee.{sitename}_{module}'''.replace('-', '_') logging.info( f'Beginning ETL for {sitename} - {module} into {table}') last_sync_date = get_last_sync_date(conn_id, sitename, module) logging.info(f'Last Table Sync Time: {last_sync_date}') chargebee.configure(api_key, sitename) logging.info('Beginning Extract') docs = extract(module, last_sync_date=last_sync_date) logging.info(f'Extracted {len(docs)} documents') if len(docs) == 0: logging.info('Skipping...') continue logging.info('Beginning Transform') docs_t = transform(docs) logging.info('Beginning Load') load(conn_id, docs_t, table) logging.info('Updated ETL Log') update_etl_log(conn_id, docs, sitename, module)
def streams(self, config) -> List[Stream]: # Configure the Chargebee Python SDK chargebee.configure(api_key=config["site_api_key"], site=config["site"]) kwargs = {"start_date": config["start_date"]} product_catalog_version = config["product_catalog"] # Below streams are suitable for both `Product Catalog 1.0` and `Product Catalog 2.0`. common_streams = [ Coupon(**kwargs), CreditNote(**kwargs), Customer(**kwargs), Event(**kwargs), Invoice(**kwargs), Order(**kwargs), Subscription(**kwargs), Transaction(**kwargs), ] if product_catalog_version == "1.0": # Below streams are suitable only for `Product Catalog 1.0`. product_catalog_v1_streams = [ Addon(**kwargs), Plan(**kwargs), ] return common_streams + product_catalog_v1_streams # Below streams are suitable only for `Product Catalog 2.0`. product_catalog_v2_streams = [ Item(**kwargs), ItemPrice(**kwargs), AttachedItem(**kwargs), ] return common_streams + product_catalog_v2_streams
def create_app(config_name: str): app = Flask(__name__) # See https://github.com/getsentry/raven-python/blob/master/docs/integrations/flask.rst # and https://github.com/WeAreWizards/proppyweb/issues/480 # (sentry reporting wrong remote address) app.wsgi_app = ProxyFix(app.wsgi_app) conf = config[config_name] # type: Any # logging config needs to come before first call to log if not conf.TESTING: logging.basicConfig(level=logging.INFO) logging.getLogger().addHandler(logging.handlers.SysLogHandler(address='/run/systemd/journal/dev-log')) app.config.from_object(conf) conf.init_app(app) zapier.init_app(app) mail.init_app(app) db.init_app(app) cors.init_app(app) bcrypt.init_app(app) if not conf.DEBUG and not conf.TESTING: sentry.init_app(app, dsn=conf.SENTRY_DSN) chargebee.configure(conf.CHARGEBEE_API_KEY, conf.CHARGEBEE_SITE) from .api import api_bp app.register_blueprint(api_bp) return app
def init(self, crb_site, crb_api_key): self.crb_site = crb_site self.crb_api_key = crb_api_key chargebee.configure(api_key=self.crb_api_key, site=self.crb_site) self.is_configured = True return self
def configure_chargebee(reset=False): global CHARGEBEE_CONFIGURED if reset: CHARGEBEE_CONFIGURED = False return if not CHARGEBEE_CONFIGURED: chargebee.configure(settings.CHARGEBEE_APIKEY, settings.CHARGEBEE_SITENAME) CHARGEBEE_CONFIGURED = True
def create_portal_session(request): # chargebee.configure("test_jqXGuQLkBHUSR2PM0qgUV21W1VqSFJIU", "honeycomics-v3-test") chargebee.configure("test_qDNCoDWdlzgkepytSgFgcucch5lrqWXsh", "cartstuff-test") result = chargebee.PortalSession.create({ "customer": { "id": "AzqgjFS8UDtnD7cf" # [email protected] } }) portal_session = result._response['portal_session'] data = portal_session return JsonResponse(data)
def check_connection(self, logger, config: Mapping[str, Any]) -> Tuple[bool, any]: # Configure the Chargebee Python SDK chargebee.configure(api_key=config["site_api_key"], site=config["site"]) try: subscription_stream = Subscription(start_date=config["start_date"]) next( subscription_stream.read_records( sync_mode=SyncMode.full_refresh)) return True, None except Exception as err: # Should catch all exceptions which are already handled by Chargebee Python wrapper. # https://github.com/chargebee/chargebee-python/blob/5346d833781de78a9eedbf9d12502f52c617c2d2/chargebee/http_request.py return False, repr(err)
def streams(self, config) -> List[Stream]: # Configure the Chargebee Python SDK chargebee.configure( api_key=config["site_api_token"], site=config["site"], ) # Add the streams streams = [ SubscriptionStream(), CustomerStream(), InvoiceStream(), OrderStream(), PlanStream(), AddonStream(), ] return streams
def init_app(self, app, blueprint=None): api_key = app.config.get('CHARGEBEE_API_KEY') site = app.config.get('CHARGEBEE_SITE') if not all((api_key, site)): warnings.warn('CHARGEBEE config not set', RuntimeWarning, stacklevel=2) return chargebee.configure(api_key, site) if blueprint is not None: blueprint.add_url_rule('/chargebee', 'chargebee', self.handle_webhook, methods=('POST', ))
def update_subscription(): chargebee.configure("{site_api_key}", "{site}") result = chargebee.Subscription.update( "__test__KyVnHhSBWkvzp2Yd", { "plan_id": "plan1", "end_of_term": True, "addons": [{ "id": "sub_monitor", "quantity": 2 }, { "id": "sub_ssl" }] }) subscription = result.subscription customer = result.customer card = result.card invoice = result.invoice unbilled_charges = result.unbilled_charges credit_notes = result.credit_notes
def check_connection(self, logger, config: Mapping[str, Any]) -> Tuple[bool, any]: # Configure the Chargebee Python SDK chargebee.configure( api_key=config["site_api_token"], site=config["site"], ) try: # Get one subscription to test connection Subscription.list( # Set limit # to test on a small dataset params={ "limit": 1, }, ) return True, None except Exception as err: # Should catch all exceptions # which are already handled by # Chargebee Python wrapper # https://github.com/chargebee/chargebee-python/blob/5346d833781de78a9eedbf9d12502f52c617c2d2/chargebee/http_request.py return False, str(err)
def create(self, authorization_token, plan_id, email, country): subscription_parameters = { "plan_id": plan_id, "customer": { "email": email, }, "payment_method": { "type": "card", "tmp_token": authorization_token, "gateway_account_id": self.gateway_account_id, }, } subscription_parameters = country.add(subscription_parameters) chargebee.configure(self.key, self.name) subscription = chargebee.Subscription.create( subscription_parameters, ) return SubscriptionResult( customer_email=subscription.customer.email.decode("utf-8"), customer_id=subscription.customer.id.decode("utf-8"), subscription_id=subscription.subscription.id.decode("utf-8"), plan_id=subscription.subscription.plan_id.decode("utf-8"), )
SENTRY_BACKEND_PUBLIC_DSN = os.environ.get('SENTRY_BACKEND_PUBLIC_DSN', '') SENTRY_FRONTEND_DSN = os.environ.get('SENTRY_FRONTEND_DSN', '') SENTRY_FRONTEND_PUBLIC_DSN = os.environ.get('SENTRY_FRONTEND_PUBLIC_DSN', '') RAVEN_CONFIG = { 'dsn': SENTRY_BACKEND_DSN, 'release': CURRENT_COMMIT_SHA, } CHARGEBEE_API_KEY = os.environ.get('CHARGEBEE_API_KEY', '') CHARGEBEE_SITE = os.environ.get('CHARGEBEE_SITE', 'hellolily-test') CHARGEBEE_FREE_PLAN_NAME = os.environ.get('CHARGEBEE_FREE_PLAN_NAME', 'lily-personal') CHARGEBEE_TEAM_PLAN_NAME = os.environ.get('CHARGEBEE_TEAM_PLAN_NAME', 'lily-team') CHARGEBEE_PRO_PLAN_NAME = os.environ.get('CHARGEBEE_PRO_PLAN_NAME', 'lily-professional') CHARGEBEE_PRO_TRIAL_PLAN_NAME = os.environ.get('CHARGEBEE_PRO_TRIAL_PLAN_NAME', 'lily-professional-trial') chargebee.configure(CHARGEBEE_API_KEY, CHARGEBEE_SITE) # Client ID and secret for the Lily Slack app. SLACK_LILY_CLIENT_ID = os.environ.get('SLACK_LILY_CLIENT_ID', '') SLACK_LILY_CLIENT_SECRET = os.environ.get('SLACK_LILY_CLIENT_SECRET', '') # Token used to verify requests are actually coming from Slack. SLACK_LILY_TOKEN = os.environ.get('SLACK_LILY_TOKEN', '') # Segment. SEGMENT_PYTHON_SOURCE_WRITE_KEY = os.environ.get('SEGMENT_PYTHON_SOURCE_WRITE_KEY', '') SEGMENT_JS_SOURCE_WRITE_KEY = os.environ.get('SEGMENT_JS_SOURCE_WRITE_KEY', '') # Datadog DATADOG_ENABLED = os.environ.get('DATADOG_TRACE_ENABLED', 'false') == 'true' # Since it's a string convert to bool. DATADOG_TRACE = { 'DEFAULT_SERVICE': 'web',
import logging import chargebee as chargebee from django.conf import settings chargebee.configure(settings.CHARGEBEE_API_KEY, settings.CHARGEBEE_SITE) logger = logging.getLogger(__name__) def get_plan_id_from_subscription(subscription_id): if not subscription_id: return subscription_details = get_subscription_details(subscription_id) if subscription_details: return subscription_details.subscription.plan_id def get_subscription_details(subscription_id): subscription_details = None try: subscription_details = chargebee.Subscription.retrieve(subscription_id) except chargebee.InvalidRequestError: logging.warning('Subscription not found for subscription id %s' % subscription_id) return subscription_details
def init(): api_key = 'test_jE0siZmYhi5XPkN4zNQkNANSchc7qFPg' base_url = 'personio-old-test' chargebee.configure(api_key, base_url)
''' Created on 2018. máj. 22. @author: Andris ''' #a import chargebee import sys import json import datetime import time chargebee.ChargeBee.verify_ca_certs = False chargebee.configure("test_ac68LkfLCfkacuYl5wINzwgZR9uzTecuzd","nokia-swmp-test") def write(listForUser): #input: One customer in this format: [Name,Email,Subscriptions] print(listForUser) #print all print(listForUser[0]) # Name print(listForUser[1]) # Email for subs in listForUser[2]: # For each Subsc: [data structure has been changed since -> doesnt work right now] print(subs, ": \n{") for item in listForUser[2][subs]: # for each LineItem: print(" ", item, ": \n {") print(" ", listForUser[2][subs][item][0]) #Date_From print(" ", listForUser[2][subs][item][1]) #Date_To print(" ", listForUser[2][subs][item][2]) #Amount print(" ", listForUser[2][subs][item][3]) #Description print(" },\n")
ELASTICSEARCH_URL = os.getenv('ELASTICSEARCH_URL') ELASTICSEARCH_INDEX_PREFIX = os.getenv('ELASTICSEARCH_INDEX_PREFIX') ########## END ELASTIC SEARCH CONFIGURATION TOLAUSER_OBFUSCATED_NAME = os.getenv('TOLAUSER_OBFUSCATED_NAME') DEFAULT_ORG = os.getenv('DEFAULT_ORG') DEFAULT_OAUTH_DOMAINS = os.getenv('DEFAULT_OAUTH_DOMAINS', '') CREATE_DEFAULT_PROGRAM = True if os.getenv( 'CREATE_DEFAULT_PROGRAM') == 'True' else False SET_PROGRAM_ADMIN_DEFAULT = True if os.getenv( 'SET_PROGRAM_ADMIN_DEFAULT') == 'True' else False ########## CHARGEBEE CONFIGURATION PAYMENT_PORTAL_URL = os.getenv('PAYMENT_PORTAL_URL', '') if CHARGEBEE_ENABLED: CHARGEBEE_SIGNUP_ORG_URL = os.getenv('CHARGEBEE_SIGNUP_ORG_URL') chargebee.configure(os.getenv('CHARGEBEE_SITE_API_KEY'), os.getenv('CHARGEBEE_SITE')) ########## END CHARGEBEE CONFIGURATION ########## EMAIL CONFIGURATION DEFAULT_REPLY_TO = os.getenv('DEFAULT_REPLY_TO', '') SALES_TEAM_EMAIL = os.getenv('SALES_TEAM_EMAIL', '') ########## END EMAIL CONFIGURATION
from datetime import datetime import chargebee import json import graphene import extraction import requests import json from chargebee import ChargeBee chargebee.configure("test_XLstiV7ahWpqSdxB8V8hXdNKgwFB17QB", "tvunetworks-test") class Subscription(graphene.ObjectType): id = graphene.String() planid = graphene.String(required=True) planquantity = graphene.Int() planunitprice = graphene.Int() billingperiod = graphene.Int() billingperiodunit = graphene.String() autocollection = graphene.String() customerid = graphene.String() planamount = graphene.Int() planfreequantity = graphene.Int() status = graphene.String() currenttermstart = graphene.Int() currenttermend = graphene.Int() nextbillingat = graphene.Int() createdat = graphene.Int()
from flask import Flask, request, jsonify from flask_cors import CORS import chargebee app = Flask(__name__) CORS(app) chargebee.configure("test_0kMishobocuobez4OlrbwultwfHfT51fE", "vivek1-test") @app.route('/') def hello_world(): return 'Hello World' @app.route('/api/generate_checkout_new_url', methods=['POST']) def generate_checkout_new_url(): result = chargebee.HostedPage.checkout_new({ "subscription" : { "plan_id" : request.form.get("plan_id") }, "customer" : { "id" : "cbdemo_sir" } }) hosted_page = result._response['hosted_page'] return jsonify(hosted_page) @app.route('/api/generate_checkout_existing_url', methods=['POST']) def generate_checkout_existing_url(): result = chargebee.HostedPage.checkout_existing({ "subscription" : {
def retrieve_subscription(): chargebee.configure("{site_api_key}", "{site}") result = chargebee.Subscription.retrieve("__test__KyVnHhSBWkv9J2YH") subscription = result.subscription customer = result.customer card = result.card
import chargebee import json chargebee.configure("test_qqu3aX84uFhM2zJe0qsIoI96NPfkfBtV", "rsystems-test") result = chargebee.HostedPage.checkout_one_time({ "billing_address": { "first_name": "John", "last_name": "Doe", "line1": "PO Box 9999", "city": "Walnut", "state": "California", "zip": "91789", "country": "US" }, "shipping_address": { "first_name": "John", "last_name": "Mathew", "city": "Walnut", "state": "California", "zip": "91789", "country": "US" }, "customer": { "id": "__test__3Nl7Oe7SJWjx905b" }, "addons": [{ "id": "cbdemo_setuphelp", "unit_price": 2000, "quantity": 2 }] })
def init(): api_key = 'test_W5juDKGxmAfBVbiyzl9RrIjq9zRPhi29' base_url = 'personal-test' chargebee.configure(api_key, base_url)
SENTRY_BACKEND_PUBLIC_DSN = os.environ.get('SENTRY_BACKEND_PUBLIC_DSN', '') SENTRY_FRONTEND_DSN = os.environ.get('SENTRY_FRONTEND_DSN', '') SENTRY_FRONTEND_PUBLIC_DSN = os.environ.get('SENTRY_FRONTEND_PUBLIC_DSN', '') RAVEN_CONFIG = { 'dsn': SENTRY_BACKEND_DSN, 'release': CURRENT_COMMIT_SHA, } CHARGEBEE_API_KEY = os.environ.get('CHARGEBEE_API_KEY', '') CHARGEBEE_SITE = os.environ.get('CHARGEBEE_SITE', 'hellolily-test') CHARGEBEE_FREE_PLAN_NAME = os.environ.get('CHARGEBEE_FREE_PLAN_NAME', 'lily-personal') CHARGEBEE_TEAM_PLAN_NAME = os.environ.get('CHARGEBEE_TEAM_PLAN_NAME', 'lily-team') CHARGEBEE_PRO_PLAN_NAME = os.environ.get('CHARGEBEE_PRO_PLAN_NAME', 'lily-professional') CHARGEBEE_PRO_TRIAL_PLAN_NAME = os.environ.get('CHARGEBEE_PRO_TRIAL_PLAN_NAME', 'lily-professional-trial') chargebee.configure(CHARGEBEE_API_KEY, CHARGEBEE_SITE) # Client ID and secret for the Lily Slack app. SLACK_LILY_CLIENT_ID = os.environ.get('SLACK_LILY_CLIENT_ID', '') SLACK_LILY_CLIENT_SECRET = os.environ.get('SLACK_LILY_CLIENT_SECRET', '') # Token used to verify requests are actually coming from Slack. SLACK_LILY_TOKEN = os.environ.get('SLACK_LILY_TOKEN', '') # Segment. SEGMENT_PYTHON_SOURCE_WRITE_KEY = os.environ.get('SEGMENT_PYTHON_SOURCE_WRITE_KEY', '') SEGMENT_JS_SOURCE_WRITE_KEY = os.environ.get('SEGMENT_JS_SOURCE_WRITE_KEY', '') ####################################################################################################################### # TESTING # ####################################################################################################################### TEST_RUNNER = 'lily.tests.runner.LilyNoseTestSuiteRunner'