You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+55-46Lines changed: 55 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -28,83 +28,92 @@ Please see the sections below for more details
28
28
1. check all coding conventions are adhered to (`tox`)
29
29
1. Commit your changes (`git commit -am 'Add some feature'`)
30
30
1. Push to the branch (`git push origin my-new-feature`)
31
-
1. Create new pull request
31
+
1. Create a new pull request
32
32
33
33
34
-
## Setup
34
+
## Testing
35
35
36
-
This package uses the [Poetry](https://python-poetry.org/) for packaging and dependency management. Before you get started please install it.
36
+
### Setup
37
37
38
-
Once you have cloned this repository you will then need:
39
-
* Your `Paddle Vendor ID` which can be found on the [Paddle's authentication page](https://vendors.paddle.com/authentication)
40
-
* Your `Paddle API key` which is found on the same [Paddle's authentication page](https://vendors.paddle.com/authentication)
38
+
This package uses [Poetry](https://python-poetry.org/) for packaging and dependency management. Before you get started please install it.
41
39
42
40
```bash
43
41
# Fork and clone this repo
44
42
poetry install
45
-
46
-
# Create a file called .env and add the above settings
47
-
export PADDLE_VENDOR_ID=...
48
-
export PADDLE_API_KEY="..."
49
-
50
43
poetry shell
51
-
source .env
52
44
```
53
45
46
+
An account in the [Paddle Sandbox](https://sandbox-vendors.paddle.com/authentication) has been created for testing this package and this account has been hardcoded into the tests via the paddle-client fixture so all of the tests will ignore any PADDLE_* environmental variables.
54
47
55
-
## Running tests
48
+
This sandbox account is currently configured in a state that all of the tests pass out of the box including the creation of products and subscriptions which can't be done via the API.
49
+
With that in mind, this might not be the case in the future. If a test fails due to missing data, the pytest error should make it clear what data needs to be created. Below are instructions on how to create the test data.
56
50
57
-
At the moment several of the tests require a few extra bits of information from Paddle. We are looking at removing these dependencies soon be creating them with fixtures. Please help us do it if you are up for it.
58
51
59
-
* A `Paddle Product ID` which you can get one by creating a product on [Paddle's product page](https://vendors.paddle.com/products)
60
-
* A `Paddle Plan/Subscription ID` which can be created on [Paddle's Subscription Plans page](https://vendors.paddle.com/subscriptions/plans)
61
-
* A `Paddle Checkout ID` which can be got by going into an order from the [Paddle orders page](https://vendors.paddle.com/orders). If you don't have any orders yet you can create an order for $0.
52
+
#### Creating a product
62
53
63
-
The tests currently require you to add the above as environmental variables (names below). To make them easier to set these each time the python virtual environment is loaded they can be placed into a `.env` file which can be sourced.
54
+
This requires access to the Paddle Sandbox account (`[email protected]`). If you do not have access please create a GitHub issue.
64
55
65
-
```bash
66
-
# Add the above to the relevant environmental variables (and .env file)
67
-
export PADDLE_TEST_DEFAULT_CHECKOUT_ID="..."
68
-
export PADDLE_TEST_DEFAULT_PRODUCT_ID=...
69
-
export PADDLE_TEST_DEFAULT_PLAN_ID=...
56
+
1. Go to the Sandbox products https://sandbox-vendors.paddle.com/products
57
+
1. Product Name: `test-product` (the name is used to match the fixture)
58
+
1. Fulfillment Method: `Paddle License`
59
+
* Default Activations per License: 9999
60
+
* Enable Trials: Unchecked
61
+
* Default Expiry Days: 0
62
+
1. Complete your integration of the Paddle SDK: Ignore Waiting for API requests... (this can be ignored)
63
+
1. Set Prices > Go to prices manager
64
+
* USD: $1
65
+
* Sale: Disabled
66
+
1. Close the page (without saving)
70
67
71
-
poetry shell
72
-
source .env
73
-
pytest -m "not manual_cleanup" tests/
74
-
# Coverage info is written to htmlcov/
75
68
76
-
pytest tests/ # Run all tests against Paddle's API. See mocking and cleanup below
77
-
```
69
+
#### Creating a subscription
78
70
79
-
### Mocking
71
+
Certain tests require a subscription to be created, which is simply a plan that has been paid for by a user. While there is no way to create subscriptions / payment via the Paddle API, a simple way to using the PaddleCheckout has been configured to create them manually in a few seconds:
80
72
81
-
As few mocks should be used as possible, Mocks should only be used for dangerous Paddle operations that can't be undone or cleaned up.
73
+
Before following the below steps to create a payment please run the tests as a payment may already exist. It will also make sure a Paddle plan is setup ready for a subscription and let you know of the plan ID which is needed below.
82
74
83
-
Mocks should be done at the point paddle-python interfaces with `requests` and check the exact kwargs that were sent. This will cause any change in the request to cause the mocked test to fail. All mocked tests should also be accompanied by a matching test which hits Paddle's API but has the decorator`@pytest.mark.skip()` (see an already mocked test below as an example).
75
+
1. Run a test which requires a subscription payment (to print the Plan ID) - `pytest tests/test_subscription_payments.py::test_list_subscription_payments`
76
+
1. Take note of the plan ID from the failed test (if the test does not fail you don't need to setup a new subscription)
77
+
1. Edit the PaddleCheckout HTML page at `tests/create_subscription.html` replacing `data-product="<plan-id>"` with the output of the above command:
78
+
```
79
+
<!-- If the new plan ID was 9000: -->
80
+
<a
81
+
data-product="9000"
82
+
class="paddle_button"
83
+
href="#!"
84
+
...
85
+
>
86
+
Buy Now!
87
+
</a>
88
+
```
89
+
1. Open the create_subscription checkout HTML page - `open tests/create_subscription.html`
90
+
1. Click on the `Buy Now!` button
91
+
1. In the Paddle modal enter fake card info provided on the page
* Create one off charge - `test_one_off_charges.py::test_create_one_off_charge`
94
+
## Running tests
91
95
96
+
Pytest is used to run the tests:
92
97
93
-
### Cleanup
98
+
```bash
99
+
pytest tests/
100
+
# Coverage info is written to htmlcov/
101
+
```
102
+
All tests are run against the Paddle Sandbox environment and most of the setup and teardown is handled within the tests.
94
103
95
-
_(These tests are currently not working and marked as skipped so this can be ignored)_
104
+
The only exception to this is if someone accidentally deletes all of the subscription plans and products. When this happens it means any test which requires a checkout to have been completed (payments, updates etc) will fail due to no plan or product existing.
96
105
97
-
Parts of the Paddle API have create endpoints but not delete endpoints. Because of this several tests need to be cleaned up manually after they are run:
98
106
107
+
### Mocking
99
108
100
-
*`tests/test_licenses.py::test_generate_license`
101
-
*`tests/test_pay_links.py::test_create_pay_link`
109
+
As few mocks should be used as possible, Mocks should only be used for dangerous Paddle operations that can't be undone or cleaned up via the API making it difficult to create enough test data..
102
110
111
+
Mocks should be done at the point paddle-python interfaces with `requests` and check the exact kwargs that were sent. This will cause any change in the request to cause the mocked test to fail. All mocked tests should also be accompanied by a matching test that hits Paddle's API but has the decorator`@pytest.mark.skip()` (see an already mocked test below as an example).
If `vendor_id` and `api_key` are not passed through when initalising Paddle will fall back and try and use environmental variables called `PADDLE_VENDOR_ID` and `PADDLE_API_KEY`
32
+
If `vendor_id` and `api_key` are not passed through when initialising Paddle will fall back and try and use environmental variables called `PADDLE_VENDOR_ID` and `PADDLE_API_KEY`
33
33
```bash
34
34
export PADDLE_VENDOR_ID=12345
35
35
export PADDLE_API_KEY="myapikey"
@@ -44,6 +44,30 @@ paddle.list_products()
44
44
```
45
45
46
46
47
+
### Paddle sandbox environment
48
+
49
+
The [Paddle sandbox environment](https://developer.paddle.com/getting-started/sandbox) is a separate Paddle environment which can be used for development and testing. You are required to create a new account in this environment, different to your production account.
50
+
51
+
Once you have this account setup and configured you can user the sandbox account by passing `sandbox=True` when initialising the Paddle Client. This will send all API calls to the Paddle sandbox URLs instead of the production URLs
The full documentation is available on Read the Docs: https://paddle-client.readthedocs.io
@@ -56,7 +80,7 @@ All contributions are welcome and appreciated. Please see [CONTRIBUTING.md](http
56
80
57
81
## Paddle Endpoints
58
82
59
-
The below endpoints from the [Paddle API Reference](https://developer.paddle.com/api-reference) have been implimented
83
+
The below endpoints from the [Paddle API Reference](https://developer.paddle.com/api-reference) have been implemented
60
84
61
85
For full details see the [API Reference in the docs](https://paddle-client.readthedocs.io/en/latest/api_reference.html). This includes details on parameters and return types for all the different methods as well as other helper methods around the Paddle.com API.
62
86
@@ -82,7 +106,6 @@ See [`Usage`](#usage) below for quick examples.
The below endpoints have been implimented but are not working correctly according to the tests. They have been commented out in `paddle/paddle.py` and the tests will skip is the methods do not exist
*[Reschedule subscription payment](https://developer.paddle.com/api-reference/subscription-api/payments/updatepayment) - `Paddle error 122 - Provided date is not valid` - After manually testing via Paddles API reference I believe this is an issue with Paddle's API.
195
-
196
-
197
-
## ToDo
198
-
* Fix generate license, create pay link and reschedule payment endpoints
199
-
* Get test coverage to 100%
200
-
* Use `pytest-mock``Spy` to check params, json, urls etc for test requests
201
-
* Needed to any tests which skip due to missing data
202
-
* How to deal with the manual cleanup?
203
-
* Pull request template
204
-
* TravisCI?
205
-
* Dependabot
206
-
* Remove double call for exception error message checking - How to get the exception str from `pytest.raises()`? pytest-mock `Spy`?
207
-
* Add pytest warnings to provide direct links to Paddle for bits that need to be cleaned up
@@ -50,16 +49,6 @@ As listed in the `Paddle API Reference <https://developer.paddle.com/api-referen
50
49
51
50
52
51
53
-
Broken endpoints
54
-
----------------
55
-
56
-
The below endpoints have been implimented but are not working correctly according to the tests. They have been commented out in ``paddle/paddle.py`` and the tests will skip is the methods do not exist
- `Create pay link <https://developer.paddle.com/api-reference/product-api/pay-links/createpaylink>`_ - ``Paddle error 108 - Unable to find requested product``
60
-
- `Reschedule subscription payment <https://developer.paddle.com/api-reference/subscription-api/payments/updatepayment>`_ - ``Paddle error 122 - Provided date is not valid``
Copy file name to clipboardExpand all lines: docs/getting_started.rst
+29Lines changed: 29 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -48,3 +48,32 @@ If ``vendor_id`` and ``api_key`` are not passed through when initalising Paddle
48
48
49
49
paddle = PaddleClient()
50
50
paddle.list_products()
51
+
52
+
53
+
Paddle sandbox environment
54
+
--------------------------
55
+
56
+
The `Paddle sandbox environment <https://developer.paddle.com/getting-started/sandbox>`_ is a separate Paddle environment which can be used for development and testing. You are required to create a new account in this environment, different to your production account.
57
+
58
+
Once you have this account setup and configured you can user the sandbox account by passing ``sandbox=True`` when initialising the Paddle Client. This will send all API calls to the Paddle sandbox URLs instead of the production URLs
0 commit comments