Datatrans Lightbox component for React apps
npm install react-datatrans-light-box[![NPM version][npm-version-image]][npm-url] !CI
Official Datatrans light box library for showing our payment page in React applications.
React is defined as a peer dependency and expected to be made available by your project. Other than that this library is completely dependency-free.
Beginning with v3.0.0, this component is using the Datatrans Payment JSON API.
If you're still using the legacy XML API, please refer to react-datatrans-light-box v2.0.2.
``shUse with current JSON API
npm install react-datatrans-light-box
Example usage
`js
import React, { useState } from 'react'
import Lightbox from 'react-datatrans-light-box'export default (props) => {
const { transactionId } = props
const [lightbox, showLightbox] = useState(false)
const onLoaded = () => console.log('Loaded')
const onOpened = () => console.log('Opened')
const onCancelled = () => showLightbox(false)
const onError = (data) => {
console.log('Error:', data)
showLightbox(false)
}
return
Datatrans Lightbox Demo
{lightbox
? transactionId={transactionId}
production={true}
onLoaded={this.onLoaded}
onOpened={this.onOpened}
onCancelled={this.onCancelled}
onError={this.onError}
/>
:
}
}
`Properties
The Lightbox component takes the following properties as input.
| Property | Mandatory | Type | Description |
| -------- | --------- | ---- | ----------- |
|
transactionId | Yes | String | Transaction ID returned by Initializing Transactions. |
| production | No | Boolean | Indicates whether requests hit Datatrans' production or sandbox environment. Defaults to false (sandbox). |
| onLoaded | No | Function | Called when payment page is loaded. |
| onOpened | No | Function | Called when payment page is opened. |
| onCancelled | No | Function | Called when user has cancelled payment. |
| onError` | No | Function | Called when there was an error loading the payment page. |[npm-url]: https://npmjs.com/package/react-datatrans-light-box
[npm-version-image]: https://img.shields.io/npm/v/react-datatrans-light-box.svg?style=flat-square