From 7a975a95aefc3c2165353bcb90ac7df96c6b0e0a Mon Sep 17 00:00:00 2001 From: Koen Sengers Date: Wed, 2 Mar 2022 15:47:32 +0100 Subject: [PATCH 1/3] feat(chargebee) add credit note model --- .../integration_tests/configured_catalog.json | 13 + .../source_chargebee/schemas/credit_note.json | 507 ++++++++++++++++++ .../source_chargebee/source.py | 3 +- .../source_chargebee/streams.py | 8 + 4 files changed, 530 insertions(+), 1 deletion(-) create mode 100644 airbyte-integrations/connectors/source-chargebee/source_chargebee/schemas/credit_note.json diff --git a/airbyte-integrations/connectors/source-chargebee/integration_tests/configured_catalog.json b/airbyte-integrations/connectors/source-chargebee/integration_tests/configured_catalog.json index a555bf8b014f3..a32342fc6826d 100644 --- a/airbyte-integrations/connectors/source-chargebee/integration_tests/configured_catalog.json +++ b/airbyte-integrations/connectors/source-chargebee/integration_tests/configured_catalog.json @@ -168,6 +168,19 @@ "sync_mode": "incremental", "destination_sync_mode": "append", "cursor_field": ["updated_at"] + }, + { + "stream": { + "name": "credit_note", + "json_schema": {}, + "supported_sync_modes": ["full_refresh", "incremental"], + "source_defined_cursor": true, + "default_cursor_field": ["updated_at"], + "source_defined_primary_key": [["id"]] + }, + "sync_mode": "incremental", + "destination_sync_mode": "append", + "cursor_field": ["updated_at"] } ] } diff --git a/airbyte-integrations/connectors/source-chargebee/source_chargebee/schemas/credit_note.json b/airbyte-integrations/connectors/source-chargebee/source_chargebee/schemas/credit_note.json new file mode 100644 index 0000000000000..9fe60f807dc5e --- /dev/null +++ b/airbyte-integrations/connectors/source-chargebee/source_chargebee/schemas/credit_note.json @@ -0,0 +1,507 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "name": "Credit Note", + "type": "object", + "properties": { + "id": { + "type": ["string", "null"], + "maxLength": 50 + }, + "customer_id": { + "type": ["string", "null"], + "maxLength": 50 + }, + "subscription_id": { + "type": ["string", "null"], + "maxLength": 50 + }, + "reference_invoice_id": { + "type": ["string", "null"], + "maxLength": 50 + }, + "type": { + "type": ["string", "null"], + "enum": ["adjustment", "refundable"] + }, + "reason_code": { + "type": ["string", "null"], + "enum": ["write_off", "subscription_change", "subscription_cancellation", "subscription_pause"] + }, + "status": { + "type": ["string", "null"], + "enum": ["adjusted", "refunded", "refund_due", "voided"] + }, + "vat_number": { + "type": ["string", "null"], + "maxLength": 20 + }, + "date": { + "type": ["integer", "null"] + }, + "price_type": { + "type": ["string", "null"], + "enum": ["tax_exclusive", "tax_inclusive"] + }, + "currency_code": { + "type": ["string", "null"], + "maxLength": 3 + }, + "total": { + "type": ["integer", "null"], + "minimum": 0 + }, + "amount_allocated": { + "type": ["integer", "null"], + "minimum": 0 + }, + "amount_refunded": { + "type": ["integer", "null"], + "minimum": 0 + }, + "amount_available": { + "type": ["integer", "null"], + "minimum": 0 + }, + "refunded_at": { + "type": ["integer", "null"] + }, + "voided_at": { + "type": ["integer", "null"] + }, + "generated_at": { + "type": ["integer", "null"] + }, + "resource_version": { + "type": ["integer", "null"] + }, + "updated_at": { + "type": ["integer", "null"] + }, + "sub_total": { + "type": ["integer", "null"], + "minimum": 0 + }, + "sub_total_in_local_currency": { + "type": ["integer", "null"], + "minimum": 0 + }, + "total_in_local_currency": { + "type": ["integer", "null"], + "minimum": 0 + }, + "local_currency_code": { + "type": ["string", "null"] + }, + "round_off_amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "fractional_correction": { + "type": ["integer", "null"], + "minimum": 0 + }, + "deleted": { + "type": ["boolean", "null"] + }, + "create_reason_code": { + "type": ["string", "null"] + }, + "vat_number_prefix": { + "type": ["string", "null"], + "maxLength": 10 + }, + "line_items": { + "type": ["array", "null"], + "items": { + "type": ["object", "null"], + "properties": { + "id": { + "type": ["string", "null"], + "maxLength": 40 + }, + "subscription_id": { + "type": ["string", "null"], + "maxLength": 50 + }, + "date_from": { + "type": ["integer", "null"] + }, + "date_to": { + "type": ["integer", "null"] + }, + "unit_amount": { + "type": ["integer", "null"] + }, + "quantity": { + "type": ["integer", "null"] + }, + "amount": { + "type": ["integer", "null"] + }, + "pricing_model": { + "type": ["string", "null"], + "enum": ["flat_fee", "per_unit", "tiered", "volume", "stairstep"] + }, + "is_taxed": { + "type": ["boolean", "null"] + }, + "tax_amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "tax_rate": { + "type": ["number", "null"], + "minimum": 0.0, + "maximum": 100.0 + }, + "unit_amount_in_decimal": { + "type": ["string", "null"], + "maxLength": 33 + }, + "quantity_in_decimal": { + "type": ["string", "null"], + "maxLength": 33 + }, + "amount_in_decimal": { + "type": ["string", "null"], + "maxLength": 33 + }, + "discount_amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "item_level_discount_amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "description": { + "type": ["string", "null"], + "maxLength": 250 + }, + "entity_description": { + "type": ["string", "null"], + "maxLength": 500 + }, + "entity_type": { + "type": ["string", "null"], + "enum": [ + "adhoc", + + "plan_setup", + "plan", + "addon", + + "plan_item_price", + "addon_item_price", + "charge_item_price" + ] + }, + "tax_exempt_reason": { + "type": ["string", "null"], + "enum": [ + "tax_not_configured", + "region_non_taxable", + "export", + "customer_exempt", + "product_exempt", + "zero_rated", + "reverse_charge", + "high_value_physical_goods" + ] + }, + "entity_id": { + "type": ["string", "null"], + "maxLength": 100 + }, + "customer_id": { + "type": ["string", "null"], + "maxLength": 100 + } + } + } + }, + "discounts": { + "type": ["array", "null"], + "items": { + "type": ["object", "null"], + "properties": { + "amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "description": { + "type": ["string", "null"], + "maxLength": 250 + }, + "entity_type": { + "type": ["string", "null"], + "enum": [ + "item_level_coupon", + "document_level_coupon", + "promotional_credits", + "prorated_credits" + ] + }, + "entity_id": { + "type": ["string", "null"], + "maxLength": 100 + } + } + } + }, + "line_item_discounts": { + "type": ["array", "null"], + "items": { + "type": ["object", "null"], + "properties": { + "line_item_id": { + "type": ["string", "null"], + "maxLength": 50 + }, + "discount_type": { + "type": ["string", "null"], + "enum": [ + "item_level_coupon", + "document_level_coupon", + "promotional_credits", + "prorated_credits" + ] + }, + "discount_amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + + "entity_id": { + "type": ["string", "null"], + "maxLength": 100 + } + } + } + }, + "line_item_tiers": { + "type": ["array", "null"], + "items": { + "type": ["object", "null"], + "properties": { + "line_item_id": { + "type": ["string", "null"], + "maxLength": 40 + }, + "starting_unit": { + "type": ["integer", "null"], + "minimum": 0 + }, + "ending_unit": { + "type": ["integer", "null"] + }, + "quantity_used": { + "type": ["integer", "null"], + "minimum": 0 + }, + "unit_amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "starting_unit_in_decimal": { + "type": ["string", "null"], + "maxLength": 33 + }, + "ending_unit_in_decimal": { + "type": ["string", "null"], + "maxLength": 33 + }, + "quantity_used_in_decimal": { + "type": ["string", "null"], + "maxLength": 33 + }, + "unit_amount_in_decimal": { + "type": ["string", "null"], + "maxLength": 40 + } + } + } + }, + "taxes": { + "type": ["array", "null"], + "items": { + "type": ["object", "null"], + "properties": { + "name": { + "type": ["string", "null"], + "maxLength": 100 + }, + "amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "description": { + "type": ["string", "null"], + "maxLength": 250 + } + } + } + }, + "line_item_taxes": { + "type": ["array", "null"], + "items": { + "type": ["object", "null"], + "properties": { + "line_item_id": { + "type": ["string", "null"], + "maxLength": 40 + }, + "tax_name": { + "type": ["string", "null"], + "maxLength": 100 + }, + "tax_rate": { + "type": ["number", "null"], + "minimum": 0.0, + "maximum": 100.0 + }, + "is_partial_tax_applied": { + "type": ["boolean", "null"] + }, + "is_non_compliance_tax": { + "type": ["boolean", "null"] + }, + "taxable_amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "tax_amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "tax_juris_type": { + "type": ["string", "null"], + "enum": [ + "country", + "federal", + "state", + "county", + "city", + "special", + "unincorporated", + "other" + ] + }, + "tax_juris_name": { + "type": ["string", "null"], + "maxLength": 250 + }, + "tax_juris_code": { + "type": ["string", "null"], + "maxLength": 250 + }, + "tax_amount_in_local_currency": { + "type": ["integer", "null"], + "minimum": 0 + }, + "local_currency-code": { + "type": ["string", "null"] + } + } + } + }, + "linked_refunds": { + "type": ["array", "null"], + "items": { + "type": ["object", "null"], + "properties": { + "txn_id": { + "type": ["string", "null"], + "maxLength": 40 + }, + "applied_amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "applied_at": { + "type": ["integer", "null"] + }, + "txn_status": { + "type": ["string", "null"], + "enum": [ + "in_progress", + "success", + "voided", + "failure", + "timeout", + "needs_attention" + ] + }, + "txn_date": { + "type": ["integer", "null"] + }, + "txn_amount": { + "type": ["integer", "null"], + "minimum": 1 + }, + "refund_reason_code": { + "type": ["string","null"] + } + } + } + }, + "linked_tax_withheld_refunds": { + "type": ["array", "null"], + "items": { + "type": ["object", "null"], + "properties": { + "id": { + "type": ["string", "null"], + "maxLength": 40 + }, + "amount": { + "type": ["integer", "null"], + "minimum": 1 + }, + "description": { + "type": ["string", "null"] + }, + "date": { + "type": ["integer", "null"] + }, + "reference_number": { + "type": ["string", "null"] + } + } + } + }, + "allocations": { + "type": ["array", "null"], + "items": { + "type": ["object", "null"], + "properties": { + "invoice_id": { + "type": ["string", "null"], + "maxLength": 40 + }, + "allocated_amount": { + "type": ["integer", "null"], + "minimum": 0 + }, + "allocated_at": { + "type": ["integer", "null"] + }, + "invoice_date": { + "type": ["integer", "null"] + }, + "invoice_status": { + "type": ["string", "null"], + "enum": [ + "paid", + "posted", + "payment_due", + "not_paid", + "voided", + "pending" + ] + } + } + } + } + } +} diff --git a/airbyte-integrations/connectors/source-chargebee/source_chargebee/source.py b/airbyte-integrations/connectors/source-chargebee/source_chargebee/source.py index 08e5a76238a0d..56fd7eaa42ca7 100644 --- a/airbyte-integrations/connectors/source-chargebee/source_chargebee/source.py +++ b/airbyte-integrations/connectors/source-chargebee/source_chargebee/source.py @@ -9,7 +9,7 @@ from airbyte_cdk.sources import AbstractSource from airbyte_cdk.sources.streams import Stream -from .streams import Addon, AttachedItem, Coupon, Customer, Event, Invoice, Item, ItemPrice, Order, Plan, Subscription, Transaction +from .streams import Addon, AttachedItem, Coupon, CreditNote, Customer, Event, Invoice, Item, ItemPrice, Order, Plan, Subscription, Transaction class SourceChargebee(AbstractSource): @@ -35,6 +35,7 @@ def streams(self, config) -> List[Stream]: # 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), diff --git a/airbyte-integrations/connectors/source-chargebee/source_chargebee/streams.py b/airbyte-integrations/connectors/source-chargebee/source_chargebee/streams.py index 85b80cfaaa950..a22afe46791fa 100644 --- a/airbyte-integrations/connectors/source-chargebee/source_chargebee/streams.py +++ b/airbyte-integrations/connectors/source-chargebee/source_chargebee/streams.py @@ -13,6 +13,7 @@ from chargebee.models import Addon as AddonModel from chargebee.models import AttachedItem as AttachedItemModel from chargebee.models import Coupon as CouponModel +from chargebee.models import CreditNote as CreditNoteModel from chargebee.models import Customer as CustomerModel from chargebee.models import Event as EventModel from chargebee.models import Invoice as InvoiceModel @@ -319,3 +320,10 @@ def request_params(self, **kwargs) -> MutableMapping[str, Any]: params = super().request_params(**kwargs) params["sort_by[asc]"] = "created_at" return params + +class CreditNote(IncrementalChargebeeStream): + """ + API docs: https://apidocs.chargebee.com/docs/api/credit_notes?prod_cat_ver=2#list_credit_notes + """ + + api = CreditNoteModel From 51b194d974947315be9be558e35c542fc5616735 Mon Sep 17 00:00:00 2001 From: Koen Sengers Date: Wed, 2 Mar 2022 16:02:30 +0100 Subject: [PATCH 2/3] fix(airbyte): update version Dockerfile --- airbyte-config/init/src/main/resources/seed/source_specs.yaml | 2 +- airbyte-integrations/connectors/source-chargebee/Dockerfile | 2 +- docs/integrations/sources/chargebee.md | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/airbyte-config/init/src/main/resources/seed/source_specs.yaml b/airbyte-config/init/src/main/resources/seed/source_specs.yaml index f0800c2d89d7c..8c0660f70d4c5 100644 --- a/airbyte-config/init/src/main/resources/seed/source_specs.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_specs.yaml @@ -952,7 +952,7 @@ supportsNormalization: false supportsDBT: false supported_destination_sync_modes: [] -- dockerImage: "airbyte/source-chargebee:0.1.9" +- dockerImage: "airbyte/source-chargebee:0.1.10" spec: documentationUrl: "https://apidocs.chargebee.com/docs/api" connectionSpecification: diff --git a/airbyte-integrations/connectors/source-chargebee/Dockerfile b/airbyte-integrations/connectors/source-chargebee/Dockerfile index e9f6e87d5ffb7..f4c54cc322be2 100644 --- a/airbyte-integrations/connectors/source-chargebee/Dockerfile +++ b/airbyte-integrations/connectors/source-chargebee/Dockerfile @@ -13,5 +13,5 @@ RUN pip install . ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] -LABEL io.airbyte.version=0.1.9 +LABEL io.airbyte.version=0.1.10 LABEL io.airbyte.name=airbyte/source-chargebee diff --git a/docs/integrations/sources/chargebee.md b/docs/integrations/sources/chargebee.md index 1442f5ca7836f..c1e229c02b967 100644 --- a/docs/integrations/sources/chargebee.md +++ b/docs/integrations/sources/chargebee.md @@ -28,6 +28,7 @@ Some streams may depend on Product Catalog version and be accessible only on sit * Customers * Events * Invoices + * Credit Notes * Orders * Coupons * Subscriptions @@ -40,7 +41,7 @@ Some streams may depend on Product Catalog version and be accessible only on sit * Item Prices * Attached Items -Also, 9 streams from the above 10 incremental streams are pure incremental meaning that they: +Also, 12 streams from the above 13 incremental streams are pure incremental meaning that they: * read only new records; * output only new records. @@ -84,6 +85,7 @@ Log into Chargebee and then generate an [API Key](https://apidocs.chargebee.com/ | Version | Date | Pull Request | Subject | | :--- | :--- | :--- | :--- | +| 0.1.10 | 2022-03-02 | [10795](https://github.com/airbytehq/airbyte/pull/10795) | Add support for Credit Note stream | | 0.1.9 | 2022-0224 | [10312](https://github.com/airbytehq/airbyte/pull/10312) | Add support for Transaction Stream | | 0.1.8 | 2022-02-22 | [10366](https://github.com/airbytehq/airbyte/pull/10366) | Fix broken `coupon` stream + add unit tests | | 0.1.7 | 2022-02-14 | [10269](https://github.com/airbytehq/airbyte/pull/10269) | Add support for Coupon stream | From 40ca42a461f6f11648359effc7517e92dfc1b371 Mon Sep 17 00:00:00 2001 From: Koen Sengers Date: Wed, 2 Mar 2022 16:31:19 +0100 Subject: [PATCH 3/3] fix(airbyte): update version Dockerfile v2 --- .../init/src/main/resources/seed/source_definitions.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml index 738c638e3c21b..15e199f77ee6c 100644 --- a/airbyte-config/init/src/main/resources/seed/source_definitions.yaml +++ b/airbyte-config/init/src/main/resources/seed/source_definitions.yaml @@ -112,7 +112,7 @@ - name: Chargebee sourceDefinitionId: 686473f1-76d9-4994-9cc7-9b13da46147c dockerRepository: airbyte/source-chargebee - dockerImageTag: 0.1.9 + dockerImageTag: 0.1.10 documentationUrl: https://docs.airbyte.io/integrations/sources/chargebee icon: chargebee.svg sourceType: api