Skip to content

Commit

Permalink
🐛 Source Recharge: Added the UI toggle Use 'Orders' Deprecated API
Browse files Browse the repository at this point in the history
…to switch between `deprecated` and `modern` api versions for `Orders` stream (#34707)
  • Loading branch information
bazarnov authored Feb 1, 2024
1 parent 320e694 commit 7bd2dd6
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ acceptance_tests:
bypass_reason: "volatile data"
- name: onetimes
bypass_reason: "no data from stream"
- name: orders
bypass_reason: "no data from stream"
- name: subscriptions
bypass_reason: "no data from stream"
ignored_fields:
shop:
- name: shop/updated_at
Expand All @@ -26,6 +22,27 @@ acceptance_tests:
exact_order: no
extra_records: yes
fail_on_extra_columns: false
- config_path: secrets/config_order_modern_api.json
empty_streams:
- name: collections
bypass_reason: "volatile data"
- name: discounts
bypass_reason: "volatile data"
- name: onetimes
bypass_reason: "no data from stream"
ignored_fields:
shop:
- name: shop/updated_at
bypass_reason: "updated after login"
- name: store/updated_at
bypass_reason: "updated after login"
timeout_seconds: 7200
expect_records:
path: "integration_tests/expected_records_orders_modern_api.jsonl"
extra_fields: no
exact_order: no
extra_records: yes
fail_on_extra_columns: false
connection:
tests:
- config_path: secrets/config.json
Expand All @@ -35,7 +52,7 @@ acceptance_tests:
discovery:
tests:
- backward_compatibility_tests_config:
disable_for_version: 0.2.10
disable_for_version: 1.1.2
config_path: secrets/config.json
full_refresh:
tests:
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions airbyte-integrations/connectors/source-recharge/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#

from source_recharge.run import run

import sys

from airbyte_cdk.entrypoint import launch
from source_recharge import SourceRecharge

if __name__ == "__main__":
run()
source = SourceRecharge()
launch(source, sys.argv[1:])
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data:
connectorBuildOptions:
baseImage: docker.io/airbyte/python-connector-base:1.1.0@sha256:bd98f6505c6764b1b5f99d3aedc23dfc9e9af631a62533f60eb32b1d3dbab20c
definitionId: 45d2e135-2ede-49e1-939f-3e3ec357a65e
dockerImageTag: 1.1.2
dockerImageTag: 1.1.3
dockerRepository: airbyte/source-recharge
githubIssueLabel: source-recharge
icon: recharge.svg
Expand Down
19 changes: 1 addition & 18 deletions airbyte-integrations/connectors/source-recharge/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,13 @@
]

setup(
entry_points={
"console_scripts": [
"source-recharge=source_recharge.run:run",
],
},
name="source_recharge",
description="Source implementation for Recharge.",
author="Airbyte",
author_email="contact@airbyte.io",
packages=find_packages(),
install_requires=MAIN_REQUIREMENTS,
package_data={
"": [
# Include yaml files in the package (if any)
"*.yml",
"*.yaml",
# Include all json files in the package, up to 4 levels deep
"*.json",
"*/*.json",
"*/*/*.json",
"*/*/*/*.json",
"*/*/*/*/*.json",
]
},
package_data={"": ["*.json", "schemas/*.json", "schemas/shared/*.json"]},
extras_require={
"tests": TEST_REQUIREMENTS,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

from abc import ABC, abstractmethod
from typing import Any, Iterable, List, Mapping, MutableMapping, Optional
from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Union

import pendulum
import requests
Expand Down Expand Up @@ -212,12 +212,23 @@ class Onetimes(RechargeStreamModernAPI, IncrementalRechargeStream):
"""


class Orders(RechargeStreamDeprecatedAPI, IncrementalRechargeStream):
class OrdersDeprecatedApi(RechargeStreamDeprecatedAPI, IncrementalRechargeStream):
"""
Orders Stream: https://developer.rechargepayments.com/v1-shopify?python#list-orders
Using old API version to avoid schema changes and loosing email, first_name, last_name columns, because in new version it not present
"""

name = "orders"


class OrdersModernApi(RechargeStreamModernAPI, IncrementalRechargeStream):
"""
Orders Stream: https://developer.rechargepayments.com/v1-shopify?python#list-orders
Using newer API version to fetch all the data, based on the Customer's UI toggle `use_deprecated_api: FALSE`.
"""

name = "orders"


class Products(RechargeStreamDeprecatedAPI):
"""
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,96 @@
"browser_ip": {
"type": ["null", "string"]
},
"charge": {
"type": ["null", "object"],
"additionalProperties": true,
"properties": {
"id": {
"type": ["null", "integer"]
},
"external_transaction_id": {
"type": ["null", "object"],
"additionalProperties": true,
"properties": {
"payment_processor": {
"type": ["null", "string"]
}
}
},
"payment_processor_name": {
"type": ["null", "string"]
},
"status": {
"type": ["null", "string"]
}
}
},
"client_details": {
"type": ["null", "object"],
"additionalProperties": true,
"properties": {
"browser_ip": {
"type": ["null", "string"]
},
"user_agent": {
"type": ["null", "string"]
}
}
},
"discounts": {
"type": ["null", "array"],
"items": {
"type": ["null", "string"]
}
},
"error": {
"type": ["null", "string"]
},
"external_cart_token": {
"type": ["null", "string"]
},
"external_order_id": {
"type": ["null", "object"],
"additionalProperties": true,
"properties": {
"ecommerce": {
"type": ["null", "string"]
}
}
},
"external_order_name": {
"type": ["null", "object"],
"additionalProperties": true,
"properties": {
"ecommerce": {
"type": ["null", "string"]
}
}
},
"external_order_number": {
"type": ["null", "object"],
"additionalProperties": true,
"properties": {
"ecommerce": {
"type": ["null", "string"]
}
}
},
"order_attributes": {
"type": ["null", "array"],
"items": {
"type": ["null", "string"]
}
},
"taxable": {
"type": ["null", "boolean"]
},
"total_duties": {
"type": ["null", "string"]
},
"total_weight_grams": {
"type": ["null", "integer"]
},
"charge_id": {
"type": ["null", "integer"]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@
#


from typing import Any, List, Mapping, Tuple
from typing import Any, List, Mapping, Tuple, Union

from airbyte_cdk import AirbyteLogger
from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams import Stream
from airbyte_cdk.sources.streams.http.auth import TokenAuthenticator

from .api import Addresses, Charges, Collections, Customers, Discounts, Metafields, Onetimes, Orders, Products, Shop, Subscriptions
from .api import (
Addresses,
Charges,
Collections,
Customers,
Discounts,
Metafields,
Onetimes,
OrdersDeprecatedApi,
OrdersModernApi,
Products,
Shop,
Subscriptions,
)


class RechargeTokenAuthenticator(TokenAuthenticator):
Expand All @@ -30,6 +43,12 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->
except Exception as error:
return False, f"Unable to connect to Recharge API with the provided credentials - {repr(error)}"

def select_orders_stream(self, config: Mapping[str, Any], **kwargs) -> Union[OrdersDeprecatedApi, OrdersModernApi]:
if config.get("use_orders_deprecated_api"):
return OrdersDeprecatedApi(config, **kwargs)
else:
return OrdersModernApi(config, **kwargs)

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
auth = RechargeTokenAuthenticator(token=config["access_token"])
return [
Expand All @@ -40,7 +59,8 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
Discounts(config, authenticator=auth),
Metafields(config, authenticator=auth),
Onetimes(config, authenticator=auth),
Orders(config, authenticator=auth),
# select the Orders stream class, based on the UI toggle "Use `Orders` Deprecated API"
self.select_orders_stream(config, authenticator=auth),
Products(config, authenticator=auth),
Shop(config, authenticator=auth),
Subscriptions(config, authenticator=auth),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"title": "Access Token",
"description": "The value of the Access Token generated. See the <a href=\"https://docs.airbyte.com/integrations/sources/recharge\">docs</a> for more information.",
"airbyte_secret": true
},
"use_orders_deprecated_api": {
"type": "boolean",
"title": "Use `Orders` Deprecated API",
"description": "Define whether or not the `Orders` stream should use the deprecated `2021-01` API version, or use `2021-11`, otherwise.",
"default": true
}
}
}
Expand Down
Loading

0 comments on commit 7bd2dd6

Please sign in to comment.