Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.0.0+

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.

PayPal documentation

Chilkat Visual FoxPro Downloads

Visual FoxPro
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')

*  The invoice already exists as a draft. Sending is the separate step that notifies
*  the recipient.

loHttp.SetUrlVar("id","INVOICE_ID")
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateBool("send_to_recipient",1)
loBody.UpdateBool("send_to_invoicer",0)

lnSuccess = loHttp.HttpJson("POST","https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/send",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

? "Send request accepted; HTTP " + STR(loResp.StatusCode)

RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loErrorInfo