npm.io
1.0.12 • Published 3 years ago

@utorgapp/deeplinks-generator

Licence
MIT
Version
1.0.12
Deps
1
Size
28 kB
Vulns
0
Weekly
0

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

Installation

npm i @utorg-invoicing/deeplinks-generator
yarn add @utorg-invoicing/deeplinks-generator

Usage

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) => {})
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) => {})

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

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 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 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

 * Please contact support to get specific values

parseDeepLinkValue
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

License

MIT