Xbase++ Requires Chilkat v11.0.0+
Xbase++
PayPal: Get the next invoice number
See more PayPal Examples
Read invoice_number for use as the customer-facing number on a draft. It is distinct from the PayPal invoice ID used in API paths. If you do not need to choose a number, omit it when creating the invoice.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL oBody
LOCAL oErrorInfo
LOCAL oResult
LOCAL nParsed
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 customer sees the invoice number. Subsequent REST calls need the invoice ID
// instead.
oBody := CreateObject("Chilkat.JsonObject")
nSuccess := oHttp:HttpJson("POST", "https://api-m.sandbox.paypal.com/v2/invoicing/generate-next-invoice-number", 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
oResult := CreateObject("Chilkat.JsonObject")
nParsed := oResult:Load(oResp:BodyStr)
IF (nParsed != 1)
? "Expected a JSON response; HTTP " + Str(oResp:StatusCode)
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oErrorInfo:destroy()
oResult:destroy()
RETURN
ENDIF
? "Next number: " + oResult:StringOf("invoice_number")
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oErrorInfo:destroy()
oResult:destroy()