PureBasic Stripe: Update a Source

Back to Index

Updates the specified source by setting the values of the parameters passed. Any parameters not provided will be left unchanged.

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

CURL Command

curl https://api.stripe.com/v1/sources/src_1BnETLGswQrCoh0X5KOorXEP \
   -u STRIPE_SECRET_KEY: \
   -d metadata[order_id]=6735 \
   -X POST

PureBasic Example

IncludeFile "CkRest.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ;  URL: https://api.stripe.com/v1/sources/src_1BnETLGswQrCoh0X5KOorXEP
    bTls.i = 1
    port.i = 443
    bAutoReconnect.i = 1
    success = CkRest::ckConnect(rest,"api.stripe.com",port,bTls,bAutoReconnect)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    CkRest::ckSetAuthBasic(rest,"STRIPE_SECRET_KEY","")

    CkRest::ckAddQueryParam(rest,"metadata[order_id]","6735")

    strResponseBody.s = CkRest::ckFullRequestFormUrlEncoded(rest,"POST","/v1/sources/src_1BnETLGswQrCoh0X5KOorXEP")
    If CkRest::ckLastMethodSuccess(rest) <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    jsonResponse.i = CkJsonObject::ckCreate()
    If jsonResponse.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoad(jsonResponse,strResponseBody)

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

    id = CkJsonObject::ckStringOf(jsonResponse,"id")
    object = CkJsonObject::ckStringOf(jsonResponse,"object")
    amount = CkJsonObject::ckIntOf(jsonResponse,"amount")
    client_secret = CkJsonObject::ckStringOf(jsonResponse,"client_secret")
    created = CkJsonObject::ckIntOf(jsonResponse,"created")
    currency = CkJsonObject::ckStringOf(jsonResponse,"currency")
    flow = CkJsonObject::ckStringOf(jsonResponse,"flow")
    livemode = CkJsonObject::ckBoolOf(jsonResponse,"livemode")
    metadataOrder_id = CkJsonObject::ckStringOf(jsonResponse,"metadata.order_id")
    ownerAddress = CkJsonObject::ckIsNullOf(jsonResponse,"owner.address")
    ownerEmail = CkJsonObject::ckStringOf(jsonResponse,"owner.email")
    ownerName = CkJsonObject::ckIsNullOf(jsonResponse,"owner.name")
    ownerPhone = CkJsonObject::ckIsNullOf(jsonResponse,"owner.phone")
    ownerVerified_address = CkJsonObject::ckIsNullOf(jsonResponse,"owner.verified_address")
    ownerVerified_email = CkJsonObject::ckIsNullOf(jsonResponse,"owner.verified_email")
    ownerVerified_name = CkJsonObject::ckIsNullOf(jsonResponse,"owner.verified_name")
    ownerVerified_phone = CkJsonObject::ckIsNullOf(jsonResponse,"owner.verified_phone")
    receiverAddress = CkJsonObject::ckStringOf(jsonResponse,"receiver.address")
    receiverAmount_charged = CkJsonObject::ckIntOf(jsonResponse,"receiver.amount_charged")
    receiverAmount_received = CkJsonObject::ckIntOf(jsonResponse,"receiver.amount_received")
    receiverAmount_returned = CkJsonObject::ckIntOf(jsonResponse,"receiver.amount_returned")
    receiverRefund_attributes_method = CkJsonObject::ckStringOf(jsonResponse,"receiver.refund_attributes_method")
    receiverRefund_attributes_status = CkJsonObject::ckStringOf(jsonResponse,"receiver.refund_attributes_status")
    statement_descriptor = CkJsonObject::ckIsNullOf(jsonResponse,"statement_descriptor")
    status = CkJsonObject::ckStringOf(jsonResponse,"status")
    type = CkJsonObject::ckStringOf(jsonResponse,"type")
    usage = CkJsonObject::ckStringOf(jsonResponse,"usage")
    bitcoinAddress = CkJsonObject::ckStringOf(jsonResponse,"bitcoin.address")
    bitcoinAmount = CkJsonObject::ckIntOf(jsonResponse,"bitcoin.amount")
    bitcoinAmount_charged = CkJsonObject::ckIntOf(jsonResponse,"bitcoin.amount_charged")
    bitcoinAmount_received = CkJsonObject::ckIntOf(jsonResponse,"bitcoin.amount_received")
    bitcoinAmount_returned = CkJsonObject::ckIntOf(jsonResponse,"bitcoin.amount_returned")
    bitcoinUri = CkJsonObject::ckStringOf(jsonResponse,"bitcoin.uri")


    CkRest::ckDispose(rest)
    CkJsonObject::ckDispose(jsonResponse)


    ProcedureReturn
EndProcedure

Sample JSON Response Body

{
  "id": "src_1BnETLGswQrCoh0X5KOorXEP",
  "object": "source",
  "amount": 1000,
  "client_secret": "src_client_secret_CBbgdvc1AflN5jN0wQevA2jA",
  "created": 1516662783,
  "currency": "usd",
  "flow": "receiver",
  "livemode": false,
  "metadata": {
    "order_id": "6735"
  },
  "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"
  }
}