Você está na página 1de 3

Coding Challenge

Please dont forget to read the notes at the end

Create a payment gateway client which initiates payment request and returns the
result of the transactions. Unlike the conventional payment gateway this payment
gateway directly debits the amount from the consumer account and credits it into
merchants account and returns the result of transactions.

These are the responsibilities of the client program.


1)Prepare request
2)Encrypts the request
3) Send it to the server
4) Receives the response and decrypts it
5 validate the integrity of the response using the hash
6)prints all the parameters received in the response
The parameters to send for a new request will contain
bank_ifsc_code
bank_account-number
amount
merchant_transactions_ref
transaction_date
payment_gateway_merchant_reference
They would be send to the http: //example.pg.com/transaction in a POST
request(this is a fake url.You just assume the server responds to your request
mocking this would be great )
You have to pass only one POST parameter called msg and in that parameter you
have to prepare this with the above mentioned parameters.
Step1:
Create a string from above params and values with the separator for example
Bank_ifsc_code=ICICI00000001bank_account_number=11111111amount=10000.0
0merchant_transaction_ref=txn0001transaction_date=2014-1114payement_gateway_merchant_reference=merc001

Step2:
Create SHA1 digest of above string and append it to the above string like
bank_ifsc_code=icci0000000bank_account_number=111111111amount=10000.00
merc hant_transaction_ref=txn0001transaction_date=2014-1114payement_gateway_merchant_reference=merc001hash=asdfasdf01293949dfsdf
sd1
lets call it payment_with_sha)

Step3:
Then encrypt the string using AES128CBC Algorithm of openssl and encode it using
BASE64Encoding (lets call it payload_to_pg).You will need a KEY to use AES128
which is also with the payment gateway. Use this key:
Q9fbkBF8au24C9wshGRW9ut8ecYpyXye5vhFLtFdGjRg3a4HxPYRfQaKutZx5N4
payload_to_pg=BASE64ENCODE (AES128CBC(payload_with_sha))
Step4:
Now we pass this to payment gateway server using any HTTP client as post
parameter named msg.
Step 5:
After successful or failed payment, the payment gateway gives us a response which
is encrypted the same way we have created and encrypted the request.
The correct order to read the response is:
1) Decode using Base64Decode
2) Decrypt using AES128CBC and your key
3) Verify the response (generate the hash for the rest of the string and verify with
given hash)
The payment gateway response contain the following details
txn_status=success or failure
amount
merchant_transaction_ref
transaction_date
payment_gateway_merchant_reference

payment_gateway_transaction_reference=pg_txn0001

The decrypted response will look like


txn_status=success or
failureamount=10000.00merchant_transaction_ref=txn001transaction_date=20141114payment_gateway_merchant_reference=merc001payment_gateway_transaction_
reference=pg_txn_0001hash=abdedffduedd0000009887

Output:Print all the parameters received from the payment gateway.


Important points:1) Use any programming language
2) Please create the client as modular as you can. Do not write everything in one
class.
3) Additional points for writing specs
4) Push your code to a public GitHub repo and share the link to your comments

Você também pode gostar