Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Prabin1111 opened this issue Oct 18, 2022 · 5 comments

Comments

@Prabin1111
Copy link

Prabin1111 commented Oct 18, 2022

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: '[email protected]',
     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
Copy link

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

@Prabin1111
Copy link
Author

@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
Copy link

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

@sandeepsz
Copy link

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
Copy link

Sometimes it works and sometime it gives error ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants