0.4.1 • Published 3 years ago

rocketfuel-js-sdk v0.4.1

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

Rocketfuel JS SDK

JS SDK for RocketFuel Payment Method

  1. Go to https://stage1.rocketdemo.net/ and register as a Merchant
  2. Confirm your email
  3. Connect your e-shop = click Edit in the lower left corner, fill in all the fields, copy your merchantID
  4. Type in your shop callback URL (for example, https://yourshop.com/rocketfuel-callback)

Payments (via Rocketfuel extension or popup window/iframe)

After a user creates a new order in your shop and clicks Rocketfuel payment method button on a checkout page, order information should be sent to Rocketfuel

Install

$ npm install rocketfuel-js-sdk

Usage

Basic usage

// if you use sdk on browser
import Rocketfuel from 'rocketfuel-js-sdk';
// or
const Rocketfuel = require('rocketfuel-js-sdk').default;

// if you use sdk on nodejs
const Rocketfuel = require('rocketfuel-js-sdk');

// you need to specify the baseUrl to which requests will be sent
// For example: https://stage1.rocketdemo.net/api or 'https://dev.rocketdemo.net/api'
const baseURL = 'https://stage1.rocketdemo.net/api'
const rocketfuel = new Rocketfuel(baseURL);

const authData = {
  email: 'some@mail.com',
  password: 'some password',
  totp: 123456, // Authorization code from google authenticator. Pass it if you have two-factor authentication enabled
}

const auth = await rocketfuel.auth(authData);
// => {
//     "ok": true,
//     "result": {
//       access: "string",
//       refresh: "string",
//       status: 0
//     }
//   }

// set an access token to gain access to private methods
rocketfuel.setAccessToken(auth.result.access);

// now you can request data
const userData = await rocketfuel.getUser()

/*
=> {
    "ok": true,
    "result": {
      avatar: "string"
      "id": "12345678-9253-42f5-802e-244817c01150",
      "email": "test@rocketfuel.com",
      "username": "username",
      "profile": {},
      "status": 0,
      "type": 1,
      "shopData": {
        "url": "string",
        "logo": "string",
        "companyName": "companyName",
        "description": "desc"
      },
    }
  }
*/

SDK instance

API

auth()

User authorization. The method accepts data for authorization and returns JWT tokens and user status

const auth = {
  email,
  password, 
  totp, // Authorization code from google authenticator. Pass it if you have two-factor authentication enabled
}
await rocketfuel.auth(auth);

/*
=> {
    "ok": true,
    "result": {
      access: "string",
      refresh: "string",
      status: 0
    }
  }
*/

setAccessToken()

Access token setting method. You must call this method once before starting to work with the SDK so that you have access to other methods.

After the token expires, you need to call the refreshTokens() method to get new tokens. After that, call the setAccessToken() method again.

An access token can be obtained during authorization (auth() methods) or when refreshing tokens (refreshTokens() method)

rocketfuel.setAccessToken(access);
// => void

refreshTokens()

Token refresh method. If you receive a 401 Unauthorized error, then you need to use this method to update tokens.

The method accepts a refresh token that you received after authorization. The method returns new tokens

const refresh = await rocketfuel.refreshTokens(refreshToken);

/*
=> {
    "ok": true,
    "result": {
      access: "string",
      refresh: "string",
      status: 0
    }
  }
*/

getUser()

Private method.

The method returns the data of the user under which you are logged in. Doesn't take any arguments

const user = await rocketfuel.getUser();

/*
=> {
    "ok": true,
    "result": {
      "avatar": "string" // User image in base64 format
      "email": "test@rocketfuel.com",
      "fullname": "First Last"
      "id": "51659634-9253-42f5-889e-244817c01150",
      "is2faEnabled": true, // two-factor authentication connection status
      "username": "username",
      "profile": {}, // User profile data
      "status": 0,
      "type": 1,
      "shopData": {
        "url": "string",
        "logo": "string",
        "companyName": "companyName",
        "description": "desc"
      },
    }
  }
*/

getUserPaymentSettings()

Private method.

The method gives the user payment settings. Doesn't take any arguments.

const userSettings = await rocketfuel.getUserPaymentSettings();
/*
=> {
     accountId: "string"
     displayCurrency: "usd"
     isUserConfigured: true
     method: "crypto"
     stockId: "sting"
   }
*/

accountId - user identifier.
displayCurrency - a currency to be displayed in rocketfuel popup window (for convenience purposes). stockId - identifier for exchange/wallet (as Coinbase, Binance, etc.).

setUserPaymentSettings()

Private method.

Method for setting up user payments.

Accepts a required settings object as an argument.

// settings object
// stockId and accountId get in method getMyStockMarket()
const settings = {
  "stockId": "string", // required
  "accountId": "string", // required
  "displayCurrency": "usd" // optional. by default "usd"
}

const result =  await rocketfuel.setUserPaymentSettings(settings);

/*
=> {
  ok: true,
  result: {
    sucess: true,
  }
}
*/

getCurrencies()

The method returns a list of currencies. Doesn't take any arguments.

const currencies = await rocketfuel.getCurrencies();

/*
=> {
    "ok": true,
    "result": [
      {
        currentRate: "34205.99500000000130103443"
        decimals: 8 // the value by which you need to shift the comma in to convert an integer to a float
        fiatEquivalent: null
        fullTitle: "Bitcoin"
        id: "BTC"
        isFiat: false
        isPayment: true
        sort: 1
      },
      ...
    ]
  }
*/

getMyStockMarket()

Private method.

Takes one optional argument: isUpdate = false.

const isUpdate = true; // optional. default isUpdate = false

const myStockMarket = await rocketfuel.getMyStockMarket(isUpdate);

/*
=> {
    ok: true,
    result: {
      accounts: [{}, ... ],
      id: "string",
      nameStock: "coinbase",
      paymentMethod: "crypto",
      status: 2,
      stock: {
        nameStock: "coinbase", 
        logo: "Coinbase", 
        currencies: ["string",..],
      },
      userId: "80d7b067-8c2a-4f69-9ae3-bc01f1e4bc66",
    }
  }
*/

getStores()

Private method.

Returns a list of stores. Accepts a pagination object and an boolean as arguments. Both arguments are optional

// optional. default limit = 10, offset = 0
const pagination = {
  limit: 10, 
  offset: 0, 
};

// optional. default false
const isNew = true; 

const stores = await rocketfuel.getStores(pagination, isNew);

/*
=> {
    "ok": true,
    "result": {
      "count": 0,
      "rows": [
        {
          "id": "string",
          "shopData": {
            "logo": "string",
            "companyName": "string",
            "description": "string",
            "url": "string"
          }
        }
      ]
    }
  }
*/

getStoreByMerchantId()

Private method

The method returns a shop by merchant ID. It takes the merchant id as an argument.

// merchant Id is required. Get id in getStores() method.
const merchantId = "string" 

const store = await rocketfuel.getStoreByMerchantId(merchantId);

/*
=> {
    "ok": true,
    "result": {
      "id": "string",
      "shopData": {
        "logo": "string",
        "companyName": "string",
        "description": "string",
        "url": "string"
      }
    }
  }
*/

getTransactions()

Private method

The method returns a list of user transactions. Accepts an optional pagination object as an argument.

// optional. Default limit = 10, offset = 0
const pagination = {
  limit: 10,
  offset: 0, 
}

const transactions = await rocketfuel.getTransactions(pagination);

/* 
=> {
    ok: true,
    result: {
      count: 0,
      txs: [{}, ...],
    }
  }
*/

purchase()

Private method

Method for making a purchase.

const options = {
  clientId: "string", // required
  amount: 0, // required
  currency: "string",
  accountId: "string", // required
  cart: [
    {
      id: "string",
      price: 0, // Price per item
      name: "string",
      quantity: 1 // Optional. Specifies the quantity of the product, by default it is 1
    }
  ],
  stockId: "string", // required
  offerId: "string",
  code2fa: "string"
}

// options is required
const result = await rocketfuel.purchase(options);

clientId - identifier of a shopper. amount - amount of money to be paid. currency - currency of the purchase.
stockId - identifier of wallet/exchange (for Coinbase, Binance, etc.) offerId - identifier of a purchase within a shop.

purchaseApprove()

Private method

Method to confirm purchase

const options = {
  txId: "string", // required
  code2fa: "string" // required
}

// options is required
const result = await rocketfuel.purchaseApprove(options);

purchaseExternal()

Private method

const options = {
  clientId: "string", // required
  amount: 0, // required
  currency: "BTC",
  cart: [
    {
      id: "string",
      price: 0, // Price per item
      name: "string",
      quantity: 1 // Optional. Specifies the quantity of the product, by default it is 1
    }
  ],
  offerId: "string",
}

// options is required
const result = await rocketfuel.purchaseExternal(options);
0.4.1

3 years ago

0.4.0

3 years ago

0.1.2

3 years ago

0.3.2

3 years ago

0.2.2

3 years ago

0.1.1

3 years ago

0.0.0

3 years ago