コード例 #1
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var username = "******";
            var apiKey   = "APIKEY....";
            var from     = "+2ABXXYYYYYY";
            var to       = "+254720000000,+25472000000, [email protected]";
            // Optional Param
            var id = "Test";

            var gateway = new AfricasTalkingGateway(username, apiKey);

            try
            {
                var results = gateway.Call(from, to, id);
                Console.WriteLine(results);
            }
            catch (AfricasTalkingGatewayException exception)
            {
                Console.WriteLine("Something went horribly wrong: " + exception.Message + ".\nCaused by :" +
                                  exception.StackTrace);
            }

            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // Console.WriteLine("Hello World!");
            var    username = "******";
            var    apiKey   = "yourAPIKEY";
            string env      = "sandbox";
            var    recep    = "+254724587654";
            var    msg      = "Super awesome message ☻ 😁";


            var gateway = new AfricasTalkingGateway(username, apiKey, env);

            try
            {
                dynamic res = gateway.SendMessage(recep, msg);
                foreach (var re in res["SMSMessageData"]["Recipients"])
                {
                    Console.WriteLine((string)re["number"] + ": ");
                    Console.WriteLine((string)re["status"] + ": ");
                    Console.WriteLine((string)re["messageId"] + ": ");
                    Console.WriteLine((string)re["cost"] + ": ");
                }
            }
            catch (AfricasTalkingGatewayException exception)
            {
                Console.WriteLine(exception);
            }

            Console.ReadLine();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            const string username                = "******";
            const string apikey                  = "1f6c70805d287caf585e4062f0f2abeccc1d067ce7a36b28038d5057c823c727";
            const int    productCode             = 1234;
            const string productName             = "coolproduct";
            decimal      amount                  = 150M;
            string       currencyCode            = "KES";
            Dictionary <string, string> metadata = new Dictionary <string, string>
            {
                { "mode", "transfer" }
            };

            var gw = new AfricasTalkingGateway(username, apikey);

            try
            {
                Console.WriteLine("Hello World!");
                StashResult res = gw.WalletTransfer(productName, productCode, currencyCode, amount, metadata);
                Console.WriteLine(res.ToString());
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("We had an errror: " + e);
            }

            Console.ReadLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var username    = "******";
            var environment = "sandbox";
            var apiKey      = "afd635a4f295dd936312836c0b944d55f2a836e8ff2b63987da5e717cd5ff745";
            var productName = "coolproduct";
            var phoneNumber = "+254724587654";
            var currency    = "KES";
            int amount      = 35700;
            var channel     = "mychannel";
            var metadata    = new Dictionary <string, string>
            {
                { "reason", "broken car" }
            };

            var gw = new AfricasTalkingGateway(username, apiKey, environment);

            try
            {
                var checkout = gw.Checkout(productName, phoneNumber, currency, amount, channel, metadata);
                Console.WriteLine(checkout);
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("We ran into problems: " + e.Message);
            }
            Console.ReadLine();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var username  = "******";
            var apikey    = "KEY";
            var env       = "sandbox";
            var gateway   = new AfricasTalkingGateway(username, apikey, env);
            var shortCode = "NNNNN";
            var keyword   = "keyword";
            var phoneNum  = "+254XXXXXXXXX";
            var token     = "Token";

            try
            {
                var response = gateway.CreateSubscription(phoneNum, shortCode, keyword, token);
                Console.WriteLine(response);
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("We hit a snag: " + e.StackTrace + ". " + e.Message);
                throw;
            }

            Console.ReadLine();
        }
コード例 #6
0
    public static void Main()
    {
        // Specify your login credentials
        string username = "******";
        string apiKey   = "MyAfricasTalking_APIKey";

        // Specify your AfricasTalking phone number in international format.
        // Comma separate them for more than one number
        string phoneNumbers = "+254711082XXX,+254205134YYY";

        // Create a new instance of our awesome gateway class
        AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);

        // Wrap the call in a try-catch block
        // Any gateway errors will be captured by our custom Exception class below
        try {

            dynamic results = gateway.getNumQueuedCalls(phoneNumbers);

            foreach(dynamic result in results) {
             Console.Write("Phone number: " + result["phoneNumber"]);
             Console.Write("Queue name: " + result["queueName"]);
             Console.WriteLine("Number of queued calls: " + result["numCalls"]);
            }

        } catch (AfricasTalkingGatewayException e) {

            Console.WriteLine ("Encountered an error: " + e.Message);

        }
    }
コード例 #7
0
ファイル: Program.cs プロジェクト: dorohin/africastalking.Net
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            const string Username      = "******";
            const string Otp           = "1234";
            const string ApiKey        = "Key";
            const string TransactionId = "ATPid_LFDVLSDNLDSFLDSKLKDE39240DSKFLWDFWI29221efvsdw";
            const string Env           = "sandbox";
            var          gateway       = new AfricasTalkingGateway(Username, ApiKey, Env);

            try
            {
                var validate = gateway.ValidateCardOtp(TransactionId, Otp);
                var res      = JsonConvert.DeserializeObject(validate);
                if (res["status"] == "Success")
                {
                    Console.WriteLine("Awesome");
                }
                else
                {
                    Console.WriteLine("We had an error " + res["status"]);
                }
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("Validation Error occured : " + e.Message);
                throw;
            }

            Console.ReadLine();
        }
コード例 #8
0
    public static void Main()
    {
        string username = "******";
        string apiKey   = "MyAfricasTalkingAPIKey";

        string recipients = "+254711XXXYYY,+254733XXXYYY";

        string message = "I'm a lumberjack and its ok, I sleep all night and I work all day";

        // Specify your AfricasTalking shortCode or sender id
        string from = "shortCode or senderId";

        AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);

        try {

            dynamic results = gateway.sendMessage (recipients, message, from);

            foreach( dynamic result  in results){
                Console.Write((string)result["number"] + ",");
                Console.Write((string)result["status"] + ",");
                Console.Write((string)result["messageId"] + ",");
                Console.WriteLine((string)result["cost"]);
            }
        } catch (AfricasTalkingGatewayException e) {

            Console.WriteLine ("Encountered an error: " + e.Message);

        }
    }
コード例 #9
0
        static void Main(string[] args)
        {
            const string username                = "******";
            const string apikey                  = "54a533717fcb1be4577e96ea7a02c1ca9c6e802a56a670379085582ca3c118a7";
            const string productName             = "coolproduct";
            decimal      amount                  = 150M;
            string       currencyCode            = "KES";
            Dictionary <string, string> metadata = new Dictionary <string, string> {
                { "what this is", "cool stuff" }
            };

            var gw = new AfricasTalkingGateway(username, apikey);

            try
            {
                Console.WriteLine("Hello World!");
                StashResponse res = gw.TopupStash(productName, currencyCode, amount, metadata);
                Console.WriteLine(res.ToString());
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("We had an errror: " + e);
            }

            Console.ReadLine();
        }
コード例 #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            const string Username    = "******";
            const string Apikey      = "afd635a4f295dd936312836c0b944d55f2a836e8ff2b63987da5e717cd5ff745";
            const string Env         = "sandbox";
            var          gateway     = new AfricasTalkingGateway(Username, Apikey, Env);
            var          tokenId     = "CkTkn_94248929024020408fh3hf02302qawjlasj32";
            const string PhoneNumber = "+2348092226042";
            const string Menu        = "CON You're about to love C#\n1.Accept my fate\n2.No Never\n";

            // Let's create a checkout token  first
            try
            {
                var tkn = gateway.CreateCheckoutToken(PhoneNumber);
                if (tkn["description"] == "Success")
                {
                    tokenId = tkn["token"];
                }

                // Then send user menu...
                var prompt = gateway.InitiateUssdPushRequest(PhoneNumber, Menu, tokenId);
                if (prompt["errorMessage"] == "None")
                {
                    Console.WriteLine("Awesome");
                }
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("Woopsies : " + e.Message);
            }

            Console.ReadLine();
        }
コード例 #11
0
        static void Main(string[] args)
        {
            var username = "******";
            var apiKey   = "afd635a4f295dd936312836c0b944d55f2a836e8ff2b63987da5e717cd5ff745";
            var recep    = "+254724587654,+254714587654,+254704876545";
            var msg      = "Super awesome message ☻ 😁";


            var gateway = new AfricasTalkingGateway(username, apiKey);

            try
            {
                dynamic res = gateway.SendMessage(recep, msg);
                foreach (var re in res["SMSMessageData"]["Recipients"])
                {
                    Console.WriteLine((string)re["number"] + ": ");
                    Console.WriteLine((string)re["status"] + ": ");
                    Console.WriteLine((string)re["messageId"] + ": ");
                    Console.WriteLine((string)re["cost"] + ": ");
                }
            }
            catch (AfricasTalkingGatewayException exception)
            {
                Console.WriteLine(exception);
            }

            Console.ReadLine();
        }
コード例 #12
0
    public static void Main()
    {
        // Specify your login credentials
        string username = "******";
        string apiKey   = "MyAfricasTalking_APIKey";

        // Specify your the url of file to be uploaded
        string url = "http://onlineMediaUrl.com/file.wav";

        // Create a new instance of our awesome gateway class
        AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);

        // Any gateway errors will be captured by our custom Exception class below,
        // so wrap the call in a try-catch block
        try {

            gateway.uploadMediaFile(url);
            Console.WriteLine ("File upload initiated. Time for song and dance!");

        } catch (AfricasTalkingGatewayException e) {

            Console.WriteLine ("Encountered an error: " + e.Message);

        }
    }
コード例 #13
0
        static void Main(string[] args)
        {
            const string username = "******";
            const string apikey   = "e952920d25a20cc9a8144ae200363d722f3459273815201914d8d4603e59d047";

            AfricasTalkingGateway gateway = new AfricasTalkingGateway(username, apikey);
            var     phoneNumber           = "+254720000001";
            var     productName           = "coolproduct";
            var     currency        = "KES";
            decimal amount          = 1000M;
            var     providerChannel = "mychannel";
            var     metadata        = new Dictionary <string, string>
            {
                { "dest", "oracle" }
            };

            try
            {
                // Example only | Use older transactions, the results here will be "Failure"
                C2BDataResults checkoutResponse = gateway.Checkout(productName, phoneNumber, currency, amount, providerChannel, metadata);
                var            transactionId    = checkoutResponse.TransactionId;
                var            findId           = gateway.FindTransaction(transactionId);
                JObject        findIdObject     = JObject.Parse(findId);
                Console.WriteLine(findIdObject);
            }
            catch (AfricasTalkingGatewayException e)
            {
                throw new AfricasTalkingGatewayException(e.Message);
            }
        }
コード例 #14
0
    static public void _Smsshortcode()
    {
        string username = "******";
        string apiKey   = "MyAfricasTalkingAPIKey";

        string recipients = "+254711XXXYYY,+254733YYYZZZ";

        string message = "I'm a lumberjack and its ok, I sleep all night and I work all day";

        // Specify your AfricasTalking shortCode or sender id
        string from = "shortCode or senderId";

        AfricasTalkingGateway gateway = new AfricasTalkingGateway(username, apiKey);

        try {
            dynamic results = gateway.sendMessage(recipients, message, from);

            foreach (dynamic result  in results)
            {
                Console.Write((string)result["number"] + ",");
                Console.Write((string)result["status"] + ",");
                Console.Write((string)result["messageId"] + ",");
                Console.WriteLine((string)result["cost"]);
            }
        } catch (AfricasTalkingGatewayException e) {
            Console.WriteLine("Encountered an error: " + e.Message);
        }
        Console.Read();
    }
コード例 #15
0
    public static void testCalling()
    {
        // Specify your login credentials
        string username = "******";
        string apiKey   = "MyAfricasTalking_APIKey";

        // Specify your Africa's Talking phone number in international format
        string from = "+254711082XYZ";

        // Specify the numbers that you want to call to in a comma-separated list
        // Please ensure you include the country code (+254 for Kenya in this case)
        string to   = "+254711XXXYYY,+254733YYYZZZ";

        // Create a new instance of our awesome gateway class
        AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);

        // Any gateway error will be captured by our custom Exception class below,
        // so wrap the call in a try-catch block
        try {

            gateway.call(from, to);
            Console.WriteLine ("Calls have been initiated. Time for song and dance!");

            // Our API will now contact your callback URL once the recipient answers the call!

        } catch (AfricasTalkingGatewayException e) {

            Console.WriteLine ("Encountered an error: " + e.Message);

        }
    }
コード例 #16
0
        public async Task <IActionResult> AddCustomerExperience(string customerId, string responseId, string isFirst)
        {
            ViewData["CustomerId"] = customerId;
            if (isFirst.Equals("True", StringComparison.InvariantCultureIgnoreCase))
            {
                var m = await _context.Questions.OrderBy(i => i.Code).FirstOrDefaultAsync();

                ViewData["Question"]  = m;
                ViewData["Responses"] = await _context.Responses.Where(i => i.QuestionId == m.Id).ToListAsync();

                return(View());
            }
            var response = await _context.Responses.FirstOrDefaultAsync(i => i.Id == responseId);

            if (string.IsNullOrEmpty(response.NextQuestion))
            {
                string id       = customerId;
                string username = "******";                                                          // substitute with your username if mot using sandbox
                string apikey   = "5e515cfb45d3056ee46fa24c73414b61c2cb0a43424e0e835100e2ce075bffbc"; // substitute with your production API key if not using sandbox
                var    customer = await _context.Customers.FindAsync(customerId);

                var gateway = new AfricasTalkingGateway(username, apikey);
                var sms     = gateway.SendMessage(customer.Phone, $"Dear {customer.FullName} Thank you for contactinG ABC ");
                return(RedirectToAction("GetCustomerResponse", "Customers", new{ id }));
            }
            var q = await _context.Questions.Where(i => i.Id == response.NextQuestion).FirstOrDefaultAsync();

            ViewData["Question"]  = q;
            ViewData["Responses"] = await _context.Responses.Where(i => i.QuestionId == q.Id).ToListAsync();

            return(View());
        }
コード例 #17
0
        static void Main(string[] args)
        {
            //Dev Credentials
            var username    = "******"; //use "sandbox for testing"
            var apikey      = "MyApiKey";   //use sandbox API key for testing
            var environment = "sandbox";    //do not declare for live

            //Registered Africa's Talking Phone Number
            var caller = "+254-MY-NUMBER";

            //Numbers to call
            var recepients = "+254-ANOTHER,+254-OTHERNMBER";

            //Create an instance of our gateway
            var gateway = new AfricasTalkingGateway(username, apikey, environment);

            try
            {
                dynamic result = gateway.Call(caller, recepients);
                foreach (var i in result)
                {
                    Console.WriteLine(result["status"] + ",");
                    Console.WriteLine(result["phoneNumber"] + "\n");
                }
            }
            catch (AfricasTalkingGatewayException exception)
            {
                Console.WriteLine("Encountered an error: " + exception.Message);
            }
        }
コード例 #18
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var username = "******";
            var apikey   = "APIKEY";
            // var env = "sandbox";
            var gateway = new AfricasTalkingGateway(username, apikey /*, env*/);
            var opts    = new Hashtable {
                ["keyword"] = "myKeyword", ["linkId"] = "NNNNNNN"
            };                                                                              // ....
            var from    = "NNNNNNNNNN";
            var to      = "+NNNNNNNNNN";
            var message = "Super Cool Message";

            try
            {
                var res = gateway.SendPremiumMessage(to, message, from, 0, opts); // Set Bulk to true
                Console.WriteLine(res);
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("Whoops: " + e.Message);
                throw;
            }
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: dorohin/africastalking.Net
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var username = "******";
            var apikey   = "KEY";
            var env      = "sandbox";
            var gateway  = new AfricasTalkingGateway(username, apikey, env);
            var opts     = new Hashtable {
                ["keyword"] = "mykeyword"
            };                                                      // ....
            var from    = "NNNNN";
            var to      = "+2547XXXXX";
            var message = "Super Cool Message";

            try
            {
                var res = gateway.SendMessage(to, message, from, 1, opts); // Set Bulk to true
                Console.WriteLine(res);
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("Whoops: " + e.Message);
                throw;
            }
        }
コード例 #20
0
    public static void Main()
    {
        // Specify your login credentials
        string username = "******";
        string apiKey   = "MyAfricasTalkingAPIKey";

        // Specify the number that you want to subscribe
        // Please ensure you include the country code (+254 for Kenya in this case)
        string phoneNumber   = "+254711YYYZZZ";

        //Specify your Africa's Talking premium short code and keyword
        string shortCode = "myAfricasTalkingShortCode";
        string keyword   = "myAfricasTalkingKeyword";

        //Create an instance of our gateway class and pass your login credentials
        AfricasTalkingGateway gateway = new AfricasTalkingGateway(username, apiKey);

        // Any gateway error will be captured by our custom Exception class as shown below,
        // so wrap the call in a try-catch block
        try {

            dynamic result = gateway.createSubscription(phoneNumber, shortCode, keyword);
            Console.WriteLine("Status: " + result["status"]);
            Console.WriteLine("Description: " + result["description"]);

        } catch (AfricasTalkingGatewayException e) {

            Console.WriteLine ("Encountered an error: " + e.Message);

        }
    }
コード例 #21
0
        private void btn_send_Click(object sender, EventArgs e)
        {
            AfricasTalkingGateway af = new AfricasTalkingGateway("studentBiometircSystem", "211dc662c27cc4198ca90d4e00ba0971da52cf005dd8c92f8382ff22aace58c1");

            af.sendMessage(txtTo.Text, txtMessage.Text);
            //clear text boxes
            txtMessage.Text = " ";
            txtTo.Text      = " ";
        }
コード例 #22
0
        public Task SendAsync(IdentityMessage message)
        {
            // Plug in your SMS service here to send a text message.
            var gateway = new AfricasTalkingGateway(Settings.Default.AfricaTalkingUserName,
                                                    Settings.Default.AfricaTalkingAPIKey);

            gateway.SendMessage(message.Destination, message.Body);
            return(Task.FromResult(0));
        }
コード例 #23
0
    public static void MobilePaymentB2C()
    {
        //Specify your credentials
        string username = "******";
        string apiKey   = "MyAfricasTalkingAPIKey";

        // NOTE: If connecting to the sandbox, please use your sandbox login credentials

        //Create an instance of our awesome gateway class and pass your credentials
        // AfricasTalkingGateway gateway = new AfricasTalkingGateway(username, apiKey,"sandbox");

        // NOTE: If connecting to the sandbox, please add the sandbox flag to the constructor:
        /// <summary>
        ///***********************************************************************************
        ///                    ****SANDBOX****
        AfricasTalkingGateway gateway = new AfricasTalkingGateway(username, apiKey, "production");
        /// *************************************************************************************
        /// </summary>

        // Specify the name of your Africa's Talking payment product
        string productName = "My Online Store";

        // The 3-Letter ISO currency code for the checkout amount
        string currencyCode = "KES";


        // Provide the details of a mobile money recipient
        MobilePaymentB2CRecipient recipient1 = new MobilePaymentB2CRecipient("+254700YYYXXX", "KES", 10M);

        recipient1.AddMetadata("name", "Clerk");
        recipient1.AddMetadata("reason", "May Salary");

        // You can provide up to 10 recipients at a time
        MobilePaymentB2CRecipient recipient2 = new MobilePaymentB2CRecipient("+254741YYYXXX", "KES", 10M);

        recipient2.AddMetadata("name", "Accountant");
        recipient2.AddMetadata("reason", "May Salary");

        // Put the recipients into an array
        IList <MobilePaymentB2CRecipient> recipients = new List <MobilePaymentB2CRecipient>();

        recipients.Add(recipient1);
        recipients.Add(recipient2);

        try
        {
            var responses = gateway.MobilePaymentB2CRequest(productName, recipients);
            Console.WriteLine(responses);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Received error response: " + ex.Message);
        }
        Console.ReadLine();
    }
コード例 #24
0
ファイル: Program.cs プロジェクト: dorohin/africastalking.Net
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            const string Username      = "******";
            const string ApiKey        = "Key";
            const string Otp           = "1234";
            const string Env           = "sandbox";
            var          gateway       = new AfricasTalkingGateway(Username, ApiKey, Env);
            var          transId       = "id";
            var          productName   = "coolproduct";
            var          accountName   = "Fela Kuti";
            var          accountNumber = "1234567890";
            var          bankCode      = 234001;
            var          currencyCode  = "NGN";
            var          amount        = 1000.5M;
            var          dob           = "2017-11-22";
            var          metadata      = new Dictionary <string, string> {
                { "Reason", "Buy Vega Records" }
            };
            var narration = "We're buying something cool";
            var receBank  = new BankAccount(accountNumber, bankCode, dob, accountName);

            try
            {
                var res = gateway.BankCheckout(productName, receBank, currencyCode, amount, narration, metadata);
                res = JsonConvert.DeserializeObject(res);
                Console.WriteLine(res);
                if (res["status"] == "PendingValidation")
                {
                    transId = res["transactionId"];
                    Console.WriteLine("Validating...");
                }

                try
                {
                    var valid = gateway.OtpValidate(transId, Otp);
                    valid = JsonConvert.DeserializeObject(valid);
                    if (valid["status"] == "Success")
                    {
                        Console.WriteLine("Whoooohoo...");
                    }
                }
                catch (AfricasTalkingGatewayException e)
                {
                    Console.WriteLine("Yikes: " + e.Message + e.StackTrace);
                }
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("Something odd happened: " + e.Message + e.StackTrace);
            }

            Console.ReadLine();
        }
コード例 #25
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // Suppose we want to move money from our *awesomeproduct* to *coolproduct*

            /*
             * Remember to register  B2B products and callback urls:else these trasactions will fail
             */
            string  username           = "******";
            string  apiKey             = "bc203009d2b240e461c22d7a959ca4d752591d4553295d991e74824d599fc9b3";
            string  productName        = "awesomeproduct";
            string  currencyCode       = "KES";
            decimal amount             = 15;
            string  provider           = "Athena";
            string  destinationChannel = "mychannel"; // This is the channel that will be receiving the payment
            string  destinationAccount = "coolproduct";

            // Transfer Type

            /*
             * BusinessBuyGoods
             * BusinessPayBill
             * DisburseFundsToBusiness
             * BusinessToBusinessTransfer
             */
            dynamic metadataDetails = new JObject();

            metadataDetails.shopName = "cartNumber";
            metadataDetails.Info     = "Stuff";
            string transferType = "BusinessToBusinessTransfer";
            var    gateWay      = new AfricasTalkingGateway(username, apiKey);

            try
            {
                string response = gateWay.MobileB2B(
                    productName,
                    provider,
                    transferType,
                    currencyCode,
                    amount,
                    destinationChannel,
                    destinationAccount,
                    metadataDetails);
                Console.WriteLine(response);
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("Woopsies! We ran into issues: " + e.StackTrace + " : " + e.Message);
            }

            Console.ReadLine();
        }
コード例 #26
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            const string username                  = "******";
            const string apikey                    = "Key";
            const string productname               = "coolproduct";
            const string env                       = "sandbox";
            var          gateway                   = new AfricasTalkingGateway(username, apikey, env);
            var          currency_code             = "NGN";
            var          recipient1_account_name   = "Alyssa Hacker";
            var          recipient1_account_number = "1234567890";
            var          recipient1_bank_code      = 234001;
            var          recipient1_amount         = 1500.50M;
            var          recipient1_narration      = "December Bonus";
            var          recipient2_account_name   = "Ben BitDiddle";
            var          recipient2_account_number = "234567891";
            var          recipient2_bank_code      = 234004;
            var          recipient2_amount         = 1500.50M;
            var          recipient2_narration      = "November Bonus";
            var          recepient1_account        =
                new BankAccount(recipient1_account_number, recipient1_bank_code, recipient1_account_name);
            var recepient1 = new BankTransferRecipients(recipient1_amount, recepient1_account, currency_code,
                                                        recipient1_narration);

            recepient1.AddMetadata("Reason", "Early Bonus");
            var recipient2_account =
                new BankAccount(recipient2_account_number, recipient2_bank_code, recipient2_account_name);
            var recipient2 = new BankTransferRecipients(recipient2_amount, recipient2_account, currency_code,
                                                        recipient2_narration);

            recipient2.AddMetadata("Reason", "Big Wins");
            IList <BankTransferRecipients> recipients = new List <BankTransferRecipients>
            {
                recepient1,
                recipient2
            };

            try
            {
                var res = gateway.BankTransfer(productname, recipients);
                Console.WriteLine(res);
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("We had issues: " + e.Message);
            }

            Console.ReadLine();
        }
コード例 #27
0
        public dynamic MakeACall(string from, string to)
        {
            var gateway = new AfricasTalkingGateway(config.sandboxUsername, config.sandboxApiKey, config.environment);

            try
            {
                var results = gateway.Call(from, to);
                var res     = JsonConvert.DeserializeObject(results);
                var status  = res["entries"];
                return(status);
            }
            catch (AfricasTalkingGatewayException ex)
            {
                return("");
            }
        }
コード例 #28
0
        static void SendSms(string phoneNo, int code)
        {
            InitialiseSettings();
            var gateway = new AfricasTalkingGateway(UserName, ApiKey);

            try
            {
                dynamic results = gateway.SendMessage(phoneNo, $"Your verification code is {code}");
                WriteLine("Sms Sent");
            }
            catch (Exception e)
            {
                WriteLine(e);
                throw;
            }
        }
コード例 #29
0
    public static void Main()
    {
        // Specify your login credentials
        string username = "******";
        string apiKey   = "MyAfricasTalking_APIKey";

        // Specify an array list to hold numbers to receive airtime
        ArrayList AirtimeRecipientsList = new ArrayList();

        // Declare hashtable to hold the first number
        // Please ensure you include the country code for phone numbers (+254 for Kenya in this case)
        // Specify the country currency and the amount as shown below (KES for Kenya in this case)

        Hashtable rec1      = new Hashtable();
        rec1["phoneNumber"] = "+254722XXXYYY";
        rec1["amount"]      = "KES XXX";

        // Add recipient to list
        AirtimeRecipientsList.Add(rec1);

        // Declare hashtable to hold the another number
        Hashtable rec2     = new Hashtable();
        rec2["phoneNumber"] = "+254722XXXYYY";
        rec2["amount"]      = "KES XXX";

        // Add recipient to list
        AirtimeRecipientsList.Add(rec2);

          // Create a new instance of our awesome gateway class
        AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);

         try {
                // That's it. Hit send and we will handle the rest

                dynamic response = gateway.sendAirtime(AirtimeRecipientsList);
                foreach (dynamic result in response) {
                    Console.Write (result["status"] + ",");
                    Console.Write (result["phoneNumber"] + ",");
                    Console.Write (result["amount"] + ",");
                    Console.Write (result["discount"] + ",");
                    Console.WriteLine (result["errorMessage"]);
                }
            }
            catch(AfricasTalkingGatewayException ex) {
                Console.WriteLine (ex.Message);
            }
    }
コード例 #30
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var phoneNumber = "+254724587654";
            var gateway     = new AfricasTalkingGateway("username", "Key", "sandbox");

            try
            {
                var token = gateway.CreateCheckoutToken(phoneNumber);
                Console.WriteLine("Your Token is:  " + token["token"]);
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadLine();
        }
コード例 #31
0
        public override TransactionResponse CommitTransaction(TransactionRequest request)
        {
            try
            {
                var recipients = new List <MobilePaymentB2CRecipient>();
                recipients.Add(new MobilePaymentB2CRecipient(request.PayeeId, AppSettings.Site.CurrencyCode, request.Payment.ToDecimal()));

                AfricasTalkingGateway gateway = new AfricasTalkingGateway(accountDetails.Username, accountDetails.ApiKey);
                var response = gateway.MobilePaymentB2CRequest(accountDetails.ProductName, recipients);

                return(new MPesaTransactionResponse(this, response));
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                return(new MPesaTransactionResponse(this, ex));
            }
        }
コード例 #32
0
    public static void Main()
    {
        // Specify your login credentials
        string username = "******";
        string apiKey   = "MyAfricasTalking_APIKey";

        // Create a new instance of our awesome gateway class
        AfricasTalkingGateway gateway  = new AfricasTalkingGateway(username, apiKey);

        // Our gateway will return 10 messages at a time back to you, starting with
        // what you currently believe is the lastReceivedId. Specify 0 for the first
        // time you access the gateway, and the ID of the last message we sent you
        // on subsequent results

        int lastReceivedId = 0;

        // Any gateway errors will be captured by our custom Exception class below,
        // so wrap the call in a try-catch block

        try {

            // Here is a sample of how to fetch all messages using a while loop
            do {

                dynamic results = gateway.fetchMessages(lastReceivedId);

                foreach(dynamic result in results) {
                    Console.WriteLine("From: " + result["from"]);
                    Console.WriteLine("To: " + result["to"]);
                    Console.WriteLine("Message: " + result["text"]);
                    Console.WriteLine("Date: " + result["date"]);
                    Console.WriteLine("linkId: " + result["linkId"]);
                    lastReceivedId = (int)result["id"];
                }
            } while ( results.Count > 0 );

        } catch (AfricasTalkingGatewayException e) {

            Console.WriteLine ("Encountered an error: " + e.Message);

        }// NOTE: Be sure to save lastReceivedId here for next time

        // DONE!!!
    }
コード例 #33
0
        public dynamic ValidateOTP(string transactionID, string OTP, string state)
        {
            if (state == "live")
            {
                AfricasTalkingGateway gateway = new AfricasTalkingGateway(config.liveUsername, config.liveApiKey, "production");

                var validate = gateway.ValidateCardOtp(transactionID, OTP);

                return(validate);
            }
            else
            {
                AfricasTalkingGateway gateway = new AfricasTalkingGateway(config.sandboxUsername, config.sandboxApiKey, config.environment);

                var validate = gateway.ValidateCardOtp(transactionID, OTP);

                return(validate);
            }
        }
コード例 #34
0
    public static void Main()
    {
        string username = "******";
        string apiKey   = "MyAfricasTalkingAPIKey";

        string recipients = "+254711XXXYYY,+254733YYYZZZ";

        string message = "Get your daily message and thats how we roll.";

        // Specify your premium shortCode and keyword
        string shortCode = "XXXXX";
        string keyword   = "premiumKeyword";

        // Set the bulkSMSMode flag to 0 so that the subscriber get charged
        int bulkSMSMode = 0;

        // Create an array which would hold the following parameters:
        // keyword: Your premium keyword,
        // retryDurationInHours: The numbers of hours our API should retry to send the message
        // incase it doesn't go through. It is optional

        Hashtable options = new Hashtable();
        options["keyword"] = keyword;
        options["retryDurationInHours"] = No. of hours to retry sending message;

        AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);

        try {

            dynamic results = gateway.sendMessage (recipients, message, shortCode, bulkSMSMode, options);

            foreach( dynamic result  in results){
                Console.Write((string)result["number"] + ",");
                Console.Write((string)result["status"] + ",");
                Console.WriteLine((string)result["messageId"]);
            }
        } catch (AfricasTalkingGatewayException e) {

            Console.WriteLine ("Encountered an error: " + e.Message);

        }
    }
コード例 #35
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            const string Username = "******";
            const string ApiKey   = "afd635a4f295dd936312836c0b944d55f2a836e8ff2b63987da5e717cd5ff745";
            var          gateway  = new AfricasTalkingGateway(Username, ApiKey);
            int          msgId    = 0;

            try
            {
                var res = gateway.FetchMessages(msgId);
                Console.WriteLine(res);
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("We had an Error: " + e.Message);
            }

            Console.ReadLine();
        }
コード例 #36
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var username = "******";
            var apiKey   = "yourLIVEAccountAPIKEY";

            var gw = new AfricasTalkingGateway(username, apiKey);

            try
            {
                var res = gw.GetUserData();
                Console.WriteLine(res);
            }
            catch (AfricasTalkingGatewayException e)
            {
                Console.WriteLine("We ran into a bunch of problems: " + e.Message + " :" + e.StackTrace);
            }

            Console.ReadLine();
        }
コード例 #37
0
    static public void _Smspremiumrate()
    {
        string username = "******";
        string apiKey   = "MyAfricasTalkingAPIKey";

        string recipients = "+254711XXXYYY,+254733YYYZZZ";

        string message = "Get your daily message and that's how we roll.";

        // Specify your premium shortCode and keyword
        string shortCode = "XXXXX";
        string keyword   = "premiumKeyword";

        // Set the bulkSMSMode flag to 0 so that the subscriber get charged
        int bulkSMSMode = 0;

        // Create an array which would hold the following parameters:
        // keyword: Your premium keyword,
        // retryDurationInHours: The numbers of hours our API should retry to send the message
        // incase it doesn't go through. It is optional

        Hashtable options = new Hashtable();

        options["keyword"] = keyword;
        options["retryDurationInHours"] = "No. of hours to retry sending message";

        AfricasTalkingGateway gateway = new AfricasTalkingGateway(username, apiKey);

        try {
            dynamic results = gateway.sendMessage(recipients, message, shortCode, bulkSMSMode, options);

            foreach (dynamic result  in results)
            {
                Console.Write((string)result["number"] + ",");
                Console.Write((string)result["status"] + ",");
                Console.WriteLine((string)result["messageId"]);
            }
        } catch (AfricasTalkingGatewayException e) {
            Console.WriteLine("Encountered an error: " + e.Message);
        }
    }
コード例 #38
0
        public dynamic DebitUserCard(CardPaymentData data, string state)
        {
            if (state == "live")
            {
                AfricasTalkingGateway gateway = new AfricasTalkingGateway(config.liveUsername, config.liveApiKey, "production");
                string ProductName            = config.livePaymentProduct;
                data.CurrencyCode = "NGN";
                data.CountryCode  = "NG";
                data.Narration    = "Testing Out LSW USSD";

                var cardDetails = new PaymentCard(data.CardPin, data.CountryCode, (short)data.CardCvv, data.ValidTillMonth, data.ValidTillYear, data.CardNum);

                var checkout = gateway.CardCheckout(
                    ProductName,
                    cardDetails,
                    data.CurrencyCode,
                    data.Amount,
                    data.Narration);

                return(checkout);
            }
            else
            {
                AfricasTalkingGateway gateway = new AfricasTalkingGateway(config.sandboxUsername, config.sandboxApiKey, config.environment);
                string ProductName            = config.sandboxPaymentProduct;
                data.CurrencyCode = "NGN";
                data.CountryCode  = "NG";
                data.Narration    = "Testing Out YellowCard USSD";

                var cardDetails = new PaymentCard(data.CardPin, data.CountryCode, (short)data.CardCvv, data.ValidTillMonth, data.ValidTillYear, data.CardNum);

                var checkout = gateway.CardCheckout(
                    ProductName,
                    cardDetails,
                    data.CurrencyCode,
                    data.Amount,
                    data.Narration);

                return(checkout);
            }
        }
コード例 #39
0
	static public void Main (){
	
		// Specify your login credentials
		string username = "******";
		string apiKey   = "MyAfricasTalkingAPIKey";
		
		// Specify your premium shortcode and keyword
		string shortCode = "XXXXX";
		string keyword   = "myPremiumKeyword";
		
		// Create a new instance of our awesome gateway class
		AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);
		
		// Our gateway will return 100 subscription numbers at a time back to you, starting with
		// what you currently believe is the lastReceivedId. Specify 0 for the first
		// time you access the gateway, and the ID of the last message we sent you
		// on subsequent results
		
		int lastReceivedId = 0;

		// Any gateway errors will be captured by our custom Exception class below,
		// so wrap the call in a try-catch block   
		try {
			// Here is a sample of how to fetch all messages using a while loop     
			do {
	        	
				dynamic results = gateway.fetchPremiumSubscriptions(shortCode, keyword, lastReceivedId);

				foreach(dynamic result in results) {
					Console.WriteLine("phoneNumber: " + result["phoneNumber"]);
					lastReceivedId = (int)result["id"];
				}
			} while ( results.Count > 0 );

		} catch (AfricasTalkingGatewayException e) {

			Console.WriteLine ("Encountered an error: " + e.Message);		

		}
}
コード例 #40
0
    public static void Main()
    {
        string username = "******";
        string apiKey   = "MyAfricasTalkingAPIKey";

        string recipients = "+254711XXXYYY,+254733YYYZZZ";

        string message = "Get your daily message and thats how we roll.";

        string shortCode = "XXXXX";
        string keyword   = "premiumKeyword"; // string keyword = null;

        int bulkSMSMode = 0;

        // Create a hashtable which would hold the parameters keyword, retryDurationInHours and linkId
        // linkId is received from the message sent by subscriber to your onDemand service
        string linkId = "messageLinkId";

        Hashtable options = new Hashtable();
        options["keyword"] = keyword;
        options["linkId"] = linkId;
        options["retryDurationInHours"] = No. of hours to retry sending message;

        AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);

        try {

            dynamic results = gateway.sendMessage (recipients, message, shortCode, bulkSMSMode, options);

            foreach( dynamic result  in results){
                Console.Write((string)result["number"] + ",");
                Console.Write((string)result["status"] + ",");
                Console.Write((string)result["messageId"] + ",");
            }
        } catch (AfricasTalkingGatewayException e) {

            Console.WriteLine ("Encountered an error: " + e.Message);

        }
    }
コード例 #41
0
    public static void Main()
    {
        // Specify your login credentials
        string username = "******";
        string apiKey   = "MyAfricasTalking_APIKey";

          	// Create a new instance of our awesome gateway class
            AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);

            // Any gateway errors will be captured by our custom Exception class below,
            // so wrap the call in a try-catch block
            try {

                dynamic response = gateway.getUserData ();
                Console.WriteLine (response["balance"]);

            } catch (AfricasTalkingGatewayException e) {

                Console.WriteLine ("Encountered an error: " + e.Message);

        }
    }
コード例 #42
0
    public static void Main()
    {
        // Specify your login credentials
        string username = "******";
        string apiKey   = "MyAfricasTalkingAPIKey";

        // Specify the numbers that you want to send to in a comma-separated list
        // Please ensure you include the country code (+254 for Kenya in this case)
        string recipients = "+254711XXXYYY,+254733YYYZZZ";

        // And of course we want our recipients to know what we really do
        string message = "I'm a lumberjack and its ok, I sleep all night and I work all day";

        // Create a new instance of our awesome gateway class
        AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);

        // Any gateway errors will be captured by our custom Exception class below,
        // so wrap the call in a try-catch block
        try {

            // Thats it, hit send and we'll take care of the rest

            dynamic results = gateway.sendMessage (recipients, message);

            foreach( dynamic result  in results){
                Console.Write((string)result["number"] + ",");
                Console.Write((string)result["status"] + ","); // status is either "Success" or "error message"
                Console.Write((string)result["messageId"] + ",");
                Console.WriteLine((string)result["cost"]);
            }
        } catch (AfricasTalkingGatewayException e) {

            Console.WriteLine ("Encountered an error: " + e.Message);

        }
    }
コード例 #43
0
    public static void Main()
    {
        string username = "******";
        string apiKey   = "MyAfricasTalkingAPIKey";

        string recipients = "+254711XXXYYY,+254733YYYZZZ";

        string message = "I'm a lumberjack and its ok, I sleep all night and I work all day";

        string from = null; //$from = "shortCode or senderId";

        int bulkSMSMode = 1; // This should always be 1 for bulk messages

        // enqueue flag is used to queue messages incase you are sending a high volume.
        // The default value is 0.
        Hashtable options = new Hashtable();
        options["enqueue"] = 1;

        AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);

        try {

            dynamic results = gateway.sendMessage (recipients, message, from, bulkSMSMode, options);

            foreach( dynamic result  in results){
                Console.Write((string)result["number"] + ",");
                Console.Write((string)result["status"] + ",");
                Console.Write((string)result["messageId"] + ",");
                Console.WriteLine((string)result["cost"]);
            }
        } catch (AfricasTalkingGatewayException e) {

            Console.WriteLine ("Encountered an error: " + e.Message);

        }
    }