AutoIt Requires Chilkat v11.0.0+
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; 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 = ObjCreate("Chilkat.Http")
$oHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
$oResp = ObjCreate("Chilkat.HttpResponse")
; Record only money already returned outside PayPal. Reconcile first if a previous
; attempt timed out.
$oHttp.SetUrlVar("id","INVOICE_ID")
$oBody = ObjCreate("Chilkat.JsonObject")
$oBody.UpdateString("method","BANK_TRANSFER")
$oBody.UpdateString("amount.currency_code","USD")
$oBody.UpdateString("amount.value","5.00")
; Use the actual date of the transfer; this example records one made today.
$oDate = ObjCreate("Chilkat.CkDateTime")
$oDate.SetFromCurrentSystemTime()
$oBody.UpdateString("refund_date",$oDate.GetAsIso8601("YYYY-MM-DD",False))
$bSuccess = $oHttp.HttpJson("POST","https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/refunds",$oBody,"application/json",$oResp)
If ($bSuccess <> True) Then
ConsoleWrite("No HTTP response: " & $oHttp.LastErrorText & @CRLF)
Exit
EndIf
If (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
$oErrorInfo = ObjCreate("Chilkat.JsonObject")
$oErrorInfo.Load($oResp.BodyStr)
ConsoleWrite("HTTP " & $oResp.StatusCode & " " & $oErrorInfo.StringOf("name") & " " & $oErrorInfo.StringOf("details[0].issue") & @CRLF)
ConsoleWrite("PayPal debug ID: " & $oErrorInfo.StringOf("debug_id") & @CRLF)
Exit
EndIf
$oResult = ObjCreate("Chilkat.JsonObject")
Local $bParsed = $oResult.Load($oResp.BodyStr)
If ($bParsed <> True) Then
ConsoleWrite("Expected a JSON response; HTTP " & $oResp.StatusCode & @CRLF)
Exit
EndIf
ConsoleWrite("Record ID: " & $oResult.StringOf("refund_id") & @CRLF)