Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
PayPal: Cancel a sent, unpaid invoice
See more PayPal Examples
Cancel an unpaid invoice that has already been sent and notify the customer why. For a draft use delete instead. Cancellation does not return funds.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loBody
LOCAL loErrorInfo
lnSuccess = 0
* See Unlock Chilkat before making requests.
* For the merchant's internal backoffice application. Load the sandbox token
* from the merchant's credential store. Keep it out of publicly distributed apps.
* See Get a PayPal access token.
loHttp = CreateObject('Chilkat.Http')
loHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
loResp = CreateObject('Chilkat.HttpResponse')
* This cancels a sent, unpaid invoice. It does not send a refund.
loHttp.SetUrlVar("id","INVOICE_ID")
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateString("subject","Inspection invoice canceled")
loBody.UpdateString("note","The inspection was canceled before work began.")
loBody.UpdateBool("send_to_recipient",1)
lnSuccess = loHttp.HttpJson("POST","https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/cancel",loBody,"application/json",loResp)
IF (lnSuccess <> 1) THEN
? "No HTTP response: " + loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
RELEASE loBody
CANCEL
ENDIF
IF ((loResp.StatusCode < 200) OR (loResp.StatusCode >= 300)) THEN
loErrorInfo = CreateObject('Chilkat.JsonObject')
loErrorInfo.Load(loResp.BodyStr)
? "HTTP " + STR(loResp.StatusCode) + " " + loErrorInfo.StringOf("name") + " " + loErrorInfo.StringOf("details[0].issue")
? "PayPal debug ID: " + loErrorInfo.StringOf("debug_id")
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loErrorInfo
CANCEL
ENDIF
? "Cancellation accepted; HTTP " + STR(loResp.StatusCode)
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loErrorInfo