UNPKG

paysom

Version:

paysom is an easy way to integrate payment solution to your web apps

68 lines (59 loc) 2.13 kB
const { default: axios } = require("axios") const { isauthenticated } = require("../providers/authprofider") const resources = require("../providers/_paysomconfig") class Subscribtions{ baseurl= resources.subbaseUrl // check if the user is authenticated to use the api // if not authenticated then return error message // if authenticated then perform the action that the user wants to perform // create intent createsubscription = async({type,name,amount})=>{ let authenticated=await isauthenticated() if(!authenticated){ throw new Error('You are not authenticated to use this api please setup your keys') } else{ try { let res = await axios.post(`${this.baseurl}/create/${authenticated}`,{ type:type, name:name, amount:amount }) return res.data } catch (error) { return error.response } } } // track intent tracksubscribtion = async(subid)=>{ let authenticated=await isauthenticated() if(!authenticated){ throw new Error('You are not authenticated to use this api please setup your keys') } else{ try { let res = await axios.post(`${this.baseurl}/getstatus/${authenticated}`,{ subid:subid }) return res.data } catch (error) { return error.response }}} // get intent info getall = async()=>{ let authenticated=await isauthenticated() if(!authenticated){ throw new Error('You are not authenticated to use this api please setup your keys') } else{ try { let res = await axios.post(`${this.baseurl}/getall/${authenticated}`) return res } catch (error) { return error.response } } } } module.exports=Subscribtions