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: README.md
+52-22Lines changed: 52 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
# Cheddar Bindings for Python
2
2
3
-
A Python wrapper for Cheddar's application interface. Cheddar is a payment gateway for processing and executing transactions within a neat and universal API.
3
+
A Python wrapper for Cheddar's application interface. Cheddar is a payment gateway for processing and executing
4
+
transactions within a neat and universal API.
4
5
5
6
At the moment, the following payment methods and services are supported by the Cheddar service and this library:
6
7
@@ -13,7 +14,8 @@ At the moment, the following payment methods and services are supported by the C
13
14
- GP webpay – Global Payments Europe, s.r.o.
14
15
- PayPal – PayPal (Europe) S.à r.l. et Cie, S.C.A.
15
16
16
-
To see what is new or changed in the current version, check out the [changelog](https://github.com/backbonesk/cheddar-python/blob/master/CHANGELOG.md).
17
+
To see what is new or changed in the current version, check out the
@@ -33,7 +35,8 @@ For the API client to work you would need Python 2.7+ or Python 3.4+.
33
35
34
36
## Usage
35
37
36
-
First off, you need to require the library and provide authentication information by providing your user handle and shared secret you got from the provider.
38
+
First off, you need to require the library and provide authentication information by providing your user handle and
39
+
shared secret you got from the provider.
37
40
38
41
```python
39
42
import cheddar
@@ -47,17 +50,23 @@ client = cheddar.Cheddar(
47
50
)
48
51
```
49
52
50
-
In case you'd like to use the sandbox mode use `cheddar.Environment.Sandbox` when creating configuration object. You can also create your own environment pointing to any valid URL with Cheddar instance running:
53
+
In case you'd like to use the sandbox mode use `cheddar.Environment.Sandbox` when creating configuration object. You
54
+
can also create your own environment pointing to any valid URL with Cheddar instance running:
**Please note** that only VÚB eCard, iTerminal, GP webpay and PayPal currently allow for using their test environments so in case of other providers production URLs will be used! When using sandbox with supported bank or financial institution never use real world credit cards / accounts for testing payment methods implementation (they will not work). Always use virtual testing cards / accounts provided for this purpose by the payment institution.
58
+
**Please note** that only VÚB eCard, iTerminal, GP webpay and PayPal currently allow for using their test environments
59
+
so in case of other providers production URLs will be used! When using sandbox with supported bank or financial
60
+
institution never use real world credit cards / accounts for testing payment methods implementation (they will not
61
+
work). Always use virtual testing cards / accounts provided for this purpose by the payment institution.
55
62
56
63
### Creating a transaction
57
64
58
65
It is quite simple to instantiate a payment.
59
66
60
-
Here’s a quick piece of example code to get you started which will call the Cheddar service and retrieve UUID – universal identifier of the transaction and set the transaction status to `none` (see next section for more on transaction statuses).
67
+
Here’s a quick piece of example code to get you started which will call the Cheddar service and retrieve UUID –
68
+
universal identifier of the transaction and set the transaction status to `none` (see next section for more on
When using the wrapper in web context, the user's IP is automatically added to the data array from the environment variables. If you wish to provide your own, add `payer_ip_address` key with valid address as a value.
87
+
When using the wrapper in web context, the user's IP is automatically added to the data array from the environment
88
+
variables. If you wish to provide your own, add `payer_ip_address` key with valid address as a value.
79
89
80
90
First argument is a service provider, which can currently be one of the following:
81
91
@@ -89,9 +99,11 @@ First argument is a service provider, which can currently be one of the followin
Second argument to the function call is an associative array of configuration options. Which options have to be used and which have no effect at all depends on the service provider. The next table lists all possible attributes:
105
+
Second argument to the function call is an associative array of configuration options. Which options have to be used
106
+
and which have no effect at all depends on the service provider. The next table lists all possible attributes:
95
107
96
108
| Attribute name | Data type | Required? | Notes |
@@ -110,13 +122,21 @@ Second argument to the function call is an associative array of configuration op
110
122
|`cpp_cart_border_color`|string||HEX code of colour at PayPal<br>_applicable only to PayPal transactions_|
111
123
|`periodicity`|integer||periodicity in days, when the next periodical payment will be automatically executed; default value is 30 days<br>_applicable only to ComfortPay transactions_|
112
124
113
-
Note that all of the supported currencies are available as a simple constant on `cheddar.Currency` class to make it easier in code.
125
+
Note that all of the supported currencies are available as a simple constant on `cheddar.Currency` class to make it
126
+
easier in code.
114
127
115
-
After the call you can inspect the returning `Payment` object, which is described in the `Getting transaction details` part of this document.
128
+
After the call you can inspect the returning `Payment` object, which is described in the `Getting transaction details`
129
+
part of this document.
116
130
117
-
To get to the URL of a payments gateway at the bank where the payment is processed just redirect the user to value of `payment.redirect_url` property.
131
+
To get to the URL of a payments gateway at the bank where the payment is processed just redirect the user to value of
132
+
`payment.redirect_url` property.
118
133
119
-
After the payment process at the payment gateway is finished, you will be redirected to the URL you specified in `return_url` / `callback` parameter during the create call in the example above. The URL will have two more GET parameters added - `uuid`, for the payment identifier and `status`, for the current status of the payment transaction (for some payment methods this may change in time, and you will be notified about the change to the URL you specified in the `notification_url` parameter [see the `Asynchronous transaction notifications` part of this document for more info])
134
+
After the payment process at the payment gateway is finished, you will be redirected to the URL you specified in
135
+
`return_url` / `callback` parameter during the create call in the example above. The URL will have two more GET
136
+
parameters added - `uuid`, for the payment identifier and `status`, for the current status of the payment transaction
137
+
(for some payment methods this may change in time, and you will be notified about the change to the URL you specified
138
+
in the `notification_url` parameter
139
+
[see the `Asynchronous transaction notifications` part of this document for more info])
120
140
121
141
122
142
#### Allowed transaction statuses
@@ -161,17 +181,21 @@ Afterwards you can inspect the returning object, which contains these properties
161
181
162
182
### Asynchronous transaction notifications
163
183
164
-
Transactions may have a `notification_url` attribute (in case of PayPal and ComfortPay the attribute is mandatory), that will receive a ping on every change to a transaction (in case of PayPal or ComfortPay it is also the only way to find out the status of the payment).
184
+
Transactions may have a `notification_url` attribute (in case of PayPal and ComfortPay the attribute is mandatory),
185
+
that will receive a ping on every change to a transaction (in case of PayPal or ComfortPay it is also the only way to
186
+
find out the status of the payment).
165
187
166
-
Cheddar calls the value of `notification_url` attribute as POST request with GET attributes `uuid` and `signature` (which needs to be verified) and `application/json` body with full payment details as explained in the previous section.
188
+
Cheddar calls the value of `notification_url` attribute as POST request with GET attributes `uuid` and `signature`
189
+
(which needs to be verified) and `application/json` body with full payment details as explained in the previous section.
167
190
168
191
To validate the signature, you need to call the following:
In case the signature is incorrect a `cheddar.errors.MessageIntegrityError` is thrown, otherwise the function returns `true`. After a successful validation you can trust the json-encoded body of the request.
197
+
In case the signature is incorrect a `cheddar.errors.MessageIntegrityError` is thrown, otherwise the function returns
198
+
`true`. After a successful validation you can trust the json-encoded body of the request.
175
199
176
200
The JSON-encoded body will look something like this:
177
201
@@ -209,7 +233,8 @@ The JSON-encoded body will look something like this:
209
233
210
234
### Updating planned transaction
211
235
212
-
The next use case is the ability to change date and / or amount of a next planned periodical payment. The output of the call is summary of the planned payment including its UUID.
236
+
The next use case is the ability to change date and / or amount of a next planned periodical payment. The output of
237
+
the call is summary of the planned payment including its UUID.
However, also the status of the planned payment might be changed – from `none` to `cancelled` or the other way. Just make sure that the `charge_on` attribute is set to correct value or explicitly set it, when changing the status.
248
+
However, also the status of the planned payment might be changed – from `none` to `cancelled` or the other way. Just
249
+
make sure that the `charge_on` attribute is set to correct value or explicitly set it, when changing the status.
224
250
225
251
### Refunding transactions
226
252
227
-
With Poštová banka’s iTerminal service you might once request a refund on executed transaction in part, or in full. In case of Tatra banka's CardPay service you might request as many refunds as you'd like until sum of all prior refunds reaches the amount of the original transaction.
253
+
With Poštová banka’s iTerminal service you might once request a refund on executed transaction in part, or in full. In
254
+
case of Tatra banka's CardPay service you might request as many refunds as you'd like until sum of all prior refunds
255
+
reaches the amount of the original transaction.
228
256
229
-
The `reason` is more informative and should be one of either `requested_by_customer`, `fraudelent`, `duplicate` or `unknown` (default). Currency has to be the same as when executing the original payment.
257
+
The `reason` is more informative and should be one of either `requested_by_customer`, `fraudelent`, `duplicate` or
258
+
`unknown` (default). Currency has to be the same as when executing the original payment.
230
259
231
260
```python
232
261
payment = client.payments.refund(uuid, [
@@ -252,11 +281,12 @@ Run the linter with:
252
281
253
282
make lint
254
283
255
-
The client library uses Black for code formatting. Code must be formatted with Black before PRs are submitted. Run the formatter with:
284
+
The client library uses Black for code formatting. Code must be formatted with Black before PRs are submitted. Run the
0 commit comments