Xbase++ Requires Chilkat v11.0.0+
Xbase++
PayPal: Send a draft invoice
See more PayPal Examples
Send a draft to its sandbox recipient. PayPal can accept delivery for later when the issue date is in the future. After an uncertain response, look up the invoice before trying again.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL oBody
LOCAL oErrorInfo
nSuccess := 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.
oHttp := CreateObject("Chilkat.Http")
oHttp:AuthToken := "SANDBOX_ACCESS_TOKEN"
oResp := CreateObject("Chilkat.HttpResponse")
// The invoice already exists as a draft. Sending is the separate step that notifies
// the recipient.
oHttp:SetUrlVar("id", "INVOICE_ID")
oBody := CreateObject("Chilkat.JsonObject")
oBody:UpdateBool("send_to_recipient", 1)
oBody:UpdateBool("send_to_invoicer", 0)
nSuccess := oHttp:HttpJson("POST", "https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/send", oBody, "application/json", oResp)
IF (nSuccess != 1)
? "No HTTP response: " + oHttp:LastErrorText
oHttp:destroy()
oResp:destroy()
oBody:destroy()
RETURN
ENDIF
IF ((oResp:StatusCode < 200) .OR. (oResp:StatusCode >= 300))
oErrorInfo := CreateObject("Chilkat.JsonObject")
oErrorInfo:Load(oResp:BodyStr)
? "HTTP " + Str(oResp:StatusCode) + " " + oErrorInfo:StringOf("name") + " " + oErrorInfo:StringOf("details[0].issue")
? "PayPal debug ID: " + oErrorInfo:StringOf("debug_id")
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oErrorInfo:destroy()
RETURN
ENDIF
? "Send request accepted; HTTP " + Str(oResp:StatusCode)
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oErrorInfo:destroy()