C# Stripe: Create a Source

Back to Index

Creates a new source object.

Documentation: https://stripe.com/docs/api/curl#create_source

CURL Command

curl https://api.stripe.com/v1/sources \
   -u STRIPE_SECRET_KEY: \
   -d type=bitcoin \
   -d amount=1000 \
   -d currency=usd \
   -d owner[email]="jenny.rosen@example.com" \
   -X POST

C# Example

Chilkat.Rest rest = new Chilkat.Rest();
bool success;

//  URL: https://api.stripe.com/v1/sources
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = rest.Connect("api.stripe.com",port,bTls,bAutoReconnect);
if (success != true) {
    Debug.WriteLine("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
    Debug.WriteLine(rest.LastErrorText);
    return;
}

rest.SetAuthBasic("STRIPE_SECRET_KEY","");

rest.AddQueryParam("type","bitcoin");
rest.AddQueryParam("amount","1000");
rest.AddQueryParam("currency","usd");
rest.AddQueryParam("owner[email]","jenny.rosen@example.com");

string strResponseBody = rest.FullRequestFormUrlEncoded("POST","/v1/sources");
if (rest.LastMethodSuccess != true) {
    Debug.WriteLine(rest.LastErrorText);
    return;
}

Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
jsonResponse.Load(strResponseBody);

string id;
string object;
int amount;
string client_secret;
int created;
string currency;
string flow;
bool livemode;
bool ownerAddress;
string ownerEmail;
bool ownerName;
bool ownerPhone;
bool ownerVerified_address;
bool ownerVerified_email;
bool ownerVerified_name;
bool ownerVerified_phone;
string receiverAddress;
int receiverAmount_charged;
int receiverAmount_received;
int receiverAmount_returned;
string receiverRefund_attributes_method;
string receiverRefund_attributes_status;
bool statement_descriptor;
string status;
string type;
string usage;
string bitcoinAddress;
int bitcoinAmount;
int bitcoinAmount_charged;
int bitcoinAmount_received;
int bitcoinAmount_returned;
string bitcoinUri;

id = jsonResponse.StringOf("id");
object = jsonResponse.StringOf("object");
amount = jsonResponse.IntOf("amount");
client_secret = jsonResponse.StringOf("client_secret");
created = jsonResponse.IntOf("created");
currency = jsonResponse.StringOf("currency");
flow = jsonResponse.StringOf("flow");
livemode = jsonResponse.BoolOf("livemode");
ownerAddress = jsonResponse.IsNullOf("owner.address");
ownerEmail = jsonResponse.StringOf("owner.email");
ownerName = jsonResponse.IsNullOf("owner.name");
ownerPhone = jsonResponse.IsNullOf("owner.phone");
ownerVerified_address = jsonResponse.IsNullOf("owner.verified_address");
ownerVerified_email = jsonResponse.IsNullOf("owner.verified_email");
ownerVerified_name = jsonResponse.IsNullOf("owner.verified_name");
ownerVerified_phone = jsonResponse.IsNullOf("owner.verified_phone");
receiverAddress = jsonResponse.StringOf("receiver.address");
receiverAmount_charged = jsonResponse.IntOf("receiver.amount_charged");
receiverAmount_received = jsonResponse.IntOf("receiver.amount_received");
receiverAmount_returned = jsonResponse.IntOf("receiver.amount_returned");
receiverRefund_attributes_method = jsonResponse.StringOf("receiver.refund_attributes_method");
receiverRefund_attributes_status = jsonResponse.StringOf("receiver.refund_attributes_status");
statement_descriptor = jsonResponse.IsNullOf("statement_descriptor");
status = jsonResponse.StringOf("status");
type = jsonResponse.StringOf("type");
usage = jsonResponse.StringOf("usage");
bitcoinAddress = jsonResponse.StringOf("bitcoin.address");
bitcoinAmount = jsonResponse.IntOf("bitcoin.amount");
bitcoinAmount_charged = jsonResponse.IntOf("bitcoin.amount_charged");
bitcoinAmount_received = jsonResponse.IntOf("bitcoin.amount_received");
bitcoinAmount_returned = jsonResponse.IntOf("bitcoin.amount_returned");
bitcoinUri = jsonResponse.StringOf("bitcoin.uri");

Sample JSON Response Body

{
  "id": "src_1BnETKGswQrCoh0XUrU9xVhU",
  "object": "source",
  "amount": 1000,
  "client_secret": "src_client_secret_CBbgwhcWX2mz2uzcVsX3vjfe",
  "created": 1516662782,
  "currency": "usd",
  "flow": "receiver",
  "livemode": false,
  "metadata": {},
  "owner": {
    "address": null,
    "email": "jenny.rosen@example.com",
    "name": null,
    "phone": null,
    "verified_address": null,
    "verified_email": null,
    "verified_name": null,
    "verified_phone": null
  },
  "receiver": {
    "address": "test_1MBhWS3uv4ynCfQXF3xQjJkzFPukr4K56N",
    "amount_charged": 0,
    "amount_received": 0,
    "amount_returned": 0,
    "refund_attributes_method": "email",
    "refund_attributes_status": "missing"
  },
  "statement_descriptor": null,
  "status": "pending",
  "type": "bitcoin",
  "usage": "single_use",
  "bitcoin": {
    "address": "test_1MBhWS3uv4ynCfQXF3xQjJkzFPukr4K56N",
    "amount": 2371000,
    "amount_charged": 0,
    "amount_received": 0,
    "amount_returned": 0,
    "uri": "bitcoin:test_1MBhWS3uv4ynCfQXF3xQjJkzFPukr4K56N?amount=0.02371000"
  }
}