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

@noaignite/react-centra-checkout

v2.0.1

Published

React components and helpers for Centra checkout api

Downloads

304

Readme

@noaignite/react-centra-checkout

NoA Ignite Centra helpers. Previously known as @oakwood/accelerator.

Installation

react-centra-checkout is available as an npm package.

// with pnpm
pnpm install @noaignite/react-centra-checkout

// with npm
npm install @noaignite/react-centra-checkout

// with yarn
yarn add @noaignite/react-centra-checkout

Why

This package exists to ease development of react frontend applications using the Centra Checkout API.

Most importantly, it exposes a CentraProvider that you wrap your application with (for Next.js projects, usually in _app.js), and a set of hooks to fetch api endpoints and update the user selection.

It does not attempt to abstract the Centra api, but rather exposes the endpoints in a React way of calling them.

Getting started

Start by wrapping your applications root component with CentraProvider and supply it with apiUrl (the api url to your Centra checkout api), paymentReturnPage (url to the api route in your app which handles successful payments) and paymentFailedPage (url to the api route for failed payments) like so:

import { CentraProvider } from '@noaignite/react-centra-checkout'

<CentraProvider
  apiUrl={process.env.CHECKOUT_API}
  paymentReturnPage={`${process.env.APP_URL}/api/centra/checkout-success`}
  paymentFailedPage={`${process.env.APP_URL}/api/centra/checkout-failed`}
>
  <AppProvider>
    <AppBase>
      <Component {...pageProps} />
    </AppBase>
  </AppProvider>
</CentraProvider>

By default, the CentraProvider will handle fetching the initial selection for the user, so by wrapping your apps root component, you get access to the useCentraSelection and useCentraHandlers hooks.

Getting things from the selection

To get data from the current selection, simply destruct whatever you want from the useCentraSelection hook, like so:

import { useCentraSelection } from '@noaignite/react-centra-checkout'

const { selection, paymentMethods } = useCentraSelection()
const { items, currency, totals } = selection

Updating the selection

To update the selection, call one of the update handlers from the useCentraHandlers hook:

import { useCentraHandlers } from '@noaignite/react-centra-checkout'

const { addItem } = useCentraHandlers()

addItem(size, quantity)

Calling endpoints server-side

The Centra selection and handlers will only be available client-side. To make api calls against Centra server-side (e.g when fetching products), you need to call the api directly using the Api client:

import { ApiClient } from '@noaignite/react-centra-checkout'

const response = await ApiClient.default.request('POST', 'products', { categories: ['15'] })

Documentation

https://react-centra-checkout-docs.vercel.app