@@ -91,7 +91,7 @@ pub struct InitializeTransactionBody {
9191}
9292
9393/// struct ListTransactionsQuery
94- #[ derive( Debug , Serialize ) ]
94+ #[ derive( Debug , Default , Serialize ) ]
9595#[ serde( rename_all = "camelCase" ) ]
9696pub struct ListTransactionsParams {
9797 /// Specify how many records you want to retrieve per page. If not specify we use a default value of 50.
@@ -110,7 +110,7 @@ pub struct ListTransactionsParams {
110110 pub amount : Option < i128 > ,
111111}
112112
113- #[ derive( Serialize , Debug ) ]
113+ #[ derive( Serialize , Default , Debug ) ]
114114pub struct ChargeAuthorizationBody {
115115 /// Amount should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents, if currency is ZAR
116116 pub amount : String ,
@@ -136,7 +136,7 @@ pub struct ChargeAuthorizationBody {
136136 pub queue : Option < bool > ,
137137}
138138
139- #[ derive( Debug , Serialize ) ]
139+ #[ derive( Debug , Default , Serialize ) ]
140140#[ serde( rename_all = "camelCase" ) ]
141141pub struct TransactionsTotal {
142142 /// Specify how many records you want to retrieve per page. If not specify we use a default value of 50.
@@ -153,7 +153,7 @@ pub struct TransactionsTotal {
153153 pub to : Option < DateTime < Utc > > ,
154154}
155155
156- #[ derive( Debug , Serialize ) ]
156+ #[ derive( Debug , Default , Serialize ) ]
157157pub struct CheckAuthorizationBody {
158158 /// Amount should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents, if currency is ZAR
159159 pub amount : String ,
@@ -165,7 +165,7 @@ pub struct CheckAuthorizationBody {
165165 pub currency : Option < Currency > ,
166166}
167167
168- #[ derive( Debug , Serialize ) ]
168+ #[ derive( Debug , Default , Serialize ) ]
169169pub struct PartialDebitBody {
170170 /// Amount should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents, if currency is ZAR
171171 pub amount : String ,
@@ -211,6 +211,20 @@ pub struct ExportTransactionsBody {
211211
212212impl Transaction {
213213 /// Initialize a transaction from your backend
214+ /// ```rust
215+ /// # use std::env;
216+ /// # use paystack_rs::prelude::Paystack;
217+ /// use paystack_rs::prelude::InitializeTransactionBody;
218+ ///
219+ /// # let key = env::var("PAYSTACK_SECRET_KEY").unwrap();
220+ /// let paystack = Paystack::new(key);
221+ /// let body = InitializeTransactionBody{
222+ /// email: "randomemail@gmail.com".to_string(),
223+ /// amount: 10000,
224+ /// ..Default::default()
225+ /// };
226+ /// paystack.transaction.initialize_transaction(body);
227+ /// ```
214228 pub fn initialize_transaction (
215229 & self ,
216230 body : InitializeTransactionBody ,
@@ -225,6 +239,14 @@ impl Transaction {
225239 }
226240
227241 /// verify a transaction. it takes an argument reference which is the reference_id of a transaction you want to verify
242+ /// ```rust
243+ /// # use std::env;
244+ /// # use paystack_rs::prelude::Paystack;
245+ ///
246+ /// # let key = env::var("PAYSTACK_SECRET_KEY").unwrap();
247+ /// let paystack = Paystack::new(key);
248+ /// paystack.transaction.verify_transaction("DG4uishudoq90LD".to_string());
249+ /// ```
228250 pub fn verify_transaction ( & self , reference : String ) -> Result < Response , String > {
229251 let full_url = format ! (
230252 "{}/transaction/verify/:{}" ,
@@ -236,18 +258,53 @@ impl Transaction {
236258 }
237259
238260 /// list_transactions lists all the transactions available
261+ /// ```rust
262+ /// # use std::env;
263+ /// # use paystack_rs::prelude::Paystack;
264+ /// use paystack_rs::prelude::ListTransactionsParams;
265+ ///
266+ /// # let key = env::var("PAYSTACK_SECRET_KEY").unwrap();
267+ /// let paystack = Paystack::new(key);
268+ /// /// Retrieve 50 transactions per page
269+ /// let body = ListTransactionsParams{
270+ /// per_page: Some(50),
271+ /// ..Default::default()
272+ /// };
273+ /// paystack.transaction.list_transactions(body);
239274 pub fn list_transactions ( & self , body : ListTransactionsParams ) -> Result < Response , String > {
240275 let res = make_get_request ( & self . bearer_auth , TRANSACTION_URL , Some ( body) ) ;
241276 return res;
242277 }
243278
279+ /// ```rust
280+ /// # use std::env;
281+ /// # use paystack_rs::prelude::Paystack;
282+ ///
283+ /// # let key = env::var("PAYSTACK_SECRET_KEY").unwrap();
284+ /// let paystack = Paystack::new(key);
285+ /// paystack.transaction.fetch_transaction(123412);
286+ /// ```
244287 pub fn fetch_transaction ( & self , transaction_id : i64 ) -> Result < Response , String > {
245288 let url = format ! ( "{}/{}" , TRANSACTION_URL , transaction_id) ;
246289 let res = make_get_request ( & self . bearer_auth , & url, None :: < String > ) ;
247290 return res;
248291 }
249292
250293 /// All authorizations marked as reusable can be charged with this endpoint whenever you need to receive payments.
294+ /// ```rust
295+ /// # use std::env;
296+ /// # use paystack_rs::prelude::Paystack;
297+ /// use paystack_rs::prelude::ChargeAuthorizationBody;
298+ ///
299+ /// # let key = env::var("PAYSTACK_SECRET_KEY").unwrap();
300+ /// let paystack = Paystack::new(key);
301+ /// let body = ChargeAuthorizationBody{
302+ /// amount: "5000".to_string(),
303+ /// email: "randomemail@gmail.com".to_string(),
304+ /// authorization_code: "2aeserqwdEAW".to_string(),
305+ /// ..Default::default()
306+ /// };
307+ /// paystack.transaction.charge_authorization(body);
251308 pub fn charge_authorization (
252309 & self ,
253310 params : ChargeAuthorizationBody ,
@@ -268,19 +325,48 @@ impl Transaction {
268325 ///
269326 ///
270327 /// ⚠️ Warning You shouldn't use this endpoint to check a card for sufficient funds if you are going to charge the user immediately. This is because we hold funds when this endpoint is called which can lead to an insufficient funds error.
328+ /// ```rust
329+ /// # use std::env;
330+ /// # use paystack_rs::prelude::Paystack;
331+ /// use paystack_rs::prelude::CheckAuthorizationBody;
332+ ///
333+ /// # let key = env::var("PAYSTACK_SECRET_KEY").unwrap();
334+ /// let paystack = Paystack::new(key);
335+ /// let body = CheckAuthorizationBody{
336+ /// amount: "5000".to_string(),
337+ /// email: "randomemail@gmail.com".to_string(),
338+ /// authorization_code: "2aeserqwdEAW".to_string(),
339+ /// ..Default::default()
340+ /// };
341+ /// paystack.transaction.check_authorization(body);
271342 pub fn check_authorization ( & self , param : CheckAuthorizationBody ) -> Result < Response , String > {
272343 let full_url = CHARGE_AUTHORIZATION_URL ;
273344 let res = make_request ( & self . bearer_auth , full_url, Some ( param) , REQUEST :: POST ) ;
274345 return res;
275346 }
276347
348+ /// ```rust
349+ /// # use std::env;
350+ /// # use paystack_rs::prelude::Paystack;
351+ ///
352+ /// # let key = env::var("PAYSTACK_SECRET_KEY").unwrap();
353+ /// let paystack = Paystack::new(key);
354+ /// paystack.transaction.view_transaction_timeline("DG4uishudoq90LD".to_string());
277355 pub fn view_transaction_timeline ( & self , id : String ) -> Result < Response , String > {
278356 let full_url = format ! ( "{}/timeline/{}" , TRANSACTION_URL , id) . to_string ( ) ;
279357 let res = make_get_request ( & self . bearer_auth , & full_url, None :: < String > ) ;
280358 return res;
281359 }
282360
283361 /// Total amount received on your account
362+ /// ```rust
363+ /// # use std::env;
364+ /// # use paystack_rs::prelude::Paystack;
365+ ///
366+ /// # let key = env::var("PAYSTACK_SECRET_KEY").unwrap();
367+ /// let paystack = Paystack::new(key);
368+ /// /// Retrieve total transactions
369+ /// paystack.transaction.transactions_total(None);
284370 pub fn transactions_total (
285371 & self ,
286372 params : Option < TransactionsTotal > ,
@@ -291,6 +377,14 @@ impl Transaction {
291377 }
292378
293379 /// Export transactions carried out on your integration.
380+ /// ```rust
381+ /// # use std::env;
382+ /// # use paystack_rs::prelude::Paystack;
383+ ///
384+ /// # let key = env::var("PAYSTACK_SECRET_KEY").unwrap();
385+ /// let paystack = Paystack::new(key);
386+ /// /// Retrieve total transactions
387+ /// paystack.transaction.export_transactions(None);
294388 pub fn export_transactions (
295389 & self ,
296390 params : Option < ExportTransactionsBody > ,
@@ -301,6 +395,20 @@ impl Transaction {
301395 }
302396
303397 /// Retrieve part of a payment from a customer
398+ /// ```rust
399+ /// # use std::env;
400+ /// # use paystack_rs::prelude::Paystack;
401+ /// use paystack_rs::prelude::PartialDebitBody;
402+ ///
403+ /// # let key = env::var("PAYSTACK_SECRET_KEY").unwrap();
404+ /// let paystack = Paystack::new(key);
405+ /// let body = PartialDebitBody{
406+ /// amount: "5000".to_string(),
407+ /// email: "randomemail@gmail.com".to_string(),
408+ /// authorization_code: "2aeserqwdEAW".to_string(),
409+ /// ..Default::default()
410+ /// };
411+ /// paystack.transaction.partial_debit(body);
304412 pub fn partial_debit ( & self , body : PartialDebitBody ) -> Result < Response , String > {
305413 let full_url = format ! ( "{}/partial_debit" , TRANSACTION_URL ) ;
306414 let res = make_request ( & self . bearer_auth , & full_url, Some ( body) , REQUEST :: POST ) ;
0 commit comments