Authorize
Here is an example of how to authorize a new card.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum
scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Iframe Demo</title>
<link rel="stylesheet" type="text/css"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div id="containerIframe" class="d-flex justify-content-center align-items-center p-4">
<!-- You can specify the width here -->
<div style="width: 468px;">
<span>Payment Method - Auth</span>
<div class="card">
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header p-0">
<h2 class="mb-0">
<button style="width: 100%" class="btn btn-light btn-block text-left p-3 rounded-0"
data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria
controls="collapseOne">
<div class="d-flex align-items-center justify-content-between">
<span>Credit card</span>
</div>
</button>
</h2>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data
parent="#accordionExample">
<form>
<div id="iframeContent"></div>
<div
style="padding-left: 1rem !important; padding-right: 1rem !important; padding-bottom:
1rem !important;">
<button type="submit" class="btn btn-block free-button" style="background-color: #dd051f;
color: white">
Pay With Credit Card
</button>
</div>
<div>
<p style="text-align:center" id="response"></p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto
js.min.js"></script>
<script>
const locationId = __LOCATION_ID__;
let accessToken = "";
let sessionID = '0db08136-feec-4d17-b54c-b38d6460b527';
async function fetchAccessToken() {
const url = 'https://sandbox-api-gtw.softpoint.io/api/locations/' + locationId + '/access_token';
const params = {
api_key: '__API_KEY__',
client: '__CLIENT__'
};
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(params),
};
const res = fetch(url, requestOptions)
.then(response => response.json())
.then(data => {
const accessToken = data.accessToken;
return accessToken;
})
.catch(error => console.error('Error:', error));
return res;
}
async function loadAndProcessOrderWithAccessToken() {
accessToken = await fetchAccessToken();
const scriptElement = document.createElement("script");
scriptElement.src = `https://sandbox-iframe-gtw.softpoint.io/api/softpoint
pay?location_id=`+locationId+`&session_key=${accessToken}`;
document.head.appendChild(scriptElement);
scriptElement.onload = function () {
const conf = {
"location_id": locationId,
"access_token": accessToken,
"process_type": "authorize",
"include-cardholder": 1,
"user_id": '5000',
"country_iso": "US",
};
initPaymentForm('iframeContent', conf);
};
}
loadAndProcessOrderWithAccessToken();
const form = document.querySelector('form');
form.addEventListener('submit', (event) => {
event.preventDefault();
//Prepare settings
let amount = 201.50;
const paymentDetails = {
"session_id": sessionID,
"location_id": locationId,
"access_token": accessToken,
"amount": amount,
"user_id": "5000",
"country_iso": "US",
"phone_number": "1869762446",
"msisdn": "18697624464",
"email": "[email protected]",
"storeCard": 0,
"order": {
"items": [
{
"id": "1000",
"name": "ProductSKU",
"type": "MobileRecharge",
"productSKU": "productSKU",
"productProvider": "DC",
"quantity": 1,
"price": 200.50,
"tax_type": "Inclusive",
"tax": 1.00,
"phone_number": "1869762446",
}
]
}
}
submitPayment(paymentDetails);
});
function onApprovedCallback(e) {
console.log('onApprovedCallback called', e);
const response = document.querySelector('#response');
response.innerHTML = JSON.stringify(e);
response.style.color = 'green';
var btn = document.getElementById('btnSubmit');
btn.disabled = false;
btn.innerText = 'Custom Submit';
}
function onDeclinedCallback(e) {
console.log('onDeclinedCallback called', e);
if (e == 'input_error') {
var btn = document.getElementById('btnSubmit');
btn.disabled = false;
} else {
const response = document.querySelector('#response');
response.innerHTML = JSON.stringify(e);
var btn = document.getElementById('btnSubmit');
response.style.color = 'red';
btn.disabled = false;
btn.innerText = 'Custom Submit';
}
}
function onErrorCallback(e) {
console.log('onErrorCallback called', e);
}
function onDecline(e) {
console.log('onSuccess called', e);
}
</script>
</body>
</html>Response Fields
| Field | Type | Description |
|---|---|---|
amount_approved | String | The approved amount for the authorization |
servicefee_amount | Number | Any service fees applied |
authcode | String | Authorization code from the payment processor |
reference_id | String | Reference identifier for the transaction |
currency_iso | String | Currency code (e.g., "USD") |
transaction_id | String | Unique transaction identifier |
card_data | Object | Information about the card used |
card_data.cardfullname | String | Full name on the card |
card_data.expiry_information | String | Card expiration date (MM/YY format) |
card_data.last4 | String | Last 4 digits of the card number |
card_data.card_brand | String | Card brand (e.g., "MasterCard", "Visa") |
surcharge_amount | Number | Any surcharge fee applied to the transaction |
tip_amount_approved | Number | Tip amount approved for the transaction |
conveniencefee_amount | Number | Convenience fee applied to the transaction |
order_id | String | Merchant order identifier associated with the transaction |
approvalCode | String | Approval code returned by the payment processor |
networkTransactionId | String | Network transaction identifier returned by the processor |
inv_number | String | Invoice number associated with the transaction |
networkReconciliationId | String | Network reconciliation identifier used for settlement tracking |
avsCode | String | Address Verification Service result code |
avsCodeRaw | String | Raw AVS response returned by the processor |
cardVerification | String | Card verification result (e.g., CVV check result) |
cardVerificationRaw | String | Raw card verification response returned by the processor |
transaction_no | String | Processor transaction number |
card_data.token | String | Token representing the stored card |
Response Example
{
"amount_approved": 5,
"servicefee_amount": 0,
"surcharge_amount": 0,
"tip_amount_approved": 0,
"conveniencefee_amount": 0,
"order_id": "58589",
"authcode": "016150703802094",
"approvalCode": "831000",
"networkTransactionId": "016150703802094",
"reference_id": "",
"currency_iso": "usd",
"inv_number": "SP-INV-005",
"networkReconciliationId": "GIHKML924LU8",
"avsCode": "Y",
"avsCodeRaw": "Y",
"cardVerification": "",
"cardVerificationRaw": "",
"transaction_id": "19B911F1-520D-B9ED-94EA-D05099D6021D",
"transaction_no": "016150703802094",
"card_data": {
"token": "HGsUt72tLuVn1111",
"cardfullname": "John Doe",
"expiry_information": "10/30",
"last4": "1111",
"card_brand": "Visa"
}
}Updated 18 days ago
What’s Next
