2.7.2 โ€ข Published 27 days ago

@voucherify/react-widget v2.7.2

Weekly downloads
79
License
MIT
Repository
github
Last release
27 days ago

Voucherify React Widget contains several client-side Voucherify methods, which are useful in integrating your promotion logic straight to your e-commerce store.

Voucherify React Widget uses Voucherify JS SDK which is fully consistent with restful API Voucherify provides and has fully integrated TypeScript support. It also combines together our previously maintained Voucherify Node.js SDK and Voucherify.js.

Learn more about Voucherify by visiting our site.

๐Ÿ“ Documentation

You will find detailed description and example responses at our official documentation. Most method headers point to more detailed descriptions of arguments you can use.

You can also use our detailed documentation provided by our package here.

๐Ÿ“š Want to learn more? Visit our official site or our Success Portal.

๐Ÿ‘ฝ Having troubles? Check our Help center.

๐Ÿงช Looking for promotion ideas? Check our Cookbook to get an inspiration.

โš™๏ธ Installation and requirements

React Widgets require React and React-DOM version at least 17.0.0

Local installation:

npm install @voucherify/react-widget --save

CDN installation:

<head>
	<!-- Attach Voucherify React Widget styles in the head of your document --->

	<link
		type="text/css"
		rel="stylesheet"
		href="https://unpkg.com/@voucherify/react-widget/dist/voucherify.css"
	/>
</head>

<body>
	<!-- Attach Voucherify React Widget script in the bottom of your document --->

	<script
		type="text/javascript"
		src="https://unpkg.com/@voucherify/sdk/dist/voucherifysdk.umd.production.min.js"
		crossorigin
	></script>
</body>

Then, login to your Voucherify Dashboard and get your API keys from Configuration and allow client requests from your domain.

If you want to use Redeem or Publish Widget, remember to allow client-side redemption and publication.

Each widget requires clientApplicationId and clientSecretKey to be passed as type of string.

๐Ÿ“ Tracking

We are tracking users by a tracking_id. For that we are setting up an identity for the user during widget initialization:

<VoucherifyValidate
	clientApplicationId="39f0d4d7-ca5b-4e49-bd5b-730a4d9dce99"
	clientSecretKey="9ec904dc-7cfe-457e-89ca-e54e5aae1d1b"
	trackingId="gustav@purpleson.com"
/>

or

This method will generate a tracking_id on the server side unless you specify it on your own using client.setIdentity method. In both cases you will receive it in the validation response.

๐Ÿค– Widgets

Validate

import * as React from 'react'

import * as ReactDOM from 'react-dom'

import '@voucherify/react-widget/dist/voucherify.css'
import { VoucherifyValidate } from '@voucherify/react-widget'

const App = () => {
	const onValidatedResponse = response => {
		console.log('Do something with response: ', response)
	}

	const onErrorResponse = error => {
		console.log('Do something with error: ', error)
	}

	return (
		<VoucherifyValidate
			clientApplicationId="39f0d4d7-ca5b-4e49-bd5b-730a4d9dce99"
			clientSecretKey="9ec904dc-7cfe-457e-89ca-e54e5aae1d1b"
			textPlaceholder="e.g. Testing7fjWdr"
			trackingId="gustav@purpleson.com"
			amount
			onValidated={onValidatedResponse}
			onError={onErrorResponse}
		/>
	)
}

export default App

ReactDOM.render(<App />, document.getElementById('root'))

Additional props for Validate Voucherify React Widget

PropTypeDescription
classInvalidstringCSS class applied to the input when entered code is invalid
classInvalidAnimationstringCSS class describing animation of the input field when entered code is invalid
classValidstringCSS class applied to the input when entered code is valid
classValidAnimationstringCSS class describing animation of the input field when entered code is valid
logoSrcstringsource of the image appearing in the circle at the top
logoAltstringalt message of the image appearing in the circle at the top
onValidatedfunctiona callback function invoked when the entered code is valid, it takes the validation response as a parameter
onErrorfunctiona callback function invoked when there is an error
amountbooleanflag enables the amount input field
textPlaceholderstringtext displayed as a placeholder in the code input field
amountPlaceholderstringtext displayed as a placeholder in the amount input field (amount: true is required)
textValidatestringa text displayed on the button (default: "Validate")

Redeem

import * as React from 'react'

import * as ReactDOM from 'react-dom'

import '@voucherify/react-widget/dist/voucherify.css'
import { VoucherifyRedeem } from '@voucherify/react-widget'

const App = () => {
	const onRedeemResponse = response => {
		console.log('Do something with response: ', response)
	}

	const onErrorResponse = error => {
		console.log('Do something with error: ', error)
	}

	return (
		<VoucherifyRedeem
			clientApplicationId="39f0d4d7-ca5b-4e49-bd5b-730a4d9dce99"
			clientSecretKey="9ec904dc-7cfe-457e-89ca-e54e5aae1d1b"
			trackingId="gustav@purpleson.com"
			textPlaceholder="e.g. Testing7fjWdr"
			amount
			onRedeem={onRedeemResponse}
			onError={onErrorResponse}
		/>
	)
}

export default App

ReactDOM.render(<App />, document.getElementById('root'))

Additional props for Redeem Voucherify React Widget

PropTypeDescription
classInvalidstringCSS class applied to the input when entered code is invalid
classInvalidAnimationstringCSS class describing animation of the input field when entered code is invalid
classValidstringCSS class applied to the input when entered code is valid
classValidAnimationstringCSS class describing animation of the input field when entered code is valid
logoSrcstringsource of the image appearing in the circle at the top
logoAltstringalt message of the image appearing in the circle at the top
onRedeemedfunctiona callback function invoked when the entered code is valid, it takes the redemption response as a parameter
onErrorfunctiona callback function invoked when there is an error
amountbooleanflag enables the amount input field
textPlaceholderstringtext displayed as a placeholder in the code input field
amountPlaceholderstringtext displayed as a placeholder in the amount input field (amount: true is required)
textRedeemstringa text displayed on the button (default: "Redeem")

Publish

import * as React from 'react'

import * as ReactDOM from 'react-dom'

import '@voucherify/react-widget/dist/voucherify.css'
import { VoucherifyPublish } from '@voucherify/react-widget'

const App = () => {
	const onPublishedResponse = response => {
		console.log('Do something with response: ', response)
	}

	const onErrorResponse = error => {
		console.log('Do something with error: ', error)
	}

	return (
		<VoucherifyPublish
			clientApplicationId="39f0d4d7-ca5b-4e49-bd5b-730a4d9dce99"
			clientSecretKey="9ec904dc-7cfe-457e-89ca-e54e5aae1d1b"
			trackingId="gustav@purpleson.com"
			textPublish="Get your voucher!"
			onPublished={onPublishedResponse}
			onError={onErrorResponse}
			campaignName="Test Campaign"
			customerFields={[
				{ name: 'name', required: true },
				{ name: 'email', required: false },
			]}
		/>
	)
}

export default App

ReactDOM.render(<App />, document.getElementById('root'))

Additional props for Publish Voucherify React Widget

PropTypeDescription
classInvalidstringCSS class applied to the input when entered data is invalid
classInvalidAnimationstringCSS class describing animation of the input field when entered data is invalid
classValidstringCSS class applied to the input when entered data is valid
classValidAnimationstringCSS class describing animation of the input field when entered data is valid
logoSrcstringsource of the image appearing in the circle at the top
logoAltstringalt message of the image appearing in the circle at the top
onPublishedfunctiona callback function invoked after the voucher publication, it takes the publication response as a parameter
onErrorfunctiona callback function invoked when there is an error
campaignNamestringrequired field Name of the campaign to which voucher will be published
customerFieldsarrayarray containing customerFields objects
customerNamePlaceholderstringPlaceholder for name input field
customerEmailPlaceholderstringPlaceholder for email input field
customerPhonePlaceholderstringPlaceholder for phone input field
customerLine1PlaceholderstringPlaceholder for name input field
customerLine2PlaceholderstringPlaceholder for address line 1 input field
customerPostalCodePlaceholderstringPlaceholder for address line 2 input field
customerCityPlaceholderstringPlaceholder for address city input field
customerStatePlaceholderstringPlaceholder for address state input field
customerCountryPlaceholderstringPlaceholder for address country input field
textPublishstringa text displayed on the button (default: "Get voucher")

customerFields object

KeyTypeValue
namestring'name', 'email', 'phone', 'line_1', 'line_2', 'city', 'postal_code', 'state', 'country'
requiredboolean

Subscribe

import * as React from 'react'

import * as ReactDOM from 'react-dom'

import '@voucherify/react-widget/dist/voucherify.css'
import { VoucherifySubscribe } from '@voucherify/react-widget'

const App = () => {
	const onSubscribedResponse = response => {
		console.log('Do something with response: ', response)
	}

	const onErrorResponse = error => {
		console.log('Do something with error: ', error)
	}

	return (
		<VoucherifySubscribe
			clientApplicationId="39f0d4d7-ca5b-4e49-bd5b-730a4d9dce99"
			clientSecretKey="9ec904dc-7cfe-457e-89ca-e54e5aae1d1b"
			trackingId="gustav@purpleson.com"
			textSubscribe="Subscribe now!"
			onSubscribed={onSubscribedResponse}
			onError={onErrorResponse}
			consents={[{ id: 'cnst_Dfzhg69KrRPGHffXK9EwUaOL', required: true }, { id: 'cnst_KIcC6Gmff1HxGPR3Y0V3x8Lr' }]}
			customerFields={[
				{ name: 'name', required: true },
				{ name: 'email', required: false },
			]}
		/>
	)
}

export default App

ReactDOM.render(<App />, document.getElementById('root'))

Additional props for Subscribe Voucherify React Widget

PropTypeDescription
classInvalidstringCSS class applied to the input when entered data is invalid
classInvalidAnimationstringCSS class describing animation of the input field when entered data is invalid
classValidstringCSS class applied to the input when entered data is valid
classValidAnimationstringCSS class describing animation of the input field when entered data is valid
logoSrcstringsource of the image appearing in the circle at the top
logoAltstringalt message of the image appearing in the circle at the top
onSubscribedfunctiona callback function invoked after the successful subscription, it takes the updated consents response as a parameter
onErrorfunctiona callback function invoked when there is an error
enableDoubleOptInbooleanrequire customer to confirm subscription by email
customerFieldsarrayarray containing customerFields subscribe objects
emailPlaceholderstringa placeholder text to displayed on required 'email' field
consentsarrayarray containing consents objects
textSubscribestringaa text displayed on the button (default: "Subscribe")
textSubscribeSuccessstringa text displayed after successful subscription (default: "Thank you for subscribing")

customerFields subscribe object

KeyTypeValue
namestring'name', 'phone', 'line_1', 'line_2', 'city', 'postal_code', 'state', 'country'
requiredboolean
placeholder`string

consents object

KeyType
idstring
requiredboolean

๐Ÿฆธ TypeScript

Voucherify React Widget includes TypeScript declarations.

๐Ÿ˜จ Error handling

Voucherify error object always has consistent structure, described in details in our API reference.

๐Ÿ–ผ๏ธ Alternatives - iframe

In case you're looking for something plain and simple, you're used to working with iframes and jQuery on your website, and for whatever technical reason the React-based snippet doesn't work for you, then you might want to stick with our legacy voucherify.js SDK for the time being. In such case, please refer to the widget section in the documentation.

๐Ÿ› ๏ธ Contributing

Bug reports and pull requests are welcome through GitHub Issues.

Read more about how to Contribute to Voucherify JS SDK by visiting CONTRIBUTING.md

๐Ÿ—„๏ธ Changelog

Visit CHANGELOG to learn more about new changes.

Voucherify JS SDK CHANGELOG can be found here

2.7.2

27 days ago

2.7.1

4 months ago

2.7.0

4 months ago

2.4.0

7 months ago

2.6.0

7 months ago

2.2.6

9 months ago

2.3.0

8 months ago

2.5.0

7 months ago

2.2.5

12 months ago

2.2.4

12 months ago

2.2.1

1 year ago

2.2.0

1 year ago

2.2.3

1 year ago

2.2.2

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

2.1.9

1 year ago

2.1.2

1 year ago

2.1.1

2 years ago

2.0.16

2 years ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.0

2 years ago

2.0.17

2 years ago

2.0.15

2 years ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.11

2 years ago

2.0.7

2 years ago

2.0.12

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.10

2 years ago

2.0.8

2 years ago

2.0.5

2 years ago

2.0.3

2 years ago

2.0.4

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.5

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago