peter-tanner / AliExpress-Invoice-Downloader

Adds download buttons to the Aliexpress order page (https://www.aliexpress.com/p/order/index.html) and a bulk download button to download all invoices on the order page to save time.
GNU General Public License v3.0
1 stars 0 forks source link

Doesn't work or PEBCAK with Chrome #2

Open nwiek opened 4 months ago

nwiek commented 4 months ago

I'm unable to find the download all invoices button. Tampermonkey says script is running.

Please let me know where I should find the button in more detail.

peter-tanner commented 4 months ago

I havent tested it yet on chrome, i am using firefox 126.0.1 the button should appear as an element fixed to the bottom left corner of the viewport, but i know that rarely the "download invoice" buttons for each part / the "download all invoices" button don't appear, and i need to refresh the page. still not sure what is causing this issue.

nwiek commented 4 months ago

Hi Peter,

Thanks or your reply. I installed FireFox and indeed see the download button. Schermafbeelding 2024-06-27 084849

However the files downloaded are not PDF document but HTML and JScript files. Am I doing something wrong?

invoice_3036086006532935_NodemcuEsp8266.pdf

fbndny commented 2 months ago

Seems to be missing the invoiceId, I fixxed it by replacing the download function with this:

  function downloadInvoice(orderId, name) {
        GM_xmlhttpRequest({
            responseType: 'json',
            method: "GET",
            url: `https://trade.aliexpress.com/ajax/invoice/queryInvoiceIdAjax.htm?orderIds=${orderId}`,
            onload: function (response) {
                const invoiceId = response.response[0];
                const sanitizedFileName = sanitizeFileName(name);
                const url = `https://trade.aliexpress.com/ajax/invoice/invoiceExportAjax.htm?orderId=${orderId}&invoiceId=${invoiceId}&name=${sanitizedFileName}`;
                console.log(url);
                GM_download({
                    url: url,
                    name: `invoice_${orderId}_${sanitizedFileName}.pdf`,
                    onerror: function (error) {
                        console.error("Error downloading:", error);
                    },
                });
            },
            onerror: function (error) {
                console.error("Error downloading:", error);
            },
        });
  }

You also need to add this to the header:

// @grant        GM_xmlhttpRequest

I'm not sure if there may be cases when the additional request returns an array with multiple invoiceIds – won't work with this code. For my testing, using only the index 0 was enough.