DataFlex Requires Chilkat v11.0.0+
DataFlex
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.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vResp
Handle hoResp
Variant vBody
Handle hoBody
Handle hoErrorInfo
String sTemp1
String sTemp2
Integer iTemp1
Integer iTemp2
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComAuthToken Of hoHttp To "SANDBOX_ACCESS_TOKEN"
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
// Replace both PayPal IDs and the sample tracking number with values from the same
// shipped order.
Get ComSetUrlVar Of hoHttp "id" "ORDER_ID" To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoBody
If (Not(IsComObjectCreated(hoBody))) Begin
Send CreateComObject of hoBody
End
Get ComUpdateString Of hoBody "capture_id" "CAPTUREID" To iSuccess
Get ComUpdateString Of hoBody "tracking_number" "1Z999AA10123456784" To iSuccess
Get ComUpdateString Of hoBody "carrier" "UPS" To iSuccess
Get ComUpdateBool Of hoBody "notify_payer" False To iSuccess
Get pvComObject of hoBody to vBody
Get pvComObject of hoResp to vResp
Get ComHttpJson Of hoHttp "POST" "https://api-m.sandbox.paypal.com/v2/checkout/orders/{$id}/track" vBody "application/json" vResp To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln "No HTTP response: " sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Get ComStatusCode Of hoResp To iTemp2
If ((iTemp1 < 200) Or (iTemp2 >= 300)) Begin
Get Create (RefClass(cComChilkatJsonObject)) To hoErrorInfo
If (Not(IsComObjectCreated(hoErrorInfo))) Begin
Send CreateComObject of hoErrorInfo
End
Get ComBodyStr Of hoResp To sTemp1
Get ComLoad Of hoErrorInfo sTemp1 To iSuccess
Get ComStatusCode Of hoResp To iTemp1
Get ComStringOf Of hoErrorInfo "name" To sTemp1
Get ComStringOf Of hoErrorInfo "details[0].issue" To sTemp2
Showln "HTTP " iTemp1 " " sTemp1 " " sTemp2
Get ComStringOf Of hoErrorInfo "debug_id" To sTemp1
Showln "PayPal debug ID: " sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln "PayPal accepted tracking for this order. HTTP " iTemp1
End_Procedure