PureBasic Requires Chilkat v11.7.0+
PureBasic
Stripe: Identify the payment for a paid invoice
See more Stripe Examples
List the payments allocated to an invoice and identify a paid charge or PaymentIntent for refund.
Stripe documentation and cURL example
Chilkat PureBasic Downloads
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttpCurl.pb"
Procedure ChilkatExample()
success.i = 0
; Requires an unlocked Chilkat bundle. See Global Unlock Sample.
; Supply a restricted sandbox key from merchant-controlled configuration.
apiKey.s = "YOUR_STRIPE_TEST_KEY"
curl.i = CkHttpCurl::ckCreate()
If curl.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
cmd.i = CkStringBuilder::ckCreate()
If cmd.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
replaced.i
invoiceId.s = "in_FROM_BILLING_RECORD"
pageSuffix.i = CkStringBuilder::ckCreate()
If pageSuffix.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
more.i = 1
cursor.s = ""
While (more = 1)
; curl -X GET "https://api.stripe.com/v1/invoice_payments?invoice={invoiceId}&limit=100" \
; -u "$STRIPE_API_KEY:" \
; -H "Stripe-Version: 2026-10-28.endive"
CkStringBuilder::ckSetString(cmd,"curl -X GET " + Chr(34) + "https://api.stripe.com/v1/invoice_payments?invoice=@ID@&limit=100@CURSOR@" + Chr(34))
CkStringBuilder::ckAppend(cmd," -u " + Chr(34) + "@KEY@:" + Chr(34))
CkStringBuilder::ckAppend(cmd," -H " + Chr(34) + "Stripe-Version: 2026-10-28.endive" + Chr(34))
replaced = CkStringBuilder::ckReplace(cmd,"@CURSOR@",CkStringBuilder::ckGetAsString(pageSuffix))
replaced = CkStringBuilder::ckReplace(cmd,"@ID@",invoiceId)
replaced = CkStringBuilder::ckReplace(cmd,"@KEY@",apiKey)
success = CkHttpCurl::ckDoYourThing(curl,CkStringBuilder::ckGetAsString(cmd))
If success <> 1
Debug "No HTTP response. Chilkat failure code: " + Str(CkHttpCurl::ckFailReason(curl))
CkHttpCurl::ckDispose(curl)
CkStringBuilder::ckDispose(cmd)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(pageSuffix)
ProcedureReturn
EndIf
success = CkHttpCurl::ckGetResponseJson(curl,json)
If (CkHttpCurl::ckStatusCode(curl) <> 200) OR (success <> 1)
Debug "Stripe HTTP " + Str(CkHttpCurl::ckStatusCode(curl)) + " Request-Id: " + CkHttpCurl::ckGetResponseHeaderField(curl,"Request-Id")
If success = 1
Debug CkJsonObject::ckStringOf(json,"error.message")
EndIf
CkHttpCurl::ckDispose(curl)
CkStringBuilder::ckDispose(cmd)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(pageSuffix)
ProcedureReturn
EndIf
i.i = 0
count.i = CkJsonObject::ckSizeOfArray(json,"data")
While (i < count)
CkJsonObject::setCkI(json, i)
Debug CkJsonObject::ckStringOf(json,"data[i].id") + " | " + CkJsonObject::ckStringOf(json,"data[i].status") + " | " + CkJsonObject::ckStringOf(json,"data[i].amount_paid") + " | " + CkJsonObject::ckStringOf(json,"data[i].currency") + " | " + CkJsonObject::ckStringOf(json,"data[i].payment.type")
If CkJsonObject::ckStringOf(json,"data[i].payment.type") = "payment_intent"
Debug " PaymentIntent: " + CkJsonObject::ckStringOf(json,"data[i].payment.payment_intent")
EndIf
If CkJsonObject::ckStringOf(json,"data[i].payment.type") = "charge"
Debug " Charge: " + CkJsonObject::ckStringOf(json,"data[i].payment.charge")
EndIf
i = i + 1
Wend
more = CkJsonObject::ckBoolOf(json,"has_more")
If more = 1
next.s = CkJsonObject::ckStringOf(json,"data[i].id")
If (count < 1) OR (next = "") OR (next = cursor)
Debug "Invalid pagination cursor."
CkHttpCurl::ckDispose(curl)
CkStringBuilder::ckDispose(cmd)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(pageSuffix)
ProcedureReturn
EndIf
cursor = next
CkStringBuilder::ckSetString(pageSuffix,"&starting_after=")
CkStringBuilder::ckAppend(pageSuffix,cursor)
EndIf
Wend
; Select the paid allocation belonging to the order before issuing its refund.
CkHttpCurl::ckDispose(curl)
CkStringBuilder::ckDispose(cmd)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(pageSuffix)
ProcedureReturn
EndProcedure