1.0.12 • Published 8 months ago

@utorgapp/deeplinks-generator v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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

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

Usage

Generate deeplink with fixed crypto amount

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

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

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

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
MandatoryTypeDescription
addresstruestringCrypto wallet address of a customer
currency *truestringPayment crypto currency
chain *truestringPayment blockchain
paymentTypetrue'fiat' or 'crypto'Specifies the payment amount type
paymentAmount or amounttruenumberIf paymentType is 'fiat' then paymentAmount should be passed. For 'crypto' pass amount
externalId *truestringInvoice identifier prvided by merchant
merchantId *truestringMerchant's identifier
postbackUrl *falsestringA URL for sending data via postback
paymentCurrency *falsestringPayment fiat currency
emailfalsestringCustomer's email
paymentMethodId *falsestringPayment 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

1.0.12

8 months ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago