SDK Javascript
Integration
You must include aplazame.js on the button and checkout pages.
- aplazame.js
- requirejs
<script
src="https://cdn.aplazame.com/aplazame.js?public-key=api_public_key&sandbox=true"
async defer>
</script>
requirejs.config({
paths: {
aplazame: 'https://cdn.aplazame.com/aplazame.js'
}
});
require(['aplazame'], function (aplazame) {
aplazame.init({
// replace with merchant public key
public_key: "api_public_key",
sandbox: true
});
aplazame.checkout({
// ...
});
});
| Parameter | Type | Required | Description |
|---|---|---|---|
| public-key | string | Yes | Your public key. |
| sandbox | boolean | Yes | Set if the requests will be in sandbox mode (true) or production (false). |
The value of sandbox must be false for production environment
Check available financing products
To display the Aplazame payment button based on the products configured in your account
- html
- aplazame.js
- http
<button type="button"
data-aplazame-button
data-amount="12050"
data-currency="EUR"></button>
<div data-aplazame-payment-info="">
Information about payment with Aplazame that will appear and be hidden with the button
</div>
(window.aplazame = window.aplazame || []).push(function (aplazame)
aplazame.button(
selector: '#some-button-or-wrapper-id', // accepts any valid CSS selector
amount: 12050,
currency: 'EUR'
)
)
Request:
GET /checkout/button?amount=12050¤cy=EUR
Accept: application/vnd.aplazame.v1+json
Authorization: Bearer $api_tokenpublic
Host: api.aplazame.com
Response (available for this credit):
HTTP/1.1 201 OK
Response (not available for this credit):
HTTP/1.1 403 Forbidden
| Parameter | Type | Required | Description |
|---|---|---|---|
| selector | css selector | No | CSS selector to display/hide Aplazame’s payment method. |
| amount | decimal | Yes | Quantity to be financed. |
| currency | ISO 4217 | Yes | The currency code of the order. |
Check Instalments
To display the payment button with Aplazame based on the limits set in your account
The previous examples are for instalments (by default) type.
Check Pay in 15 days
To display the payment button with Aplazame based on the limits set in your account
To check "Pay later" product, yo need add data-product-type="pay_later", or product: { type: 'pay_later' } field:
- html
- aplazame.js
- http
<button type="button"
data-aplazame-button
data-amount="12050"
data-currency="EUR"
data-product-type="pay_later"></button>
<div data-aplazame-payment-info="">
Information about payment with Aplazame that will appear and be hidden with the button
</div>
(window.aplazame = window.aplazame || []).push(function (aplazame)
aplazame.button(
selector: '#some-button-or-wrapper-id', // accepts any valid CSS selector
amount: 12050,
currency: 'EUR'
product: {
type: 'pay_later'
}
)
)
Request:
GET /checkout/button?amount=12050¤cy=EUR&product[type]=pay_later
Accept: application/vnd.aplazame.v1+json
Authorization: Bearer $api_tokenpublic
Host: api.aplazame.com
Response (available for this credit):
HTTP/1.1 201 OK
Response (not available for this credit):
HTTP/1.1 403 Forbidden
Check Pay in 4
To display the payment button with Aplazame based on the limits set in your account
To check "Pay in 4" product, yo need add data-product-type="pay_in_4", or product: { type: 'pay_in_4' } field:
- html
- aplazame.js
- http
<button type="button"
data-aplazame-button
data-amount="12050"
data-currency="EUR"
data-product-type="pay_in_4"></button>
<div data-aplazame-payment-info="">
Information about payment with Aplazame that will appear and be hidden with the button
</div>
(window.aplazame = window.aplazame || []).push(function (aplazame)
aplazame.button(
selector: '#some-button-or-wrapper-id', // accepts any valid CSS selector
amount: 12050,
currency: 'EUR'
product:
type: 'pay_in_4'
)
)
Request:
GET /checkout/button?amount=12050¤cy=EUR&product[type]=pay_in_4
Accept: application/vnd.aplazame.v1+json
Authorization: Bearer $api_tokenpublic
Host: api.aplazame.com
Response (available for this credit):
HTTP/1.1 201 OK
Response (not available for this credit):
HTTP/1.1 403 Forbidden
Checkout start
Here you can see how to integrate the SDK
<script>
(window.aplazame = window.aplazame || []).push(function (aplazame)
// This function is executed when aplazame.js is ready
aplazame.checkout(checkout_id,
// callbacks ...
)
)
</script>
Show result
;(window.aplazame = window.aplazame || []).push(function (aplazame) {
// This function is executed when aplazame.js is ready
aplazame.checkout(checkout_id,
onStatusChange (result_status) {
console.log('IMPORTANT: THE CHECKOUT IS STILL OPEN')
switch (result_status) {
case 'success':
console.log('the checkout has been completed successfully')
break
case 'pending':
console.log('the checkout has been completed but is pending validation')
break
case 'ko':
console.log('the payment process has been rejected by Aplazame')
break
}
},
onClose (result_status) {
switch (result_status) {
case 'success': // equivalent to onSuccess
console.log('the checkout has been completed successfully')
break
case 'pending': // equivalent to onPending
console.log('the checkout has been completed but is pending validation')
break
case 'error': // equivalent to onError
console.log('an error occurred while loading the checkout')
break
case 'dismiss': // equivalent to onDismiss
console.log('the user closed the checkout without completing it')
break
case 'ko': // equivalent to onKO
console.log('the payment process has been rejected by Aplazame')
break
}
})
})
| Parameter | Type | Required | Description |
|---|---|---|---|
| onStatusChange | function | No | function onStatusChange(status) { /**/} Function to be called when the Checkout changes its status. Possible statuses: success, pending, ko. (When sending this signal, the checkout will remain open until a callback is made, as mentioned below). |
| onClose | function | No | Function to be called when the Checkout closes. function onClose(status) { /**/} Possible statuses: success, pending, ko, dismiss. |
| onSuccess | function | No | Function to be called when the payment is completed. When defining this function the success_url value is ignored. |
| onPending | function | No | Function to be called when the payment is pending confirmation. When defining this function the pending_url value is ignored. |
| onKO | function | No | Function to be called when the payment is denied. When defining this function the ko_url value is ignored. |
| onError | function | No | Function to be called when an error occurs. When defining this function the error_url value is ignored. |
| onDismiss | function | No | Function to be called when the user chooses to return to the store. When defining this function the dismiss_url value is ignored. |