@akinon/pz-tamara-extension

1.91.0 • Public • Published

Tamara Payment Gateway Extension

Installation

You can use the following command to install the extension with the latest plugins:

npx @akinon/projectzero@latest --plugins

Usage

Once the extension is installed, you can easily integrate the Tamara payment gateway into your application. Here's an example of how to use it.

  1. Navigate to the src/app/[commerce]/[locale]/[currency]/payment-gateway/tamara/ directory.

  2. Create a file named page.tsx and include the following code:

import { TamaraPaymentGateway } from '@akinon/pz-tamara-extension';

const TamaraGateway = async ({
  searchParams: { sessionId },
  params: { currency, locale }
}: {
  searchParams: Record<string, string>;
  params: { currency: string; locale: string };
}) => {
  return (
    <TamaraPaymentGateway
      sessionId={sessionId}
      currency={currency}
      locale={locale}
      extensionUrl={process.env.TAMARA_EXTENSION_URL}
      hashKey={process.env.TAMARA_HASH_KEY}
    />
  );
};

export default TamaraGateway;

API Routes

Check Availability API

To enable Tamara payment availability checks, you need to create an API route. Create a file at src/app/api/tamara-check-availability/route.ts with the following content:

import { POST } from '@akinon/pz-tamara-extension/src/pages/api/check-availability';

export { POST };

This API endpoint handles checking the availability of Tamara payment for a given:

  • Country
  • Phone number
  • Order amount
  • Currency

The endpoint automatically validates the request and response using hash-based security measures.

Using checkTamaraAvailability Mutation

The extension provides a Redux mutation hook that you can use to check Tamara payment availability. Here's an example of how to implement it:

import { useCheckTamaraAvailabilityMutation } from '@akinon/pz-tamara-extension/src/redux/api';

const YourComponent = () => {
  const [checkTamaraAvailability] = useCheckTamaraAvailabilityMutation();
  const [isTamaraAvailable, setIsTamaraAvailable] = useState(false);

  useEffect(() => {
    const checkAvailability = async () => {
      try {
        const response = await checkTamaraAvailability({
          country: 'AE', // Country code
          phone_number: '+971123456789', // Customer's phone number
          order_amount: 1000 // Order total amount
        }).unwrap();

        setIsTamaraAvailable(response.has_availability);
      } catch (error) {
        console.error('Error checking Tamara availability:', error);
        setIsTamaraAvailable(false);
      }
    };

    checkAvailability();
  }, [checkTamaraAvailability]);

  // Use isTamaraAvailable to conditionally render Tamara payment option
  return (
    // Your component JSX
  );
};

The mutation returns an object with the following properties:

  • has_availability: boolean indicating if Tamara payment is available
  • salt: string used for hash verification
  • hash: string for response validation

Configuration

Add these variables to your .env file

TAMARA_EXTENSION_URL=<your_extension_url>
TAMARA_HASH_KEY=<your_hash_key>

Readme

Keywords

none

Package Sidebar

Install

npm i @akinon/pz-tamara-extension

Weekly Downloads

531

Version

1.91.0

License

MIT

Unpacked Size

18.3 kB

Total Files

12

Last publish

Collaborators

  • akinon