PureBasic Requires Chilkat v11.7.0+
PureBasic
Stripe: Issue a full or partial refund
See more Stripe Examples
Issue a partial refund against a selected payment, or refund the remaining amount by omitting the amount field.
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"
; Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
operationId.s = "YOUR_SAVED_OPERATION_UUID"
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
paymentIntent.s = "pi_FROM_SELECTED_PAYMENT"
; The operator selected a partial refund of 500 minor units. Omit the amount field to refund the remaining balance. For a charge ID use charge= instead of payment_intent=.
; curl -X POST "https://api.stripe.com/v1/refunds" \
; -u "$STRIPE_API_KEY:" \
; -H "Stripe-Version: 2026-10-28.endive" \
; -H "Idempotency-Key: {operationId}-refund" \
; -d "payment_intent={paymentIntent}" \
; -d "amount=500"
CkStringBuilder::ckSetString(cmd,"curl -X POST " + Chr(34) + "https://api.stripe.com/v1/refunds" + 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))
CkStringBuilder::ckAppend(cmd," -H " + Chr(34) + "Idempotency-Key: @OP@-refund" + Chr(34))
CkStringBuilder::ckAppend(cmd," -d " + Chr(34) + "payment_intent=@PAYMENT@" + Chr(34))
CkStringBuilder::ckAppend(cmd," -d " + Chr(34) + "amount=500" + Chr(34))
replaced = CkStringBuilder::ckReplace(cmd,"@PAYMENT@",paymentIntent)
replaced = CkStringBuilder::ckReplace(cmd,"@OP@",operationId)
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)
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)
ProcedureReturn
EndIf
Debug "id = " + CkJsonObject::ckStringOf(json,"id")
Debug "status = " + CkJsonObject::ckStringOf(json,"status")
Debug "amount = " + CkJsonObject::ckStringOf(json,"amount")
Debug "currency = " + CkJsonObject::ckStringOf(json,"currency")
; Save this refund ID with the refund request for status checks.
CkHttpCurl::ckDispose(curl)
CkStringBuilder::ckDispose(cmd)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure