Skip to content

Instantly share code, notes, and snippets.

@mario-loza
Created May 23, 2017 22:11
Show Gist options
  • Save mario-loza/e37ad8b3c8dd20c3516db77b1737c4cb to your computer and use it in GitHub Desktop.
Save mario-loza/e37ad8b3c8dd20c3516db77b1737c4cb to your computer and use it in GitHub Desktop.
MyPaymentApp
using System.Text;
using System.Net.Http;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
namespace MyPaymentApp
{
class Program
{
static string securityCode = "dhacBUCadH9BpVcGluemGneEk3Fctc3jXawG2dba51K2xnlqOqyzVg==";
static void Main(string[] args)
{
//A payment has been received ! So lets register it in our azure function
//remember this is sample data, you would call this with the real paying client info
System.Console.WriteLine("\n\nRegistering Payment...");
string result = RegisterPaymentAsync("mario", "mario.loza@gmail.com", securityCode);
System.Console.WriteLine("\n\nRegistration answer: {0}",result);
System.Console.WriteLine("\n\nPress enter to exit...");
System.Console.ReadLine();
}
static string RegisterPaymentAsync(string name, string email, string securityCode)
{
string result = string.Empty;
var askForlicenseURL = "https://licensefunctions.azurewebsites.net/api/gotpayment";
var myObject = (dynamic)new JObject();
myObject.name = name;
myObject.email = email;
var content = new StringContent(myObject.ToString(), Encoding.UTF8, "application/json");
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("x-functions-key", securityCode);
using (HttpResponseMessage response = client.PostAsync(askForlicenseURL, content).Result)
using (HttpContent respContent = response.Content)
{
// ... Read the response as a string.
var tr = respContent.ReadAsStringAsync().Result;
// ... deserialize the response, we know it has a 'result' field
dynamic azureResponse = JsonConvert.DeserializeObject(tr);
// ... read the data we want
result = azureResponse.result;
}
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment