React SDK - Overview
Authentication
Usage
"dependencies": {
"@fat-zebra/sdk": "^1.5"
}Verify a new card
import React from "react";
import { HmacMD5 } from "crypto-js";
import {
Environment,
Payment,
PaymentIntent,
PublicEvent,
PaymentConfig,
Handlers,
} from "@fat-zebra/sdk/dist";
import { VerifyCard } from "@fat-zebra/sdk/dist/react";
import { useState } from "react";
// This should be generated from your backend via your OAuth credentials.
const accessToken =
"<your oauth access token goes here>";
export default function Checkout({ reference }: { reference: string }) {
const [events, setEvents] = useState<Array<PublicEvent>>([]);
const addEvent = (event: any) => {
setEvents((prev: Array<PublicEvent>) => [...prev, event]);
};
const payment: Payment = {
reference: reference,
amount: 100,
currency: "AUD",
};
// NEVER expose shared secret to client side. This is just to illustrate working example:
const [verification] = useState(
HmacMD5(
`${payment.reference}:${payment.amount}:${payment.currency}`,
"<your shared secret goes here>" // Your "Shared Secret"
).toString()
);
// These are typically sourced from your backend
const paymentIntent: PaymentIntent = {
payment,
verification,
};
const config: PaymentConfig = {
username: "your-username-here",
environment: Environment.sandbox, // or Environment.production
accessToken: accessToken,
paymentIntent: paymentIntent,
options: {
sca_enabled: true,
},
};
const tokenizationSuccessful = (event: any) => {
addEvent(event);
};
const scaSuccess = (event: any) => {
addEvent(event);
};
const scaError = (event: any) => {
addEvent(event);
};
// Subscribe to the particular events you wish to handle
const handlers: Handlers = {
[PublicEvent.FORM_VALIDATION_ERROR]: addEvent,
[PublicEvent.FORM_VALIDATION_SUCCESS]: addEvent,
[PublicEvent.TOKENIZATION_SUCCESS]: tokenizationSuccessful,
[PublicEvent.SCA_SUCCESS]: scaSuccess,
[PublicEvent.SCA_ERROR]: scaError,
};
return (
<div className="App flex gap-8 mx-8">
<div className="w-1/2">
<VerifyCard
handlers={handlers}
config={config}
iframeProps={{ width: "100%", height: "700px" }}
/>
</div>
</div>
);
}
Verify Existing Card
Calculation of verification hash
Creating a payment
Last updated