You can use the following command to install the extension with the latest plugins:
npx @akinon/projectzero@latest --plugins
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.
-
Navigate to the
src/app/[commerce]/[locale]/[currency]/payment-gateway/tamara/
directory. -
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;
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.
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
Add these variables to your .env
file
TAMARA_EXTENSION_URL=<your_extension_url>
TAMARA_HASH_KEY=<your_hash_key>