Skip to content

Commit

Permalink
✨ Source Paypal Transactions: Siver Certification (#34510)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandre Girard <alexandre@airbyte.io>
Co-authored-by: alafanechere <augustin.lafanechere@gmail.com>
Co-authored-by: Augustin <augustin@airbyte.io>
  • Loading branch information
4 people committed Feb 17, 2024
1 parent 6301a20 commit 27abc6d
Show file tree
Hide file tree
Showing 50 changed files with 4,471 additions and 248 deletions.
@@ -0,0 +1,3 @@
[run]
omit =
source_paypal_transaction/run.py
Expand Up @@ -2,3 +2,12 @@

## 0.1.0
Source implementation with support of Transactions and Balances streams

## 1.0.0
Mark Client ID and Client Secret as required files

## 2.1.0
Migration to Low code

## 2.3.0
Adding New Streams - Payments, Disputes, Invoices, Product Catalog
138 changes: 130 additions & 8 deletions airbyte-integrations/connectors/source-paypal-transaction/README.md
@@ -1,54 +1,89 @@
# Paypal-Transaction source connector


This is the repository for the Paypal-Transaction source connector, written in Python.
For information about how to use this connector within Airbyte, see [the documentation](https://docs.airbyte.com/integrations/sources/paypal-transaction).

## Local development

### Prerequisites
* Python (~=3.9)
* Poetry (~=1.7) - installation instructions [here](https://python-poetry.org/docs/#installation)

#### Prerequisites
* Python (~=3.9)
* Poetry (~=1.7) - installation instructions [here](https://python-poetry.org/docs/#installation)
* Paypal Client ID and Client Secret
* If you are going to use the data generator scripts you need to setup yourPaypal Sandbox and a Buyer user in your sandbox, to simulate the data. YOu cna get that information in the [Apps & Credentials page](https://developer.paypal.com/dashboard/applications/live).
* Buyer Username
* Buyer Password
* Payer ID (Account ID)

### Installing the connector

From this connector directory, run:
```bash
poetry install --with dev
```


### Create credentials

**If you are a community contributor**, follow the instructions in the [documentation](https://docs.airbyte.com/integrations/sources/paypal-transaction)
to generate the necessary credentials. Then create a file `secrets/config.json` conforming to the `source_paypal_transaction/spec.yaml` file.
Note that any directory named `secrets` is gitignored across the entire Airbyte repo, so there is no danger of accidentally checking in sensitive information.
See `sample_files/sample_config.json` for a sample config file.

* You must have created your credentials under the `secrets/` folder
* For the read command, you can create separate catalogs to test the streams individually. All catalogs are under the folder `integration_tests`. Select the one you want to test with the read command.


### Locally running the connector

```
poetry run source-paypal-transaction spec
poetry run source-paypal-transaction check --config secrets/config.json
poetry run source-paypal-transaction discover --config secrets/config.json
poetry run source-paypal-transaction read --config secrets/config.json --catalog sample_files/configured_catalog.json
#Example with list_payments catalog and the debug flag
poetry run source-paypal-transaction read --config secrets/config.json --catalog integration_tests/configured_catalog_list_payments.json --debug
```

### Running unit tests
To run unit tests locally, from the connector directory run:

```
poetry run pytest unit_tests
```

### Building the docker image

1. Install [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md)
2. Run the following command to build the docker image:


### Installing the connector
From this connector directory, run:
```bash
airbyte-ci connectors --name=source-paypal-transaction build
poetry install --with dev
```

##### Customizing our build process
When contributing on our connector you might need to customize the build process to add a system dependency or set an env var.
You can customize our build process by adding a `build_customization.py` module to your connector.
This module should contain a `pre_connector_install` and `post_connector_install` async function that will mutate the base image and the connector container respectively.
It will be imported at runtime by our build process and the functions will be called if they exist.

Here is an example of a `build_customization.py` module:
```python
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
# Feel free to check the dagger documentation for more information on the Container object and its methods.
# https://dagger-io.readthedocs.io/en/sdk-python-v0.6.4/
from dagger import Container
```

An image will be available on your host with the tag `airbyte/source-paypal-transaction:dev`.



### Running as a docker container
Then run any of the connector commands as follows:
```
Expand All @@ -58,23 +93,110 @@ docker run --rm -v $(pwd)/secrets:/secrets airbyte/source-paypal-transaction:dev
docker run --rm -v $(pwd)/secrets:/secrets -v $(pwd)/integration_tests:/integration_tests airbyte/source-paypal-transaction:dev read --config /secrets/config.json --catalog /integration_tests/configured_catalog.json
```


### Running our CI test suite

You can run our full test suite locally using [`airbyte-ci`](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/pipelines/README.md):

```bash
airbyte-ci connectors --name=source-paypal-transaction test
```

If you are testing locally, you can use your local credentials (config.json file) by using `--use-local-secrets`

```bash
airbyte-ci connectors --name source-paypal-transaction --use-local-secrets test
```

### Customizing acceptance Tests
Customize `acceptance-test-config.yml` file to configure acceptance tests. See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference) for more information.
If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py.

### Dependency Management

## Running Unit tests locally

To run unit tests locally, form the root `source_paypal_transaction` directory run:

```bash
python -m pytest unit_test
```

## Test changes in the sandbox

If you have a [Paypal Sandbox](https://developer.paypal.com/tools/sandbox/accounts/) you will be able to use some APIs to create new data and test how data is being created in your destinaiton and choose the best syn strategy that suits better your use case.
Some endpoints will require special permissions on the sandbox to update and change some values.

In the `bin` folder you will find several data generator scripts:

* **disputes_generator.py:**
* Update dispute: Uses the _PATCH_ method of the `https://api-m.paypal.com/v1/customer/disputes/{dispute_id}` endpoint. You need the ID and create a payload to pass it as an argument. See more information [here](https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_patch).

```bash
python disputes_generator.py update DISPUTE_ID ''[{"op": "replace", "path": "/reason", "value": "The new reason"}]'
```
* Update Evidence status: Uses the _POST_ method of the `https://api-m.paypal.com/v1/customer/disputes/{dispute_id}/require-evidence` endpoint. You need the ID and select an option to pass it as an argument. See more information [here](https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_require-evidence)
```bash
python update_dispute.py require-evidence DISPUTE_ID SELLER_EVIDENCE
```
* **invoices.py:**
* Create draft invoice: Uses the _POST_ method of the `https://api-m.sandbox.paypal.com/v2/invoicing/invoices` endpoint. It will automatically generate an invoice (no need to pass any parameters). See more information [here](https://developer.paypal.com/docs/api/invoicing/v2/#invoices_create).
```bash
python invoices.py create_draft
```
* Send a Draft Invoice: Uses the _POST_ method of the `https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{invoice_id}/send` endpoint. You need the Invoice ID, a subject and a note (just to have something to update) and an email as an argument. See more information [here](https://developer.paypal.com/docs/api/invoicing/v2/#invoices_send)
```bash
python invoices.py send_draft --invoice_id "INV2-XXXX-XXXX-XXXX-XXXX" --subject "Your Invoice Subject" --note "Your custom note" --additional_recipients example@email.com
```
* **payments_generator.py:**
* Partially update payment: Uses the _PATCH_ method of the `https://api-m.paypal.com/v1/payments/payment/{payment_id}` endpoint. You need the payment ID and a payload with new values. (no need to pass any parameters). See more information [here](https://developer.paypal.com/docs/api/invoicing/v2/#invoices_create).
```bash
python script_name.py update PAYMENT_ID '[{"op": "replace", "path": "/transactions/0/amount", "value": {"total": "50.00", "currency": "USD"}}]'
```
* **paypal_transaction_generator.py:**
Make sure you have the `buyer_username`, `buyer_password` and `payer_id` in your config file. You can get the sample configuratin in the `sample_config.json`.
* Generate transactions: This uses Selenium, so you will be prompted to your account to simulate the complete transaction flow. You can add a number at the end of the command to do more than one transaction. By default the script runs 3 transactions.
**NOTE: Be midnfu of the number of transactions, as it will be interacting with your machine, and you may not be able to use it while creating the transactions**
```bash
python paypal_transaction_generator.py [NUMBER_OF_DESIRED_TRANSACTIONS]
```
* **product_catalog.py:**
* Create a product: Uses the _POST_ method of the `https://api-m.sandbox.paypal.com/v1/catalogs/products` endpoint. You need to add the description and the category in the command line. For the proper category see more information [here](https://developer.paypal.com/docs/api/catalog-products/v1/#products_create).
```bash
python product_catalog.py --action create --description "YOUR DESCRIPTION" --category PAYPAL_CATEGORY
```
* Update a product: Uses the _PATCH_ method of the `https://developer.paypal.com/docs/api/catalog-products/v1/#products_patch` endpoint. You need the product ID, a description and the Category as an argument. See more information [here](https://developer.paypal.com/docs/api/catalog-products/v1/#products_patch)
```bash
python product_catalog.py --action update --product_id PRODUCT_ID --update_payload '[{"op": "replace", "path": "/description", "value": "My Update. Does it changes it?"}]'
```
## Dependency Management
All of your dependencies should go in `setup.py`, NOT `requirements.txt`. The requirements file is only used to connect internal Airbyte dependencies in the monorepo for local development.
We split dependencies between two groups, dependencies that are:
* required for your connector to work need to go to `MAIN_REQUIREMENTS` list.
* required for the testing need to go to `TEST_REQUIREMENTS` list
All of your dependencies should be managed via Poetry.
To add a new dependency, run:
```bash
poetry add <package-name>
```
Please commit the changes to `pyproject.toml` and `poetry.lock` files.
## Publishing a new version of the connector
Expand Down
@@ -1,69 +1,84 @@
# See [Connector Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/connector-acceptance-tests-reference)
# for more information about how to configure these tests
# Make sure the paths you have in each path matches with your data.
#For multiple env testing, you can duplicate the tests and change the path to the proper credentials file
connector_image: airbyte/source-paypal-transaction:dev
test_strictness_level: high
acceptance_tests:
spec:
tests:
#Test with Prod credentials (Make sure you purt the right ones)
- spec_path: "source_paypal_transaction/spec.yaml"
config_path: secrets/config_oauth.json
config_path: secrets/config.json
backward_compatibility_tests_config:
disable_for_version: "0.1.13"
connection:
tests:
- config_path: secrets/config_oauth.json
#Test With Prod Credentials
- config_path: secrets/config.json
status: succeed
- config_path: secrets/config_oauth_sandbox.json
status: succeed
- config_path: integration_tests/invalid_config.json
status: failed
- config_path: integration_tests/invalid_config_oauth.json
#Test with Invalid Credentials
- config_path: integration_tests/sample_files/invalid_config.json
status: failed
#Test with Sandbox Credentials
# - config_path: secrets/config_sandbox.json
# status: succeed
discovery:
tests:
- config_path: secrets/config_oauth.json
- config_path: secrets/config.json
# - config_path: secrets/config_sandbox.json
backward_compatibility_tests_config:
disable_for_version: "2.0.0" # Change in cursor field for transactions stream
basic_read:
tests:
- config_path: secrets/config_oauth.json
ignored_fields:
balances:
- name: last_refresh_time
bypass_reason: "field changes during every read"
#Test Prod Environment - Uncomment and change according to your prod setup
#Change the expected records, remember to align them with the timeframe you have selected
#Do not select streams that take more than 5 mins to load data as that can lead to timeouts
#You can comment the lines if you are sure you have data for the below streams.
- config_path: secrets/config.json
# - config_path: secrets/config_sandbox.json
empty_streams:
- name: transactions
bypass_reason: "can not populate"
timeout_seconds: 1200
expect_records:
path: "integration_tests/expected_records.jsonl"
extra_fields: no
exact_order: no
extra_records: yes
- config_path: secrets/config_oauth_sandbox.json
- name: show_product_details
bypass_reason: "Products may not exist"
- name: list_products
bypass_reason: "Product List may be too big causing timeout errors"
- name: search_invoices
bypass_reason: "Order makes the diff fail."
#Have to add for testing PR CI.
- name: list_disputes
bypass_reason: "Disputes may not exist."
ignored_fields:
balances:
- name: last_refresh_time
bypass_reason: "field changes during every read"
timeout_seconds: 1200
list_products:
- name: description
bypass_reason: "Sometimes it is not contained in the response"
timeout_seconds: 3200
expect_records:
path: "integration_tests/expected_records_sandbox.jsonl"
extra_fields: no
exact_order: no
extra_records: yes
fail_on_extra_columns: false
path: "integration_tests/sample_files/expected_records_sandbox.jsonl"
#path: "integration_tests/sample_files/expected_records.jsonl"
extra_fields: yes
exact_order: yes
extra_records: no
fail_on_extra_columns: False
incremental:
tests:
- config_path: secrets/config_oauth.json
configured_catalog_path: integration_tests/configured_catalog.json
- config_path: secrets/config.json
# - config_path: secrets/config_sandbox.json
configured_catalog_path: integration_tests/incremental_catalog.json
future_state:
future_state_path: integration_tests/abnormal_state.json
future_state_path: integration_tests/sample_files/abnormal_state.json
skip_comprehensive_incremental_tests: true
full_refresh:
tests:
- config_path: secrets/config_oauth.json
- config_path: secrets/config.json
# - config_path: secrets/config_sandbox.json
configured_catalog_path: integration_tests/full_refresh_catalog.json
ignored_fields:
balances:
- name: last_refresh_time
bypass_reason: "field changes during every read"
configured_catalog_path: integration_tests/configured_catalog.json
list_products:
- name: description
bypass_reason: "Sometimes it is not contained in the response"

0 comments on commit 27abc6d

Please sign in to comment.