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

amwal-magento-react-button

v0.0.40

Published

Amwal React Button with Magento Backend

Downloads

112

Readme

amwal-magento-react-button

This is a react component for Amwal Checkout button working in conjunction with an installed Amwal Magento API Backend

Installation.

  1. Install Amwal Magento Backend

  2. Install react component into your react project

npm i amwal-magento-react-button

Usage

import AmwalMagentoReactButton from 'amwal-magento-react-button'

const ReactPage= () => {
    ...
    // add item to cart if the button is on the product page. when used in cart or mini-cart, preCheckoutTask should be left undefined
    const submitAddToCart = async (): Promise<void> => {
      if (!formSelector) return
      const cartForm = document.querySelector(formSelector)
      if (cartForm == null) throw new Error('Product form not found')
      const formURL = cartForm.getAttribute('action') ?? window.location.href
      if (!formURL) throw new Error('Product form URL not found')
      await fetch(formURL, {
        method: 'POST',
        body: new FormData(cartForm as HTMLFormElement),
        headers: {
          'X-Requested-With': 'XMLHttpRequest'
        }
      })
    }

    <AmwalMagentoReactButton
        triggerContext={triggerContext}
        locale={locale}
        preCheckoutTask={submitAddToCart}
        extraHeaders={{
          'x-access-token': 'abc'
        }}
        buttonId="amwal-checkout-knmch"
        overrideCartId={cartId}
        redirectURL={redirectURL}
    />
    ...
}

Properties

| Property | Type | Description | |---------------------------|----------------------------------------------------------|---------------------------------------------------------------------------------------------------------------| | triggerContext | string | Context where the button is instantiated. possible values product-listing-page, regular-checkout, .. etc. | | locale | string | The locale that should be used for rendering the button. Default en. | | preCheckoutTask | () => Promise < string | undefined > | undefined | An asynchronous function that is fired when the button is clicked on checkout. Possible Uses are for performing operations such as adding product to cart if on product page. It can possibly return a new cartId to be used for checkout | | onSuccessTask | (Info: ISuccessInfo) => Promise < void > | undefined | An asynchronous function that is fired when a successful transaction happens | | onCancelTask | () => Promise < void > | undefined | An asynchronous function that is fired when the users cancels | | emptyCartOnCancellation | boolean | undefined | controls behavior if Cart is emptied when the user cancels the checkout | | baseUrl | string | undefined | base URL for the magento backend. Defaults to /rest/V1 | | extraHeaders | Record<string, string> | undefined | extra headers in JSON format to send with fetch requests | | overrideCartId | string | undefined | Useful when you want to provide your own cartId. | | redirectURL | string | undefined | URL to redirect to after checkout is completed. Only effective if performSuccessRedirection is not set| | performSuccessRedirection | (orderId: string, IncrementId:string) => void | undefined | A function that performs redirect on success, orderId has the magento order id and increment_id. | | buttonId | string | The id of the button that will be rendered. This is useful when you want to have multiple buttons on the same page. | | debug | boolean | undefined | Add debug option to button in console |