From 7044c1eaac0239e4930dbd10edbcef79763e1f79 Mon Sep 17 00:00:00 2001 From: "kenneth.marete" Date: Thu, 7 Dec 2017 15:54:53 +0300 Subject: [PATCH 1/4] Implementation example for b2b --- examples/b2bpayment.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/b2bpayment.rs diff --git a/examples/b2bpayment.rs b/examples/b2bpayment.rs new file mode 100644 index 00000000..577ab6e3 --- /dev/null +++ b/examples/b2bpayment.rs @@ -0,0 +1,36 @@ +extern crate africastalking_gateway; +#[macro_use()] +extern crate serde_json; + +use std::env; +use africastalking_gateway::AfricasTalkingGateway; + + +fn main() { + let username = env::var("AFRICAS_TALKING_USERNAME").unwrap(); + let apikey = env::var("AFRICAS_TALKING_APIKEY").unwrap(); + + let gateway = AfricasTalkingGateway::new(&username, &apikey, "sandbox"); + + let recipient_payload = json!([ + { + "username":"Matt Gathu", + "provider":"PaymentProvider", + "transferType":"BusinessBuyGoods", + "destinationChannel":"supplierProviderChannel", + "destinationAccount":"supplierAccount", + } + ]); + + let recipient_metadata = json!([ + { + "shopId" : "1234", + "itemId" : "abcdef" + } + ]); + + println!( + "{:?}", gateway.mobile_payment_b2b_request("My Online Store", recipient_payload, "KES", "100", recipient_metadata); + ); + +} \ No newline at end of file From d5ac88b7f83fe6ce62e308002e0180d9f7a6e331 Mon Sep 17 00:00:00 2001 From: "kenneth.marete" Date: Thu, 7 Dec 2017 18:05:29 +0300 Subject: [PATCH 2/4] fix the errors on hashMap found json::value --- examples/b2bpayment.rs | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/examples/b2bpayment.rs b/examples/b2bpayment.rs index 577ab6e3..ae76216f 100644 --- a/examples/b2bpayment.rs +++ b/examples/b2bpayment.rs @@ -1,8 +1,9 @@ extern crate africastalking_gateway; -#[macro_use()] +#[macro_use] extern crate serde_json; use std::env; +use std::collections::HashMap; use africastalking_gateway::AfricasTalkingGateway; @@ -12,25 +13,23 @@ fn main() { let gateway = AfricasTalkingGateway::new(&username, &apikey, "sandbox"); - let recipient_payload = json!([ - { - "username":"Matt Gathu", - "provider":"PaymentProvider", - "transferType":"BusinessBuyGoods", - "destinationChannel":"supplierProviderChannel", - "destinationAccount":"supplierAccount", - } - ]); - - let recipient_metadata = json!([ - { - "shopId" : "1234", - "itemId" : "abcdef" - } - ]); + let mut recipient_payload: HashMap<&str, &str> = HashMap::new(); + + recipient_payload.insert("username", "Matt Gathu"); + recipient_payload.insert("provider", "PaymentProvider"); + recipient_payload.insert("transferType", "BusinessBuyGoods"); + recipient_payload.insert("destinationChannel", "supplierProviderChannel"); + recipient_payload.insert("destinationAccount", "supplierAccount"); + + let mut recipient_metadata: HashMap<&str, &str> = HashMap::new(); + + recipient_metadata.insert("shopId", "1234"); + recipient_metadata.insert("itemId" , "abcdef"); + + let amount: f32 = 100; println!( - "{:?}", gateway.mobile_payment_b2b_request("My Online Store", recipient_payload, "KES", "100", recipient_metadata); + "{:?}", gateway.mobile_payment_b2b_request("My Online Store", recipient_payload, "KES", amount, recipient_metadata) ); } \ No newline at end of file From ad0d8c59a810d1c9b0ea1e7c81b4f6d00f39589b Mon Sep 17 00:00:00 2001 From: "kenneth.marete" Date: Thu, 7 Dec 2017 18:10:47 +0300 Subject: [PATCH 3/4] expected f32, found integer on amount variable --- examples/b2bpayment.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/b2bpayment.rs b/examples/b2bpayment.rs index ae76216f..c868b5f7 100644 --- a/examples/b2bpayment.rs +++ b/examples/b2bpayment.rs @@ -17,16 +17,16 @@ fn main() { recipient_payload.insert("username", "Matt Gathu"); recipient_payload.insert("provider", "PaymentProvider"); - recipient_payload.insert("transferType", "BusinessBuyGoods"); - recipient_payload.insert("destinationChannel", "supplierProviderChannel"); - recipient_payload.insert("destinationAccount", "supplierAccount"); + recipient_payload.insert("transfer_type", "BusinessBuyGoods"); + recipient_payload.insert("destination_channel", "supplierProviderChannel"); + recipient_payload.insert("destination_account", "supplierAccount"); let mut recipient_metadata: HashMap<&str, &str> = HashMap::new(); recipient_metadata.insert("shopId", "1234"); recipient_metadata.insert("itemId" , "abcdef"); - let amount: f32 = 100; + let amount: f32 = 100.0; println!( "{:?}", gateway.mobile_payment_b2b_request("My Online Store", recipient_payload, "KES", amount, recipient_metadata) From 2c072c916aaa4d17f964161b43ac8fed83a6a489 Mon Sep 17 00:00:00 2001 From: "kenneth.marete" Date: Thu, 7 Dec 2017 18:17:38 +0300 Subject: [PATCH 4/4] removed unused macro --- examples/b2bpayment.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/b2bpayment.rs b/examples/b2bpayment.rs index c868b5f7..d553da78 100644 --- a/examples/b2bpayment.rs +++ b/examples/b2bpayment.rs @@ -1,6 +1,4 @@ extern crate africastalking_gateway; -#[macro_use] -extern crate serde_json; use std::env; use std::collections::HashMap;