Python API for integrating with the RedPay Engine
Project description
Red Shepherd Python API Docs
Follow these steps for Simple API Integration
Step 1 a- Adding the payment library using pip
Add the payment library to your code using pip
Library is hosted on pypi https://pypi.org/project/redpay/
pip install redpay
Step 1 b - Create a RedPay object for secure API methods
Create a Redpay API object which lets you access all the payment functions
from redpay import RedPay
### REPLACE app, url and key with your PROD keys and use a valid account
### These are DEMO Keys which you can safely use for testing
app = "DEMO";
endpoint = "https://redpaystable.azurewebsites.net/";
key = "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAtsQxNp3vmKVNYIxfWSi0LIRgCnPaMn0MUNouxgrs4zmg4cnvSeQ3I8YP03YbpXuWA80RvOw/nWErYAKomniJw8Y+xexMfBQ5sgJgewn3ZnRPNM9Y4Z62gwfIlsrs7Bwvpz9uUtLgeQLl1ffNaumnu1IBrqRps0EZ1QyDuu41UckTyo31C40Wez6IbeMfZeusrmPlIWqyBacdviJ5zHCA3zHNq86QMnB8HOP1U81HOSs6GTTelhD7lCoJ+fHKHxcz0MDr37fNpKpC57B0/20wBXFp9tlVtSkHcIty1lyNk2/HDH8knCdqkZk+fCvWgGwdex41x8/rM+LKC13c5J/yG6Gb2PnKhwNk4lvvnz73YAdqTUJ7qNrdtWVnOTWfbMBiNlpBCVqt8xY8UK6u83AVWrWXse0xe2Pn/kRqlXmxWT0mGEoCavjvZ9lQUL7LXAXZ1dff9r+oFUZo6xDQ3ER/OTIKa4jpvaI9S/J1drsrI1f9kkMWFwEh48dCPYplGSxzAgMBAAE=";
### Use this redpay object for all the API calls
red_pay = RedPay(app, key, endpoint)
Step 2 a - Charge a Credit / Debit Card
import json
request = {
"account": "4111111111111111",
"amount": 2000,
"expmmyyyy": "122024",
"cvv": "123",
"accountHolder": "Anna Conda",
"zipCode": "10001"
}
print("CHARGE Credit Card request >>>")
print(json.dumps(request, indent=2))
response = red_pay.ChargeCard(request)
print("CHARGE Credit Card response >>>")
print(json.dumps(response, indent=2))
ChargeCard Request Example
req = {
"account": "4111111111111111",
"amount": 2000,
"expmmyyyy": "122023",
"cvv": "123",
"cardHolderName": "Anna Conda",
"avsZip": "10001",
};
ChargeCard Response
{
"responseCode": "A",
"transactionId": "DEMO.j1kbwwwh531ivcsh",
"authCode": "PPS531",
"token": "9418594164541111",
"cardLevel": "Q",
"cardBrand": "V",
"cardType": "C",
"processorCode": "CC",
"app": "DEMO",
"account": "9418594164541111",
"cardHolderName": "Anna Conda",
"amount": 2000,
"timeStamp": "12/10/2020 1:46:47 AM",
"text": "Approval Approval",
"ipAddress": "198.54.106.248:51554",
"avsCode": "Z"
}
Step 2 b - For ACH Payments
import json
request = {
"account": "1234567890",
"routing": "121122676",
"amount": 1200,
"accountHolder": "Anna Conda",
}
print("CHARGE ACH request >>>")
print(json.dumps(request, indent=2))
response = red_pay.ChargeACH(request)
print("CHARGE ACH response >>>")
print(json.dumps(response, indent=2))
ChargeACH Request Example
req = {
"account": "1234567890",
"accountType": "C",
"routing": "121122676",
"amount": 2100,
"cardHolderName": "Anna Conda",
};
ChargeACH Response
{
"responseCode": "A",
"transactionId": "DEMO.b4gxvbwexynb8u3i",
"authCode": "SRZ79B",
"token": "9120988649567890",
"cardLevel": null,
"cardBrand": null,
"cardType": null,
"processorCode": "CC",
"app": "DEMO",
"account": "9120988649567890",
"cardHolderName": null,
"amount": 2100,
"timeStamp": "12/10/2020 2:06:35 AM",
"text": "Success Success",
"ipAddress": "198.54.106.248:56473",
"avsCode": "U"
}
Step 3 - Important notes
IMPORTANT NOTE ||| API Amount is in cents ie 20.00 = 2000, 21.56 = 2156
Contact us for your Production API payment keys Email us support@redshepherd.com or go to https://dashboard.redshepherd.com/signup
Other API Functions
Get a Transaction
Retrieve existing Transaction from the API
import json
request = {
"transactionId": "DEMO.3bhjh6o8lle97cvs"
}
print("GET TRANSACTION request >>>")
print(json.dumps(request, indent=2))
response = red_pay.GetTransaction(request)
print("GET TRANSACTION response >>>")
print(json.dumps(response, indent=2))
GetTransaction Request Example
req = {
"transactionId": "DEMO.v9xnqezrwabwl1h7",
};
GetTransaction Response
{
"transactionId": "DEMO.v9xnqezrwabwl1h7",
"app": "DEMO",
"requestAmount": 1200,
"responseAmount": 1200,
"isVoided": false,
"isRefunded": false,
"responseCode": "A",
"userid": "STABLE",
"timestamp": "2020-12-24T21:28:07.841Z",
"ipaddress": "198.54.106.248:54568",
"processor": "CC"
}
Tokenize a Credit / Debit Card
Tokenize a card with us and process future payments just using the token, this is useful in saving Customer's payment information with us securely and using it to charge their account for future orders, Save the token securely on your side and tie it to the Customer's payment profile. DO NOT make this token public / visible anywhere on your UI or App
import json
request = {
"account": "4111111111111111",
"expmmyyyy": "122024",
"cvv": "123",
"accountHolder": "Anna Conda",
"zipCode": "10001"
}
print("TOKENIZE Credit Card request >>>")
print(json.dumps(request, indent=2))
response = red_pay.TokenizeCard(request)
print("TOKENIZE Credit Card response >>>")
print(json.dumps(response, indent=2))
TokenizeCard Request Example
req = {
"account": "4111111111111111",
"expmmyyyy": "122023",
"cvv": "123",
"cardHolderName": "Anna Conda",
"avsZip": "10001",
};
TokenizeCard Response
{
"responseCode": "A",
"transactionId": "DEMO.ictm5y9ppew6rk5r",
"authCode": "PPS405",
"token": "9418594164541111",
"cardLevel": "Q",
"cardBrand": "V",
"cardType": "C",
"processorCode": "CC",
"app": "DEMO",
"account": "9418594164541111",
"cardHolderName": "Anna Conda",
"amount": 2000,
"timeStamp": "12/10/2020 7:09:01 PM",
"text": "Approval Approval",
"ipAddress": "172.58.140.121:38164",
"avsCode": "Z"
}
Tokenize ACH Bank Account
Tokenize a Customer's ACH Account with us and process future payments just using the token, Save the token securely on your side and tie it to the Customer's payment profile. DO NOT make this token public / visible anywhere on your UI or App
import json
request = {
"account": "1234567890",
"routing": "121122676",
"accountHolder": "Anna Conda",
}
print("TOKENIZE ACH request >>>")
print(json.dumps(request, indent=2))
response = red_pay.TokenizeACH(request)
print("TOKENIZE ACH response >>>")
print(json.dumps(response, indent=2))
TokenizeACH Request Example
req = {
"account": "1234567890",
"accountType": "C",
"routing": "121122676",
"cardHolderName": "Anna Conda",
};
TokenizeACH Response
{
"responseCode": "A",
"token": "9hcuqcrw5kg6g2o4",
"app": "DEMO",
"account": "7890",
"cardHolderName": "Anna Conda",
"amount": 0,
"timeStamp": "12/10/2020 7:03:46 PM",
"text": "APPROVED",
"ipAddress": "172.58.140.121:51983"
}
Charge a Token
Charge an existing token by passing in the token and the amount
import json
request = {
"token": "fojid27g24u57zp1",
"amount": 1400
}
print("CHARGE TOKEN request >>>")
print(json.dumps(request, indent=2))
response = red_pay.ChargeToken(request)
print("CHARGE TOKEN response >>>")
print(json.dumps(response, indent=2))
ChargeToken Request Example
{
"token": "9hcuqcrw5kg6g2o4",
"amount": 2200
}
ChargeToken Response
{
"responseCode": "A",
"transactionId": "DEMO.p97sw7y55qive1ub",
"authCode": "2F5F9B",
"token": "9120988649567890",
"processorCode": "CC",
"app": "DEMO",
"account": "9120988649567890",
"amount": 2200,
"timeStamp": "12/10/2020 7:12:30 PM",
"text": "Success Success",
"ipAddress": "172.58.140.121:61468",
"avsCode": "U"
}
Void a Transaction
Voiding a transaction will cancel an existing unsettled transaction, transactions normally settle in 24 hours so you should use Void function to refund the customer his money if the transaction occured in the last 24 hours, ACH Transactions might take longer to settle and voiding an ACH transaction will depend on the settlement period for that particular ACH.
A good rule of thumb is that if you did not actually see the deposit from that transaction in your merchant bank account that means that the transaction is still not settled and can be voided.
import json
request = {
"transactionId": "DEMO.gu377jz1r98e5zfc"
}
print("VOID request >>>")
print(json.dumps(request, indent=2))
response = red_pay.Void(request)
print("VOID response >>>")
print(json.dumps(response, indent=2))
Void Request Example
req = {
"transactionId": "DEMO.b4gxvbwexynb8u3i",
};
Void Response
{
"responseCode": "A",
"transactionId": "DEMO.ictm5y9ppew6rk5r",
"processorCode": "CC",
"app": "DEMO",
"amount": 2000,
"timeStamp": "12/10/2020 7:16:09 PM",
"text": "Approval Approval",
"ipAddress": "172.58.140.121:65012"
}
Refund a Transaction
Refunding a transaction will cancel an existing settled transaction, transactions normally settle in 24 hours so you should use Refund function to refund the customer his money if the transaction occured more than a day in the past. I.e. the transaction has settled and you have already received the money in your merchant bank account.
import json
request = {
"transactionId": "DEMO.gu377jz1r98e5zfc"
}
print("REFUND request >>>")
print(json.dumps(request, indent=2))
response = red_pay.Refund(request)
print("REFUND response >>>")
print(json.dumps(response, indent=2))
Refund Request Example
req = {
"transactionId": "DEMO.b4gxvbwexynb8u3i",
};
Refund Response
{
"responseCode": "A",
"transactionId": "DEMO.b4gxvbwexynb8u3i",
"processorCode": "CC",
"app": "DEMO",
"amount": 2000,
"timeStamp": "12/10/2020 7:16:09 PM",
"text": "Approval Approval",
"ipAddress": "172.58.140.121:65012"
}
© Copyright 2020 Red Shepherd Inc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file redpay-1.4.0.tar.gz
.
File metadata
- Download URL: redpay-1.4.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a1179b764f4ba5eee8b62fe75d36deda7ce197a901e8ce87fe50615cbfa9e97 |
|
MD5 | 7b1e86f9e0bf94d8590d8d4e8351f9d5 |
|
BLAKE2b-256 | fd36694ddf5ba359fc0b19d1d64324ab0d70bc9a63e7b4940e2464fb3e605a0d |
File details
Details for the file redpay-1.4.0-py3-none-any.whl
.
File metadata
- Download URL: redpay-1.4.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7426396ed27fe8c04236c24cf3d28c1ab96eb452a5a9af8f87f3d0e50bc731c4 |
|
MD5 | 8abf79c621639b5c2af6715caf22187b |
|
BLAKE2b-256 | 7dac14899b53b8a7ca9978b0c4209fe2be3068d2558a968320b1fd6ca7816d89 |