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

phx-smartprice

v1.0.14

Published

Smartprice Web SDK

Downloads

8

Readme

SmartPRICE™ Web SDK

includes:

  • Embedded Registration Form to sign up users to SmartPRICE™ by invoking a button
  • APIs to register users to SmartPRICE™ with integrated verification system through SMS

Installation

# npm:
$ npm install phx-smartprice
# yarn:
$ yarn add phx-smartprice

Embedded Registration Form

index.js

import init to your workspace

import { init } from 'phx-smartprice';

register a listener to receive messages from the iframe modal

window.addEventListener('message', receiveMessage, false);

to receive member sign-up information as a callback

const receiveMessage = (event) => {
  if (event.data.message === 'confirmation') {
    console.log(event.data.value.smartPriceMemberId);
  }
};

to receive modalClose message as a callback

const receiveMessage = (event) => {
  if (event.data.message === 'closeModal'){
    document.querySelector('.iframe-lightbox-link').lightbox.close();
  }
};

index.html

Add an element <div> to your markup with the smartprice-button class

<div class="smartprice-button"></div>

additional colors available:

<div class="smartprice-button dark"></div>
<div class="smartprice-button blue"></div>

Live demo can be viewed here

Example usage can be found here

 


SmartPrice APIs

SmartPrice API allows for seamless interaction with Prescryptive's smartprice services. We provide two environments (test and prod) for all of our APIs, allowing developers to make calls directly in prod environment for real users and test environment for development purposes. For every method we provide, developers can pass in an optional string parameter "test" to make calls in test environment. By default, it is set to make calls in production environment.

sendVerificationCode(phonenumber)

CommonJS usage

const smartprice = require('phx-smartprice');

Invoking sendVerificationCode method

const smartprice = require('phx-smartprice');

// Make a request to send a verification code to a given phonenumber
smartprice
  .sendVerification('2061234567')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

// Test Environment
smartprice
  .sendVerification('2061234567', 'test')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

Response Example

Success

{ "message": "One Time Password sent successful", "status": "success" }

Failure

{
  "details": {
    "errors": [
      {
        "value": null,
        "msg": {
          "error_code": "V-2001",
          "message": "Phone number is Required"
        },
        "param": "phoneNumber",
        "location": "body"
      }
    ]
  },
  "message": "Missing/Invalid Request Data",
  "status": "failure"
}

registerUser(registrationForm)

CommonJS usage

const smartprice = require('phx-smartprice');

Invoking registerUser method

const smartprice = require('phx-smartprice');
let registrationForm = {
  firstName: 'userFirstName',
  lastName: 'userLastName',
  email: '[email protected]',
  dateOfBirth: '01/01/1997',
  phoneNumber: '2061234567',
  verifyCode: '12345', //verification code from user's phone after invoking sendverification method
};

// Make a request to register a user to smartprice
smartprice
  .registerUser(registrationForm)
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

// Test Environment
smartprice
  .registerUser(registrationForm, 'test')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

Response Example

Success

{
  "data": {
    "memberId": "AB1CDO 01",
    "rxGroup": "100A23B",
    "rxBin": "123456",
    "carrierPCN": "X01"
  },
  "message": "Ok",
  "status": "success"
}

Failure

{
  "details": {
    "errors": [
      {
        "value": "12345",
        "msg": "Verification code is required",
        "param": "verifyCode",
        "location": "body"
      }
    ]
  },
  "message": "Missing/Invalid Request Data",
  "status": "failure"
}

getDeviceToken(code, phoneNumber)

CommonJS usage

const smartprice = require('phx-smartprice');

Invoking getDeviceToken method

const smartprice = require('phx-smartprice');

// Obtain deviceToken with verification code and phoneNumber
// NOTE: verification code is sent to user's phone number on sendVerificationCode
smartprice
  .getDeviceToken(code, phoneNumber)
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

// Test Environment
smartprice
  .getDeviceToken(code, phoneNumber, 'test')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

Response Example

Success

valid code and phoneNumber

{
  "data": {
    "deviceToken": "ansdknoker1n2k3n"
  },
  "message": "Phone Number has been verified successfully. Please verify device using pin",
  "responseCode": 2002,
  "status": "success"
}

Failure

Invalid code and phoneNumber

{ "message": "Internal Server Error", "status": "error" }

Request made with missing verification code

{
  "details": {
    "errors": [
      {
        "msg": {
          "error_code": "V-2002",
          "message": "Verification Code is Required"
        },
        "param": "code",
        "location": "body"
      },
      {
        "msg": "Cannot read property 'match' of undefined",
        "param": "code",
        "location": "body"
      }
    ]
  },
  "message": "Missing/Invalid Request Data",
  "status": "failure"
}

isRegisteredUser(deviceToken)

CommonJS usage

const smartprice = require('phx-smartprice');

Invoking isRegisteredUser method

const smartprice = require('phx-smartprice');

// Verify existing SmartPrice user
// NOTE: deviceToken is generated on user registration
smartprice
  .isRegisteredUser(deviceToken)
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

// Test Environment
smartprice
  .isRegisteredUser(deviceToken, 'test')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

Response Example

Success

valid SmartPrice user

{ "data": true, "message": "Ok", "status": "success" }

Invalid/Non-Existent SmartPrice user

{ "data": false, "message": "Ok", "status": "success" }

Failure

Request made without deviceToken

{
  "message": "Device token is not supplied",
  "status": "failure"
}

Request made with incorrect deviceToken

{
  "code": 2005,
  "message": "Token is invalid",
  "status": "failure"
}

getMemberInformation(deviceToken)

CommonJS usage

const smartprice = require('phx-smartprice');

Invoking getMemberInformation method

const smartprice = require('phx-smartprice');

// get user's SmartPrice membership information
// NOTE: deviceToken is generated on user registration
smartprice
  .getMemberInformation(deviceToken)
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

// Test Environment
smartprice
  .getMemberInformation(deviceToken, 'test')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  });

Response Example

Success

  data: {
    "memberId": "AB1CDO 01",
    "rxGroup": "100A23B",
    "rxBin": "123456",
    "carrierPCN": "X01"
},

Failure

Request made without deviceToken

{
  "message": "Device token is not supplied",
  "status": "failure"
}

Request made with incorrect deviceToken

{
  "code": 2005,
  "message": "Token is invalid",
  "status": "failure"
}