Visual FoxPro 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

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL lcStrResponseBody
LOCAL loJsonResponse
LOCAL lcId
LOCAL lcObject
LOCAL lnAmount
LOCAL lcClient_secret
LOCAL lnCreated
LOCAL lcCurrency
LOCAL lcFlow
LOCAL lnLivemode
LOCAL lnOwnerAddress
LOCAL lcOwnerEmail
LOCAL lnOwnerName
LOCAL lnOwnerPhone
LOCAL lnOwnerVerified_address
LOCAL lnOwnerVerified_email
LOCAL lnOwnerVerified_name
LOCAL lnOwnerVerified_phone
LOCAL lcReceiverAddress
LOCAL lnReceiverAmount_charged
LOCAL lnReceiverAmount_received
LOCAL lnReceiverAmount_returned
LOCAL lcReceiverRefund_attributes_method
LOCAL lcReceiverRefund_attributes_status
LOCAL lnStatement_descriptor
LOCAL lcStatus
LOCAL lcType
LOCAL lcUsage
LOCAL lcBitcoinAddress
LOCAL lnBitcoinAmount
LOCAL lnBitcoinAmount_charged
LOCAL lnBitcoinAmount_received
LOCAL lnBitcoinAmount_returned
LOCAL lcBitcoinUri

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://api.stripe.com/v1/sources
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("api.stripe.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loRest.SetAuthBasic("STRIPE_SECRET_KEY","")

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

lcStrResponseBody = loRest.FullRequestFormUrlEncoded("POST","/v1/sources")
IF (loRest.LastMethodSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.Load(lcStrResponseBody)

lcId = loJsonResponse.StringOf("id")
lcObject = loJsonResponse.StringOf("object")
lnAmount = loJsonResponse.IntOf("amount")
lcClient_secret = loJsonResponse.StringOf("client_secret")
lnCreated = loJsonResponse.IntOf("created")
lcCurrency = loJsonResponse.StringOf("currency")
lcFlow = loJsonResponse.StringOf("flow")
lnLivemode = loJsonResponse.BoolOf("livemode")
lnOwnerAddress = loJsonResponse.IsNullOf("owner.address")
lcOwnerEmail = loJsonResponse.StringOf("owner.email")
lnOwnerName = loJsonResponse.IsNullOf("owner.name")
lnOwnerPhone = loJsonResponse.IsNullOf("owner.phone")
lnOwnerVerified_address = loJsonResponse.IsNullOf("owner.verified_address")
lnOwnerVerified_email = loJsonResponse.IsNullOf("owner.verified_email")
lnOwnerVerified_name = loJsonResponse.IsNullOf("owner.verified_name")
lnOwnerVerified_phone = loJsonResponse.IsNullOf("owner.verified_phone")
lcReceiverAddress = loJsonResponse.StringOf("receiver.address")
lnReceiverAmount_charged = loJsonResponse.IntOf("receiver.amount_charged")
lnReceiverAmount_received = loJsonResponse.IntOf("receiver.amount_received")
lnReceiverAmount_returned = loJsonResponse.IntOf("receiver.amount_returned")
lcReceiverRefund_attributes_method = loJsonResponse.StringOf("receiver.refund_attributes_method")
lcReceiverRefund_attributes_status = loJsonResponse.StringOf("receiver.refund_attributes_status")
lnStatement_descriptor = loJsonResponse.IsNullOf("statement_descriptor")
lcStatus = loJsonResponse.StringOf("status")
lcType = loJsonResponse.StringOf("type")
lcUsage = loJsonResponse.StringOf("usage")
lcBitcoinAddress = loJsonResponse.StringOf("bitcoin.address")
lnBitcoinAmount = loJsonResponse.IntOf("bitcoin.amount")
lnBitcoinAmount_charged = loJsonResponse.IntOf("bitcoin.amount_charged")
lnBitcoinAmount_received = loJsonResponse.IntOf("bitcoin.amount_received")
lnBitcoinAmount_returned = loJsonResponse.IntOf("bitcoin.amount_returned")
lcBitcoinUri = loJsonResponse.StringOf("bitcoin.uri")

RELEASE loRest
RELEASE loJsonResponse

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