Migration from API Version 1.5 to Version 1.6 Notes
1) Change your API end point
Old End Point URL: https://www.bttpay.com/pay/authorize/checkout.php
New End Point URL: https://www.bttpay.com/app/checkout/
2) Pass card_name parameter (Credit Card owner name).
You can add another text field in your checkout form to get Card Owner Name.
Example – Name on Card: <input type=’text’ name=’card_name’ required>
3) Pass this card_name value to the api.
Example – https://www.bttpay.com/app/checkout/?card_name=$_POST[‘card_name’]
4) City and State are now required fields
API Documentation Version 1.6
API end point | https://www.bttpay.com/app/checkout/ |
key | Your transaction key, you can get it from “my profile” section in your merchant account |
amt | Total Amount you want to charge, must be in 2 decimal places, without any currency symbol. e.g 100.00 or 100.20 |
curr | 3 digits currency code. Acceptable codes are : SGD, MYR, USD, GBP |
mode (optional) | Possible values are: test, live
Default is live. Set mode = test for testing/development environment. |
token | A unique token will be generated to represent customer’s credit card information. This token will be submitted from Credit Card information form. See a section below for more details. |
first_name | First name of customer. (required) |
last_name | Last name of customer. (required) |
card_name | Credit Card owner name. (required) |
Email ID of customer. (required) | |
zipcode | Zip Code of customer billing address (required) |
city | Customer’s billing city (required) |
state | Customer’s billing state (required) |
country | Customer’s billing country (required), must be in ISO 3 ALPHA format. e.g: USA for United States |
address | Customer’s billing Address (required) |
phone | Customer’s phone numer(required) |
notify_url | URL where results of your transaction will be sent by POST method. |
error_url | URL where customer will be redirected in case of any error. |
success_url | URL where users will be taken after a successful |
Request
https://www.bttpay.com/app/checkout/?key=$transaction_key&amt=$amount&curr=$currency&mode=$mode&token=$token
&first_name=$first_name&last_name=$last_name&card_name=$card_name&email=$email&zipcode=$zipcode&city=$city&country=$country
&address=$address&phone=$phone&
¬ify_url=$notify_url&success_url=$success_url&error_url=$error_url
Additional Variables
You can pass variables in the API to keep track of your orders, users or transaction. To pass a variable simply add a name value pair in the API link. For example if you want to pass an order id 20 to your notify_url, you can add it to your API link like &id_order=20. The above link will look like:
https://www.bttpay.com/app/checkout/?key=$transaction_key&amt=$amount&curr=$currency&mode=$mode&token=$token
&first_name=$first_name&last_name=$last_name&card_name=$card_name&email=$email&zipcode=$zipcode&city=$city&country=$country
&address=$address&phone=$phone&
¬ify_url=$notify_url&success_url=$success_url&error_url=$error_url
you can add multiple variables. And you can retrieve on your notify_url using $_POST[‘info’][‘id_order’].
Response
You will get this response on your notitify_url page.
success | True or false | |
status | Status will have one of the following values captured pending failed |
|
transaction_id | Your unique transaction id | |
time | Time of tranasaction in Unix Timestamp | |
info | Array contains information about amount, currency etc | |
key | Your Transaction Key | |
amt | Amount charged from the credit card | |
curr | 3 digits currency code | |
mode | Test or live. | |
Fee | Transaction Fee | |
Any variable you passed will be available in this array. |
Getting a Token
This is a simple html form to get credit card information from user. We recommend not to use name tags in this form to avoid submission of Credit Card information to your server. Include jquery and bttpay.js.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script> <script src="bttpay.js"></script> <form action="" method="post" id="bt-payment"> <div id="bt-errors"></div> <div> <label> <span>Card Number</span> <input type="text" size="20" id="number"> </label> </div> <div> <label> <span>Expiration (MM/YY)</span> <input type="text" size="2" id="expMonth"> </label> <span> / </span> <input type="text" size="2" id="expYear"> </div> <div> <label> <span>CVC</span> <input type="text" size="4" id="cvc"> </label> </div> <input type="submit" class="submit" value="Submit Payment"> </form> |
Above code will create a simple form to get Credit Card details. The code below will submit this information to BttPay server over a secured and encrypted connection. And return you a token . You will require an API Key for this, you can get it from my profile section in your merchants account.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<script type="text/javascript"> BttPay.setApiKey("YOUR KEY"); $('#bt-payment').submit(function(e) { var $form = $('#bt-payment'); $form.find('.submit').prop('disabled', true); BttPay.getToken({ number: $('#number').val(), cvc: $('#cvc').val(), expMonth: $('#expMonth').val(), expYear: $('#expYear').val() }, "bttPayResponse"); e.preventDefault(); }); function bttPayResponse(response) { var $form = $('#bt-payment'); if (response.error) { $form.find('#bt-errors').text(response.error); $form.find('.submit').prop('disabled', false); } else { var token = response.token; $form.append($('<input type="hidden" name="bttpayToken" />').val(token)); $form.get(0).submit(); } } </script> |
…………………………………………………………*………………………………………………………….*…………………………………………………………….
Sample Code
Refunding a transaction
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php $url = "https://www.bttpay.com/app/api/"; $params = array("action"=>"refund", "key"=>"YOUR_TRANSACTION_KEY", "tid"=>"TRANSACTION_ID"); $curl = curl_init(); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSLVERSION, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params)); $response = curl_exec($curl); curl_close($curl); $response = json_decode($response, true); if($response['success']){ //refund was successfull. }else{ //refund unsuccessfull. echo $response['message']; } ?> |