Quickstart: without pre-evaluation
To start using banca.me buy now, pay later API, follow the following steps:
- Get your API keys
API Keys
You will need a set of API keys (both Private and Public) for each merchant that integrates with banca.me.
- Create a widget session through a widgetToken
- Initiate payment: Load the widget using the widgetToken or redirect to payment URL
- Handle post-payments events
- Verify transaction through backend or webhook
widget session
widgetToken is valid for 10 minutes after creation, then it will be invalid
Step 1: Get your API Keys​
Every interaction with the banca.me API must be authenticated with the appropriate API keys. For more details about authentication, check out the Authentication guide. There are two types of keys:
- Private Key (Backend): Used for backend API authentication. This key has full access to all API endpoints and should be kept secure. Never expose this key in client-side code or public repositories.
- Public Key (Frontend): Used for frontend widget initialization. This key has limited permissions and is safe to use in client-side code. It's required for initializing the Banca.me widget. Your API keys will be available to you through 1Password.
Step 2: Create a widgetToken​
Using your API Key you need to create a widgetToken from your backend. Always create the widgetToken from your backend, or a malicious user could create widgetToken on your behalf. For more details about this endpoint, check out the widget token API reference. Here is an example of how to create a widgetToken:
- Axios JS
- Node fetch
- PHP
- Python
- Curl
const axios = require('axios');
const response = await axios.post('https://api.banca.me/partner/widget/start',
new URLSearchParams({
amount: 100000,
externalTrxId: 'your-transaction-id',
entityId: 'ex-46df3310759e9000',
email: 'customer@example.com'
}), {
headers: {
'Accept': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer <token>'
}
});
console.log(response.data);
curl -L -X POST 'https://api.banca.me/partner/widget/start' \
-H 'Accept: application/x-www-form-urlencoded' \
-H 'Authorization: Bearer <token>' \
-d 'amount=100000&externalTrxId=your-transaction-id&preApproveId=123e4567-e89b-12d3-a456-426614174000'
const response = await fetch('https://api.banca.me/partner/widget/start', {
method: 'POST',
headers: {
'Accept': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer <token>'
},
body: new URLSearchParams({
amount: '100000',
externalTrxId: 'your-transaction-id',
preApproveId: '123e4567-e89b-12d3-a456-426614174000'
})
});
const data = await response.json();
<?php
$url = 'https://api.banca.me/partner/widget/start';
$data = array(
'amount' => 100000,
'externalTrxId' => 'your-transaction-id',
'preApproveId' => '123e4567-e89b-12d3-a456-426614174000'
);
$options = array(
'http' => array(
'header' => "Content-Type: application/x-www-form-urlencoded\r\n" .
"Accept: application/x-www-form-urlencoded\r\n" .
"Authorization: Bearer <token>\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
// Handle error
} else {
$response = json_decode($result, true);
print_r($response);
}
?>
import requests
from urllib.parse import urlencode
def create_widget_token():
url = "https://api.banca.me/partner/widget/start"
headers = {
"Accept": "application/x-www-form-urlencoded",
"Authorization": "Bearer <token>"
}
data = {
"amount": 100000,
"externalTrxId": "your-transaction-id",
"preApproveId": "123e4567-e89b-12d3-a456-426614174000"
}
try:
response = requests.post(url, headers=headers, data=data)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
raise
Example response:
{
"data": {
"accepted": true,
"widgetToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
widgetToken is temporary and will expire in 10 minutes.
Step 3 - Initiate payment: Load the widget or redirect to payment URL​
There are two ways to do this. The recommend way is to use our JavaScript library. Please refer to Installation and usage section.
The other option to initiate payment is simply to rediret the customer to the payment URL in banca.me. The URL is pagos.banca.me/?widgetToken=<widgetToken>&publicKey=<publicKey>&successReturnUrl=<successReturnUrl>&errorReturnUrl=<errorReturnUrl>. The user will be redirected after 10 seconds to the errorReturnUrl?preApproveId=<preApproveId>&externalTrxId=<externalTrxId> or successReturnUrl?preApproveId=<preApproveId>&externalTrxId=<externalTrxId> in the event of an error (or rejection) and succesful payment respectively. Remember that every variable must be URL encoded.
With the preApproveId you have to check whether the transaction was succesful. Please see step 5.
preApproveId could be undefined if the user is redirected to the error URL.
Step 4: Handle widget events​
Please refer to Widget Callbacks section.
Here, banca.me sends a onSuccess event when the payment has been successful. Use the widget guide to recieve this events and run actions.
Step 5: Verify transaction​
After receiving the onSuccess event, you should verify the transaction. This can be done using our webhook or by verifying it through our REST API using your externalTrxId parameter. We recommend using the webhook. The webhook must be registered through this endpoint. For more details about this endpoint, check out the verify transaction API reference. Here's how to do it:
- Axios JS
- Node Fetch
- PHP
- Python
- Curl
curl -X GET 'https://api.banca.me/partner/pre-approve/your-transaction-id/loan' \
-H 'Authorization: Bearer YOUR_API_KEY'
const axios = require('axios');
async function verifyTransaction() {
try {
const response = await axios.post('https://api.banca.me/partner/pre-approve/your-transaction-id/loan', {}, {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
console.log(response.data);
return response.data;
} catch (error) {
console.error('Error:', error.response?.data || error.message);
throw error;
}
}
async function verifyTransaction() {
try {
const response = await fetch('https://api.banca.me/partner/pre-approve/your-transaction-id/loan', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
});
const data = await response.json();
return data;
} catch (error) {
console.error('Error:', error);
throw error;
}
}
<?php
$url = 'https://api.banca.me/partner/pre-approve/your-transaction-id/loan';
$options = array(
'http' => array(
'header' => "Authorization: Bearer YOUR_API_KEY\r\n",
'method' => 'POST'
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
// Handle error
} else {
$response = json_decode($result, true);
print_r($response);
}
?>
import requests
def verify_transaction():
url = "https://api.banca.me/partner/pre-approve/your-transaction-id/loan"
headers = {
"Authorization": "Bearer YOUR_API_KEY"
}
try:
response = requests.post(url, headers=headers)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
raise
Example response:
{
"data": {
"loanAmount": 660000,
"interestRate": 0.29,
"periods": 2,
"installmentAmount": 330000,
"lastInstallmentAmount": 330000,
"state": "ACTIVE",
"transferDate": "2022-08-01",
"externalTrxId": "your-transaction-id",
"installments": [
{
"state": "ACTIVE",
"period": 1,
"expirationDate": "2022-09-01"
},
{
"state": "ACTIVE",
"period": 2,
"expirationDate": "2022-10-01"
}
]
}
}