Xbase++ Requires Chilkat v11.0.0+
Xbase++
PayPal: Revise a draft invoice from its full billing record
See more PayPal Examples
PUT replaces the invoice. This example revises the quantity on the simple two-inspection draft to three. Rebuild the complete editable document from your billing record; omitted items, terms or recipients can be lost. Do not use this body for an unrelated 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")
// Use only the ID of the matching draft from the create example, while it is still a
// draft. Preserve all of your real draft fields, including any custom invoice number.
oHttp:SetUrlVar("id", "INVOICE_ID")
oHttp:SetRequestHeader("Prefer", "return=representation")
oBody := CreateObject("Chilkat.JsonObject")
oBody:UpdateString("detail.currency_code", "USD")
oBody:UpdateString("detail.payment_term.term_type", "NET_30")
oBody:UpdateString("primary_recipients[0].billing_info.email_address", "buyer@example.com")
oBody:UpdateString("items[0].name", "Equipment inspection")
oBody:UpdateString("items[0].quantity", "3")
oBody:UpdateString("items[0].unit_amount.currency_code", "USD")
oBody:UpdateString("items[0].unit_amount.value", "45.00")
nSuccess := oHttp:HttpJson("PUT", "https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}", 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
? "ID: " + oResult:StringOf("id")
? "Status: " + oResult:StringOf("status")
? "New total: " + oResult:StringOf("amount.value")
? "Currency: " + oResult:StringOf("amount.currency_code")
oHttp:destroy()
oResp:destroy()
oBody:destroy()
oErrorInfo:destroy()
oResult:destroy()