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

caps-ui

v1.3.9

Published

Frontend Component Library for CAPS

Downloads

1,347

Readme

npm size

    The Art of Living

caps-ui

About CAPS

CAPS (Centralized Art of Living Payment System) is an effort to have a common independent service to integrate multiple payment systems out-of-the-box.

It has two essential parts

  • the Backend Server + Database
  • the Frontend Component Library

This is the Frontend Component Library.

How It Works

  1. A project that needs to integrate CAPS needs to register itself and its corresponding api endpoints with CAPS using the admin pages.*
  2. CAPS configuration is done independently for different 'entities'
  3. An 'entity' is defined as a combination of ('country', 'organization', 'module')
  4. Adding new payment gateways to CAPS for use across all 'entities' is a task done by the highest privileged super-admin.
  5. Adding/Configuring new 'entities' can be done by respective developers of the external project.
  6. Once the configuration part is over, any frontend project can install the frontend library and use the relevant components provided.
  7. All of the rendering of different payment elements for different pgs is handled by this library based on the configuration done in the admin pages for that specific 'entity'.
  8. For creating orders and getting/updating transaction statuses at /thankyou page, CAPS-FE communicates with CAPS-BE.

*The access to admin pages can be requested by contacting the respective team members.

About The Library

🧢 caps-ui is a functional component library made to simplify integration of multiple payment systems out-of-the-box.

            🦢  can be used anywhere in the entire Art of Living ecosystem             🌙  minimal code for your frontend applications             🏵️  no more custom CSS handling for different payment-gateways*                    (to-be-shipped with standard theme options applied uniformly) * under development - not yet released Language Support React  TypeScript

Installation

Using npm:

npm install caps-ui

Using specific tarball:

# download the latest stable release from
# https://aolrepo.artofliving.org/projects/MVP/repos/caps-fe

npm install /path/to/caps-ui-x.x.x.tgz

Local Development Setup

Source code

    Download the source code from -
    https://aolrepo.artofliving.org/projects/MVP/repos/caps-fe

Environment Variables

  It is essential to add these environment files
  (where BASE_URL is the api url and API_KEY is the key used for preliminary authentication)

  .env.localdev
    - CAPS_LOCALDEV_BASE_URL
    - CAPS_LOCALDEV_API_KEY
  .env.development
    - CAPS_DEVELOPMENT_BASE_URL
    - CAPS_DEVELOPMENT_API_KEY
  .env.production
    - CAPS_PRODUCTION_BASE_URL
    - CAPS_PRODUCTION_API_KEY
  .env.qa
    - CAPS_QA_BASE_URL
    - CAPS_QA_API_KEY
  .env.uat
    - CAPS_UAT_BASE_URL
    - CAPS_UAT_API_KEY

Installation

Using custom builds:


# after making custom changes, build the bundle
npm run bundle

# and then install like previous step
npm install ./caps-ui-x.x.x.tgz

Usage

There are essentially two pages where an application needs to include components/functions provided by caps-ui to handle payments smoothly:

  • Payment Selection Page
  • Thank You Page

🟢 Payment Selection Page

This is the page where your customer chooses amongst various payment gateways configured by you, and enters credentials (or is redirect to a hosted page where they enter the credentials) and confirms to initiate a payment.

  • Under the hood, CAPS-FE will contact CAPS-BE (the backend) and request to create an order.
  • CAPS-BE will contact the pre-configured endpoint (for 'order-validation' ) belonging to the specific entity.
  • If your backend confirms that the order is proper and has indeed been initated by you, CAPS-BE will contact the respective PG and initiate a transaction.
  • CAPS-BE will share the respective order-id to CAPS-FE for further communication with PG to confirm the transaction.

On this page, include the component <PaymentGateways /> along with some config :

  • Customer Details
  • Application-Specific Metadata (for your reference)
  • Payment-Specific Details*
  • Entity-Specific Details (for our reference)
  • Styling-Specific Options**

*Please note the amount needs to be lowest denomination of currency

  • (1000,  'jpy') => ¥ 1.000
  • (1000, 'usd') => $ 10.00
  • (1000,'omr') => ﷼1.000
  • ...

** under development - not yet released

Example

import {
  GatewayAddress,
  GatewayCustomer,
  GatewayMetadata,
  GatewayStyle,
  PaymentGatewaysConfig,
  PaymentGateways,
} from "caps-ui";

const capsEnvironment: CapsEnvironment = "development";

const customerAddress: GatewayAddress = {
  line1: "Unit 530",
  line2: "910 7 Ave. SW",
  city: "Calgary",
  state: "Alberta (AB)",
  country: "CA",
  pincode: "T2P 3N8",
};

const customerDetails: GatewayCustomer = {
  name: "Raghuvir",
  surname: "Jhaveri",
  phone: "+1-6046576534",
  email: "[email protected]",
  address: customerAddress,
};

const context: GatewayMetadata = {
  donorId: "9092dc16-b783-44d9-aab4-89b9f616cdac",
  campaign: "World Culture Festival",
};

const style: GatewayStyle = {
  theme: "dark",
  size: "XL",
  shadow: [0, -1, 0, 3],
  corners: "rounded",
};

const pconfig: PaymentGatewaysConfig = {
  country: "CA",
  org: 3,
  module: "DX",
  test: false,
  amount: 150000,
  currency: "cad",
  customerInfo: customerDetails,
  metadata: context,
  appearance: style,
  returnUrl: "https://dx.artofliving.org/thankyou",
  environment: capsEnvironment,
};

export const PayPage = () => {
  return <PaymentGateways config={pconfig} />;
};

💬 Thank You Page

This is the page the user will be redirected to when their payment is resolved (successful or perhaps canceled on the bank-authorization page).

  • To fetch latest transaction status or initiate a trigger to update the same (for respective PGs like Corvuspay), it is essential to include the paymentStatus() asynchronous function call on this page (as an effect hook, perhaps)
  • Under the hood, paymentStatus() will collect the query string params and send the same back to backend.
  • From there, backend will do all the processing regarding which payment gateway this transaction belongs to, what is the current status of the transaction after redirect and will try to update CAPS internal tables, if needed (in absence of webhooks functionality for that specific payment-gateway).
  • finally CAPS-FE will receive the response from backend and paymentStatus() function will return a promise that resolves to an object of type GatewayReturnStatus

Please note, that this page can be refreshed as many times as possible and CAPS-FE will fetch the transaction status everytime for your customer's convenience.

Example

import { GatewayReturnStatus, paymentStatus } from "caps-ui";

const capsEnvironment: CapsEnvironment = "development";
const [pStatus, setPStatus] = useState<
  GatewayReturnStatus | { error: string }
>();

useEffect(() => {
  paymentStatus(capsEnvironment).then((value) => setPStatus(value));
}, []);

// handle your own frontend-logic using the pStatus state variable
export const ThankyouPage = () => {
  return (
    <div>
      <p>Thank you page</p>
      <p>Details of the payment</p>
      <hr />
      <p>Transaction ID: {pStatus?.id}</p>
      <p>Status: {pStatus?.status}</p>
      <p>Currency: {pStatus?.currency}</p>
      <p>Amount: {pStatus?.amount}</p>
      <p>Payment Method: {pStatus?.method}</p>
      <p>Payment Vendor: {pStatus?.vendor}</p>
      <p>Payment Type: {pStatus?.type}</p>
      <p>Meta data: {JSON.stringify(pStatus?.metadata)}</p>
    </div>
  );
};

Supported Payment Gateways

The list of supported payment gateways is an ongoing task.

  • As time progresses, CAPS aims to provide a comprehensive set of features for many payment gateways.
  • You can find the latest list here in README.md (both on npm and the aol git repo)

| Payment Gateway | Availability Status | | --------------- | ------------------- | | Stripe | 🚧 | | Swish | 🧾 | | Paypal | 🛠️ | | Corvuspay | 🛠️ |

Additional Resources

  • If you're interested, please find a preliminary design flow from earlier discussions regarding CAPS:      Design Flow*

*Please note, this diagram is not up-to-date since the system is still under initial development phase