diff --git a/setup.py b/setup.py index ec49844..df1423a 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,8 @@ packages=find_packages(), package_data={ 'tap_chargebee': [ - 'schemas/*.json' + 'schemas/common/*.json', + 'schemas/item_model/*.json', + 'schemas/plan_model/*.json' ] }) diff --git a/tap_chargebee/__init__.py b/tap_chargebee/__init__.py index c987517..d8d232e 100644 --- a/tap_chargebee/__init__.py +++ b/tap_chargebee/__init__.py @@ -1,5 +1,6 @@ import singer import tap_framework + import tap_chargebee.client import tap_chargebee.streams @@ -18,8 +19,8 @@ def main(): client = tap_chargebee.client.ChargebeeClient(args.config) runner = ChargebeeRunner( - args, client, tap_chargebee.streams.AVAILABLE_STREAMS - ) + args, client, get_available_streams(args, client) + ) if args.discover: runner.do_discover() @@ -29,3 +30,28 @@ def main(): if __name__ == '__main__': main() + + +def get_available_streams(self, cb_client): + site_name = self.config.get('site') + LOGGER.info("Site Name {}".format(site_name)) + configuration_url = 'https://{}.chargebee.com/api/v2/configurations'.format(site_name) + response = cb_client.make_request( + url=configuration_url, + method='GET') + site_configurations = response['configurations'] + product_catalog_version = next(iter(config['product_catalog_version'] for config in site_configurations if + config['domain'] == site_name), + None) + if product_catalog_version == 'v2': + available_streams = tap_chargebee.streams.ITEM_MODEL_AVAILABLE_STREAMS + self.config['item_model'] = True + LOGGER.info('Item Model') + elif product_catalog_version == 'v1': + available_streams = tap_chargebee.streams.PLAN_MODEL_AVAILABLE_STREAMS + self.config['item_model'] = False + LOGGER.info('Plan Model') + else: + LOGGER.error("Incorrect Product Catalog version {}".format(product_catalog_version)) + raise RuntimeError("Incorrect Product Catalog version") + return available_streams diff --git a/tap_chargebee/schemas/cards.json b/tap_chargebee/schemas/common/cards.json similarity index 100% rename from tap_chargebee/schemas/cards.json rename to tap_chargebee/schemas/common/cards.json diff --git a/tap_chargebee/schemas/credit_notes.json b/tap_chargebee/schemas/common/credit_notes.json similarity index 100% rename from tap_chargebee/schemas/credit_notes.json rename to tap_chargebee/schemas/common/credit_notes.json diff --git a/tap_chargebee/schemas/customers.json b/tap_chargebee/schemas/common/customers.json similarity index 88% rename from tap_chargebee/schemas/customers.json rename to tap_chargebee/schemas/common/customers.json index 9d56d36..3c5492c 100644 --- a/tap_chargebee/schemas/customers.json +++ b/tap_chargebee/schemas/common/customers.json @@ -140,46 +140,6 @@ "custom_fields": { "type": ["null", "string"] }, - "vat_number_validated_time": { - "type": ["null", "string"], - "format": "date-time" - }, - "vat_number_status": { - "type": ["null", "string"] - }, - "is_location_valid": { - "type": ["null", "boolean"] - }, - "created_from_ip": { - "type": ["null", "string"] - }, - "entity_code": { - "type": ["null", "string"] - }, - "exempt_number": { - "type": ["null", "string"] - }, - "resource_version": { - "type": ["null", "integer"] - }, - "fraud_flag": { - "type": ["null", "string"] - }, - "backup_payment_source_id": { - "type": ["null", "string"] - }, - "registered_for_gst": { - "type": ["null", "boolean"] - }, - "customer_type": { - "type": ["null", "string"] - }, - "meta_data": { - "type": ["null", "string"] - }, - "exemption_details": { - "type": ["null", "string"] - }, "billing_address": { "type": ["null","object"], "properties": { @@ -344,6 +304,23 @@ } } } + }, + "relationship": { + "type": ["null","object"], + "properties": { + "parent_id": { + "type": ["null", "string"] + }, + "payment_owner_id": { + "type": ["null", "string"] + }, + "invoice_owner_id": { + "type": ["null", "string"] + }, + "root_id": { + "type": ["null", "string"] + } + } } } } diff --git a/tap_chargebee/schemas/events.json b/tap_chargebee/schemas/common/events.json similarity index 100% rename from tap_chargebee/schemas/events.json rename to tap_chargebee/schemas/common/events.json diff --git a/tap_chargebee/schemas/gifts.json b/tap_chargebee/schemas/common/gifts.json similarity index 100% rename from tap_chargebee/schemas/gifts.json rename to tap_chargebee/schemas/common/gifts.json diff --git a/tap_chargebee/schemas/orders.json b/tap_chargebee/schemas/common/orders.json similarity index 100% rename from tap_chargebee/schemas/orders.json rename to tap_chargebee/schemas/common/orders.json diff --git a/tap_chargebee/schemas/payment_sources.json b/tap_chargebee/schemas/common/payment_sources.json similarity index 100% rename from tap_chargebee/schemas/payment_sources.json rename to tap_chargebee/schemas/common/payment_sources.json diff --git a/tap_chargebee/schemas/transactions.json b/tap_chargebee/schemas/common/transactions.json similarity index 100% rename from tap_chargebee/schemas/transactions.json rename to tap_chargebee/schemas/common/transactions.json diff --git a/tap_chargebee/schemas/virtual_bank_accounts.json b/tap_chargebee/schemas/common/virtual_bank_accounts.json similarity index 100% rename from tap_chargebee/schemas/virtual_bank_accounts.json rename to tap_chargebee/schemas/common/virtual_bank_accounts.json diff --git a/tap_chargebee/schemas/item_model/coupons.json b/tap_chargebee/schemas/item_model/coupons.json new file mode 100644 index 0000000..ab75f97 --- /dev/null +++ b/tap_chargebee/schemas/item_model/coupons.json @@ -0,0 +1,232 @@ +{ + "type":[ + "null", + "object" + ], + "additionalProperties":false, + "properties":{ + "id":{ + "type":[ + "null", + "string" + ] + }, + "name":{ + "type":[ + "null", + "string" + ] + }, + "invoice_name":{ + "type":[ + "null", + "string" + ] + }, + "discount_type":{ + "type":[ + "null", + "string" + ] + }, + "discount_percentage":{ + "type":[ + "null", + "number" + ] + }, + "discount_amount":{ + "type":[ + "null", + "number" + ] + }, + "currency_code":{ + "type":[ + "null", + "string" + ] + }, + "duration_type":{ + "type":[ + "null", + "string" + ] + }, + "duration_month":{ + "type":[ + "null", + "integer" + ] + }, + "max_redemptions":{ + "type":[ + "null", + "integer" + ] + }, + "status":{ + "type":[ + "null", + "string" + ] + }, + "apply_discount_on":{ + "type":[ + "null", + "string" + ] + }, + "apply_on":{ + "type":[ + "null", + "string" + ] + }, + "created_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "archived_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "resource_version":{ + "type":[ + "null", + "integer" + ] + }, + "updated_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "object":{ + "type":[ + "null", + "string" + ] + }, + "redemptions":{ + "type":[ + "null", + "integer" + ] + }, + "invoice_notes":{ + "type":[ + "null", + "string" + ] + }, + "meta_data":{ + "type":[ + "null", + "string" + ] + }, + "item_constraints":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "object" + ], + "properties":{ + "item_type":{ + "type":[ + "null", + "string" + ] + }, + "constraint":{ + "type":[ + "null", + "string" + ] + }, + "item_price_ids":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "string" + ] + } + } + } + } + }, + "item_constraint_criteria":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "object" + ], + "properties":{ + "item_type":{ + "type":[ + "null", + "string" + ] + }, + "currencies":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "string" + ] + } + }, + "item_family_ids":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "string" + ] + } + }, + "item_price_periods":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "string" + ] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/tap_chargebee/schemas/invoices.json b/tap_chargebee/schemas/item_model/invoices.json similarity index 99% rename from tap_chargebee/schemas/invoices.json rename to tap_chargebee/schemas/item_model/invoices.json index 556d300..1d9d1c9 100644 --- a/tap_chargebee/schemas/invoices.json +++ b/tap_chargebee/schemas/item_model/invoices.json @@ -99,6 +99,9 @@ "round_off_amount": { "type": ["null", "integer"] }, + "payment_owner": { + "type": ["null", "string"] + }, "deleted": { "type": ["null", "boolean"] }, @@ -558,9 +561,6 @@ }, "subscription_id": { "type": ["null", "string"] - }, - "total": { - "type": ["null", "integer"] } } } diff --git a/tap_chargebee/schemas/item_model/item_families.json b/tap_chargebee/schemas/item_model/item_families.json new file mode 100644 index 0000000..c9ecde9 --- /dev/null +++ b/tap_chargebee/schemas/item_model/item_families.json @@ -0,0 +1,51 @@ +{ + "type":[ + "null", + "object" + ], + "properties":{ + "id":{ + "type":[ + "null", + "string" + ] + }, + "name":{ + "type":[ + "null", + "string" + ] + }, + "description":{ + "type":[ + "null", + "string" + ] + }, + "status":{ + "type":[ + "null", + "string" + ] + }, + "resource_version":{ + "type":[ + "null", + "integer" + ] + }, + "updated_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "object":{ + "type":[ + "null", + "string" + ] + } + } +} \ No newline at end of file diff --git a/tap_chargebee/schemas/item_model/item_prices.json b/tap_chargebee/schemas/item_model/item_prices.json new file mode 100644 index 0000000..e3f04e1 --- /dev/null +++ b/tap_chargebee/schemas/item_model/item_prices.json @@ -0,0 +1,286 @@ +{ + "type":[ + "null", + "object" + ], + "properties":{ + "id":{ + "type":[ + "null", + "string" + ] + }, + "name":{ + "type":[ + "null", + "string" + ] + }, + "item_family_id":{ + "type":[ + "null", + "string" + ] + }, + "item_id":{ + "type":[ + "null", + "string" + ] + }, + "description":{ + "type":[ + "null", + "string" + ] + }, + "status":{ + "type":[ + "null", + "string" + ] + }, + "external_name":{ + "type":[ + "null", + "string" + ] + }, + "pricing_model":{ + "type":[ + "null", + "string" + ] + }, + "price":{ + "type":[ + "null", + "integer" + ] + }, + "period":{ + "type":[ + "null", + "integer" + ] + }, + "currency_code":{ + "type":[ + "null", + "string" + ] + }, + "period_unit":{ + "type":[ + "null", + "string" + ] + }, + "trial_period":{ + "type":[ + "null", + "integer" + ] + }, + "trial_period_unit":{ + "type":[ + "null", + "string" + ] + }, + "shipping_period":{ + "type":[ + "null", + "integer" + ] + }, + "shipping_period_unit":{ + "type":[ + "null", + "string" + ] + }, + "billing_cycles":{ + "type":[ + "null", + "integer" + ] + }, + "free_quantity":{ + "type":[ + "null", + "integer" + ] + }, + "resource_version":{ + "type":[ + "null", + "integer" + ] + }, + "updated_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "created_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "invoice_notes":{ + "type":[ + "null", + "string" + ] + }, + "is_taxable":{ + "type":[ + "null", + "boolean" + ] + }, + "metadata":{ + "type":[ + "null", + "string" + ] + }, + "item_type":{ + "type":[ + "null", + "string" + ] + }, + "show_description_in_invoices":{ + "type":[ + "null", + "boolean" + ] + }, + "show_description_in_quotes":{ + "type":[ + "null", + "boolean" + ] + }, + "object":{ + "type":[ + "null", + "string" + ] + }, + "tiers":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "object" + ], + "properties":{ + "starting_unit":{ + "type":[ + "null", + "integer" + ] + }, + "ending_unit":{ + "type":[ + "null", + "integer" + ] + }, + "price":{ + "type":[ + "null", + "integer" + ] + } + } + } + }, + "tax_detail":{ + "type":[ + "null", + "object" + ], + "properties":{ + "tax_profile_id":{ + "type":[ + "null", + "string" + ] + }, + "avalara_sale_type":{ + "type":[ + "null", + "string" + ] + }, + "avalara_transaction_type":{ + "type":[ + "null", + "integer" + ] + }, + "avalara_service_type":{ + "type":[ + "null", + "integer" + ] + }, + "avalara_tax_code":{ + "type":[ + "null", + "string" + ] + }, + "taxjar_product_code":{ + "type":[ + "null", + "string" + ] + } + } + }, + "accounting_detail":{ + "type":[ + "null", + "object" + ], + "properties":{ + "sku":{ + "type":[ + "null", + "string" + ] + }, + "accounting_code":{ + "type":[ + "null", + "string" + ] + }, + "accounting_category1":{ + "type":[ + "null", + "string" + ] + }, + "accounting_category2":{ + "type":[ + "null", + "string" + ] + } + } + } + } +} \ No newline at end of file diff --git a/tap_chargebee/schemas/item_model/items.json b/tap_chargebee/schemas/item_model/items.json new file mode 100644 index 0000000..3faf51b --- /dev/null +++ b/tap_chargebee/schemas/item_model/items.json @@ -0,0 +1,155 @@ +{ + "type":[ + "null", + "object" + ], + "properties":{ + "id":{ + "type":[ + "null", + "string" + ] + }, + "name":{ + "type":[ + "null", + "string" + ] + }, + "description":{ + "type":[ + "null", + "string" + ] + }, + "status":{ + "type":[ + "null", + "string" + ] + }, + "resource_version":{ + "type":[ + "null", + "integer" + ] + }, + "updated_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "item_family_id":{ + "type":[ + "null", + "string" + ] + }, + "type":{ + "type":[ + "null", + "string" + ] + }, + "is_shippable":{ + "type":[ + "null", + "boolean" + ] + }, + "is_giftable":{ + "type":[ + "null", + "boolean" + ] + }, + "redirect_url":{ + "type":[ + "null", + "string" + ] + }, + "enabled_for_checkout":{ + "type":[ + "null", + "boolean" + ] + }, + "enabled_in_portal":{ + "type":[ + "null", + "boolean" + ] + }, + "included_in_mrr":{ + "type":[ + "null", + "boolean" + ] + }, + "item_applicability":{ + "type":[ + "null", + "string" + ] + }, + "gift_claim_redirect_url":{ + "type":[ + "null", + "string" + ] + }, + "unit":{ + "type":[ + "null", + "string" + ] + }, + "metered":{ + "type":[ + "null", + "boolean" + ] + }, + "usage_calculation":{ + "type":[ + "null", + "string" + ] + }, + "metadata":{ + "type":[ + "null", + "string" + ] + }, + "object":{ + "type":[ + "null", + "string" + ] + }, + "applicable_items":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "object" + ], + "properties":{ + "id":{ + "type":[ + "null", + "string" + ] + } + } + } + } + } +} \ No newline at end of file diff --git a/tap_chargebee/schemas/promotional_credits.json b/tap_chargebee/schemas/item_model/promotional_credits.json similarity index 100% rename from tap_chargebee/schemas/promotional_credits.json rename to tap_chargebee/schemas/item_model/promotional_credits.json diff --git a/tap_chargebee/schemas/item_model/subscriptions.json b/tap_chargebee/schemas/item_model/subscriptions.json new file mode 100644 index 0000000..e2173cf --- /dev/null +++ b/tap_chargebee/schemas/item_model/subscriptions.json @@ -0,0 +1,644 @@ +{ + "type":[ + "null", + "object" + ], + "additionalProperties":false, + "properties":{ + "id":{ + "type":[ + "null", + "string" + ] + }, + "currency_code":{ + "type":[ + "null", + "string" + ] + }, + "start_date":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "trial_end":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "remaining_billing_cycles":{ + "type":[ + "null", + "integer" + ] + }, + "po_number":{ + "type":[ + "null", + "string" + ] + }, + "customer_id":{ + "type":[ + "null", + "string" + ] + }, + "status":{ + "type":[ + "null", + "string" + ] + }, + "coupon":{ + "type":[ + "null", + "string" + ] + }, + "trial_start":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "current_term_start":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "current_term_end":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "next_billing_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "created_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "started_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "activated_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "pause_date":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "resume_date":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "cancelled_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "cancel_reason":{ + "type":[ + "null", + "string" + ] + }, + "created_from_ip":{ + "type":[ + "null", + "string" + ] + }, + "resource_version":{ + "type":[ + "null", + "integer" + ] + }, + "object":{ + "type":[ + "null", + "string" + ] + }, + "updated_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "has_scheduled_changes":{ + "type":[ + "null", + "boolean" + ] + }, + "payment_source_id":{ + "type":[ + "null", + "string" + ] + }, + "auto_collection":{ + "type":[ + "null", + "string" + ] + }, + "billing_period":{ + "type":[ + "null", + "integer" + ] + }, + "billing_period_unit":{ + "type":[ + "null", + "string" + ] + }, + "due_invoices_count":{ + "type":[ + "null", + "integer" + ] + }, + "due_since":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "total_dues":{ + "type":[ + "null", + "integer" + ] + }, + "mrr":{ + "type":[ + "null", + "integer" + ] + }, + "exchange_rate":{ + "type":[ + "null", + "number" + ] + }, + "base_currency_code":{ + "type":[ + "null", + "string" + ] + }, + "invoice_notes":{ + "type":[ + "null", + "string" + ] + }, + "meta_data":{ + "type":[ + "null", + "string" + ] + }, + "deleted":{ + "type":[ + "null", + "boolean" + ] + }, + "subscription_items":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "object" + ], + "properties":{ + "item_price_id":{ + "type":[ + "null", + "string" + ] + }, + "item_type":{ + "type":[ + "null", + "string" + ] + }, + "quantity":{ + "type":[ + "null", + "integer" + ] + }, + "unit_price":{ + "type":[ + "null", + "integer" + ] + }, + "amount":{ + "type":[ + "null", + "integer" + ] + }, + "free_quantity":{ + "type":[ + "null", + "integer" + ] + }, + "trial_end":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "billing_cycles":{ + "type":[ + "null", + "integer" + ] + }, + "service_period_days":{ + "type":[ + "null", + "integer" + ] + }, + "charge_on_event":{ + "type":[ + "null", + "string" + ] + }, + "charge_once":{ + "type":[ + "null", + "boolean" + ] + }, + "charge_on_option":{ + "type":[ + "null", + "string" + ] + }, + "object":{ + "type":[ + "null", + "string" + ] + } + } + } + }, + "item_tiers":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "object" + ], + "properties":{ + "item_price_id":{ + "type":[ + "null", + "string" + ] + }, + "starting_unit":{ + "type":[ + "null", + "integer" + ] + }, + "ending_unit":{ + "type":[ + "null", + "integer" + ] + }, + "price":{ + "type":[ + "null", + "integer" + ] + } + } + } + }, + "charged_items":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "object" + ], + "properties":{ + "item_price_id":{ + "type":[ + "null", + "string" + ] + }, + "last_charged_at":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + } + } + } + }, + "coupons":{ + "type":[ + "null", + "array" + ], + "items":{ + "type":[ + "null", + "object" + ], + "properties":{ + "coupon_id":{ + "type":[ + "null", + "string" + ] + }, + "apply_till":{ + "type":[ + "null", + "string" + ], + "format":"date-time" + }, + "applied_count":{ + "type":[ + "null", + "integer" + ] + }, + "coupon_code":{ + "type":[ + "null", + "string" + ] + }, + "object":{ + "type":[ + "null", + "string" + ] + } + } + } + }, + "shipping_address":{ + "type":[ + "null", + "object" + ], + "properties":{ + "first_name":{ + "type":[ + "null", + "string" + ] + }, + "last_name":{ + "type":[ + "null", + "string" + ] + }, + "email":{ + "type":[ + "null", + "string" + ] + }, + "company":{ + "type":[ + "null", + "string" + ] + }, + "phone":{ + "type":[ + "null", + "string" + ] + }, + "line1":{ + "type":[ + "null", + "string" + ] + }, + "line2":{ + "type":[ + "null", + "string" + ] + }, + "line3":{ + "type":[ + "null", + "string" + ] + }, + "city":{ + "type":[ + "null", + "string" + ] + }, + "state_code":{ + "type":[ + "null", + "string" + ] + }, + "state":{ + "type":[ + "null", + "string" + ] + }, + "country":{ + "type":[ + "null", + "string" + ] + }, + "zip":{ + "type":[ + "null", + "string" + ] + }, + "validation_status":{ + "type":[ + "null", + "string" + ] + }, + "object":{ + "type":[ + "null", + "string" + ] + } + } + }, + "referral_info":{ + "type":[ + "null", + "object" + ], + "properties":{ + "referral_code":{ + "type":[ + "null", + "string" + ] + }, + "coupon_code":{ + "type":[ + "null", + "string" + ] + }, + "referrer_id":{ + "type":[ + "null", + "string" + ] + }, + "external_reference_id":{ + "type":[ + "null", + "string" + ] + }, + "reward_status":{ + "type":[ + "null", + "string" + ] + }, + "referral_system":{ + "type":[ + "null", + "string" + ] + }, + "account_id":{ + "type":[ + "null", + "string" + ] + }, + "campaign_id":{ + "type":[ + "null", + "string" + ] + }, + "external_campaign_id":{ + "type":[ + "null", + "string" + ] + }, + "friend_offer_type":{ + "type":[ + "null", + "string" + ] + }, + "referrer_reward_type":{ + "type":[ + "null", + "string" + ] + }, + "notify_referral_system":{ + "type":[ + "null", + "string" + ] + }, + "destination_url":{ + "type":[ + "null", + "string" + ] + }, + "post_purchase_widget_enabled":{ + "type":[ + "null", + "boolean" + ] + } + } + } + } +} \ No newline at end of file diff --git a/tap_chargebee/schemas/addons.json b/tap_chargebee/schemas/plan_model/addons.json similarity index 89% rename from tap_chargebee/schemas/addons.json rename to tap_chargebee/schemas/plan_model/addons.json index b277eab..5633ddf 100644 --- a/tap_chargebee/schemas/addons.json +++ b/tap_chargebee/schemas/plan_model/addons.json @@ -101,7 +101,7 @@ }, "invoice_notes": { "type": ["null", "string"], - "maxLength": 1000 + "maxLength": 2000 }, "taxable": { "type": ["null", "boolean"] @@ -122,6 +122,9 @@ "custom_fields": { "type": ["null", "string"] }, + "price_in_decimal": { + "type": ["null", "string"] + }, "tiers": { "type": ["null", "array"], "items": { @@ -137,6 +140,15 @@ "price ": { "type": ["null", "integer"], "minimum": 0 + }, + "starting_unit_in_decimal": { + "type": ["null", "string"] + }, + "ending_unit_in_decimal": { + "type": ["null", "string"] + }, + "price_in_decimal": { + "type": ["null", "string"] } } } diff --git a/tap_chargebee/schemas/coupons.json b/tap_chargebee/schemas/plan_model/coupons.json similarity index 100% rename from tap_chargebee/schemas/coupons.json rename to tap_chargebee/schemas/plan_model/coupons.json diff --git a/tap_chargebee/schemas/plan_model/invoices.json b/tap_chargebee/schemas/plan_model/invoices.json new file mode 100644 index 0000000..3547fe4 --- /dev/null +++ b/tap_chargebee/schemas/plan_model/invoices.json @@ -0,0 +1,587 @@ +{ + "type": ["null", "object"], + "additionalProperties": false, + "properties": { + "id": { + "type": ["null", "string"] + }, + "po_number": { + "type": ["null", "string"] + }, + "customer_id": { + "type": ["null", "string"] + }, + "recurring": { + "type": ["null", "boolean"] + }, + "status": { + "type": ["null", "string"] + }, + "vat_number": { + "type": ["null", "string"] + }, + "price_type": { + "type": ["null", "string"] + }, + "date": { + "type": ["null", "string"], + "format": "date-time" + }, + "due_date": { + "type": ["null", "string"], + "format": "date-time" + }, + "net_term_days": { + "type": ["null", "integer"] + }, + "currency_code": { + "type": ["null", "string"] + }, + "total": { + "type": ["null", "integer"] + }, + "amount_paid": { + "type": ["null", "integer"] + }, + "amount_adjusted": { + "type": ["null", "integer"] + }, + "write_off_amount": { + "type": ["null", "integer"] + }, + "credits_applied": { + "type": ["null", "integer"] + }, + "amount_due": { + "type": ["null", "integer"] + }, + "paid_at": { + "type": ["null", "string"], + "format": "date-time" + }, + "dunning_status": { + "type": ["null", "string"] + }, + "next_retry_at": { + "type": ["null", "string"], + "format": "date-time" + }, + "resource_version": { + "type": ["null", "integer"] + }, + "voided_at": { + "type": ["null", "string"], + "format": "date-time" + }, + "updated_at": { + "type": ["null", "string"], + "format": "date-time" + }, + "sub_total": { + "type": ["null", "integer"] + }, + "tax": { + "type": ["null", "integer"] + }, + "first_invoice": { + "type": ["null", "boolean"] + }, + "has_advance_charges": { + "type": ["null", "boolean"] + }, + "expected_payment_date": { + "type": ["null", "string"], + "format": "date-time" + }, + "amount_to_collect": { + "type": ["null", "integer"] + }, + "round_off_amount": { + "type": ["null", "integer"] + }, + "payment_owner": { + "type": ["null", "string"] + }, + "deleted": { + "type": ["null", "boolean"] + }, + "is_gifted": { + "type": ["null", "boolean"] + }, + "term_finalized": { + "type": ["null", "boolean"] + }, + "line_items": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "string"] + }, + "subscription_id": { + "type": ["null", "string"] + }, + "date_from": { + "type": ["null", "string"], + "format": "date-time" + }, + "date_to": { + "type": ["null", "string"], + "format": "date-time" + }, + "unit_amount": { + "type": ["null", "integer"] + }, + "quantity": { + "type": ["null", "integer"] + }, + "is_taxed": { + "type": ["null", "boolean"] + }, + "tax_amount": { + "type": ["null", "integer"] + }, + "tax_rate": { + "type": ["null", "integer"] + }, + "amount": { + "type": ["null", "integer"] + }, + "discount_amount": { + "type": ["null", "integer"] + }, + "item_level_discount_amount": { + "type": ["null", "integer"] + }, + "description": { + "type": ["null", "string"] + }, + "entity_type": { + "type": ["null", "string"] + }, + "tax_exempt_reason": { + "type": ["null", "string"] + }, + "entity_id": { + "type": ["null", "string"] + }, + "pricing_model": { + "type": ["null", "string"] + }, + "object": { + "type": ["null", "string"] + }, + "amount_in_decimal": { + "type": ["null", "string"] + }, + "quantity_in_decimal": { + "type": ["null", "string"] + }, + "unit_amount_in_decimal": { + "type": ["null", "string"] + } + } + } + }, + "discounts": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "amount": { + "type": ["null", "integer"] + }, + "description": { + "type": ["null", "string"] + }, + "entity_type": { + "type": ["null", "string"] + }, + "entity_id": { + "type": ["null", "string"] + }, + "object": { + "type": ["null", "string"] + } + } + } + }, + "line_item_discounts": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "line_item_id": { + "type": ["null", "string"] + }, + "discount_type": { + "type": ["null", "string"] + }, + "coupon_id": { + "type": ["null", "string"] + }, + "discount_amount": { + "type": ["null", "integer"] + } + } + } + }, + "taxes": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "name": { + "type": ["null", "string"] + }, + "amount": { + "type": ["null", "integer"] + }, + "description": { + "type": ["null", "string"] + } + } + } + }, + "line_item_taxes": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "line_item_id": { + "type": ["null", "string"] + }, + "tax_name": { + "type": ["null", "string"] + }, + "tax_rate": { + "type": ["null", "integer"] + }, + "is_partial_tax_applied": { + "type": ["null", "boolean"] + }, + "is_non_compliance_tax": { + "type": ["null", "boolean"] + }, + "taxable_amount": { + "type": ["null", "integer"] + }, + "tax_amount": { + "type": ["null", "integer"] + }, + "tax_juris_type": { + "type": ["null", "string"] + }, + "tax_juris_name": { + "type": ["null", "string"] + }, + "tax_juris_code": { + "type": ["null", "string"] + } + } + } + }, + "line_item_tiers": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "line_item_id": { + "type": ["null", "string"] + }, + "starting_unit": { + "type": ["null", "integer"] + }, + "ending_unit": { + "type": ["null", "integer"] + }, + "quantity_used": { + "type": ["null", "integer"] + }, + "unit_amount": { + "type": ["null", "integer"] + }, + "starting_unit_in_decimal": { + "type": ["null", "string"] + }, + "ending_unit_in_decimal": { + "type": ["null", "string"] + }, + "quantity_used_in_decimal": { + "type": ["null", "string"] + }, + "unit_amount_in_decimal": { + "type": ["null", "string"] + } + } + } + }, + "linked_payments": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "txn_id": { + "type": ["null", "string"] + }, + "applied_amount": { + "type": ["null", "integer"] + }, + "applied_at": { + "type": ["null", "string"], + "format": "date-time" + }, + "txn_status": { + "type": ["null", "string"] + }, + "txn_date": { + "type": ["null", "string"], + "format": "date-time" + }, + "txn_amount": { + "type": ["null", "integer"] + } + } + } + }, + "applied_credits": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "cn_id": { + "type": ["null", "string"] + }, + "applied_amount": { + "type": ["null", "integer"] + }, + "applied_at": { + "type": ["null", "string"], + "format": "date-time" + }, + "cn_reason_code": { + "type": ["null", "string"] + }, + "cn_date": { + "type": ["null", "string"], + "format": "date-time" + }, + "cn_status": { + "type": ["null", "string"] + } + } + } + }, + "adjustment_credit_notes": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "cn_id": { + "type": ["null", "string"] + }, + "cn_reason_code": { + "type": ["null", "string"] + }, + "cn_date": { + "type": ["null", "string"], + "format": "date-time" + }, + "cn_total": { + "type": ["null", "integer"] + }, + "cn_status": { + "type": ["null", "string"] + } + } + } + }, + "issued_credit_notes": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "cn_id": { + "type": ["null", "string"] + }, + "cn_reason_code": { + "type": ["null", "string"] + }, + "cn_date": { + "type": ["null", "string"], + "format": "date-time" + }, + "cn_total": { + "type": ["null", "integer"] + }, + "cn_status": { + "type": ["null", "string"] + } + } + } + }, + "linked_orders": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "id": { + "type": ["null", "string"] + }, + "document_number": { + "type": ["null", "string"] + }, + "status": { + "type": ["null", "string"] + }, + "order_type": { + "type": ["null", "string"] + }, + "reference_id": { + "type": ["null", "string"] + }, + "fulfillment_status": { + "type": ["null", "string"] + }, + "batch_id": { + "type": ["null", "string"] + }, + "created_at": { + "type": ["null", "string"], + "format": "date-time" + } + } + } + }, + "notes": { + "type": ["null", "array"], + "items": { + "type": ["null", "object"], + "properties": { + "entity_type": { + "type": ["null", "string"] + }, + "note": { + "type": ["null", "string"] + }, + "entity_id": { + "type": ["null", "string"] + } + } + } + }, + "shipping_address": { + "type": ["null","object"], + "properties": { + "first_name": { + "type": ["null", "string"] + }, + "last_name": { + "type": ["null", "string"] + }, + "email": { + "type": ["null", "string"] + }, + "company": { + "type": ["null", "string"] + }, + "phone": { + "type": ["null", "string"] + }, + "line1": { + "type": ["null", "string"] + }, + "line2": { + "type": ["null", "string"] + }, + "line3": { + "type": ["null", "string"] + }, + "city": { + "type": ["null", "string"] + }, + "state_code": { + "type": ["null", "string"] + }, + "state": { + "type": ["null", "string"] + }, + "country": { + "type": ["null", "string"] + }, + "zip": { + "type": ["null", "string"] + }, + "validation_status,": { + "type": ["null", "string"] + } + } + }, + "billing_address": { + "type": ["null","object"], + "properties": { + "first_name": { + "type": ["null", "string"] + }, + "last_name": { + "type": ["null", "string"] + }, + "email": { + "type": ["null", "string"] + }, + "company": { + "type": ["null", "string"] + }, + "phone": { + "type": ["null", "string"] + }, + "line1": { + "type": ["null", "string"] + }, + "line2": { + "type": ["null", "string"] + }, + "line3": { + "type": ["null", "string"] + }, + "city": { + "type": ["null", "string"] + }, + "state_code": { + "type": ["null", "string"] + }, + "state": { + "type": ["null", "string"] + }, + "country": { + "type": ["null", "string"] + }, + "zip": { + "type": ["null", "string"] + }, + "validation_status": { + "type": ["null", "string"] + }, + "object": { + "type": ["null", "string"] + } + } + }, + "exchange_rate": { + "type": ["null", "number"] + }, + "base_currency_code": { + "type": ["null", "string"] + }, + "new_sales_amount": { + "type": ["null", "integer"] + }, + "object": { + "type": ["null", "string"] + }, + "subscription_id": { + "type": ["null", "string"] + } + } +} diff --git a/tap_chargebee/schemas/plans.json b/tap_chargebee/schemas/plan_model/plans.json similarity index 86% rename from tap_chargebee/schemas/plans.json rename to tap_chargebee/schemas/plan_model/plans.json index f90cc72..66a7888 100644 --- a/tap_chargebee/schemas/plans.json +++ b/tap_chargebee/schemas/plan_model/plans.json @@ -121,6 +121,12 @@ "custom_fields": { "type": ["null", "string"] }, + "free_quantity_in_decimal": { + "type": ["null", "string"] + }, + "price_in_decimal": { + "type": ["null", "string"] + }, "tiers": { "type": ["null", "array"], "items": { @@ -134,6 +140,15 @@ }, "price": { "type": ["null", "integer"] + }, + "starting_unit_in_decimal": { + "type": ["null", "string"] + }, + "ending_unit_in_decimal": { + "type": ["null", "string"] + }, + "price_in_decimal": { + "type": ["null", "string"] } } } @@ -145,6 +160,9 @@ "properties": { "id": { "type": ["null", "string"] + }, + "quantity_in_decimal": { + "type": ["null", "string"] } } } @@ -165,6 +183,9 @@ }, "charge_once": { "type": ["null", "boolean"] + }, + "quantity_in_decimal": { + "type": ["null", "string"] } } } diff --git a/tap_chargebee/schemas/plan_model/promotional_credits.json b/tap_chargebee/schemas/plan_model/promotional_credits.json new file mode 100644 index 0000000..dba033e --- /dev/null +++ b/tap_chargebee/schemas/plan_model/promotional_credits.json @@ -0,0 +1,47 @@ +{ + "type": ["null", "object"], + "additionalProperties": false, + "properties": { + "id": { + "type": ["null", "string"], + "maxLength": 150 + }, + "customer_id": { + "type": ["null", "string"], + "maxLength": 50 + }, + "type":{ + "type": ["null", "string"] + }, + "amount": { + "type": ["null", "string"] + }, + "amount_in_decimal": { + "type": ["null", "string"] + }, + "currency_code": { + "type": ["null", "string"] + }, + "description": { + "type": ["null", "string"] + }, + "credit_type": { + "type": ["null", "string"] + }, + "reference": { + "type": ["null", "string"] + }, + "closing_balance": { + "type": ["null", "integer"], + "minimum": 0 + }, + "done_by": { + "type": ["null", "string"], + "maxLength": 100 + }, + "created_at": { + "type": ["null", "string"], + "format": "date-time" + } + } +} \ No newline at end of file diff --git a/tap_chargebee/schemas/subscriptions.json b/tap_chargebee/schemas/plan_model/subscriptions.json similarity index 91% rename from tap_chargebee/schemas/subscriptions.json rename to tap_chargebee/schemas/plan_model/subscriptions.json index 831c814..e82fc1a 100644 --- a/tap_chargebee/schemas/subscriptions.json +++ b/tap_chargebee/schemas/plan_model/subscriptions.json @@ -157,6 +157,18 @@ "custom_fields": { "type": ["null", "string"] }, + "plan_amount_in_decimal" : { + "type": ["null", "string"] + }, + "plan_free_quantity_in_decimal" : { + "type": ["null", "string"] + }, + "plan_quantity_in_decimal" : { + "type": ["null", "string"] + }, + "plan_unit_price_in_decimal" : { + "type": ["null", "string"] + }, "addons": { "type": ["null", "array"], "items": { @@ -183,6 +195,15 @@ }, "object": { "type": ["null", "string"] + }, + "quantity_in_decimal": { + "type": ["null", "string"] + }, + "unit_price_in_decimal": { + "type": ["null", "string"] + }, + "amount_in_decimal": { + "type": ["null", "string"] } } } @@ -209,6 +230,12 @@ }, "object": { "type": ["null", "string"] + }, + "quantity_in_decimal": { + "type": ["null", "string"] + }, + "unit_price_in_decimal": { + "type": ["null", "string"] } } } diff --git a/tap_chargebee/streams/__init__.py b/tap_chargebee/streams/__init__.py index b93e33b..64206d1 100644 --- a/tap_chargebee/streams/__init__.py +++ b/tap_chargebee/streams/__init__.py @@ -4,6 +4,9 @@ from .customers import CustomersStream from .events import EventsStream from .invoices import InvoicesStream +from .item_families import ItemFamiliesStream +from .item_prices import ItemPricesStream +from .items import ItemsStream from .payment_sources import PaymentSourcesStream from .plans import PlansStream from .subscriptions import SubscriptionsStream @@ -12,11 +15,10 @@ from .credit_notes import CreditNotesStream from .gifts import GiftsStream from .orders import OrdersStream -from.promotional_credits import PromotionalCreditsStream +from .promotional_credits import PromotionalCreditsStream -AVAILABLE_STREAMS = [ +COMMON_AVAILABLE_STREAMS = [ EventsStream, - AddonsStream, CouponsStream, CreditNotesStream, CustomersStream, @@ -25,8 +27,18 @@ OrdersStream, PaymentSourcesStream, PromotionalCreditsStream, - PlansStream, SubscriptionsStream, TransactionsStream, VirtualBankAccountsStream ] + +PLAN_MODEL_AVAILABLE_STREAMS = COMMON_AVAILABLE_STREAMS + [ + AddonsStream, + PlansStream +] + +ITEM_MODEL_AVAILABLE_STREAMS = COMMON_AVAILABLE_STREAMS + [ + ItemsStream, + ItemPricesStream, + ItemFamiliesStream +] diff --git a/tap_chargebee/streams/addons.py b/tap_chargebee/streams/addons.py index 97a030b..69889e6 100644 --- a/tap_chargebee/streams/addons.py +++ b/tap_chargebee/streams/addons.py @@ -12,6 +12,8 @@ class AddonsStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'plan_model/addons' + SORT_BY = None def get_url(self): return 'https://{}.chargebee.com/api/v2/addons'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/base.py b/tap_chargebee/streams/base.py index b3544f3..1f3b1ef 100644 --- a/tap_chargebee/streams/base.py +++ b/tap_chargebee/streams/base.py @@ -3,6 +3,9 @@ import json import os +import pytz +from datetime import datetime, timedelta + from .util import Util from dateutil.parser import parse from tap_framework.streams import BaseStream @@ -61,7 +64,7 @@ def generate_catalog(self): os.path.normpath( os.path.join( self.get_class_path(), - '../schemas/{}.json'.format("cards")))) + '../schemas/common/{}.json'.format("cards")))) refs = {"cards.json": cards} @@ -119,6 +122,7 @@ def sync_data(self): table = self.TABLE api_method = self.API_METHOD done = False + sync_interval_in_mins = 2 # Attempt to get the bookmark date from the state file (if one exists and is supplied). LOGGER.info('Attempting to get the most recent bookmark_date for entity {}.'.format(self.ENTITY)) @@ -133,22 +137,29 @@ def sync_data(self): # Convert bookmarked start date to POSIX. bookmark_date_posix = int(bookmark_date.timestamp()) - + to_date = datetime.now(pytz.utc) - timedelta(minutes=sync_interval_in_mins) + to_date_posix = int(to_date.timestamp()) + sync_window = str([bookmark_date_posix, to_date_posix]) + LOGGER.info("Sync Window {} for schema {}".format(sync_window, table)) # Create params for filtering if self.ENTITY == 'event': - params = {"occurred_at[after]": bookmark_date_posix} + params = {"occurred_at[between]": sync_window} bookmark_key = 'occurred_at' elif self.ENTITY == 'promotional_credit': - params = {"created_at[after]": bookmark_date_posix} + params = {"created_at[between]": sync_window} bookmark_key = 'created_at' else: - params = {"updated_at[after]": bookmark_date_posix} + params = {"updated_at[between]": sync_window} bookmark_key = 'updated_at' + # Add sort_by[asc] to prevent data overwrite by oldest deleted records + if self.SORT_BY is not None: + params['sort_by[asc]'] = self.SORT_BY + LOGGER.info("Querying {} starting at {}".format(table, bookmark_date)) while not done: - max_date = bookmark_date + max_date = to_date response = self.client.make_request( url=self.get_url(), @@ -187,13 +198,6 @@ def sync_data(self): singer.write_records(table, to_write) ctr.increment(amount=len(to_write)) - - for item in to_write: - #if item.get(bookmark_key) is not None: - max_date = max( - max_date, - parse(item.get(bookmark_key)) - ) self.state = incorporate( self.state, table, 'bookmark_date', max_date) @@ -207,3 +211,6 @@ def sync_data(self): bookmark_date = max_date save_state(self.state) + + def get_schema(self): + return self.load_schema_by_name(self.SCHEMA) diff --git a/tap_chargebee/streams/coupons.py b/tap_chargebee/streams/coupons.py index cddc960..94c44bb 100644 --- a/tap_chargebee/streams/coupons.py +++ b/tap_chargebee/streams/coupons.py @@ -12,7 +12,13 @@ class CouponsStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'plan_model/coupons' + SORT_BY = 'created_at' + def __init__(self, config, state, catalog, client): + BaseChargebeeStream.__init__(self, config, state, catalog, client) + if self.config['item_model']: + self.SCHEMA = 'item_model/coupons' def get_url(self): return 'https://{}.chargebee.com/api/v2/coupons'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/credit_notes.py b/tap_chargebee/streams/credit_notes.py index 092a871..d29f113 100644 --- a/tap_chargebee/streams/credit_notes.py +++ b/tap_chargebee/streams/credit_notes.py @@ -12,6 +12,8 @@ class CreditNotesStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'common/credit_notes' + SORT_BY = 'date' def get_url(self): return 'https://{}.chargebee.com/api/v2/credit_notes'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/customers.py b/tap_chargebee/streams/customers.py index 6a51d9f..7e5d154 100644 --- a/tap_chargebee/streams/customers.py +++ b/tap_chargebee/streams/customers.py @@ -12,6 +12,8 @@ class CustomersStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'common/customers' + SORT_BY = 'updated_at' def get_url(self): return 'https://{}.chargebee.com/api/v2/customers'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/events.py b/tap_chargebee/streams/events.py index 4c8a6d2..559fb0d 100644 --- a/tap_chargebee/streams/events.py +++ b/tap_chargebee/streams/events.py @@ -12,6 +12,8 @@ class EventsStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['occurred_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'common/events' + SORT_BY = 'occurred_at' def get_url(self): return 'https://{}.chargebee.com/api/v2/events'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/gifts.py b/tap_chargebee/streams/gifts.py index 956d1ed..da7a9b5 100644 --- a/tap_chargebee/streams/gifts.py +++ b/tap_chargebee/streams/gifts.py @@ -12,6 +12,8 @@ class GiftsStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'common/gifts' + SORT_BY = None def get_url(self): return 'https://{}.chargebee.com/api/v2/gifts'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/invoices.py b/tap_chargebee/streams/invoices.py index ed84367..783d3ce 100644 --- a/tap_chargebee/streams/invoices.py +++ b/tap_chargebee/streams/invoices.py @@ -12,6 +12,13 @@ class InvoicesStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'plan_model/invoices' + SORT_BY = 'updated_at' + + def __init__(self, config, state, catalog, client): + BaseChargebeeStream.__init__(self, config, state, catalog, client) + if self.config['item_model']: + self.SCHEMA = 'item_model/invoices' def get_url(self): return 'https://{}.chargebee.com/api/v2/invoices'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/item_families.py b/tap_chargebee/streams/item_families.py new file mode 100644 index 0000000..dcc920c --- /dev/null +++ b/tap_chargebee/streams/item_families.py @@ -0,0 +1,19 @@ +from tap_chargebee.streams.base import BaseChargebeeStream + + +class ItemFamiliesStream(BaseChargebeeStream): + TABLE = 'item_families' + ENTITY = 'item_family' + REPLICATION_METHOD = 'INCREMENTAL' + REPLICATION_KEY = 'updated_at' + KEY_PROPERTIES = ['id'] + BOOKMARK_PROPERTIES = ['updated_at'] + SELECTED_BY_DEFAULT = True + VALID_REPLICATION_KEYS = ['updated_at'] + INCLUSION = 'available' + API_METHOD = 'GET' + SCHEMA = 'item_model/item_families' + SORT_BY = None + + def get_url(self): + return 'https://{}.chargebee.com/api/v2/item_families'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/item_prices.py b/tap_chargebee/streams/item_prices.py new file mode 100644 index 0000000..85d20197 --- /dev/null +++ b/tap_chargebee/streams/item_prices.py @@ -0,0 +1,19 @@ +from tap_chargebee.streams.base import BaseChargebeeStream + + +class ItemPricesStream(BaseChargebeeStream): + TABLE = 'item_prices' + ENTITY = 'item_price' + REPLICATION_METHOD = 'INCREMENTAL' + REPLICATION_KEY = 'updated_at' + KEY_PROPERTIES = ['id'] + BOOKMARK_PROPERTIES = ['updated_at'] + SELECTED_BY_DEFAULT = True + VALID_REPLICATION_KEYS = ['updated_at'] + INCLUSION = 'available' + API_METHOD = 'GET' + SCHEMA = 'item_model/item_prices' + SORT_BY = 'updated_at' + + def get_url(self): + return 'https://{}.chargebee.com/api/v2/item_prices'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/items.py b/tap_chargebee/streams/items.py new file mode 100644 index 0000000..43c8934 --- /dev/null +++ b/tap_chargebee/streams/items.py @@ -0,0 +1,19 @@ +from tap_chargebee.streams.base import BaseChargebeeStream + + +class ItemsStream(BaseChargebeeStream): + TABLE = 'items' + ENTITY = 'item' + REPLICATION_METHOD = 'INCREMENTAL' + REPLICATION_KEY = 'updated_at' + KEY_PROPERTIES = ['id'] + BOOKMARK_PROPERTIES = ['updated_at'] + SELECTED_BY_DEFAULT = True + VALID_REPLICATION_KEYS = ['updated_at'] + INCLUSION = 'available' + API_METHOD = 'GET' + SCHEMA = 'item_model/items' + SORT_BY = 'updated_at' + + def get_url(self): + return 'https://{}.chargebee.com/api/v2/items'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/orders.py b/tap_chargebee/streams/orders.py index 0cb1ec7..39b80ce 100644 --- a/tap_chargebee/streams/orders.py +++ b/tap_chargebee/streams/orders.py @@ -12,6 +12,8 @@ class OrdersStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'common/orders' + SORT_BY = 'updated_at' def get_url(self): return 'https://{}.chargebee.com/api/v2/orders'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/payment_sources.py b/tap_chargebee/streams/payment_sources.py index 8b1d6b0..07eb7f8 100644 --- a/tap_chargebee/streams/payment_sources.py +++ b/tap_chargebee/streams/payment_sources.py @@ -12,6 +12,8 @@ class PaymentSourcesStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'common/payment_sources' + SORT_BY = None def get_url(self): return 'https://{}.chargebee.com/api/v2/payment_sources'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/plans.py b/tap_chargebee/streams/plans.py index de62953..d92595b 100644 --- a/tap_chargebee/streams/plans.py +++ b/tap_chargebee/streams/plans.py @@ -12,6 +12,8 @@ class PlansStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'plan_model/plans' + SORT_BY = None def get_url(self): return 'https://{}.chargebee.com/api/v2/plans'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/promotional_credits.py b/tap_chargebee/streams/promotional_credits.py index a795865..0f6df0a 100644 --- a/tap_chargebee/streams/promotional_credits.py +++ b/tap_chargebee/streams/promotional_credits.py @@ -12,6 +12,13 @@ class PromotionalCreditsStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['created_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'plan_model/promotional_credits' + SORT_BY = None + + def __init__(self, config, state, catalog, client): + BaseChargebeeStream.__init__(self, config, state, catalog, client) + if self.config['item_model']: + self.SCHEMA = 'item_model/promotional_credits' def get_url(self): return 'https://{}.chargebee.com/api/v2/promotional_credits'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/subscriptions.py b/tap_chargebee/streams/subscriptions.py index 5f04033..72a47f6 100644 --- a/tap_chargebee/streams/subscriptions.py +++ b/tap_chargebee/streams/subscriptions.py @@ -12,6 +12,13 @@ class SubscriptionsStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'plan_model/subscriptions' + SORT_BY = 'updated_at' + + def __init__(self, config, state, catalog, client): + BaseChargebeeStream.__init__(self, config, state, catalog, client) + if self.config['item_model']: + self.SCHEMA = 'item_model/subscriptions' def get_url(self): return 'https://{}.chargebee.com/api/v2/subscriptions'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/transactions.py b/tap_chargebee/streams/transactions.py index a287604..ba30af0 100644 --- a/tap_chargebee/streams/transactions.py +++ b/tap_chargebee/streams/transactions.py @@ -12,6 +12,8 @@ class TransactionsStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'common/transactions' + SORT_BY = 'updated_at' def get_url(self): return 'https://{}.chargebee.com/api/v2/transactions'.format(self.config.get('site')) diff --git a/tap_chargebee/streams/virtual_bank_accounts.py b/tap_chargebee/streams/virtual_bank_accounts.py index edabb90..8ff5484 100644 --- a/tap_chargebee/streams/virtual_bank_accounts.py +++ b/tap_chargebee/streams/virtual_bank_accounts.py @@ -12,6 +12,8 @@ class VirtualBankAccountsStream(BaseChargebeeStream): VALID_REPLICATION_KEYS = ['updated_at'] INCLUSION = 'available' API_METHOD = 'GET' + SCHEMA = 'common/virtual_bank_accounts' + SORT_BY = None def get_url(self): return 'https://{}.chargebee.com/api/v2/virtual_bank_accounts'.format(self.config.get('site'))