cinetpay.ts 797 B

1234567891011121314151617181920212223242526272829303132333435
  1. // src/services/cinetpay.ts
  2. import axios from 'axios';
  3. import dotenv from 'dotenv';
  4. dotenv.config();
  5. const baseURL = process.env.CINETPAY_BASE_URL || 'https://api-checkout.cinetpay.com/v2';
  6. const api = axios.create({
  7. baseURL,
  8. headers: { 'Content-Type': 'application/json' },
  9. });
  10. export async function initiatePayment(data: {
  11. amount: number;
  12. currency: string;
  13. transaction_id: string;
  14. description: string;
  15. customer_name: string;
  16. customer_surname: string;
  17. customer_email: string;
  18. customer_phone_number: string;
  19. notify_url: string;
  20. return_url: string;
  21. }) {
  22. const response = await api.post('/payment', {
  23. apikey: process.env.CINETPAY_API_KEY,
  24. site_id: process.env.CINETPAY_SITE_ID,
  25. ...data,
  26. channels: 'ALL',
  27. lang: 'fr',
  28. });
  29. return response.data;
  30. }