npm package: @getivy/react-sdk
Description: Ivy checkout react library
Author: getivy
Latest version: 0.0.5

# Ivy checkout react SDK

### Installation


```
npm install @getivy/react-sdk
```

### Usage


1. Import `IvyCheckout` component and css styles:
```
import { IvyCheckout } from "@getivy/react-sdk";
import "@getivy/react-sdk/dist/index.css";
```

2. Render `IvyCheckout` component and pass required props:
```
<IvyCheckout
    checkoutUrl={checkoutUrl}
    displayOptions={{
        type: "embedded",
    }}
    onSuccess={({ redirectUrl, referenceId }) => {
        handleSuccess({ redirectUrl, referenceId });
    }}
    onCancel={({ redirectUrl, referenceId }) => {
        handleCancel({ redirectUrl, referenceId });
    }}
/>
```


### Props


#### checkoutUrl

`checkoutUrl: string`
Ivy checkout url returned from `POST` https://api.getivy.de/api/service/checkout/session/create request


#### displayOptions

```
displayOptions: {
	type: "embedded" | "modal"
	maxHeight?: number
	maxWidth?: number
}
```
Configures how the checkout will be rendered:

- `embedded` type renders checkout inside a wrapping `JSX` element inheriting it's height and width.
- `modal` type renders checkout as modal covering the current page content independent of the parent element styles
- `maxWidth` and `maxHeight` limits the size of rendered iframe / modal div element. `embedded` type by default takes 100% height and witdh of parent component. `modal` default max height is `700px` and max width is `520px`


#### onSuccess

`onSuccess: (data: { redirectUrl: string, referenceId: string}) => void`
Callback fired after a successful payment. It provides the success `redirectUrl` configured in merchant dashboard and `referenceId` of the successful order.


#### onCancel

`onCancel: (data: { redirectUrl: string, referenceId: string}) => void`
Callback fired after cancelling payment. It provides the error `redirectUrl` configured in merchant dashboard and `referenceId` of the canceled order.


### CSS Styles

`@getivy/react-sdk/dist/index.css` returns some basic styles for rendering embedded and modal `IvyCheckout` component:

```
.ivy-embedded-checkout-screen {
  border: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
}
.ivy-modal-content {
  position: fixed;
  z-index: 999999;
  inset: 0;
  color: #000;
  background-color: rgba(10, 10, 10, 0.25);
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
}
.ivy-modal-content .ivy-modal-iframe-container {
  border: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 16px;
  transform: translateZ(0);
  width: 100%;
  height: 100%;
  background-color: transparent;
}
.ivy-modal-content .ivy-modal-checkout-screen {
  border: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100% !important;
  height: 100% !important;
}
@media (min-width: 450px) {
  .ivy-modal-content {
    padding: 16px 32px 32px;
  }
}

@media (max-width: 450px) {
  .ivy-modal-content .ivy-modal-iframe-container {
    border-radius: 0px;
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
  }
}

```