This application is a simple payment gateway implementing a JSON API via the Rails 5 API mode. Usually merchants with online businesses integrate with payment gateways in order to offer electronic payments to their customers. The API allows you to trigger Sale and Void transactions and receive the transaction's status and unique identifier.
A Sale transaction allows the merchant to bill directly the customer's credit card.
A Sale transaction can be reversed with a Void transaction and this way it will not show up on the customer's credit card statement. Real world Void transactions can be triggered only on the same day the corresponding Sale transaction took place.
- Update ubuntu -> 5 minutes
sudo apt-get update
- Install required dependencies -> 3 min
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.2.2
rvm use 2.2.2 --default
ruby -v
gem install bundler
- Configure Git -> 2 min optional
git config --global color.ui true
git config --global user.name "YOUR NAME"
git config --global user.email "[email protected]"
ssh-keygen -t rsa -b 4096 -C "[email protected]"
cat ~/.ssh/id_rsa.pub
ssh -T [email protected]
- Clone the repository and issue the following commands:
$ bundle install
$ bundel exec rake db:create:all
$ bundle exec rake db:schema:load
$ bundle exec rails s -p 3001
-
PaymentTransactionsController -> 15/20 minutes
- expalin routes.rb - 2 min
- strong params
- make 'create' action - 15 min
-
PaymentTransaction model -> 25/30 minutes
- factory! method - 10 min
- process! - 10 min
-
Gateway model -> 15/25 minutes
- process method - 5 min
- process_transaction method - 15
To interact with the gateway API, you need to provide login credentials using standard HTTP Basic Authentication. Credentials can be set in your config file.
http://localhost:3001
POST /payment_transactions
name | description |
---|---|
card_number | Card Number |
cvv | Three digit number printed on the back of the card |
expiration_date | Card's expiration date |
amount | Amount to be charged |
usage | Reason for the payment |
transaction_type | sale |
card_holder | Card holder's name |
Customer's email address | |
address | Customer's address |
$ curl http://localhost:3001/payment_transactions \
-H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: Basic cGFuZGFoYXB2YTprYWNoYW1haw==" \
-d '{
"payment_transaction": {
"card_number": "4200000000000000",
"cvv": "123",
"expiration_date": "06/2019",
"amount": "500",
"usage": "Coffeemaker",
"transaction_type": "sale",
"card_holder": "Panda Panda",
"email": "[email protected]",
"address": "Panda Street, China"
}
}'
HTTP/1.1 200 OK
Content-Type:application/json;charset=UTF-8
{
"unique_id": "0e08644635ccb520c2eeb54f33865660",
"status": "approved",
"usage": "Coffeemaker",
"amount": 500,
"transaction_time": "2016-11-11T15:32:01.368Z",
"message": "Your transaction has been approved."
}
POST /payment_transactions
name | description |
---|---|
reference_id | Sale transaction unique_id |
transaction_type | void |
$ curl http://localhost:3001/payment_transactions \
-H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: Basic cGFuZGFoYXB2YTprYWNoYW1haw==" \
-d '{
"payment_transaction": {
"reference_id": "0e08644635ccb520c2eeb54f33865660",
"transaction_type": "void"
}
}'
HTTP/1.1 200 OK
Content-Type:application/json;charset=UTF-8
{
"unique_id": "7e59f0116b74d62e3980ee0231b02dc4",
"status": "approved",
"usage": "Coffeemaker",
"amount": 500,
"transaction_time": "2016-11-11T15:25:38.817Z",
"message": "Your transaction has been voided successfully"
}
Status Code | Description |
---|---|
200 | OK |
401 | Access denied |
422 | Unprocessable entity |
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
{
"unique_id": "2f256d59ce3472459704dc43040f0788",
"status": "declined",
"usage": "Coffeemaker",
"amount": 500,
"transaction_time": "2016-11-11T15:32:34.913Z",
"message": "Your transaction has been declined!"
}
HTTP/1.1 422 Unprocessable entity
Content-Type: application/json;charset=UTF-8
{
"reference_id": ["Invalid reference transaction!"]
}