Unicode 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

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    const wchar_t *strResponseBody;
    HCkJsonObjectW jsonResponse;
    const wchar_t *id;
    const wchar_t *object;
    int amount;
    const wchar_t *client_secret;
    int created;
    const wchar_t *currency;
    const wchar_t *flow;
    BOOL livemode;
    BOOL ownerAddress;
    const wchar_t *ownerEmail;
    BOOL ownerName;
    BOOL ownerPhone;
    BOOL ownerVerified_address;
    BOOL ownerVerified_email;
    BOOL ownerVerified_name;
    BOOL ownerVerified_phone;
    const wchar_t *receiverAddress;
    int receiverAmount_charged;
    int receiverAmount_received;
    int receiverAmount_returned;
    const wchar_t *receiverRefund_attributes_method;
    const wchar_t *receiverRefund_attributes_status;
    BOOL statement_descriptor;
    const wchar_t *status;
    const wchar_t *type;
    const wchar_t *usage;
    const wchar_t *bitcoinAddress;
    int bitcoinAmount;
    int bitcoinAmount_charged;
    int bitcoinAmount_received;
    int bitcoinAmount_returned;
    const wchar_t *bitcoinUri;

    rest = CkRestW_Create();

    //  URL: https://api.stripe.com/v1/sources
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"api.stripe.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_SetAuthBasic(rest,L"STRIPE_SECRET_KEY",L"");

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

    strResponseBody = CkRestW_fullRequestFormUrlEncoded(rest,L"POST",L"/v1/sources");
    if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_Load(jsonResponse,strResponseBody);

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


    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(jsonResponse);

    }

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"
  }
}