npm.io
0.2.0 • Published 3 years ago

@zokshpay/sdk-react

Licence
ISC
Version
0.2.0
Deps
0
Size
20 kB
Vulns
0
Weekly
0

sdk-react

React wrapper on latest zoksh embed.js for easy, secure and up-to-date integration.

Usage example

import { useZoksh } from './useZoksh';

export const Example = () => {
  const { status, addEventHandler, initOrder } = useZoksh({
    environment: 'test',
  });

  const initHandler = useCallback(() => {
    console.log('payment init');
  }, [status]);

  const validatedHandler = useCallback(() => {
    console.log('payment validated');
  }, [status]);

  useEffect(() => {
    if (status === 'ready') {
      addEventHandler({ event: 'payment-init', handler: initHandler });
      addEventHandler({ event: 'payment-validated', handler: validatedHandler });

      initOrder('821uosadfnq230aa822nc');
    }
  }, [status, addEventHandler]);

  return (
    <>
      <p>{`Current status: ${status}`}</p>
      {status === 'ready' && <p>You can use the script here.</p>}
    </>
  );
};

Keywords