Sample code for 30+ languages & platforms
Unicode C++ 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 Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkJsonObjectW.h>
#include <CkHttpRequestW.h>

void ChilkatSample(void)
    {
    bool success = 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.
    CkHttpW http;
    http.put_AuthToken(L"SANDBOX_ACCESS_TOKEN");
    CkHttpResponseW resp;

    http.SetUrlVar(L"id",L"DISPUTE_ID");

    success = http.HttpNoBody(L"GET",L"https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}",resp);
    if (success != true) {
        wprintf(L"No HTTP response: %s\n",http.lastErrorText());
        return;
    }

    if ((resp.get_StatusCode() < 200) || (resp.get_StatusCode() >= 300)) {
        CkJsonObjectW errorInfo;
        errorInfo.Load(resp.bodyStr());
        wprintf(L"HTTP %d %s %s\n",resp.get_StatusCode(),errorInfo.stringOf(L"name"),errorInfo.stringOf(L"details[0].issue"));
        wprintf(L"PayPal debug ID: %s\n",errorInfo.stringOf(L"debug_id"));
        return;
    }

    CkJsonObjectW result;
    bool parsedResult = result.Load(resp.bodyStr());
    if (parsedResult != true) {
        wprintf(L"Expected a JSON response; HTTP %d\n",resp.get_StatusCode());
        return;
    }

    bool canSubmit = false;
    int linkIndex = 0;
    while ((linkIndex < result.SizeOfArray(L"links"))) {
        result.put_I(linkIndex);
        if (result.StringOfEquals(L"links[i].rel",L"provide_evidence",true) == true) {
            canSubmit = true;
        }

        linkIndex = linkIndex + 1;
    }

    bool requested = false;
    int i = 0;
    while ((i < result.SizeOfArray(L"evidences"))) {
        result.put_I(i);
        if ((result.StringOfEquals(L"evidences[i].evidence_type",L"PROOF_OF_FULFILLMENT",true) == true) && (result.StringOfEquals(L"evidences[i].source",L"REQUESTED_FROM_SELLER",true) == true)) {
            requested = true;
        }

        i = i + 1;
    }

    if ((canSubmit != true) || (requested != true)) {
        wprintf(L"PayPal is not requesting seller fulfillment evidence for this case.\n");
        return;
    }

    CkJsonObjectW body;
    body.UpdateString(L"evidences[0].evidence_type",L"PROOF_OF_FULFILLMENT");
    body.UpdateString(L"evidences[0].evidence_info.tracking_info[0].carrier_name",L"FEDEX");
    body.UpdateString(L"evidences[0].evidence_info.tracking_info[0].tracking_number",L"123456789012");
    body.UpdateString(L"evidences[0].notes",L"The attached carrier receipt corresponds to this shipment.");
    CkHttpRequestW upload;
    upload.put_HttpVerb(L"POST");
    upload.put_ContentType(L"multipart/form-data");
    success = upload.AddStringForUpload2(L"input",L"",body.emit(),L"utf-8",L"application/json");
    if (success != true) {
        wprintf(L"%s\n",upload.lastErrorText());
        return;
    }

    success = upload.AddFileForUpload2(L"file1",L"carrier-receipt.pdf",L"application/pdf");
    if (success != true) {
        wprintf(L"%s\n",upload.lastErrorText());
        return;
    }

    success = http.HttpReq(L"https://api-m.sandbox.paypal.com/v1/customer/disputes/{$id}/provide-evidence",upload,resp);
    if (success != true) {
        wprintf(L"No HTTP response: %s\n",http.lastErrorText());
        return;
    }

    if ((resp.get_StatusCode() < 200) || (resp.get_StatusCode() >= 300)) {
        CkJsonObjectW submitError;
        submitError.Load(resp.bodyStr());
        wprintf(L"HTTP %d %s %s\n",resp.get_StatusCode(),submitError.stringOf(L"name"),submitError.stringOf(L"details[0].issue"));
        wprintf(L"PayPal debug ID: %s\n",submitError.stringOf(L"debug_id"));
        return;
    }

    wprintf(L"PayPal accepted the evidence.\n");
    }