Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loBody
LOCAL loErrorInfo
LOCAL loResult
LOCAL lnParsed
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')
* 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.
loHttp.SetUrlVar("id","INVOICE_ID")
loHttp.SetRequestHeader("Prefer","return=representation")
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateString("detail.currency_code","USD")
loBody.UpdateString("detail.payment_term.term_type","NET_30")
loBody.UpdateString("primary_recipients[0].billing_info.email_address","buyer@example.com")
loBody.UpdateString("items[0].name","Equipment inspection")
loBody.UpdateString("items[0].quantity","3")
loBody.UpdateString("items[0].unit_amount.currency_code","USD")
loBody.UpdateString("items[0].unit_amount.value","45.00")
lnSuccess = loHttp.HttpJson("PUT","https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}",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
loResult = CreateObject('Chilkat.JsonObject')
lnParsed = loResult.Load(loResp.BodyStr)
IF (lnParsed <> 1) THEN
? "Expected a JSON response; HTTP " + STR(loResp.StatusCode)
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loErrorInfo
RELEASE loResult
CANCEL
ENDIF
? "ID: " + loResult.StringOf("id")
? "Status: " + loResult.StringOf("status")
? "New total: " + loResult.StringOf("amount.value")
? "Currency: " + loResult.StringOf("amount.currency_code")
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loErrorInfo
RELEASE loResult