Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Adyen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,14 @@ def _determine_hpp_url(platform, action):
result = '/'.join([base_uri, service])
return result

def _determine_checkout_url(self, platform, action):
def _determine_checkout_url(self, platform, action, path_param=None):
"""This returns the Adyen API endpoint based on the provided platform,
service and action.

Args:
platform (str): Adyen platform, ie 'live' or 'test'.
action (str): the API action to perform.
path_param Optional[(str)]: a generic id that can be used to modify a payment e.g. paymentPspReference.
"""
api_version = settings.API_CHECKOUT_VERSION
if platform == "test":
Expand All @@ -171,6 +172,14 @@ def _determine_checkout_url(self, platform, action):
action = "payments/details"
if action == "paymentsResult":
action = "payments/result"
if action == "paymentsCancelsWithoutReference":
action = "payments/cancels"
if action == "paymentsCancelsWithReference":
action = f"payments/{path_param}/cancels"
if action == "paymentsReversals":
action = f"payments/{path_param}/reversals"
if action == "payments/Refunds":
action = f"payments/{path_param}/refunds"
if action == "originKeys":
api_version = settings.API_CHECKOUT_UTILITY_VERSION
if action == "paymentMethodsBalance":
Expand Down Expand Up @@ -437,7 +446,7 @@ class instance.
status_code, headers, message)
return adyen_result

def call_checkout_api(self, request_data, action, idempotency_key=None,
def call_checkout_api(self, request_data, action, idempotency_key=None, path_param=None,
**kwargs):
"""This will call the checkout adyen api. xapi key merchant_account,
and platform are pulled from root module level and or self object.
Expand All @@ -452,6 +461,7 @@ def call_checkout_api(self, request_data, action, idempotency_key=None,
https://docs.adyen.com/developers/checkout/api-integration
service (str): This is the API service to be called.
action (str): The specific action of the API service to be called
path_param (str): This is used to pass the id or referenceID to the API sercie
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
path_param (str): This is used to pass the id or referenceID to the API sercie
path_param (str): This is used to pass the ID or referenceID to the API service

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix this and open a new PR to develop,

"""
if not self.http_init:
self.http_client = HTTPClient(self.USER_AGENT_SUFFIX,
Expand Down Expand Up @@ -520,7 +530,7 @@ def call_checkout_api(self, request_data, action, idempotency_key=None,
headers = {}
if idempotency_key:
headers[self.IDEMPOTENCY_HEADER_NAME] = idempotency_key
url = self._determine_checkout_url(platform, action)
url = self._determine_checkout_url(platform, action, path_param)

raw_response, raw_request, status_code, headers = \
self.http_client.request(url, json=request_data,
Expand Down
43 changes: 43 additions & 0 deletions Adyen/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ class AdyenCheckoutApi(AdyenServiceBase):
payments/details
originKeys

Modifications:
capture
refunds
cancels
reversals


Please refer to the checkout documentation for specifics around the API.
https://docs.adyen.com/developers/checkout

Expand Down Expand Up @@ -322,6 +329,42 @@ def payment_result(self, request=None, **kwargs):
action = "paymentsResult"
return self.client.call_checkout_api(request, action, **kwargs)

def payment_captures(self, path_param, request=None, idempotency_key=None, **kwargs):
if path_param == "":
raise ValueError(
'must contain a pspReference in the path_param, path_param cannot be empty'
)
action = "paymentsCapture"
return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs)

def payments_cancels_without_reference(self, request=None, idempotency_key=None, **kwargs):
action = "paymentsCancelsWithoutReference"
return self.client.call_checkout_api(request, action, idempotency_key, **kwargs)

def payments_cancels_with_reference(self, path_param, request=None, idempotency_key=None, **kwargs):
if path_param == "":
raise ValueError(
'must contain a pspReference in the path_param, path_param cannot be empty'
)
action = "paymentsCancelsWithReference"
return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs)

def payments_reversals(self, path_param, request=None, idempotency_key=None, **kwargs):
if path_param == "":
raise ValueError(
'must contain a pspReference in the path_param, path_param cannot be empty'
)
action = "paymentsReversals"
return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs)

def payments_refunds(self, path_param, request=None, idempotency_key=None, **kwargs):
if path_param == "":
raise ValueError(
'must contain a pspReference in the path_param, path_param cannot be empty'
)
action = "paymentsRefunds"
return self.client.call_checkout_api(request, action, path_param, idempotency_key, **kwargs)

def origin_keys(self, request=None, **kwargs):
action = "originKeys"
return self.client.call_checkout_api(request, action, **kwargs)
Expand Down
105 changes: 61 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,85 @@
[![Build Status](https://travis-ci.org/Adyen/adyen-python-api-library.svg?branch=master)](https://travis-ci.org/Adyen/adyen-python-api-library)
[![Coverage Status](https://coveralls.io/repos/github/Adyen/adyen-python-api-library/badge.svg?branch=master)](https://coveralls.io/github/Adyen/adyen-python-api-library?branch=master)

# Adyen APIs Library for Python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but these changes are stale now. Will not include them when I reopen.


This library simplifies working with Adyen APIs and allows you to integrate Adyen
payments within any Python application.

## Integration
The Library supports all APIs under the following services:

* checkout
* checkout utility
* payments
* modifications
* payouts
* recurring

## Requirements

This is the officially supported Python library for using Adyen's APIs.
## Integration
The library supports all APIs under the following services:

* [Checkout API](https://docs.adyen.com/api-explorer/#/CheckoutService/v67/overview): Our latest integration for accepting online payments. Current supported version: **v67**
* [Payments API](https://docs.adyen.com/api-explorer/#/Payment/v64/overview): Our classic integration for online payments. Current supported version: **v64**
* [Recurring API](https://docs.adyen.com/api-explorer/#/Recurring/v49/overview): Endpoints for managing saved payment details. Current supported version: **v49**
* [Payouts API](https://docs.adyen.com/api-explorer/#/Payout/v64/overview): Endpoints for sending funds to your customers. Current supported version: **v64**
* [Orders API](https://docs.adyen.com/api-explorer/#/CheckoutService/v67/post/orders): Endpoints for creating and canceling orders. Current supported version: **v67**
* [Utility API](https://docs.adyen.com/api-explorer/#/CheckoutService/v67/post/originKeys): This operation takes the origin domains and returns a JSON object containing the corresponding origin keys for the domains. Current supported version: **v67**

For more information, refer to our [documentation](https://docs.adyen.com/) or the [API Explorer](https://docs.adyen.com/api-explorer/).


## Prerequisites

- [Adyen test account](https://docs.adyen.com/get-started-with-adyen)
- [API key](https://docs.adyen.com/development-resources/api-credentials#generate-api-key). For testing, your API credential needs to have the [API PCI Payments role](https://docs.adyen.com/development-resources/api-credentials#roles).
- Python 2.7 or 3.6
- Packages: requests or pycurl ( optional )
- Adyen account. If you don't have this you can request it here: https://www.adyen.com/home/discover/test-account-signup#form

## Installation
## Installation

### For development propose

Clone this repository and run ```make install```
Clone this repository and run
~~~~ bash
make install
~~~~

### For usage propose

Use pip command: ```pip install Adyen```

## Usage

Create a class instance of the 'Adyen' class.

```python
Use pip command:
~~~~ bash
pip install Adyen
~~~~

## Using the library


### General use with API key

~~~~ python
import Adyen

ady = Adyen.Adyen()

ady.payment.client.username = "webservice user name"
ady.payment.client.xapikey = "YourXapikey"
ady.payment.client.skin_code = "skin code for Hosted Payment pages"
ady.payment.client.hmac = "HMAC key for skin code"
ady.payment.client.platform = "test" # Environment to use the library in.
ady.payment.client.merchant_account = "merchant account name from CA"
ady.payment.client.password = "webservice user password"
```

## Documentation
* https://docs.adyen.com/developers/development-resources/libraries
* https://docs.adyen.com/developers/checkout
~~~~

### Example integration

For a closer look at how our Python library works, clone our [example integration](https://github.com/adyen-examples/adyen-python-online-payments). This includes commented code, highlighting key features and concepts, and examples of API calls that can be made using the library.

## Support
If you have a feature request, or spotted a bug or a technical problem, create a GitHub issue. For other questions, contact our [support team](https://support.adyen.com/hc/en-us/requests/new?ticket_form_id=360000705420).

## Contributing
We strongly encourage you to join us in contributing to this repository so everyone can benefit from:
* New features and functionality
* Resolved bug fixes and issues
* Any general improvements

Read our [**contribution guidelines**](CONTRIBUTING.md) to find out how.


We encourage you to contribute to this repository, so everyone can benefit from new features, bug fixes, and any other improvements.


Have a look at our [contributing guidelines](https://github.com/Adyen/adyen-python-api-library/blob/develop/CONTRIBUTING.md) to find out how to raise a pull request.


## Support
If you have a feature request, or spotted a bug or a technical problem, [create an issue here](https://github.com/Adyen/adyen-web/issues/new/choose).

For other questions, [contact our Support Team](https://www.adyen.help/hc/en-us/requests/new?ticket_form_id=360000705420).


## Licence
MIT license see LICENSE
This repository is available under the [MIT license](https://github.com/Adyen/adyen-python-api-library/blob/master/LICENSE.md).


## See also
* [Example integration](https://github.com/adyen-examples/adyen-python-online-payments)
* [Adyen docs](https://docs.adyen.com/)
* [API Explorer](https://docs.adyen.com/api-explorer/)
Loading