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

PayPal: Submit proof of fulfillment for a dispute

See more PayPal Examples

Inspect the actions and evidence requested for a selected dispute. When PayPal requests proof of fulfillment from the seller, attach the matching carrier receipt PDF with tracking details in a multipart request. Replace the file and tracking number with those for this case.

PayPal documentation

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Resp
oleobject loo_ErrorInfo
oleobject loo_Result
long li_ParsedResult
long li_CanSubmit
long li_LinkIndex
long li_Requested
long i
oleobject loo_Body
oleobject loo_Upload
oleobject loo_SubmitError

li_Success = 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.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Http.AuthToken = "SANDBOX_ACCESS_TOKEN"
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

loo_Http.SetUrlVar("id","DISPUTE_ID")

li_Success = loo_Http.HttpNoBody("GET","https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}",loo_Resp)
if li_Success <> 1 then
    Write-Debug "No HTTP response: " + loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Resp
    return
end if

if (loo_Resp.StatusCode < 200) OR (loo_Resp.StatusCode >= 300) then
    loo_ErrorInfo = create oleobject
    li_rc = loo_ErrorInfo.ConnectToNewObject("Chilkat.JsonObject")

    loo_ErrorInfo.Load(loo_Resp.BodyStr)
    Write-Debug "HTTP " + string(loo_Resp.StatusCode) + " " + loo_ErrorInfo.StringOf("name") + " " + loo_ErrorInfo.StringOf("details[0].issue")
    Write-Debug "PayPal debug ID: " + loo_ErrorInfo.StringOf("debug_id")
    destroy loo_Http
    destroy loo_Resp
    destroy loo_ErrorInfo
    return
end if

loo_Result = create oleobject
li_rc = loo_Result.ConnectToNewObject("Chilkat.JsonObject")

li_ParsedResult = loo_Result.Load(loo_Resp.BodyStr)
if li_ParsedResult <> 1 then
    Write-Debug "Expected a JSON response; HTTP " + string(loo_Resp.StatusCode)
    destroy loo_Http
    destroy loo_Resp
    destroy loo_ErrorInfo
    destroy loo_Result
    return
end if

li_CanSubmit = 0
li_LinkIndex = 0
do while (li_LinkIndex < loo_Result.SizeOfArray("links"))
    loo_Result.I = li_LinkIndex
    if loo_Result.StringOfEquals("links[i].rel","provide_evidence",1) = 1 then
        li_CanSubmit = 1
    end if

    li_LinkIndex = li_LinkIndex + 1
loop
li_Requested = 0
i = 0
do while (i < loo_Result.SizeOfArray("evidences"))
    loo_Result.I = i
    if (loo_Result.StringOfEquals("evidences[i].evidence_type","PROOF_OF_FULFILLMENT",1) = 1) AND (loo_Result.StringOfEquals("evidences[i].source","REQUESTED_FROM_SELLER",1) = 1) then
        li_Requested = 1
    end if

    i = i + 1
loop
if (li_CanSubmit <> 1) OR (li_Requested <> 1) then
    Write-Debug "PayPal is not requesting seller fulfillment evidence for this case."
    destroy loo_Http
    destroy loo_Resp
    destroy loo_ErrorInfo
    destroy loo_Result
    return
end if

loo_Body = create oleobject
li_rc = loo_Body.ConnectToNewObject("Chilkat.JsonObject")

loo_Body.UpdateString("evidences[0].evidence_type","PROOF_OF_FULFILLMENT")
loo_Body.UpdateString("evidences[0].evidence_info.tracking_info[0].carrier_name","FEDEX")
loo_Body.UpdateString("evidences[0].evidence_info.tracking_info[0].tracking_number","123456789012")
loo_Body.UpdateString("evidences[0].notes","The attached carrier receipt corresponds to this shipment.")
loo_Upload = create oleobject
li_rc = loo_Upload.ConnectToNewObject("Chilkat.HttpRequest")

loo_Upload.HttpVerb = "POST"
loo_Upload.ContentType = "multipart/form-data"
li_Success = loo_Upload.AddStringForUpload2("input","",loo_Body.Emit(),"utf-8","application/json")
if li_Success <> 1 then
    Write-Debug loo_Upload.LastErrorText
    destroy loo_Http
    destroy loo_Resp
    destroy loo_ErrorInfo
    destroy loo_Result
    destroy loo_Body
    destroy loo_Upload
    return
end if

li_Success = loo_Upload.AddFileForUpload2("file1","carrier-receipt.pdf","application/pdf")
if li_Success <> 1 then
    Write-Debug loo_Upload.LastErrorText
    destroy loo_Http
    destroy loo_Resp
    destroy loo_ErrorInfo
    destroy loo_Result
    destroy loo_Body
    destroy loo_Upload
    return
end if

li_Success = loo_Http.HttpReq("https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence",loo_Upload,loo_Resp)
if li_Success <> 1 then
    Write-Debug "No HTTP response: " + loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Resp
    destroy loo_ErrorInfo
    destroy loo_Result
    destroy loo_Body
    destroy loo_Upload
    return
end if

if (loo_Resp.StatusCode < 200) OR (loo_Resp.StatusCode >= 300) then
    loo_SubmitError = create oleobject
    li_rc = loo_SubmitError.ConnectToNewObject("Chilkat.JsonObject")

    loo_SubmitError.Load(loo_Resp.BodyStr)
    Write-Debug "HTTP " + string(loo_Resp.StatusCode) + " " + loo_SubmitError.StringOf("name") + " " + loo_SubmitError.StringOf("details[0].issue")
    Write-Debug "PayPal debug ID: " + loo_SubmitError.StringOf("debug_id")
    destroy loo_Http
    destroy loo_Resp
    destroy loo_ErrorInfo
    destroy loo_Result
    destroy loo_Body
    destroy loo_Upload
    destroy loo_SubmitError
    return
end if

Write-Debug "PayPal accepted the evidence."


destroy loo_Http
destroy loo_Resp
destroy loo_ErrorInfo
destroy loo_Result
destroy loo_Body
destroy loo_Upload
destroy loo_SubmitError