Skip to content

Commit 33436e3

Browse files
authored
Merge pull request #1 from FasterPay/prashant-updates
Updating Fixes for Auto Submitting Pay Now Button and Adding Refund a…
2 parents 17b536c + ba47353 commit 33436e3

29 files changed

Lines changed: 382 additions & 58 deletions

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ if __name__ == "__main__":
2424

2525
gateway = Gateway("<your private key>", "<your public key>")
2626

27-
payload = {
28-
"description": "Golden Ticket",
29-
"amount": "0.01",
30-
"currency": "EUR",
31-
"merchant_order_id": "xxxxx",
32-
"success_url": "https://yourcompanywebsite.com/success"
27+
parameters = {
28+
"payload": {
29+
"description": "Golden Ticket",
30+
"amount": "0.01",
31+
"currency": "EUR",
32+
"merchant_order_id": random.randint(1000, 9999),
33+
"success_url": "http://localhost:12345/success.php",
34+
},
35+
"auto_submit_form": True
3336
}
3437

35-
paymentForm = gateway.payment_form().build_form(payload)
38+
paymentForm = gateway.payment_form().build_form(parameters)
3639

37-
print paymentForm
40+
print paymentForm
3841
```
3942

4043
For more information on the API Parameters, refer to our entire API Documentation [here](https://docs.fasterpay.com/api#section-custom-integration)
@@ -43,7 +46,7 @@ For more information on the API Parameters, refer to our entire API Documentatio
4346

4447
```python
4548
from flask import request
46-
from fasterpay.gateway import FP_Gateway
49+
from fasterpay.gateway import Gateway
4750
gateway = Gateway("<your private key>", "<your public key>")
4851
if gateway.pingback().validate({"apiKey": request.headers.get("X-ApiKey")}) is True:
4952
print "OK"
@@ -57,7 +60,7 @@ FasterPay has a Sandbox environment called Test Mode. Test Mode is a virtual tes
5760
### Initiating FasterPay Gateway in Test-Mode
5861
```python
5962
from fasterpay.gateway import Gateway
60-
gateway = Gateway("<your private key>", "<your public key>", "https://pay.sandbox.faterpay.com")
63+
gateway = Gateway("<your private key>", "<your public key>", is_test=False)
6164
```
6265

6366
### Questions?
File renamed without changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/python
2+
3+
class Config:
4+
5+
def __init__(self, privateKey, publicKey, is_test = False, apiVersion = None):
6+
self.publicKey = publicKey
7+
self.privateKey = privateKey
8+
if is_test is not False :
9+
self.API_BASE_URL = "http://pay.fasterpay.com"
10+
else:
11+
self.API_BASE_URL = "http://pay.sandbox.fasterpay.com"
12+
13+
if apiVersion is not None :
14+
self.VERSION = apiVersion
15+
else:
16+
self.VERSION = "1.0.0"
17+
18+
def get_public_key(self):
19+
return self.publicKey
20+
21+
def get_private_key(self):
22+
return self.privateKey
23+
24+
def get_api_url(self):
25+
return self.API_BASE_URL
26+
27+
def get_api_version(self):
28+
return self.VERSION
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/python
2+
from fasterpay.config import Config
3+
from signature import Signature
4+
from pingback import Pingback
5+
from paymentform import PaymentForm
6+
from refund import Refund
7+
from subscription import Subscription
8+
9+
10+
class Gateway:
11+
12+
def __init__(self, private_key, public_key, is_test=False, api_version=None):
13+
self.config = Config(private_key, public_key, is_test, api_version)
14+
15+
def payment_form(self):
16+
return PaymentForm(self)
17+
18+
def signature(self):
19+
return Signature(self)
20+
21+
def pingback(self):
22+
return Pingback(self)
23+
24+
def get_config(self):
25+
return self.config
26+
27+
def refund(self):
28+
return Refund(self)
29+
30+
def subscription(self):
31+
return Subscription(self)
32+
33+
34+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
class PaymentForm:
3+
4+
def __init__(self, gateway):
5+
self.gateway = gateway
6+
7+
def build_form(self, parameters):
8+
payload = parameters.get("payload")
9+
payload.update({"api_key": self.gateway.config.get_public_key()})
10+
payload.update({"hash": self.gateway.signature().calculate_hash(payload)})
11+
12+
form = '<form align="center" method="post" action="' + self.gateway.config.get_api_url() + '/payment/form">'
13+
for param in payload:
14+
form += '<input type="hidden" name="' + param + '" value="' + str(payload[param]) + '" />'
15+
16+
form += '<input type="Submit" value="Pay Now" id="fasterpay-submit"/></form>'
17+
18+
if "auto_submit_form" in parameters:
19+
form += "<script type=\"text/javascript\">document.getElementById(\"fasterpay-submit\").click(); </script>"
20+
21+
return form
File renamed without changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/python
2+
3+
import requests
4+
5+
6+
class Refund:
7+
8+
def __init__(self, gateway):
9+
self.gateway = gateway
10+
11+
def process(self, order_id=None, amount=None):
12+
response = requests.post(self.gateway.config.get_api_url() + "/payment/" + str(order_id) + "/refund",
13+
data={"amount": amount},
14+
headers={"X-ApiKey": self.gateway.config.get_private_key()})
15+
16+
return response.json()
File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/python
2+
3+
import requests
4+
5+
6+
class Subscription:
7+
8+
def __init__(self, gateway):
9+
self.gateway = gateway
10+
11+
def cancel(self, order_id=None):
12+
print self.gateway.config.get_api_url() + "/api/subscription/" + str(order_id) + "/cancel"
13+
14+
response = requests.post(self.gateway.config.get_api_url() + "/api/subscription/" + str(order_id) + "/cancel",
15+
data={},
16+
headers={"X-ApiKey": self.gateway.config.get_private_key()})
17+
18+
return response.json()

fasterpay/validator/__init__.py renamed to build/lib.linux-x86_64-2.7/fasterpay/tests/__init__.py

File renamed without changes.

0 commit comments

Comments
 (0)