0.0.1-5 • Published 2 years ago

@uniblock/onramper v0.0.1-5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Uniblock SDK Onramper

Steps to call functions from Onramper Docs:

  1. First we call to getGateways to get a list of the cryptos, currencies and payment methods available.

  2. Once we have selected the fromCurrency, the toCurrency, the paymentMethod and the amount we want to buy, we make a call to getRate to know which onramps are availables for that combination.

  3. If the amount is enough to give us at least one onramp available, we can start the process of buying crypto. If not, we should make another call fixing one of the errors described in the attribute error.

  4. Now that we have selected the onramp we want to use, we should check the attribute nextStep to know which is the first step to start with the purchase flow. Once we complete a step, we will get a new step on the response. We will keep executing steps until the flow is finished. To execute step, please call executeStep with given url.

How to Install Package

  1. Run yarn run compile or npm run compile in uniblock-sdk-onramper (you should also do this each time you've made changes to this package)

  2. Run yarn link or npm link in uniblock-sdk-onramper

  3. In the project you want to use this package, run yarn link "@uniblock/onramper" or npm link "@uniblock/onramper"

Quickstart

In order to access the SDK's functionalities, you must first create an instance of the Onramper class. This is done using the initializeOnramper function. You may then use the returned object to call desired methods. When calling the initializeOnramper function, you must ensure to pass in the Uniblock and Onramper API keys.

import { initializeOnramper } from '@uniblock/onramper';

// getting instance of the Onramper class
const onramper = await initializeOnramper(uniblockApiKey, apiKey);

getGateways

Call getGateways() to get a list of the cryptos, currencies and payment methods available.

Params

parametertypedescription
searchParamsgetGatewaySearchParamsContains optional search parameters.

Optional search parameters: | search parameter | type | description | | -------------- | ---------------------- | ------------------------------------ | | country? | string | Defines which onramps are available. By default, country is automatically detected by the API using client's IP but can be overwritten by providing its ISO 3166 alpha-2 code (eg: 'us', 'gb'...). | | includeIcons? | boolean | If true, includes icons of the cryptos, currencies and payment methods in the response. |

Example

type getGatewaysSearchParams = {
  country?: string,
  includeIcons?: boolean,
};

const searchParams: getGatewaysSearchParams = {
  country: 'ca',
  includeIcons: false,
};

await onramper.getGateways(searchParams);
//  For onramper, check initializing step

getRate

Call getRate() to get a list of accessible onramps.

Params

parametertypedescription
fromCurrencystringThe Currency to pay with. Currently, only fiat currencies are allowed.
toCurrencystringThe Currency to buy. Currently, only cryptocurrencies are allowed.
paymentMethodstringThe Payment method to use.
amountnumberThe amount of currency to buy, by default, amount of fromCurrency.
searchParamsgetRateSearchParamsContains optional search parameters

Optional search parameters:

search parametertypedescription
country?stringDefines which onramps are available. By default, country is automatically detected by the API using client's IP but can be overwriten by providing its ISO 3166 alpha-2 code (eg: 'us', 'gb'...).
includeIcons?booleanIf true, includes icons of the cryptos, currencies and payment methods in the response.
amountInCrypto?numberIf true, the amount specified in {amount} represents the amount of crypto user wants to buy.

accepted paymentMethod values: creditCard, bankTransfer, applePay, googlePay, paynow, fps, alipay-hk, prompt-pay, instapay, upi, gojek-id, viettel-pay, duit-now, ideal, bancontact, giropay, sofort, sepaBankTransfer

Example

const fromCurrency: string = 'EUR';

const toCurrency: string = 'BTC';

const paymentMethod: string = 'creditCard';

const amount: number = 100;

type getRateSearchParams = {
  country?: string,
  includeIcons?: boolean,
  amountInCrypto?: number,
};

const searchParams: getGatewaysSearchParams = {
  country: 'ca',
  includeIcons: false,
};

await onramper.getGateways(
  fromCurrency,
  toCurrency,
  paymentMethod,
  amount,
  searchParams,
);
//  For onramper, check initializing step

executeStep

Call executeStep() to get a list of accessable onramps.

Example

const nextStepUrl: string =
  'https://onramper.tech/transaction/Moonpay/redirect/WyJXeUo3WENKcFpGd2lPbHdpTkhoTE9YSk5NVTFyV21GTlpFcGtSMUZLYmpaTlFTMHRYQ0lzWENKaGJXOTFiblJjSWpveU1EQXNYQ0pwYmtOMWNuSmxibU41WENJNlhDSkRRVVJjSWl4Y0ltOTFkRU4xY25KbGJtTjVYQ0k2WENKQ1ZFTmNJaXhjSW5CaGVXMWxiblJOWlhSb2IyUmNJanBjSW1OeVpXUnBkRU5oY21SY0lpeGNJa0ZRU1V0bGVWd2lPbHdpY0d0ZmRHVnpkRjl4TmpoRk5HNUVRamd4WTJaUk9ISllNRXc1VEdobE9HVkVlSHBTWVc0MGRWRnZWamhrTTJWR01IRkZNRndpTEZ3aVpYaHdaV04wWldSU1pXTmxhWFpsWkVOeWVYQjBiMXdpT2pJd01DeGNJbkJoY25SdVpYSkdaV1ZjSWpvd0xGd2liMjV5WVcxd1pYSkdaV1ZjSWpveExGd2lZM0o1Y0hSdlFXUmtjbVZ6YzF3aU9tNTFiR3dzWENKamNubHdkRzlCWkdSeVpYTnpWR0ZuWENJNmJuVnNiSDBpWFE9PSIsIjE0MjQ3MGE1OGVhNzhlZGRkYWFiY2VkYzI4ZTA0MDQyYmViNjI5ODcwNjA1ZDIzY2ZjOWY4Y2Y3YWViMjUyOTciXQ==?country=ca';

const method: string = 'POST';
// In most cases, method is POST, sometimes it is PUT.

const body: object = {};

await onramper.getGateways(nextStepUrl, method, body);
//  For onramper, check initializing step
0.0.1-5

2 years ago

0.0.1-4

2 years ago

0.0.1-3

2 years ago

0.0.1-2

2 years ago

0.0.1-1

2 years ago

0.0.1-0

3 years ago

1.0.0-0

3 years ago