Search code examples
phppaypalpaypal-ipnebay-api

PayPal IPN, eBay Multi-Line Order ebay_txn_id = 0


I am building a system to automatically process our PayPal orders through both a website cart and eBay transactions. When an order comes through eBay which is a combined invoice order (multiple items bought at the same time through eBay) the eBay transaction ID (ebay_txn_id) for each item is 0.

I use the eBay transasction ID to gain more information about the order that eBay does not send us and I cannot find any other ID in the IPN that can help with this.

Anyone else have this issue?


Solution

  • The item_number for each cart item in the IPN data is the eBay auction number. You can hit eBay's GetItemTransactions API to pull all of the transactions associated with that particular item/auction.

    Of course, there could be more than one transaction associated with an individual auction, so to ensure you're grabbing the correct data you can use some XPath.

    The eBay transaction data includes the PayPal transaction ID in what it calls "external transaction" data.

    I just recently did all of this in a project of my own, and this is what I used to pull the specific data based on the PayPal transaction ID.

    $DOM = new DOMDocument();
    $DOM->loadXML($GetItemTransactionsResponse);
    $XPath = new DOMXPath($DOM);
    $XPath->registerNamespace("ns","urn:ebay:apis:eBLBaseComponents");
    
    $eBayTransID = $XPath->query("//ns:Transaction[ns:ExternalTransaction/ns:ExternalTransactionID = '" . $txn_id . "']/ns:TransactionID/text()")->item(0)->data;
    $shipping_method = $XPath->query("//ns:Transaction[ns:ExternalTransaction/ns:ExternalTransactionID = '" . $txn_id . "']/ns:ShippingServiceSelected/ns:ShippingService/text()")->item(0)->data;
    $buyer_feedback_score = $XPath->query("//ns:Transaction[ns:ExternalTransaction/ns:ExternalTransactionID = '" . $txn_id . "']/ns:Buyer/ns:FeedbackScore/text()")->item(0)->data;
    

    So the XPath being used there is basically saying "grab this data where the ExternalTransactionID = $txn_id, which is from the PayPal IPN data.

    So it's a few pieces to plug together but it will work nicely for you.