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

PayPal: Add shipment tracking to a captured order

See more PayPal Examples

Use the order ID in the URL and the capture ID for this shipment in the body. Send the carrier and tracking number from your shipping record. Set notify_payer according to how your business sends shipping notices.

PayPal documentation

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 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.
    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttp::setCkAuthToken(http, "SANDBOX_ACCESS_TOKEN")
    resp.i = CkHttpResponse::ckCreate()
    If resp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Replace both PayPal IDs and the sample tracking number with values from the same
    ;  shipped order.
    CkHttp::ckSetUrlVar(http,"id","ORDER_ID")
    body.i = CkJsonObject::ckCreate()
    If body.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(body,"capture_id","CAPTUREID")
    CkJsonObject::ckUpdateString(body,"tracking_number","1Z999AA10123456784")
    CkJsonObject::ckUpdateString(body,"carrier","UPS")
    CkJsonObject::ckUpdateBool(body,"notify_payer",0)

    success = CkHttp::ckHttpJson(http,"POST","https://api-m.sandbox.paypal.com/v2/checkout/orders/{$id}/track",body,"application/json",resp)
    If success <> 1
        Debug "No HTTP response: " + CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkHttpResponse::ckDispose(resp)
        CkJsonObject::ckDispose(body)
        ProcedureReturn
    EndIf

    If (CkHttpResponse::ckStatusCode(resp) < 200) OR (CkHttpResponse::ckStatusCode(resp) >= 300)
        errorInfo.i = CkJsonObject::ckCreate()
        If errorInfo.i = 0
            Debug "Failed to create object."
            ProcedureReturn
        EndIf

        CkJsonObject::ckLoad(errorInfo,CkHttpResponse::ckBodyStr(resp))
        Debug "HTTP " + Str(CkHttpResponse::ckStatusCode(resp)) + " " + CkJsonObject::ckStringOf(errorInfo,"name") + " " + CkJsonObject::ckStringOf(errorInfo,"details[0].issue")
        Debug "PayPal debug ID: " + CkJsonObject::ckStringOf(errorInfo,"debug_id")
        CkHttp::ckDispose(http)
        CkHttpResponse::ckDispose(resp)
        CkJsonObject::ckDispose(body)
        CkJsonObject::ckDispose(errorInfo)
        ProcedureReturn
    EndIf

    Debug "PayPal accepted tracking for this order. HTTP " + Str(CkHttpResponse::ckStatusCode(resp))


    CkHttp::ckDispose(http)
    CkHttpResponse::ckDispose(resp)
    CkJsonObject::ckDispose(body)
    CkJsonObject::ckDispose(errorInfo)


    ProcedureReturn
EndProcedure