Skip to content

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

@Prabin1111

Description

@Prabin1111

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});
  } 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions