@utorgapp/deeplinks-generator
v1.0.12
Published
Provides an API for deep link generation. The links are used to onboard users with invoices to UTORG mobile app.
Downloads
45
Keywords
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
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: '[email protected]',
}
)
.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: '[email protected]',
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}
wheretemplate
andtemplatePath
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
- attributes (optional) - marketing attributes (AppsFlyer OneLink attributes)
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 [email protected]