# @utorgapp/deeplinks-generator

> Provides an API for deep link generation. The links are used to onboard users with invoices to UTORG mobile app.

Latest version **1.0.12** (published 2023-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @utorgapp/deeplinks-generator
pnpm add @utorgapp/deeplinks-generator
yarn add @utorgapp/deeplinks-generator
bun add @utorgapp/deeplinks-generator
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.12 |
| Published | 2023-09-21 |
| First published | 2023-04-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 28.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | pasynkov, andrew0hub, kirillrodichev, samkrew |

## Links

- npm: https://www.npmjs.com/package/@utorgapp/deeplinks-generator
- Repository: https://github.com/utorg/invoicing-deeplinks
- Homepage: https://github.com/utorg/invoicing-deeplinks#readme
- Issues: https://github.com/utorg/invoicing-deeplinks/issues
- npm.io page: https://npm.io/package/@utorgapp/deeplinks-generator

## Dependencies (1)

- [lz-string](https://npm.io/package/lz-string.md) ^1.5.0

## Recent versions

- 1.0.12 (latest) — 2023-09-21
- 1.0.11 — 2023-05-02
- 1.0.10 — 2023-05-02
- 1.0.9 — 2023-05-02
- 1.0.8 — 2023-04-30
- 1.0.7 — 2023-04-25
- 1.0.6 — 2023-04-24
- 1.0.5 — 2023-04-12
- 1.0.4 — 2023-04-12
- 1.0.3 — 2023-04-10
- 1.0.2 — 2023-04-07
- 1.0.1 — 2023-04-07
- 1.0.0 — 2023-04-07

## README

# Utorg Invoicing Deep links

Provides an API for deep link generation. The links are used to onboard users with invoices to UTORG mobile app.

- [Installation](#Installation)
- [Usage](#Usage)
    - [Generate deeplink](#generate-deeplink)
    - [Extract options from deep_link_value](#extract-options-from-deep_link_value)
- [API](#API)
  - [generateDeepLink](#generateDeepLink)
  - [parseDeepLinkValue](#parseDeepLinkValue)
- [Support](#support)
- [License](#license)

## Installation
```shell
npm i @utorg-invoicing/deeplinks-generator
```
```shell
yarn add @utorg-invoicing/deeplinks-generator
```

## Usage

### Generate deeplink with fixed crypto amount

```ts
import { generateDeepLink } from '@utorg-invoicing/deeplinks-generator'

// User pays 100 USDT (Polygon) 
generateDeepLink(
  'https://link.utorg.com/${template}/${templatePath}',
  {
    address: 'some crypto wallet address',
    externalId: 'merchant-invoice-1',
    merchantId: 'merchant id',
    paymentType: 'crypto',
    amount: 100,
    currency: 'USDT',
    chain: 'POLYGON',
    paymentCurrency: 'EUR',
    paymentMethodId: 'payment method id',
    postbackUrl: 'https://merchant.com/utorg/callback',
    email: 'test@test.com',
  }
)
  .then((cryptoDeepLink) => {})
  .catch((error) => {})
```

### Generate deeplink with fixed fiat amount

```ts
import { generateDeepLink } from '@utorg-invoicing/deeplinks-generator'

// User pays 200 EUR in USDT (Polygon) 
generateDeepLink(
  'https://link.utorg.com/${template}/${templatePath}',
  {
    address: 'some crypto wallet address',
    externalId: 'merchant-invoice-2',
    postbackUrl: 'https://merchant.com/utorg/callback',
    currency: 'USDT',
    chain: 'POLYGON',
    paymentCurrency: 'EUR',
    email: 'test@test.com',
    merchantId: 'merchant id',
    paymentMethodId: 'payment method id',
    paymentType: 'fiat',
    paymentAmount: 200,
  }
)
  .then((fiatDeepLink) => {})
  .catch((error) => {})
```

### Extract options from `deep_link_value`
```ts

const url = 'https://link.utorg.com/${template}/${templatePath}?deep_link_value=N4IghgtgdgLiBcBGADMgNCADmAngQWjiVQzABMyAnBcCygUwGdGQMBjACyhrwDU8AMngByAYQASAUVYg2AV2rwQfPAA0Z2HKIU8AqgBEQAXyA'
const searchParams = new URLSearchParams(new URL(url).search);
const deepLinkValue = searchParams.get('deep_link_value'); // N4IghgtgdgLiBcBGADMgNCADmAngQWjiVQzABMyAnBcCygUwGdGQMBjACyhrwDU8AMngByAYQASAUVYg2AV2rwQfPAA0Z2HKIU8AqgBEQAXyA

parseDeepLinkValue(deepLinkValue)
  .then((options) => {
    const crypto = `${options.currency} (${options.chain})`
    if (options.paymentType === 'crypto') {
        return `User pays ${options.amount} ${crypto}`
    }
    return `User pays ${options.paymentAmount} ${options.paymentCurrency} in ${crypto}`
  })
  .catch((err) => {
    console.error('deep link parsing error', err)
  })
```

## API

### generateDeepLink

```ts
async function generateDeepLink(
  baseUrl: string,
  options: DeepLinkOptions,
  attributes: Record<string, string> = {}
): Promise<string> {}
```

Appends compressed and encoded options string as `deep_link_value` query param to the `baseUrl`. Attributes are reserved for [AppsFlyer OneLink attributes](https://support.appsflyer.com/hc/en-us/articles/207447163-Attribution-link-structure-and-parameters#attribution-link-parameters) and added without compression

Rejects a promise if options are invalid

Deep link example: `https://link.utorg.com/${template}/${templatePath}?deep_link_value=N4IghgtgdgLiBcBGADMgNCADmAngQWjiVQzABMyAnBcCygUwGdGQMBjACyhrwDU8AMngByAYQASAUVYg2AV2rwQfPAA0Z2HKIU8AqgBEQAXyA`

- **baseUrl** - `https://link.utorg.com/${template}/${templatePath}` where `template` and `templatePath` determine the way the link will be handled by the UTORG app. Please contact [support](#support) to get the template values.
- **options** - deep links options object

|                                 | Mandatory | Type               | Description                                                                                        |
|---------------------------------|-----------|--------------------|----------------------------------------------------------------------------------------------------|
| **address**                     | true      | string             | Crypto wallet address of a customer                                                                |
| **currency** *                  | true      | string             | Payment crypto currency                                                                            |
| **chain** *                     | true      | string             | Payment blockchain                                                                                 |
| **paymentType**                 | true      | 'fiat' or 'crypto' | Specifies the payment amount type                                                                  |
| **paymentAmount** or **amount** | true      | number             | If **paymentType** is 'fiat' then **paymentAmount** should be passed. For 'crypto' pass **amount** |
| **externalId** *                | true      | string             | Invoice identifier prvided by merchant                                                             |
| **merchantId** *                | true      | string             | Merchant's identifier                                                                              |
| **postbackUrl** *               | false     | string             | A URL for sending data via postback                                                                |
| **paymentCurrency** *           | false     | string             | Payment fiat currency                                                                              |
| **email**                       | false     | string             | Customer's email                                                                                   |
| **paymentMethodId** *           | false     | string             | Payment method external identifier                                                                                 |

&nbsp;* Please contact [support](#support) to get specific values

- **attributes** (optional) - marketing attributes ([AppsFlyer OneLink attributes](https://support.appsflyer.com/hc/en-us/articles/207447163-Attribution-link-structure-and-parameters#attribution-link-parameters))

### parseDeepLinkValue
```ts
function parseDeepLinkValue(deepLinkValue: string): Promise<DeepLinkOptions> {}
```
Parses the value of `deep_link_value` to an object shaped as `DeepLinkOptions`

## Support

If any questions occur please contact us [support@utorg.pro](mailto:support@utorg.pro)

## License

[MIT](./LICENSE)

---
_Source: https://npm.io/package/@utorgapp/deeplinks-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
