Skip to content

Commit 1804063

Browse files
committed
Merge branch 'develop' into 'master'
Develop See merge request Modules/fasterpay-python3!3
2 parents 3c57f3c + bdce0cb commit 1804063

20 files changed

+379
-0
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0 - 19/09/2019 --- Initial Release

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 FasterPay
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.txt
2+
recursive-include docs *.txt

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Welcome to FasterPay Python SDK
2+
3+
FasterPay Python SDK enables you to integrate the FasterPay's Checkout Page seamlessly without having the hassle of integrating everything from Scratch.
4+
Once your customer is ready to pay, FasterPay will take care of the payment, notify your system about the payment and return the customer back to your Thank You page.
5+
6+
## Downloading the FasterPay Python SDK
7+
8+
```sh
9+
$ git clone https://github.com/FasterPay/fasterpay-python3.git
10+
```
11+
12+
## Installing the FasterPay Python SDK.
13+
```sh
14+
$ cd fasterpay-python3
15+
$ sudo python setup.py install
16+
```
17+
18+
## Initiating Payment Request using Python SDK
19+
20+
```python
21+
from fasterpay.gateway import Gateway
22+
23+
if __name__ == "__main__":
24+
25+
gateway = Gateway("<your private key>", "<your public key>", True)
26+
27+
parameters = {
28+
"payload": {
29+
"description": "Golden Ticket",
30+
"amount": "0.01",
31+
"currency": "EUR",
32+
"merchant_order_id": str(random.randint(1000, 9999)),
33+
"success_url": "https://4f9f73c1.ngrok.io/success",
34+
"sign_version": "v2",
35+
"pingback_url": "https://4f9f73c1.ngrok.io/pingback",
36+
}
37+
}
38+
39+
paymentForm = gateway.payment_form().build_form(parameters)
40+
print paymentForm
41+
```
42+
43+
For more information on the API Parameters, refer to our entire API Documentation [here](https://docs.fasterpay.com/api#section-custom-integration)
44+
45+
## Handling FasterPay Pingbacks
46+
47+
```python
48+
from flask import request
49+
from fasterpay.gateway import FP_Gateway
50+
gateway = Gateway("<your private key>", "<your public key>", True)
51+
pingback_data = request.get_data()
52+
if request.headers.get("X-Fasterpay-Signature-Version") == "v2":
53+
headers = {
54+
"X-Fasterpay-Signature": str(request.headers.get("X-Fasterpay-Signature")),
55+
"X-Fasterpay-Signature-Version": str(request.headers.get("X-Fasterpay-Signature-Version"))
56+
}
57+
else:
58+
headers = {
59+
"X-ApiKey": str(request.headers.get("X-ApiKey"))
60+
}
61+
62+
if gateway.pingback().validate(pingback_data, headers) is True:
63+
return "OK"
64+
else:
65+
return "NOK"
66+
```
67+
68+
## FasterPay Test Mode
69+
FasterPay has a Sandbox environment called Test Mode. Test Mode is a virtual testing environment which is an exact replica of the live FasterPay environment. This allows businesses to integrate and test the payment flow without being in the live environment. Businesses can create a FasterPay account, turn on the **Test Mode** and begin to integrate the widget using the test integration keys.
70+
71+
### Initiating FasterPay Gateway in Test-Mode
72+
```python
73+
from fasterpay.gateway import Gateway
74+
gateway = Gateway("<your private key>", "<your public key>", True)
75+
```
76+
77+
### Questions?
78+
* Common questions are covered in the [FAQ](https://www.fasterpay.com/support).
79+
* For integration and API questions, feel free to reach out Integration Team via [integration@fasterpay.com](mailto:integration@fasterpay.com)
80+
* For business support, email us at [merchantsupport@fasterpay.com](mailto:merchantsupport@fasterpay.com)
81+
* To contact sales, email [sales@fasterpay.com](mailto:sales@fasterpay.com).

fasterpay/__init__.py

Whitespace-only changes.

fasterpay/config.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Config:
2+
3+
def __init__(self, privateKey, publicKey, is_test = False, apiVersion = None):
4+
self.publicKey = publicKey
5+
self.privateKey = privateKey
6+
if is_test is True :
7+
self.API_BASE_URL = "http://pay.fasterpay.com"
8+
else:
9+
self.API_BASE_URL = "http://pay.sandbox.fasterpay.com"
10+
11+
if apiVersion is not None :
12+
self.VERSION = apiVersion
13+
else:
14+
self.VERSION = "1.0.0"
15+
16+
def get_public_key(self):
17+
return self.publicKey
18+
19+
def get_private_key(self):
20+
return self.privateKey
21+
22+
def get_api_url(self):
23+
return self.API_BASE_URL
24+
25+
def get_api_version(self):
26+
return self.VERSION

fasterpay/gateway.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from fasterpay.config import Config
2+
from fasterpay.signature import Signature
3+
from fasterpay.pingback import Pingback
4+
from fasterpay.paymentform import PaymentForm
5+
from fasterpay.refund import Refund
6+
from fasterpay.subscription import Subscription
7+
8+
9+
class Gateway:
10+
11+
def __init__(self, private_key, public_key, api_url=None, api_version=None):
12+
self.config = Config(private_key, public_key, api_url, api_version)
13+
14+
def payment_form(self):
15+
return PaymentForm(self)
16+
17+
def signature(self):
18+
return Signature(self)
19+
20+
def pingback(self):
21+
return Pingback(self)
22+
23+
def get_config(self):
24+
return self.config
25+
26+
def refund(self):
27+
return Refund(self)
28+
29+
def subscription(self):
30+
return Subscription(self)
31+
32+
33+

fasterpay/paymentform.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class PaymentForm:
2+
3+
def __init__(self, gateway):
4+
self.gateway = gateway
5+
6+
def build_form(self, parameters):
7+
payload = parameters.get("payload")
8+
payload.update({"api_key": self.gateway.config.get_public_key()})
9+
10+
if "sign_version" in payload:
11+
hash = self.gateway.signature().calculate_hash(payload, payload.get("sign_version"))
12+
else:
13+
hash = self.gateway.signature().calculate_hash(payload)
14+
15+
payload.update({"hash": hash})
16+
17+
form = '<form align="center" method="post" action="' + self.gateway.config.get_api_url() + '/payment/form">'
18+
for param in payload:
19+
form += '<input type="hidden" name="' + param + '" value="' + str(payload[param]) + '" />'
20+
21+
form += '<input type="Submit" value="Pay Now" id="fasterpay-submit"/></form>'
22+
23+
if "auto_submit_form" in parameters:
24+
form += "<script type=\"text/javascript\">document.getElementById(\"fasterpay-submit\").click(); </script>"
25+
26+
return form

fasterpay/pingback.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Pingback:
2+
3+
def __init__(self, gateway):
4+
self.gateway = gateway
5+
6+
def validate(self, pingbackdata, headers):
7+
if len(headers) == 0:
8+
return False
9+
10+
if len(pingbackdata) == 0:
11+
return False
12+
13+
if headers.get("X-Fasterpay-Signature-Version") == "v2":
14+
generated_hash = self.gateway.signature().calculate_pingback_hash(pingbackdata)
15+
if generated_hash == headers.get("X-Fasterpay-Signature"):
16+
return True
17+
else:
18+
if headers.get("X-ApiKey") == self.gateway.config.get_private_key():
19+
return True
20+
21+
return False

fasterpay/refund.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import requests
2+
import json
3+
4+
class Refund:
5+
6+
def __init__(self, gateway):
7+
self.gateway = gateway
8+
9+
def process(self, order_id=None, amount=None):
10+
response = requests.post(self.gateway.config.get_api_url() + "/payment/" + str(order_id) + "/refund",
11+
data=json.dumps({"amount": amount}),
12+
headers={"X-ApiKey": self.gateway.config.get_private_key()})
13+
14+
return response

0 commit comments

Comments
 (0)