Skip to content

Instantly share code, notes, and snippets.

@rramsden
Last active January 5, 2016 01:50
Show Gist options
  • Save rramsden/1b16042ce3a68848f32c to your computer and use it in GitHub Desktop.
Save rramsden/1b16042ce3a68848f32c to your computer and use it in GitHub Desktop.
Komoju API C#, ASP.NET
// Creating a payment using JSON API
// See https://docs.komoju.com/api/overview#payments
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Collections.Specialized;
public class HelloWorld
{
static public void Main ()
{
string url = @"https://sandbox.komoju.com/api/v1/payments";
WebClient client = new WebClient();
String username = "komoju-mart"; // SECRET KEY (Goto Manage -> Merchant Account -> Secret Key)
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":"));
client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials);
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
NameValueCollection myParameters = new NameValueCollection();
myParameters.Add("amount", "1000");
myParameters.Add("tax", "0");
myParameters.Add("currency", "JPY");
myParameters.Add("payment_details[type]", "credit_card");
myParameters.Add("payment_details[given_name]", "Taro");
myParameters.Add("payment_details[family_name]", "Yamada");
myParameters.Add("payment_details[month]", "01");
myParameters.Add("payment_details[number]", "4111111111111111");
myParameters.Add("payment_details[year]", "2016");
myParameters.Add("payment_details[verification_value]", "123");
byte[] responseBytes = client.UploadValues(url, "POST", myParameters);
string responseBody = Encoding.UTF8.GetString(responseBytes);
Console.WriteLine(responseBody);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment