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

react-xpay-build

v1.2.3

Published

React SDK for XPay Build

Downloads

184

Readme

React XPay Build

React library for Nexi's XPay Build

Requirements

The minimum supported version of React is v16.8. If you use an older version you need to upgrade React to use this library.

Documentation

Library usage example

  • Import XPay's sdk script with loadSdk helper. Use isProduction = false to load the test environment.
  • Use XPayProvider component passing the formatted order obtained from your backend integration Documentation
  • Pass a nonceHandler function to the provider to handle card payments. It's called at the custom event XPay_Nonce.
import React from "react";
import { loadXPay, XPayProvider } from "react-xpay-build";

const sdkLoader = loadXPay({
	alias: "YOUR_ALIAS",
	isProduction: false,
});

const App = () => {
	const nonceHandler = (_nonceResp) => {
		// submit nonce response data to your backend
		// to pay with the server-to-server integration
	};
	return (
		<XPayProvider
			sdk={sdkLoader}
			apiKey="YOUR_ALIAS"
			order={order}
			nonceHandler={nonceHandler}
		>
			<YourCheckoutComponent />
		</XPayProvider>
	);
};

Pay with card

  • In your checkout component you can use the XPayCard component to show XPay's card input.

  • To pay you can use the use yourCardRef.current.createNonce() or the helper pay function from useCard
    You need to pass a ref to the XPayCard component

import { XPayCard, useCard } from "react-xpay-build";

const YourCheckoutComponent = () => {
	const cardRef = useRef(null);
	const handlePayWithComponent = () => {
		cardRef.current.createNonce();
	};
	const { pay } = useCard();
	const handlePayWithHelperFx = useCallback(() => {
		pay(cardRef);
	}, [cardRef]);

	return (
		<>
			<XPayCard ref={cardRef} />
			<button onClick={handlePayWithHelperFx}>Pay</button>
			<button onClick={handlePayWithComponent}>Or use this Pay button</button>
		</>
	);
};

Customizing card component

### XPay Card

You can pass a style prop to XPayCard component to customize input forms.

XPay Build does not support all css properties (e.g. backgroundColor or border), you'll find available ones on style prop type.

Here is an example of available properties.

const style = {
	common: {
		fontFamily: "Arial",
		fontSize: "15px",
		fontStyle: "Normal",
		fontVariant: "Normal",
		letterSpacing: "1px",
		"::placeholder": {
			color: "#d41111",
		},
		color: "#5c5c5c",
	},
	correct: {
		fontFamily: "Arial",
		fontSize: "15px",
		fontStyle: "Normal",
		fontVariant: "Normal",
		letterSpacing: "1px",
		"::placeholder": {
			color: "#d41111",
		},
		color: "#5c5c5c",
	},
	error: {
		fontFamily: "Arial",
		fontSize: "15px",
		fontStyle: "Normal",
		fontVariant: "Normal",
		letterSpacing: "1px",
		"::placeholder": {
			color: "#d41111",
		},
		color: "#5c5c5c",
	},
};

<XPayCard ref={cardRef} style={style} />;

Customizing card's wrapper div

You can pass a react style object prop styleWrapper to XPayCard to customize the card's wrapper div.

const Component = () => {
	return <XPayCard ref={cardRef} styleWrapper={{ background: "#ccc" }} />;
};

Card errors

By default card errors are enabled.

You can style errors with styleErrors property

const Component = () => {
	return <XPayCard ref={cardRef} styleErrors={{ color: "red" }} />;
};

You can hide default errors and pass an handler that will be called on XPay_Card_Error event, to handle your own errors (e.g. to trigger an alert/toast with the error message)

const Component = () => {
	const cardErrorHandler = (msg: string) => alert(msg);
	return (
		<XPayCard
			ref={cardRef}
			showErrors={false}
			cardErrorHandler={cardErrorHandler}
		/>
	);
};

Pay with Alternate Payment Methods (APM)

  • In your XPayProvider you need to pass a paymentResultHandler documentation callback function, it will be called at XPay_Payment_Result XPay's custom event.
  • In your checkout component (inside XPayProvider) you can use <XPayAPM /> component to pay with alternate payment methods
  • You can choose which APM buttons to show passing a single payment method or a payment methods array to the APM component
const App = () => {
	return (
		<XPayProvider
			sdk={sdkLoader}
			apiKey="YOUR_ALIAS"
			order={order}
			paymentResultHandler={paymentResultHandler}
		>
			<YourCheckoutComponent />
		</XPayProvider>
	);
};
  • Pay with all available payment methods
import { XPayAPM } from "react-xpay-build";

const YourCheckoutComponent = () => {
	return <XPayAPM />;
};
  • Show only APM buttons in the selected array
import { XPayAPM } from "react-xpay-build";

const YourCheckoutComponent = () => {
	return <XPayAPM paymentMethodName={["SATISPAY", "PAYPAL"]} />;
};
  • Pick your selected APM buttons (e.g. to show them in different page sections)
import { XPayAPM } from "react-xpay-build";

const YourCheckoutComponent = () => {
	return (
		<>
			<div style={{ paddingBottom: "20px" }}>
				<XPayAPM paymentMethodName="PAYPAL" />
			</div>
			<XPayAPM paymentMethodName="AMAZONPAY" />
			<XPayAPM paymentMethodName="SATISPAY" />
		</>
	);
};

Recurring Payments & Custom configs

You can pass a customConfig object to XPayProvider to handle recurring payments and other custom parameters. All parameters in the customConfig will be added to the library config object. Properties into the main object will be appended to tha main config object.

const customConfig = {
	main: {
		requestType: "AN",
		serviceType: "AN",
	},
	baseConfig: {},
	paymentParams: {},
	customParams: {
		num_contratto: "123",
	},
	language: "ITA",
};

const App = () => {
	return (
		<XPayProvider
			sdk={sdkLoader}
			apiKey="YOUR_ALIAS"
			order={order}
			paymentResultHandler={paymentResultHandler}
			customConfig={customConfig}
		>
			<YourCheckoutComponent />
		</XPayProvider>
	);
};