-
Notifications
You must be signed in to change notification settings - Fork 3
Upgrade SDK to support Payload API V2 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d7eef8e
91a99bb
f195602
f21fafa
eb30edf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ A Python library for integrating [Payload](https://payload.com). | |
|
|
||
| ## Installation | ||
|
|
||
| ## Install using pip | ||
| ### Install using pip | ||
|
|
||
| ```bash | ||
| pip install payload-api | ||
|
|
@@ -39,6 +39,27 @@ import payload | |
| pl = payload.Session('secret_key_3bW9JMZtPVDOfFNzwRdfE') | ||
| ``` | ||
|
|
||
| ### API Versioning | ||
|
|
||
| The Payload API supports multiple versions. You can specify which version to use when making requests: | ||
|
|
||
| ```python | ||
| import payload as pl | ||
| pl.api_key = 'secret_key_3bW9JMZtPVDOfFNzwRdfE' | ||
| pl.api_version = 'v2' # Use API v2 | ||
| ``` | ||
|
|
||
| Or with sessions: | ||
|
|
||
| ```python | ||
| import payload | ||
| pl = payload.Session( | ||
| 'secret_key_3bW9JMZtPVDOfFNzwRdfE', | ||
| api_version='v2' | ||
| ) | ||
| ``` | ||
|
|
||
| API v2 introduces new objects including `Profile`, `Intent`, `Entity`, `Transfer`, `ProcessingAgreement`, and more. See the [Payload API Documentation](https://docs.payload.com) for details on API versions. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you wait to merge until the docs are live?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we need to get these out so we can expose the docs. |
||
|
|
||
| ### Creating an Object | ||
|
|
||
|
|
@@ -60,7 +81,9 @@ customer = pl.Customer.create( | |
| payment = pl.Payment.create( | ||
| amount=100.0, | ||
| payment_method=pl.Card( | ||
| card_number='4242 4242 4242 4242' | ||
| card_number='4242 4242 4242 4242', | ||
| expiry='12/28', | ||
| card_code='123' | ||
| ) | ||
| ) | ||
| ``` | ||
|
|
@@ -107,12 +130,21 @@ payments = pl.Payment.filter_by( | |
|
|
||
| ### Testing the Payload Python Library | ||
|
|
||
| Tests are contained within the tests/ directory. To run a test file, once within the | ||
| pipenv shell, enter the command in terminal | ||
| Tests are contained within the tests/ directory. To run tests: | ||
|
|
||
| ```bash | ||
| TEST_SECRET_KEY=test_api_key pytest tests/{__FILENAME__}.py | ||
| ``` | ||
| # Install dependencies | ||
| pdm install | ||
|
|
||
| # Run integration tests | ||
| TEST_SECRET_KEY=test_api_key pdm run pytest tests/int/ | ||
|
|
||
| # Run unit tests | ||
| pdm run pytest tests/unit/ | ||
|
|
||
| # Run a specific test file | ||
| TEST_SECRET_KEY=test_api_key pdm run pytest tests/int/test_transaction.py | ||
| ``` | ||
|
|
||
|
|
||
| ## Documentation | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,20 +4,151 @@ | |
|
|
||
| Documentation: https://docs.payload.com | ||
|
|
||
| :copyright: (c) 2021 Payload (http://payload.com) | ||
| :copyright: (c) 2026 Payload (http://payload.com) | ||
| :license: MIT License | ||
| """ | ||
|
|
||
| from .version import __version__ | ||
| from .exceptions import * | ||
| from .objects import * | ||
| from .arm import Attr as attr, ARMRequest, session_factory | ||
| __all__ = [ | ||
| # Version | ||
| '__version__', | ||
| # ARM | ||
| 'ARMRequest', | ||
| 'attr', | ||
| 'session_factory', | ||
| 'Session', | ||
| # Functions | ||
| 'create', | ||
| 'update', | ||
| 'delete', | ||
| # Module variables | ||
| 'URL', | ||
| 'api_key', | ||
| 'api_url', | ||
| 'api_version', | ||
| # Submodules | ||
| 'objects', | ||
| # Exceptions | ||
| 'BadRequest', | ||
| 'Forbidden', | ||
| 'InternalServerError', | ||
| 'InvalidAttributes', | ||
| 'NotFound', | ||
| 'PayloadError', | ||
| 'ServiceUnavailable', | ||
| 'TooManyRequests', | ||
| 'TransactionDeclined', | ||
| 'Unauthorized', | ||
| 'UnknownResponse', | ||
| # Objects | ||
| 'AccessToken', | ||
| 'Account', | ||
| 'BankAccount', | ||
| 'BillingCharge', | ||
| 'BillingSchedule', | ||
| 'Card', | ||
| 'ChargeItem', | ||
| 'ClientToken', | ||
| 'Credit', | ||
| 'Customer', | ||
| 'Deposit', | ||
| 'Invoice', | ||
| 'Ledger', | ||
| 'LineItem', | ||
| 'OAuthToken', | ||
| 'Org', | ||
| 'Payment', | ||
| 'PaymentActivation', | ||
| 'PaymentItem', | ||
| 'PaymentLink', | ||
| 'PaymentMethod', | ||
| 'ProcessingAccount', | ||
| 'ProcessingRule', | ||
| 'Refund', | ||
| 'Transaction', | ||
| 'User', | ||
| 'Webhook', | ||
| # New API v2 Objects | ||
| 'Profile', | ||
| 'BillingItem', | ||
| 'Intent', | ||
| 'InvoiceItem', | ||
| 'PaymentAllocation', | ||
| 'Entity', | ||
| 'Stakeholder', | ||
| 'ProcessingAgreement', | ||
| 'Transfer', | ||
| 'TransactionOperation', | ||
| 'CheckFront', | ||
| 'CheckBack', | ||
| 'ProcessingSettings', | ||
| ] | ||
|
|
||
| from . import objects | ||
| from .arm import ARMRequest | ||
| from .arm import Attr as attr | ||
| from .arm import session_factory | ||
| from .exceptions import ( | ||
| BadRequest, | ||
| Forbidden, | ||
| InternalServerError, | ||
| InvalidAttributes, | ||
| NotFound, | ||
| PayloadError, | ||
| ServiceUnavailable, | ||
| TooManyRequests, | ||
| TransactionDeclined, | ||
| Unauthorized, | ||
| UnknownResponse, | ||
| ) | ||
| from .objects import ( # API v2 Objects | ||
| AccessToken, | ||
| Account, | ||
| BankAccount, | ||
| BillingCharge, | ||
| BillingItem, | ||
| BillingSchedule, | ||
| Card, | ||
| ChargeItem, | ||
| CheckBack, | ||
| CheckFront, | ||
| ClientToken, | ||
| Credit, | ||
| Customer, | ||
| Deposit, | ||
| Entity, | ||
| Intent, | ||
| Invoice, | ||
| InvoiceItem, | ||
| Ledger, | ||
| LineItem, | ||
| OAuthToken, | ||
| Org, | ||
| Payment, | ||
| PaymentActivation, | ||
| PaymentAllocation, | ||
| PaymentItem, | ||
| PaymentLink, | ||
| PaymentMethod, | ||
| ProcessingAccount, | ||
| ProcessingAgreement, | ||
| ProcessingRule, | ||
| ProcessingSettings, | ||
| Profile, | ||
| Refund, | ||
| Stakeholder, | ||
| Transaction, | ||
| TransactionOperation, | ||
| Transfer, | ||
| User, | ||
| Webhook, | ||
| ) | ||
| from .version import __version__ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you have to adjust all of these imports?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we don't use |
||
|
|
||
| URL = 'https://api.payload.com' | ||
|
|
||
| api_key = None | ||
| api_url = URL | ||
| api_version = None | ||
|
|
||
| Session = session_factory('PayloadSession', objects) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this isn't a real secret key?