1.0.10 • Published 12 days ago

@tap-payments/benefit-pay-button v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
12 days ago

benefit-pay-button

Handling Benefit Pay button in React and vanilla JS

Install

This is a React module available through the npm registry. Installation is done using the npm install command:

npm install @tap-payments/benefit-pay-button

---------------------------- OR -------------------------

yarn add @tap-payments/benefit-pay-button

Examples

ES6

import React from 'react'
import { BenefitPayButton, Edges, Environment, Locale } from '@tap-payments/benefit-pay-button'

const App = () => {
	return (
		<BenefitPayButton
			// required (The public Key provided by Tap)
			operator={{
				publicKey: 'pk_test_XXXXXXXX'
			}}
			// required (The environment of the SDK and it can be one of these environments)
			environment={Environment.Development}
			// optional (to enable the debug mode)
			debug={true}
			// required
			merchant={{
				// required (The merchant identifier provided by Tap)
				id: 'merchant_xxxxxxxxxx'
			}}
			// required
			transaction={{
				// required (The amount to be charged)
				amount: '12',
				// required (The currency of the amount)
				currency: 'BHD'
			}}
			reference={{
				transaction: 'txn_123',
				order: 'ord_123'
			}}
			// optional (The billing contact information)
			customer={{
				//"OPTIONAL : Customer ID",
				names: [
					{
						// required : en or ar",
						lang: Locale.EN,
						// required : First name of the customer.",
						first: 'test',
						// required : Last name of the customer.",
						last: 'tester',
						// optional : Middle name of the customer.",
						middle: 'test'
					}
				],
				// optional: Defines the contact details for the customer
				contact: {
					// optional: The customer's email",
					email: 'test@gmail.com',
					// optional: The customer's phone number"
					phone: {
						// required:  The customer's country code",
						countryCode: '+20',
						// required:  The customer's phone number
						number: '1000000000'
					}
				}
			}}
			//optional (for styling button)
			interface={{
				// optional (The locale of the Apple Pay button and it can be one of these locales:[EN,AR])
				locale: Locale.EN,
				// optional (The border of the button and it can be one of these values:[curved,straight])
				edges: Edges.CURVED
			}}
			post={{
				url: ''
			}}
			// optional (A callback function that will be called when you button is clickable)
			onReady={() => {
				console.log('Ready')
			}}
			// optional (A callback function that will be called when the button clicked)
			onClick={() => {
				console.log('Clicked')
			}}
			// optional (A callback function that will be called when you cancel the payment)
			onCancel={() => console.log('cancelled')}
			// optional (A callback function that will be called when you have an error)
			onError={(err) => console.log('onError', err)}
			// optional (A async function that will be called after creating the token successfully)
			onSuccess={(data) => {
				// do your stuff here...
				console.log(data)
			}}
		/>
	)
}

Vanilla JS

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>apple pay button</title>
		<script src="https://tap-sdks.b-cdn.net/benefit-pay/build-1.0.10/main.js"></script>
	</head>

	<body>
		<div id="benefit-pay-button"></div>
		<script type="text/javascript">
			const { render, Edges, Environment, Locale, ThemeMode } = window.TapBenefitpaySDK
			render(
				{
					operator: {
						publicKey: 'pk_test_XXXXXXXX'
					},
					environment: Environment.Development,
					debug: true,
					merchant: {
						id: 'merchant_xxxxxxxxxx'
					},
					transaction: {
						amount: '12',
						currency: 'BHD'
					},
					reference: {
						transaction: 'txn_123',
						order: 'ord_123'
					},
					customer: {
						names: [
							{
								lang: Locale.EN,
								first: 'test',
								last: 'tester',
								middle: 'test'
							}
						],
						contact: {
							email: 'test@gmail.com',
							phone: {
								countryCode: '20',
								number: '1000000000'
							}
						}
					},
					interface: {
						locale: Locale.EN,
						edges: Edges.CURVED
					},
					post: {
						url: ''
					},
					onReady: () => {
						console.log('Ready')
					},
					onClick: () => {
						console.log('Clicked')
					},
					onCancel: () => console.log('cancelled'),
					onError: (err) => console.log('onError', err),
					onSuccess: (data) => {
						console.log(data)
					}
				},
				'benefit-pay-button'
			)
		</script>
	</body>
</html>

Configurations

NameTypeR/ODescription
operatorobjectRequiredThe operator object that contains the public key + hashString
operator.publicKeystringRequiredThe public key provided by Tap
operator.hashStringstringOptionalThe hash string can be set it to secure your transaction
environmentstringRequiredThe environment of the SDK and it can be one of these environments: Development, Live
debugboolOptionalTo enable the debug mode
merchantobjectRequiredThe merchant object that contains the merchant identifier
merchant.idstringRequiredThe merchant identifier provided by Tap
transactionobjectRequiredThe transaction object that contains the amount and currency
transaction.amountstringRequiredThe amount to be charged
transaction.currencystringRequiredThe currency of the amount
referenceobjectOptionalThe reference object that contains the transaction and order references
reference.transactionstringOptionalpassed by the merchant for further processing whenever needed.
reference.orderstringOptionalpassed by the merchant for further processing whenever needed.
customerobjectOptionalThe customer object that contains the customer details
customer.idobjectOptionalThe customer ID
customer.namesarrayOptionalThe customer names and it can be one of these values: EN, AR
customer.namesidx.langstringRequiredThe customer name language and it can be one of these values: EN, AR
customer.namesidx.firststringRequiredThe customer first name
customer.namesidx.laststringRequiredThe customer last name
customer.namesidx.middlestringOptionalThe customer middle name
customer.contactobjectOptionalThe customer contact object that contains the email and phone number
customer.contact.emailstringOptionalThe customer email
customer.contact.phoneobjectOptionalThe customer phone object that contains the country code and number
customer.contact.phone.countryCodestringRequiredThe customer country code
customer.contact.phone.numberstringRequiredThe customer phone number
interfaceobjectOptionalThe interface object that contains the locale and edges
interface.localestringOptionalThe locale of the Apple Pay button and it can be one of these locales: EN, AR
interface.edgesstringOptionalThe border of the button and it can be one of these values: CURVED, STRAIGHT
postobjectOptionalThis is the webhook for your server, if you want us to update you server to server.
onReadyfuncOptionalA callback function that will be called when the button become ready
onClickfuncOptionalA callback function that will be called when the button clicked
onCancelfuncOptionalA callback function that will be called when you cancel the payment
onErrorfuncOptionalA callback function that will be called when you have an error
onSuccessfuncOptionalA callback function that will be called after finishing the payment successfully
1.0.9

12 days ago

1.0.8

12 days ago

1.0.10

12 days ago

1.0.7

29 days ago

1.0.6

4 months ago

1.0.5

7 months ago

0.0.14-test

8 months ago

0.0.13-test

8 months ago

0.0.12-test

8 months ago

0.0.11-test

8 months ago

0.0.10-test

8 months ago

0.0.9-test

8 months ago

1.0.4

9 months ago

0.0.8-test

9 months ago

1.0.3

9 months ago

0.0.7-test

9 months ago

1.0.2

9 months ago

0.0.6-test

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

0.0.5-test

9 months ago

0.0.2

9 months ago

0.0.4-test

9 months ago

0.0.3-test

9 months ago

0.0.2-test

9 months ago

0.0.1

9 months ago

0.0.1-test

9 months ago