khalti / docs.khalti.com

Khalti Payment Gateway Documentation
https://docs.khalti.com
54 stars 63 forks source link

Getting CORS error for epayment/initiate api while impleme khalti-epayment #41

Open Prabin1111 opened 1 year ago

Prabin1111 commented 1 year ago

added test test_secret_key on the authorization header and pointed API is https://a.khalti.com/api/v2/epayment/initiate

interface

 export interface Ikhalti {
  return_url: string;
  website_url: string;
  amount: number;
  purchase_order_id: string;
  purchase_order_name: string;
  customer_info: {
    name: string;
    email: string;
    phone: string;
  },
  amount_breakdown: {
    label: string;
    amount: number;
  }[];
  product_details: {
    identity: string;
    name: string;
    total_price: number;
    quantity: number;
    unit_price: number;
  }[];
} 

used dummy from repayment docs body

    return_url: 'http://localhost:8100/tabs/home',
    website_url: 'http://localhost:8100/tabs/home',
    amount: 1300,
    purchase_order_id: 'test12',
    purchase_order_name: 'test',
    customer_info: {
      name: 'Ashim Upadhaya',
      email: 'example@gmail.com',
      phone: '9811496763'
    },
    amount_breakdown: [
      {
        label: 'Mark Price',
        amount: 1000
      },
      {
        label: 'VAT',
        amount: 300
      }
    ],
    product_details: [
      {
        identity: '1234567890',
        name: 'Khalti logo',
        total_price: 1300,
        quantity: 1,
        unit_price: 1300
      }
    ]
  }; 

method

payment(): Observable<any> {
    const headers = new HttpHeaders();
    headers.set('Authorization', '<test_secret_key>');
    headers.set('content-type', 'application/json');
    headers.set('Access-Control-Allow-Origin', '*');
    return this.httpClient.post('https://a.khalti.com/api/v2/epayment/initiate', {body: this.body },
    {'headers':headers});
  } 
Roopaish commented 1 year ago

Hello @Prabin1111 , did you fix it? Can you plz share it

Prabin1111 commented 1 year ago

@Roopaish i have not found any solution. And i am also not activity involved in khalti integration so have not got chances to look at it.

Roopaish commented 1 year ago

IMG_20230531_165549 So you have to make your own api and hit the khalti server from the backend.

sandeepsz commented 3 months ago

I created a khalti api on the server using Node.js and deployed it on render. It works but when I hit this api from the frontend, the response is:

Screenshot 2024-06-11 125258

sandeepsz commented 3 months ago

Sometimes it works and sometime it gives error ?