npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rocketfuel-node-sdk

v0.1.4

Published

JS SDK for RocketFuel Payment Method

Downloads

10

Readme

Rocketfuel JS SDK

JS SDK for RocketFuel Payment Method

  1. Go to https://merchant-rocketefuelblockchain.com/ or https://merchant-sandbox.rocketefuelblockchain.com/ 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/Webhook URL (for example, https://yourshop.com/rocketfuel-callback)
  5. Generate your clientId and clientSecret from Settings tab.

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

Usage

Basic usage

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

// if you use sdk on nodejs
const Rocketfuel = require('rocketfuel-node-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 environment = production || sandbox;
const rocketfuel = new Rocketfuel(environment);

const authData = {
  clientId: 'YOUR_CLIENT_ID',
  encryptedPayload: 'YOUR_ENCRYPTED_PAYLOAD'
}

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

SDK instance

API

encrypt()

Encrypt is uded for generating secure payload for token generation/ auth. It takes two parameters, tokenInfo and clientSecret to generate encrypted data. Token Info consist of merchantId and totp.

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

/*
=> U2FsdGVkX1/6QwJJRTTjYnt/bzMeQO370pjWPakPbNZQw8oXRmC0F3QYG8fM8WeCQbmlTHitMrAVCEP8I5vCQiHFIqSygcwNR3lVB+fTsAw=
*/

decrypt()

Decrypt works opposite of encrypt. It accepts encryptedText and clientSecret as the parameters.

await rocketfuel.decrypt(encryptedText, clientSecret);

/*
=> {
  merchantId, 
  totp, // Authorization code from google authenticator. Pass it if you have two-factor authentication enabled
}
*/

auth()

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

const auth = {
  clientId,
  encryptedPayload
}
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
    }
  }
*/

generateUUID()

Private method

Method for making a purchase.

const options = {
    amount: "59.97",
    merchant_id: process.env.MERCHANT_ID,
    cart: [
      {
        id: "23",
        name: "Tshirt with round nect (L)",
        price: "10",
        quantity: "1",
      },
      {
        id: "24",
        name: "Flower Formal T-shirt (L)",
        price: "15",
        quantity: "1",
      },
      {
        id: "25",
        name: "Printed White Tshirt (L)",
        price: "9",
        quantity: "1",
      },
    ],
    currency: "USD",
    order: "390",
    redirectUrl: "",
    customerInfo: {
      name: 'Customer Name',
      email: 'Customer Email',
    }
  }

// options is required
const result = await rocketfuel.generateUUID(options);
/*
=> {
    "ok": true,
    "result": {
      uuid: "string",
      url: "string"
    }
  }
*/

merchant_id - identifier of a shopper. amount - amount of money to be paid. currency - currency of the purchase.
order - identifier of a purchase within a shop.

lookup()

Private method

It is used to fetch the currenct stauts of the transaction record.


// options is required
const result = await rocketfuel.lookup(txnId, merchantId);
/*
=> {
    "ok": true,
    "result": [
        {
            "id": <Transaction_id>,
            "status": <Status>,
            "meta": {
                "offerId": <Offer_id>
            },
            "amount": "1.598457239956444619",
            "receivedAmount": "0",
            "currency": "ETH"
        }
    ]
}

// Values received in response are
1. id – RKFL identifier
2. status – code will be interpreted as follows
    1 = RocketFuel received the amount successfully 
    0 = Amount is Pending to be received by RocketFuel 
    -1 = RocketFuel didn’t receive the amount, and the transaction is failed 
    101 = RocketFuel received a partial payment of the total amount 
3. meta
    3.1 offerId – Unique identifier of the merchant 
4. amount - the total price of the complete order. 
5. receivedAmount – Amount received by RocketFuel for an order.  
6. currency – Unit of currency used by Shopper to make the payment for an order
*/

webhook()

Private method

It is used to match the signature of the webhook received. It accepts the webhook payload received as a paramter.


// options is required
const result = await rocketfuel.webhook(requestBody);
/*
=> // verify webhook
  const webhookAuthentic = await rocket.webhook(requestBody); // true false
  console.log('Webhook authentic: ', webhookAuthentic);
*/