@@ -80,7 +80,8 @@ def update_user(self, reference, data):
8080
8181 Args:
8282 reference (string): the reference of the indexed user
83- data (dict): the data to be updated
83+ data (dict): the data to be updated which is a dictionary
84+ of at least one of the fields (name, identifier, identifier_type,email)
8485
8586 Returns:
8687 dict: the json response from the server containing the user's id and
@@ -108,9 +109,91 @@ def delete_user(self, reference):
108109 except Exception as e :
109110 raise SwitchErrorStates (e ).switch ()
110111
112+ def get_user_links (self , reference ):
113+ """this method helps to get the user's payment links on thepeer's servers
114+
115+
116+ Args:
117+ reference (string): the reference of the indexed user
118+
119+ Returns:
120+ dict: the json response from the server containing the linked accounts
121+ related to the user's id and other related information
122+ """
123+ try :
124+ response = httpx .get (f"{ self .url } /users/{ reference } /links" , headers = dict (self .headers ))
125+ return response .json ()
126+ except Exception as e :
127+ raise SwitchErrorStates (e ).switch ()
128+
129+ def get_single_link (self , link_id ):
130+ """this method returns a user's linked account details on thepeer's servers
131+
132+
133+ Args:
134+ link_id (string): the link ID
135+
136+ Returns:
137+ dict: the json response from the server containing the payment link id and
138+ other related information
139+ """
140+ try :
141+ response = httpx .get (f"{ self .url } /link/{ link_id } " , headers = dict (self .headers ))
142+ return response .json ()
143+ except Exception as e :
144+ raise SwitchErrorStates (e ).switch ()
145+
146+ def charge_link (self , link_id , amount , remark , currency = "NGN" ):
147+ """allows a business to charge a user via their linked account
148+
149+ Args:
150+ link_id (string):the link ID
151+ data (dict): the request payload which contains the amount and remark and optionally,
152+ a currency (which could be NGN or USD default being NGN)
153+
154+ Returns:
155+ dict: a transaction object generated from a webhook. more info about a
156+ transaction object here https://docs.thepeer.co/transaction/transaction-object
157+ """
158+ try :
159+ data = json .dumps ({"amount" : amount , "remark" : remark , "currency" : currency })
160+ response = httpx .post (
161+ f"{ self .url } /link/{ link_id } /charge" , data = data , headers = dict (self .headers )
162+ )
163+ return response .json ()
164+ except Exception as e :
165+ raise SwitchErrorStates (e ).switch ()
166+
167+ def authorize_direct_charge (self , auth_charge_reference , event ):
168+ """allows a business to authorize a direct charge request made by a user
169+
170+ Args:
171+ auth_charge_reference (string): reference generated from the direct charge webhook event
172+ event (string): a string which contains the kind of webhook event
173+
174+ Returns:
175+ dict: containing a key value pair of the event(key) and the type of event
176+ """
177+ try :
178+ data = json .dumps ({"event" : event })
179+ response = httpx .post (
180+ f"{ self .url } /authorization/{ auth_charge_reference } " ,
181+ data = data ,
182+ headers = dict (self .headers ),
183+ )
184+ return response .json ()
185+
186+ except Exception as e :
187+ raise SwitchErrorStates (e ).switch ()
188+
111189
112190# test function
113191thepeer = ThePeerInit (config ("PEER_SECRET_KEY" ))
114192test = thepeer .index_user ("Osagie Iyayi" , "iyayiemmanuel1@gmail.com" , "iyayiemmanuel1@gmail.com" )
115- get = thepeer .delete_user ("e09c7080-acd9-452d-b3e4-83902fc1368b" )
116- print (test )
193+ get = thepeer .update_user (
194+ "3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd" , {"identifier" : "iyayiemmanuel1@gmail.com" }
195+ )
196+ charge = thepeer .authorize_direct_charge ("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd" , "failed" )
197+ view = thepeer .view_user ("3bbb0fbf-82fa-48a0-80eb-d2c0338fe7dd" )
198+ # print(view)
199+ # print(get)
0 commit comments