Last active
April 14, 2021 20:07
-
-
Save darul75/433d878fce5ef7f801672b52ff0e019a to your computer and use it in GitHub Desktop.
stripe_invalid_request.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Net; | |
using System.Web; | |
using Newtonsoft.Json; | |
using System.Web.Mvc; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
const string ChargeUrl = "https://api.stripe.com/v1/charges?amount={0}¤cy={1}&source={2}&description={3}"; | |
string requestUrl = HttpUtility.UrlPathEncode( | |
String.Format(ChargeUrl, 1000, "usd", "tok_19xLu8HN9aKw9vrkUsflNWOI", "Test charge to [email protected]")); | |
CreateCharge("tok_bypassPending"); | |
} | |
public static void CreateCharge2(string token) { | |
/* | |
* Accepts token id (eg. tok_xxx) and creates charge using the Stripe API. | |
* https://stripe.com/docs/api#create_charge | |
*/ | |
// Get the Stripe Secret API Key from Configuration File. (eg. sk_test_W8xJYzw56NCHun0FT9iGIJeI) | |
//string clientSecretKey = ConfigurationManager.AppSettings["ClientSecretKey"]; | |
string clientSecretKey = "sk_test_W8xJYzw56NCHun0FT9iGIJeI"; | |
const string ChargeUrl = "https://api.stripe.com/v1/charges?amount={0}¤cy={1}&source={2}&description={3}"; | |
string requestUrl = HttpUtility.UrlPathEncode( | |
String.Format(ChargeUrl, 1000, "usd", "tok_19xLHN9aKw9vrkUsflNWOI", "Test charge to [email protected]")); | |
HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest; | |
request.Headers.Add("Authorization", "Bearer sk_test_W8xJYzw56NCHun0FT9iGIJeI"); | |
request.ContentType = "application/x-www-form-urlencoded"; | |
request.Method = "POST"; | |
dynamic response; | |
try { | |
HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse; | |
StreamReader reader = new StreamReader(httpResponse.GetResponseStream()); string | |
jsonResponse = reader.ReadToEnd(); | |
response = JsonConvert.DeserializeObject(jsonResponse); | |
System.Console.WriteLine(response.id); | |
} | |
catch (Exception ex) { | |
Console.WriteLine( "\nMessage ---\n{0}", ex.Message ); | |
Console.WriteLine( | |
"\nHelpLink ---\n{0}", ex.HelpLink ); | |
Console.WriteLine( "\nSource ---\n{0}", ex.Source ); | |
Console.WriteLine( | |
"\nStackTrace ---\n{0}", ex.StackTrace ); | |
Console.WriteLine( | |
"\nTargetSite ---\n{0}", ex.TargetSite ); | |
} | |
/* | |
using (HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse) { | |
StreamReader reader = new StreamReader(httpResponse.GetResponseStream()); string | |
jsonResponse = reader.ReadToEnd(); | |
response = JsonConvert.DeserializeObject(jsonResponse); | |
} | |
*/ | |
// Write the Charge ID to the console. | |
//return RedirectToAction("Index", "Home"); | |
} | |
public static void CreateCharge(string token) { | |
/* | |
* Accepts token id (eg. tok_xxx) and creates charge using the Stripe API. | |
* https://stripe.com/docs/api#create_charge | |
*/ | |
// Get the Stripe Secret API Key from Configuration File. (eg. sk_test_W8xJYzw56NCHun0FT9iGIJeI) | |
string clientSecretKey = "sk_test_W8xJYzw56NCHun0FT9iGIJeI"; | |
const string ChargeUrl = "https://api.stripe.com/v1/charges?amount={0}¤cy={1}&source={2}&description={3}"; | |
string requestUrl = HttpUtility.UrlPathEncode( | |
String.Format(ChargeUrl, 1000, "usd", "tok_bypassPending", "Test charge to [email protected]")); | |
HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest; | |
request.Headers.Add("Authorization", "Bearer sk_test_W8xJYzw56NCHun0FT9iGIJeI"); | |
request.ContentType = "application/x-www-form-urlencoded"; | |
request.Method = "POST"; | |
dynamic response; | |
using (HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse) { | |
StreamReader reader = new StreamReader(httpResponse.GetResponseStream()); string | |
jsonResponse = reader.ReadToEnd(); | |
response = JsonConvert.DeserializeObject(jsonResponse); | |
} | |
// Write the Charge ID to the console. | |
System.Console.WriteLine(response.id); | |
// return RedirectToAction("Index", "Home"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment