Package Tracking

Server-side configuration

1. Place transaction

  1. Node.js
const saleRequest = {
    amount: req.body.amount,
    paymentMethodNonce: req.body.nonce,
    deviceData: req.body.device_data,
    orderId: "Mapped to PayPal Invoice Number",
    options: {
        submitForSettlement: true,
        paypal: {
            customField: "PayPal custom field",
            description: "Description for PayPal email receipt",
        },
    },
    lineItems: [
        {
            name: "Product",
            kind: "debit",
            quantity: "10.0000",
            unitAmount: "9.5000",
            totalAmount: "95.0000",
            productCode: "54321",
            upcCode: "012345678912",
            //New field
            upcType: "UPC-A",
            //New field
            url: "https://example.com",
            //New field
            imageUrl: "https://example.com/product.jpeg", //New field
        }
    ]
};
gateway.transaction.sale(saleRequest, (err, result) => {
    if (err) {
        console.log("Error: " + err);
    } else if (result.success) {
        console.log("Success! Transaction ID: " + result.transaction.id);
    } else {
        console.log("Error: " + result.message);
    }
});

2. Create tracking for transaction after submitting for settlement:

  1. Node.js
function sampleIntegration() {
    // Create a Package Tracking request with optional line items
    let package = {
        carrier: "UPS",
        trackingNumber: "tracking_number_1",
        notifyPayer: true,
        lineItems: [
            // Optionally create line items
            {
                productCode: "ABC 01",
                quantity: "1",
                name: "Product Name",
                description: "Product Description",
                upcCode: "012345678912",
                //New field
                upcType: "UPC-A",
                //New field
                url: "https://example.com",
                //New field
                imageUrl: "https://example.com/product.jpeg",
                //New field
            },
            {
                productCode: "ABC 02",
                quantity: "1",
                name: "Product Name",
                description: "Product Description"
            },
        ],
    };

    // Send the package tracking request for the transaction
    gateway.transaction.packageTracking(
        transactionId,
        package,
        function (err, response) {
            // handle error and response
            id = response.transaction.packages[0].id;
            carrier = response.transaction.packages[0].carrier;
            trackingNumber = response.transaction.packages[0].trackingNumber;
            //The PayPal tracker ID will not be immediately available in response to
            //package_tracking(). But should be there when merchant does a findTransaction
            //request at a later stage.
        }
    );
}

3. Retrieve transactions with package trackers:

  1. Node.js
function retrievePackageTrackers() {
    gateway.transaction.find(response.transaction.id, function (err, transaction) {
        // Get more details of the individual packages like so, replace 0 with the element #:
        id = transaction.packages[0].id;
        carrier = transaction.packages[0].carrier;
        trackingNumber = transaction.packages[0].trackingNumber;
        paypalTrackerId = transaction.packages[0].paypalTrackerId;
        //The PayPal tracker ID will not be immediately available in response to
        //package_tracking(). But should be there when merchant does a findTransaction
        //request at a later stage.
    });
}