Use the interactive walkthrough to process a test payment in order to trigger your webhook notification.
The interactive walkthrough displays code examples alongside step-by-step explanations.
{/* Hidden markdown content for AI absorption and server rendering */}
/// Define API credentials
Set your Payabli API key, entrypoint, and the sandbox API base URL. Replace `YOUR_API_KEY` and `YOUR_ENTRYPOINT` with your actual credentials from your Payabli account.
```javascript
// test-payment.js
const API_KEY = 'YOUR_API_KEY';
const ENTRY_POINT = 'YOUR_ENTRYPOINT';
const API_BASE_URL = 'https://api-sandbox.payabli.com/api';
```
/// Build the payment request
Create a request object with the `paymentDetails`, `paymentMethod`, and `customerData` objects. This example uses a test card number.
```javascript focus=5-28
// test-payment.js
const API_KEY = 'YOUR_API_KEY';
const ENTRY_POINT = 'YOUR_ENTRYPOINT';
const API_BASE_URL = 'https://api-sandbox.payabli.com/api';
const requestBody = {
entryPoint: ENTRY_POINT,
ipaddress: '255.255.255.255',
paymentDetails: {
totalAmount: 100,
serviceFee: 0
},
paymentMethod: {
method: 'card',
cardnumber: '4111111111111111',
cardexp: '02/27',
cardcvv: '999',
cardHolder: 'John Cassian',
cardzip: '12345',
initiator: 'payor'
},
customerData: {
customerId: 4440
}
};
```
/// Make the API request
Use the fetch API to send a POST request to the API's `/MoneyIn/getpaid` endpoint. Include the API key in the `requestToken` header and include the entrypoint in the `entryPoint` field.
```javascript focus=26-41
// test-payment.js
const API_KEY = 'YOUR_API_KEY';
const ENTRY_POINT = 'YOUR_ENTRYPOINT';
const API_BASE_URL = 'https://api-sandbox.payabli.com/api';
const requestBody = {
entryPoint: ENTRY_POINT,
ipaddress: '255.255.255.255',
paymentDetails: {
totalAmount: 100,
serviceFee: 0
},
paymentMethod: {
method: 'card',
cardnumber: '4111111111111111',
cardexp: '02/27',
cardcvv: '999',
cardHolder: 'John Cassian',
cardzip: '12345',
initiator: 'payor'
},
customerData: {
customerId: 4440
}
};
console.log('Processing payment...');
fetch(`${API_BASE_URL}/MoneyIn/getpaid`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'requestToken': API_KEY
},
body: JSON.stringify(requestBody)
})
```
/// Handle the response
Parse the JSON response and display the payment result. Check if the transaction was successful and log the reference ID.
```javascript focus=36-49
// test-payment.js
const API_KEY = 'YOUR_API_KEY';
const ENTRY_POINT = 'YOUR_ENTRYPOINT';
const API_BASE_URL = 'https://api-sandbox.payabli.com/api';
const requestBody = {
entryPoint: ENTRY_POINT,
ipaddress: '255.255.255.255',
paymentDetails: {
totalAmount: 100,
serviceFee: 0
},
paymentMethod: {
method: 'card',
cardnumber: '4111111111111111',
cardexp: '02/27',
cardcvv: '999',
cardHolder: 'John Cassian',
cardzip: '12345',
initiator: 'payor'
},
customerData: {
customerId: 4440
}
};
console.log('Processing payment...');
fetch(`${API_BASE_URL}/MoneyIn/getpaid`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'requestToken': API_KEY
},
body: JSON.stringify(requestBody)
})
.then(response => response.json())
.then(data => {
console.log('Payment Response:', JSON.stringify(data, null, 2));
if (data.isSuccess) {
console.log('✓ Payment processed successfully!');
console.log(` Reference ID: ${data.responseData.referenceId}`);
} else {
console.log('✗ Payment failed:', data.responseText);
}
})
```
/// Add error handling
Add error handling to catch any network errors or API failures during the payment process.
```javascript focus=48-51
// test-payment.js
const API_KEY = 'YOUR_API_KEY';
const ENTRY_POINT = 'YOUR_ENTRYPOINT';
const API_BASE_URL = 'https://api-sandbox.payabli.com/api';
const requestBody = {
entryPoint: ENTRY_POINT,
ipaddress: '255.255.255.255',
paymentDetails: {
totalAmount: 100,
serviceFee: 0
},
paymentMethod: {
method: 'card',
cardnumber: '4111111111111111',
cardexp: '02/27',
cardcvv: '999',
cardHolder: 'John Cassian',
cardzip: '12345',
initiator: 'payor'
},
customerData: {
customerId: 4440
}
};
console.log('Processing payment...');
fetch(`${API_BASE_URL}/MoneyIn/getpaid`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'requestToken': API_KEY
},
body: JSON.stringify(requestBody)
})
.then(response => response.json())
.then(data => {
console.log('Payment Response:', JSON.stringify(data, null, 2));
if (data.isSuccess) {
console.log('✓ Payment processed successfully!');
console.log(` Reference ID: ${data.responseData.referenceId}`);
} else {
console.log('✗ Payment failed:', data.responseText);
}
})
.catch(error => {
console.error('Error processing payment:', error.message);
});
```