Perl script monitors payments and feedback in eBay sales

eBay Can't Add

You might not realize that some people out there actually add up the individual line items of a computer-generated invoice and check whether the bottom line is right. But, I must confess, sometimes I cannot resist – especially for the monthly eBay invoice when just four items are listed, as in Figure 4.

Figure 4: On eBay, 4.40 + 0.45 + 1.00 + 0.39 does not come to $6.24, but $6.25.

Every second grader with a calculator could verify in a breeze that 4.40 + 0.45 + 1.00 + 0.39 adds up to the total sum of $6.24. Yet, eBay's Java jockeys are apparently not aware of the article on floating-point arithmetic that every programmer should read [2]. Otherwise, they'd realized that CPUs save floating-point numbers inaccurately; for that reason, astonishing rounding errors can arise during addition.

That explains why eBay brazenly charged me $6.25, although the total sum for the line items should, without a doubt, have come to $6.24. I had already called into the customer service center a while ago on a different issue and spent a half hour talking to a representative from overseas to report a discrepancy of a few cents. I will save this one-cent complaint for a very special day.


The script in Listing 2 helps to automatically conduct this audit every month. It relies on the official eBay API, identifying itself with a token for the eBay web service and retrieving the previous month's invoice as an XML document. The line items are found there under the NetDetailAmount tag, as is the total amount under InvoiceBalance. The pipelined invoice-check in Listing 3 is then able to check whether eBay calculated the sum of the line items correctly (Figure 5).

Listing 2



Listing 3



Figure 5: Two scripts fetch the last eBay invoice and check its veracity.

Key to the Kingdom of Data

An application that reads or writes eBay user data must identify itself to the platform with a token. To accomplish this, the developer must register with the eBay Developers Program and enter an application name. In the normal flow for a smartphone app, for example, the user would be guided through the login process on eBay, and, upon confirmation, receive a token that the app can use going forward. If developers only need a token for test purposes and for their own account, they can instead click the Sign in to Production button on the eBay Developer Program sign-up page and receive a token this way (Figure 6) [3].

Figure 6: Developers can get a token for their own eBay account for test purposes.

This token is then valid for the account actually in live production, as opposed to the sandbox in which developers can test out their apps until they are sure that they are ready for production (Figure 7).

Figure 7: After login, eBay asks whether the developer really trusts their app.

Requests for personal data then require the token to be included, embedded in the RequesterCredentials tag in the request's XML (see Listing 2, line 35). It consists of an 872-character hex string that must be placed between the eBayAuthToken tags without line breaks.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95