Reveni features a JavaScript SDK library which you can integrate either as an npm package or loading from our CDN using the script tag.
You can install the JavaScript SDK library using one of the available methods. The Reveni JavaScript SDK library is publicly available in GitHub: https://github.com/reveni-io/reveni-js-sdk#reveni-js-sdk.
npmjs: https://www.npmjs.com/package/reveni-js-sdk
npm install reveni-js-sdk
import reveni from 'reveni-js-sdk'
function App() {
const open = () => {
reveni.init('orderId', 'returnId', 'token', '#reveni')
}
return (
<div className="App">
<button onClick={open}>Open iframe</button>
<div id="reveni"></div>
</div>
)
}
export default App
<script src="<https://cdn.reveni.io/js/latest/reveni-js-sdk.js>"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="<https://cdn.reveni.io/js/latest/reveni-js-sdk.js>"></script>
<script>
function instantRefund() {
reveni.init('test', 'test', 'token', '#div')
}
</script>
</head>
<body>
<button onClick="instantRefund()">Open iframe</button>
<div id="div"></div>
</body>
</html>
Otherwise, you can set the parameters to the init
method as query params in the URL:
<script src="<https://cdn.reveni.io/js/latest/reveni-js-sdk.js?orderId=test&returnId=test2&elementSelector=#div&token=tokenTest>"></script>
This is the only available method of the Reveni library, which initializes the instant refund process in an iframe attached to a DOM element.
The init
method accepts the following parameters:
| Property | Description | Required | Example |
| ----------------- | -------------------------------------------------------------------------- | -------- | --------------------------------------------------------------------- |
| orderId | Order id | true | a3a7640d671c4cde8adff13560e25f7b |
| returnId | Return id | true | a3a7640d671c4cde8adff13560e25f7b |
| token | Token to authenticate a user | false | eyJ0eXAiOiJKV1Q.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwifQ.vWXQ2gwzuM |
| elementSelector | CSS selector to render reveni iframe | true | #reveni |
| sandbox | Use sandbox environment | false | true or false. By default is false |
| callbacks object | Invoked when the customer finishes the return process | false | { onFinish: (status) => {}, onSuccess: () => {}, onReject: () => {} } |
The init
method accepts a callback object parameter that allows you to define a set of callback functions that will be invoked when the customer finishes the return process.
When defined, these callback functions override the success_url
, reject_url
and dismiss_url
provided in the Create Return API.
| Function | Description | Overrides | Example |
| ----------------- | ----------------------------------------------------------------------------- | ----------- | --------------------------------------------------------------------- |
| onSuccess | Invoked when the return is finished with success status | success_url | onSuccess() => alert('success!') |
| onReject | Invoked when the return is finished with rejected status | reject_url | onReject() => alert('rejected!') |
| onDismiss | Invoked when the return is finished with dismissed status | dismiss_url | onDismiss() => alert('dismissed!') |
| onFinish | Invoked when the return is finished, receiving the result status as parameter | all urls | onFinish(status) => alert(status) |