Automated Invoicing Script

We would like a script to automate the sending of invoices from our BrickLink webstore. Most of the individual pieces of this process already exist as code built for other projects and we would anticipate that this script would simply tie a few of the existing pieces together and implement some additional logic. This script should be written in python to match our existing scripts and is expected to be run via cron every 15 minutes.

The script would work something like this:

[url removed, login to view] to BrickLink and download the orders list. For any orders in the “Pending” or “Updated” status with unsent invoices, invoices will need to be sent.

[url removed, login to view] the priority mail “pin” is selected, or if the order is a domestic shipment over 1 lb use the Priority Mail rate. If the cheapest shipping “pin” is selected, use the cheapest shipping rate from the shipping calculator. If the shipping methods of “warehouse pickup” or “event delivery” are used, no shipping or insurance charges are needed.

[url removed, login to view] domestic buyers, insurance charges should be calculated at $1 per $100. Example, $99.99 and under is $1, $100-$199.99 is $2, $200-$299.99 is $3, etc. For international buyers, insurance is $1 for $20 and under, then $2 per $100 afterward. Example, $20.01-$99.99 is $2, $100.01-$199.99 is $4, $200.01-$299.99 is $6, etc.

[url removed, login to view] with more than 30 lots and an Order Total (merchandise only) of less than $100 have lot charges of $0.10 per lot above 30 would be added to the “Additional Charges 1” field. Examples, a 52 lot $25 order would have $2.20 in lot fees, but a 52 lot $125 order would have $0 in lot fees. A note (exact text will be provided) about lot fees and the lot fee total would be inserted into the invoice text if the lot fees are greater than $0.

[url removed, login to view] buyers in the state of Ohio only, the “Additional Charges 2” field would need to be calculated at 6.5% of the Order Total (merchandise only).

[url removed, login to view] the order comments to see if the buyer does not want insurance if not already done in step 4.

[url removed, login to view] the only comments are “Thank you” type comments, or if there are no comments go ahead and send the invoice.

[url removed, login to view] the payment type is “Google Wallet” or if there are other comments send an email to a specified email address with the order number as the subject and the order comments in the body so that the invoice can be sent manually.