Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
PayPal: Record an external refund against an invoice
See more PayPal Examples
Record USD 5 already returned by bank transfer for a paid invoice. This call does not move money. To refund a PayPal capture, use the Payments v2 capture refund example instead.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loBody
LOCAL loDate
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')
* Record only money already returned outside PayPal. Reconcile first if a previous
* attempt timed out.
loHttp.SetUrlVar("id","INVOICE_ID")
loBody = CreateObject('Chilkat.JsonObject')
loBody.UpdateString("method","BANK_TRANSFER")
loBody.UpdateString("amount.currency_code","USD")
loBody.UpdateString("amount.value","5.00")
* Use the actual date of the transfer; this example records one made today.
loDate = CreateObject('Chilkat.CkDateTime')
loDate.SetFromCurrentSystemTime()
loBody.UpdateString("refund_date",loDate.GetAsIso8601("YYYY-MM-DD",0))
lnSuccess = loHttp.HttpJson("POST","https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/refunds",loBody,"application/json",loResp)
IF (lnSuccess <> 1) THEN
? "No HTTP response: " + loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loDate
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 loDate
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 loDate
RELEASE loErrorInfo
RELEASE loResult
CANCEL
ENDIF
? "Record ID: " + loResult.StringOf("refund_id")
RELEASE loHttp
RELEASE loResp
RELEASE loBody
RELEASE loDate
RELEASE loErrorInfo
RELEASE loResult