Web
SDK
How to Start
$ npm install idpay-b2b-sdkAvailable methods
1
init(options)
import { YouSDK } from "idpay-b2b-sdk";
const initializeYouSDK = async () => {
try {
const result = await YouSDK.init({
env: 'uat', // It will only be filled in if it is a test environment
hasPayments: true // if uses payment in the You flow
});
if (result?.statusPreValidation === 'DEVICE_SUPPORTED') {
// SDK ready. Proceeding to process creation
return;
}
// Handle the scenario where the device isn't compatible. No proceed to invoice creation
} catch (error) {
// Handle initialization failures
}
}2
open(options)
const id = '9bc22bac-1e64-49a5-94d6-9e4f8ec9a1bf';
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
const process = {
transaction: {
id: '9bc22bac-1e64-49a5-94d6-9e4f8ec9a1bf',
token: 'V_adQssw5c', // last 10 caracteres from token
concluded: true,
}
};
const onFinishCallback = invoice => {
console.log('Process', process);
}
YouSDK.open({
transactionId: id,
token: token,
onFinish: onFinishCallback
});
// You can also close the SDK explicitly using the method below
YouSDK.close();Sequence Diagram

How it should look in onboarding experience

How it should look in payments experience

3
renderButton(options)
import { YouSDK } from "idpay-b2b-sdk";
const id = '9bc22bac-1e64-49a5-94d6-9e4f8ec9a1bf';
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
const button = YouSDK.renderButton({
container: '#unico-pay-button',
id,
token,
env: 'uat', // only for test environments
onReady: () => {
// Button is on screen
},
onClick: () => {
// User clicked the button (the flow opens next)
},
onFinish: (process) => {
console.log('Process', process);
},
onError: ({ reason }) => {
// e.g. DEVICE_NOT_SUPPORT — do not show the button
},
});
// Lifecycle handle
button.destroy(); // unmounts the button and removes listeners
button.refresh(); // re-renders the buttonError reasons (onError)
reason
When
Sequence Diagram

Security
Atualizado