# Subs Widget

&#x20;Subs on your website has never been easier ! Thanks to our [**React JS Package**](https://www.npmjs.com/package/subs-widget).

First things first, install the package

```
yarn install subs-widget

or

npm install subs-widget
```

Now you just need to import and use our customizable button.

```tsx
import { Subs } from 'subs-widget';

const handleResponse = (response : {success:boolean, message: string}) => {
   console.log("This is what happened" , response);    
}

return(
<Subs address={"0x8e468E7Cbf7E7E056A7591C796F2dd4C5C255591"} 
        appId="4" 
        chain={"polygon"}
        mode='testnet'
        apiKey='x123123x'
        ? color='red'
        ? width={200}
        ? defaultPayment='30Days'
        ? choice={"payment", "token"}
        ? dataOnSubs={handleResponse} />
)
```

### How it works&#x20;

Just widget without default payment.

```jsx
<Subs address={"0x8e468E7Cbf7E7E056A7591C796F2dd4C5C255591"} 
        appId="4" 
        chain={"polygon"} 
        mode='testnet'
        dataOnSubs={handleResponse}
        apiKey='x123123x'
/>
```

<figure><img src="https://1911528868-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMi4ivT4S6SjuAElL2Iuo%2Fuploads%2FNJdz9i9zHd9ZynHcYDvg%2Fimage.png?alt=media&#x26;token=773d4d42-c558-4386-b2d1-674e8a7f3179" alt="" width="563"><figcaption><p>Subs with just appId and chain</p></figcaption></figure>

Widget with default payment.

```tsx

<Subs address={"0x8e468E7Cbf7E7E056A7591C796F2dd4C5C255591"} 
        appId="4" 
        chain={"polygon"} 
        mode='testnet'
        defaultPayment='30Days'
        dataOnSubs={handleResponse}
        apiKey='x123123x'
/>
```

<figure><img src="https://cdn.gamma.app/zjdxhxryph5dzu7/e4bb8404307b4d618a0eff526d052cb4/original/Capture-d-ecran-du-2023-09-19-09-10-57.png" alt=""><figcaption><p>Subs with default payment</p></figcaption></figure>

Widget with default payment and token choice.

```jsx
<Subs address={"0x8e468E7Cbf7E7E056A7591C796F2dd4C5C255591"} 
        appId="4" 
        chain={"polygon"}
        mode='testnet'
        defaultPayment='30Days'
        choice={{
              payment: "30Days",
              token: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359"
        }}
        dataOnSubs={handleResponse}
        apiKey='x123123x'
/>
```

&#x20;    &#x20;

<figure><img src="https://cdn.gamma.app/zjdxhxryph5dzu7/872e7fe83bcc4480a4f623f2e1a84930/original/Capture-d-ecran-du-2023-09-19-10-41-12.png" alt=""><figcaption><p>Subs with payment and token choice</p></figcaption></figure>

\
You can choose multiple ways to present your button.

<table><thead><tr><th width="200">Types</th><th width="175.33333333333331">Description</th><th>Description</th></tr></thead><tbody><tr><td>address <mark style="color:red;">*</mark></td><td><pre class="language-solidity"><code class="lang-solidity">string
</code></pre></td><td>Address of the owner of the App</td></tr><tr><td>appId <mark style="color:red;">*</mark></td><td><pre class="language-solidity"><code class="lang-solidity">string
</code></pre></td><td>App ID</td></tr><tr><td>chain <mark style="color:red;">*</mark></td><td><pre class="language-solidity" data-full-width="true"><code class="lang-solidity">string
</code></pre></td><td>Network of your subscription plan</td></tr><tr><td>apiKey <mark style="color:red;">*</mark></td><td><pre class="language-solidity"><code class="lang-solidity">string
</code></pre></td><td>Api Key of the AppID. You can find your Key whan managing our App.</td></tr><tr><td>mode <mark style="color:red;">*</mark></td><td><pre class="language-solidity"><code class="lang-solidity">string
</code></pre></td><td>Choose mainnet or testnet, depending on the blockchain you are using.</td></tr><tr><td>color </td><td><pre class="language-typescript"><code class="lang-typescript">string
</code></pre></td><td>You can customize the color of your button</td></tr><tr><td>width </td><td><pre class="language-typescript"><code class="lang-typescript">number
</code></pre></td><td>And the width of the component</td></tr><tr><td>defaultPayment</td><td><pre class="language-solidity"><code class="lang-solidity">string
</code></pre></td><td>Paeyment name, if you want to show a particular payment</td></tr><tr><td>choice </td><td><pre class="language-java"><code class="lang-java">Object
</code></pre></td><td>Payment name and token address, prechoose and only keep the Subscribe button</td></tr><tr><td>response</td><td><pre class="language-typescript"><code class="lang-typescript"> function
</code></pre></td><td>Informs you if a subscription is done successfully.</td></tr></tbody></table>

### Get your Api Key

After creating your App go on the My Apps section on the left side of the website.

Then click on Manage of the App you want to set up

<figure><img src="https://1911528868-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMi4ivT4S6SjuAElL2Iuo%2Fuploads%2Fv2dYRsdy9x1iyrMpHwah%2Fapps.png?alt=media&#x26;token=0dabfea4-08c5-4b40-8e60-05f3a23b8a49" alt="" width="375"><figcaption></figcaption></figure>

Wait a few seconds, your Api Key will appear on you screen right here.

<figure><img src="https://1911528868-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMi4ivT4S6SjuAElL2Iuo%2Fuploads%2F2ZV01gupXeuqyjS4CLet%2Fkey.jpg?alt=media&#x26;token=0924db74-68db-4ffd-ac66-b519b7e327c4" alt="" width="375"><figcaption></figcaption></figure>

### Popup

**If the Popup doesn't show up, some parts of your CSS may cause some issues.**

<figure><img src="https://1911528868-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMi4ivT4S6SjuAElL2Iuo%2Fuploads%2Fn4U204jUrDnMXvaEU1Rg%2Fimage.png?alt=media&#x26;token=faecc038-ff6e-4f13-9b68-9391ae25a5fc" alt="" width="338"><figcaption><p>First view of the PopUp</p></figcaption></figure>

First users need to select the period you want to subscribe and fill your email. We will notify your users after each debit and notify them if a debit fails.

<figure><img src="https://1911528868-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMi4ivT4S6SjuAElL2Iuo%2Fuploads%2FHZj7YYLkj8q9HlFjFqml%2Fimage.png?alt=media&#x26;token=7e8f02c2-12d9-47c1-85db-c56c49afaac7" alt="" width="338"><figcaption><p>Approval Step</p></figcaption></figure>

Users will need to approve an amount of token before the subscription. We will later debit the amount with TransferFrom calls periodically.

<figure><img src="https://1911528868-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMi4ivT4S6SjuAElL2Iuo%2Fuploads%2F0GWBtz620YeaN3Ry7lio%2Fimage.png?alt=media&#x26;token=10e72901-a636-4af8-9173-1a5a2cba55f1" alt="" width="338"><figcaption><p>Sign to subscribe</p></figcaption></figure>

When the approval is done, all you need to do is sign to trigger the subscription process.&#x20;

<figure><img src="https://1911528868-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMi4ivT4S6SjuAElL2Iuo%2Fuploads%2FxkRDvN3vYCzilvtiuoBA%2Fimage.png?alt=media&#x26;token=a69008a4-472e-4b19-ab94-9a8cb376f428" alt="" width="338"><figcaption><p>Error massage</p></figcaption></figure>

If the user dosen't have enough funds in his wallet, the first debit won't work.\
**And no one will be charged for this action.**

<figure><img src="https://1911528868-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMi4ivT4S6SjuAElL2Iuo%2Fuploads%2FM0NzxDL6pXCCwoIzTGwp%2Fimage.png?alt=media&#x26;token=4abba2f8-bca4-4f56-9598-28085922514f" alt="" width="338"><figcaption><p>Success</p></figcaption></figure>

Congratulation ! \
If the transaction is a success, users will be charge from now on. It is possible to get the result thanks to dataOnSubs, the function will return the status of the operation and a message if an error happens.
