amazon-orders 4.9.4__tar.gz → 4.9.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/CHANGELOG.md +23 -1
  2. {amazon_orders-4.9.4/amazon_orders.egg-info → amazon_orders-4.9.6}/PKG-INFO +8 -9
  3. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/README.md +6 -5
  4. {amazon_orders-4.9.4 → amazon_orders-4.9.6/amazon_orders.egg-info}/PKG-INFO +8 -9
  5. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazon_orders.egg-info/SOURCES.txt +4 -0
  6. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazon_orders.egg-info/requires.txt +1 -3
  7. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/__init__.py +1 -1
  8. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/cli.py +104 -1
  9. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/constants.py +15 -0
  10. amazon_orders-4.9.6/amazonorders/entity/invoice_pdf.py +58 -0
  11. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/order.py +2 -1
  12. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/parsable.py +1 -1
  13. amazon_orders-4.9.6/amazonorders/entity/prime_payment.py +108 -0
  14. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/recipient.py +15 -2
  15. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/forms.py +8 -1
  16. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/orders.py +104 -17
  17. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/output.py +58 -0
  18. amazon_orders-4.9.6/amazonorders/prime.py +108 -0
  19. amazon_orders-4.9.6/amazonorders/py.typed +0 -0
  20. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/selectors.py +60 -7
  21. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/session.py +20 -17
  22. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/transactions.py +2 -1
  23. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/util.py +18 -4
  24. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/pyproject.toml +4 -3
  25. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/tests/testcase.py +6 -4
  26. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/LICENSE +0 -0
  27. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/MANIFEST.in +0 -0
  28. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazon_orders.egg-info/dependency_links.txt +0 -0
  29. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazon_orders.egg-info/entry_points.txt +0 -0
  30. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazon_orders.egg-info/top_level.txt +0 -0
  31. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/banner.txt +0 -0
  32. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/conf.py +0 -0
  33. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/contrib/__init__.py +0 -0
  34. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/contrib/browser/__init__.py +0 -0
  35. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/contrib/browser/playwright.py +0 -0
  36. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/contrib/waf/__init__.py +0 -0
  37. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/contrib/waf/anticaptcha.py +0 -0
  38. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/contrib/waf/base.py +0 -0
  39. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/contrib/waf/capsolver.py +0 -0
  40. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/contrib/waf/twocaptcha.py +0 -0
  41. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/__init__.py +0 -0
  42. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/family_member.py +0 -0
  43. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/gift_card_activity.py +0 -0
  44. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/item.py +0 -0
  45. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/seller.py +0 -0
  46. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/shipment.py +0 -0
  47. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/tracking.py +0 -0
  48. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/entity/transaction.py +0 -0
  49. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/exception.py +0 -0
  50. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/gift_cards.py +0 -0
  51. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/paging.py +0 -0
  52. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/amazonorders/region_data.py +0 -0
  53. {amazon_orders-4.9.4 → amazon_orders-4.9.6}/setup.cfg +0 -0
@@ -4,7 +4,29 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased](https://github.com/alexdlaird/amazon-orders/compare/4.9.4...HEAD)
7
+ ## [Unreleased](https://github.com/alexdlaird/amazon-orders/compare/4.9.6...HEAD)
8
+
9
+ ## [4.9.6](https://github.com/alexdlaird/amazon-orders/compare/4.9.5...4.9.6) - 2026-10-21
10
+
11
+ ### Added
12
+
13
+ - `AmazonPrime`, the `PrimePayment` entity, and the `prime-payments` CLI command, for the Prime membership payment history.
14
+
15
+ ### Fixed
16
+
17
+ - Bug fixes and stability improvements.
18
+
19
+ ## [4.9.5](https://github.com/alexdlaird/amazon-orders/compare/4.9.4...4.9.5) - 2026-10-20
20
+
21
+ ### Added
22
+
23
+ - `InvoicePdf` entity, `AmazonOrders.get_invoice_pdfs()`, `parse_invoice_pdfs()`, and `download_invoice_pdf()`, and the `invoice-pdfs` CLI command (with `--download`), for an Order's invoice PDFs, including credit notes.
24
+ - Parsing of `amazon.de` in English, with British English labels ("Postage & Packing", "Estimated VAT").
25
+
26
+ ### Fixed
27
+
28
+ - `Recipient.address` keeps every line of the address, including the country.
29
+ - Bug fixes and stability improvements.
8
30
 
9
31
  ## [4.9.4](https://github.com/alexdlaird/amazon-orders/compare/4.9.3...4.9.4) - 2026-10-19
10
32
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amazon-orders
3
- Version: 4.9.4
3
+ Version: 4.9.6
4
4
  Summary: A Python library (and CLI) for Amazon order history, line items, and transactions
5
5
  Author-email: Alex Laird <contact@alexlaird.com>
6
6
  Maintainer-email: Alex Laird <contact@alexlaird.com>
@@ -31,7 +31,7 @@ License-File: LICENSE
31
31
  Requires-Dist: click>=7.1
32
32
  Requires-Dist: requests>=2.23
33
33
  Requires-Dist: Pillow>=9.0.1
34
- Requires-Dist: beautifulsoup4>=4.12
34
+ Requires-Dist: beautifulsoup4>=4.14
35
35
  Requires-Dist: PyYAML>=6.0.3
36
36
  Requires-Dist: python-dateutil>=2.9.0.post0
37
37
  Requires-Dist: pyotp>=2.9
@@ -64,14 +64,12 @@ Requires-Dist: sphinx-notfound-page; extra == "docs"
64
64
  Requires-Dist: sphinx_autodoc_typehints; extra == "docs"
65
65
  Requires-Dist: mypy; extra == "docs"
66
66
  Requires-Dist: types-requests; extra == "docs"
67
- Requires-Dist: types-beautifulsoup4; extra == "docs"
68
67
  Requires-Dist: types-Pillow; extra == "docs"
69
68
  Requires-Dist: types-PyYAML; extra == "docs"
70
69
  Requires-Dist: types-python-dateutil; extra == "docs"
71
70
  Requires-Dist: sphinx-sitemap; extra == "docs"
72
71
  Requires-Dist: sphinxext-opengraph; extra == "docs"
73
72
  Requires-Dist: furo; extra == "docs"
74
- Requires-Dist: sphinxcontrib-googleanalytics; extra == "docs"
75
73
  Dynamic: license-file
76
74
 
77
75
  <p align="center"><img alt="amazon-orders - A Python library (and CLI) for Amazon order history" src="https://amazon-orders.readthedocs.io/_images/logo.png" /></p>
@@ -108,7 +106,8 @@ ensure you always get the latest stable release.
108
106
  You'll use [`AmazonSession`](https://amazon-orders.readthedocs.io/api.html#amazonorders.session.AmazonSession) to
109
107
  authenticate your Amazon account, then [`AmazonOrders`](https://amazon-orders.readthedocs.io/api.html#amazonorders.orders.AmazonOrders),
110
108
  [`AmazonTransactions`](https://amazon-orders.readthedocs.io/api.html#amazonorders.transactions.AmazonTransactions),
111
- and [`AmazonGiftCards`](https://amazon-orders.readthedocs.io/api.html#amazonorders.gift_cards.AmazonGiftCards)
109
+ [`AmazonGiftCards`](https://amazon-orders.readthedocs.io/api.html#amazonorders.gift_cards.AmazonGiftCards),
110
+ and [`AmazonPrime`](https://amazon-orders.readthedocs.io/api.html#amazonorders.prime.AmazonPrime)
112
111
  to interact with account data. [`get_order_history`](https://amazon-orders.readthedocs.io/api.html#amazonorders.orders.AmazonOrders.get_order_history)
113
112
  and [`get_order`](https://amazon-orders.readthedocs.io/api.html#amazonorders.orders.AmazonOrders.get_order) are good places to start.
114
113
 
@@ -152,10 +151,10 @@ amazon-orders history --last-3-months
152
151
 
153
152
  ### Output Formats
154
153
 
155
- The `history`, `order`, `transactions`, `order-transactions`, `gift-card-activity`, and `family-members` commands
156
- accept `--output`, which renders Orders, Transactions, Gift Card activity, and Amazon Household members as `text` (the
157
- default), `json`, `yaml`, or `csv`. Progress messages are written to `stderr`, so redirecting `stdout` captures only
158
- the data.
154
+ The `history`, `order`, `invoice-pdfs`, `transactions`, `order-transactions`, `gift-card-activity`, `family-members`,
155
+ and `prime-payments` commands accept `--output`, which renders Orders, Invoice PDFs, Transactions, Gift Card activity,
156
+ Amazon Household members, and Prime payments as `text` (the default), `json`, `yaml`, or `csv`. Progress messages are
157
+ written to `stderr`, so redirecting `stdout` captures only the data.
159
158
 
160
159
  ```sh
161
160
  amazon-orders history --year 2023 --output json > orders.json
@@ -32,7 +32,8 @@ ensure you always get the latest stable release.
32
32
  You'll use [`AmazonSession`](https://amazon-orders.readthedocs.io/api.html#amazonorders.session.AmazonSession) to
33
33
  authenticate your Amazon account, then [`AmazonOrders`](https://amazon-orders.readthedocs.io/api.html#amazonorders.orders.AmazonOrders),
34
34
  [`AmazonTransactions`](https://amazon-orders.readthedocs.io/api.html#amazonorders.transactions.AmazonTransactions),
35
- and [`AmazonGiftCards`](https://amazon-orders.readthedocs.io/api.html#amazonorders.gift_cards.AmazonGiftCards)
35
+ [`AmazonGiftCards`](https://amazon-orders.readthedocs.io/api.html#amazonorders.gift_cards.AmazonGiftCards),
36
+ and [`AmazonPrime`](https://amazon-orders.readthedocs.io/api.html#amazonorders.prime.AmazonPrime)
36
37
  to interact with account data. [`get_order_history`](https://amazon-orders.readthedocs.io/api.html#amazonorders.orders.AmazonOrders.get_order_history)
37
38
  and [`get_order`](https://amazon-orders.readthedocs.io/api.html#amazonorders.orders.AmazonOrders.get_order) are good places to start.
38
39
 
@@ -76,10 +77,10 @@ amazon-orders history --last-3-months
76
77
 
77
78
  ### Output Formats
78
79
 
79
- The `history`, `order`, `transactions`, `order-transactions`, `gift-card-activity`, and `family-members` commands
80
- accept `--output`, which renders Orders, Transactions, Gift Card activity, and Amazon Household members as `text` (the
81
- default), `json`, `yaml`, or `csv`. Progress messages are written to `stderr`, so redirecting `stdout` captures only
82
- the data.
80
+ The `history`, `order`, `invoice-pdfs`, `transactions`, `order-transactions`, `gift-card-activity`, `family-members`,
81
+ and `prime-payments` commands accept `--output`, which renders Orders, Invoice PDFs, Transactions, Gift Card activity,
82
+ Amazon Household members, and Prime payments as `text` (the default), `json`, `yaml`, or `csv`. Progress messages are
83
+ written to `stderr`, so redirecting `stdout` captures only the data.
83
84
 
84
85
  ```sh
85
86
  amazon-orders history --year 2023 --output json > orders.json
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amazon-orders
3
- Version: 4.9.4
3
+ Version: 4.9.6
4
4
  Summary: A Python library (and CLI) for Amazon order history, line items, and transactions
5
5
  Author-email: Alex Laird <contact@alexlaird.com>
6
6
  Maintainer-email: Alex Laird <contact@alexlaird.com>
@@ -31,7 +31,7 @@ License-File: LICENSE
31
31
  Requires-Dist: click>=7.1
32
32
  Requires-Dist: requests>=2.23
33
33
  Requires-Dist: Pillow>=9.0.1
34
- Requires-Dist: beautifulsoup4>=4.12
34
+ Requires-Dist: beautifulsoup4>=4.14
35
35
  Requires-Dist: PyYAML>=6.0.3
36
36
  Requires-Dist: python-dateutil>=2.9.0.post0
37
37
  Requires-Dist: pyotp>=2.9
@@ -64,14 +64,12 @@ Requires-Dist: sphinx-notfound-page; extra == "docs"
64
64
  Requires-Dist: sphinx_autodoc_typehints; extra == "docs"
65
65
  Requires-Dist: mypy; extra == "docs"
66
66
  Requires-Dist: types-requests; extra == "docs"
67
- Requires-Dist: types-beautifulsoup4; extra == "docs"
68
67
  Requires-Dist: types-Pillow; extra == "docs"
69
68
  Requires-Dist: types-PyYAML; extra == "docs"
70
69
  Requires-Dist: types-python-dateutil; extra == "docs"
71
70
  Requires-Dist: sphinx-sitemap; extra == "docs"
72
71
  Requires-Dist: sphinxext-opengraph; extra == "docs"
73
72
  Requires-Dist: furo; extra == "docs"
74
- Requires-Dist: sphinxcontrib-googleanalytics; extra == "docs"
75
73
  Dynamic: license-file
76
74
 
77
75
  <p align="center"><img alt="amazon-orders - A Python library (and CLI) for Amazon order history" src="https://amazon-orders.readthedocs.io/_images/logo.png" /></p>
@@ -108,7 +106,8 @@ ensure you always get the latest stable release.
108
106
  You'll use [`AmazonSession`](https://amazon-orders.readthedocs.io/api.html#amazonorders.session.AmazonSession) to
109
107
  authenticate your Amazon account, then [`AmazonOrders`](https://amazon-orders.readthedocs.io/api.html#amazonorders.orders.AmazonOrders),
110
108
  [`AmazonTransactions`](https://amazon-orders.readthedocs.io/api.html#amazonorders.transactions.AmazonTransactions),
111
- and [`AmazonGiftCards`](https://amazon-orders.readthedocs.io/api.html#amazonorders.gift_cards.AmazonGiftCards)
109
+ [`AmazonGiftCards`](https://amazon-orders.readthedocs.io/api.html#amazonorders.gift_cards.AmazonGiftCards),
110
+ and [`AmazonPrime`](https://amazon-orders.readthedocs.io/api.html#amazonorders.prime.AmazonPrime)
112
111
  to interact with account data. [`get_order_history`](https://amazon-orders.readthedocs.io/api.html#amazonorders.orders.AmazonOrders.get_order_history)
113
112
  and [`get_order`](https://amazon-orders.readthedocs.io/api.html#amazonorders.orders.AmazonOrders.get_order) are good places to start.
114
113
 
@@ -152,10 +151,10 @@ amazon-orders history --last-3-months
152
151
 
153
152
  ### Output Formats
154
153
 
155
- The `history`, `order`, `transactions`, `order-transactions`, `gift-card-activity`, and `family-members` commands
156
- accept `--output`, which renders Orders, Transactions, Gift Card activity, and Amazon Household members as `text` (the
157
- default), `json`, `yaml`, or `csv`. Progress messages are written to `stderr`, so redirecting `stdout` captures only
158
- the data.
154
+ The `history`, `order`, `invoice-pdfs`, `transactions`, `order-transactions`, `gift-card-activity`, `family-members`,
155
+ and `prime-payments` commands accept `--output`, which renders Orders, Invoice PDFs, Transactions, Gift Card activity,
156
+ Amazon Household members, and Prime payments as `text` (the default), `json`, `yaml`, or `csv`. Progress messages are
157
+ written to `stderr`, so redirecting `stdout` captures only the data.
159
158
 
160
159
  ```sh
161
160
  amazon-orders history --year 2023 --output json > orders.json
@@ -20,6 +20,8 @@ amazonorders/gift_cards.py
20
20
  amazonorders/orders.py
21
21
  amazonorders/output.py
22
22
  amazonorders/paging.py
23
+ amazonorders/prime.py
24
+ amazonorders/py.typed
23
25
  amazonorders/region_data.py
24
26
  amazonorders/selectors.py
25
27
  amazonorders/session.py
@@ -36,9 +38,11 @@ amazonorders/contrib/waf/twocaptcha.py
36
38
  amazonorders/entity/__init__.py
37
39
  amazonorders/entity/family_member.py
38
40
  amazonorders/entity/gift_card_activity.py
41
+ amazonorders/entity/invoice_pdf.py
39
42
  amazonorders/entity/item.py
40
43
  amazonorders/entity/order.py
41
44
  amazonorders/entity/parsable.py
45
+ amazonorders/entity/prime_payment.py
42
46
  amazonorders/entity/recipient.py
43
47
  amazonorders/entity/seller.py
44
48
  amazonorders/entity/shipment.py
@@ -1,7 +1,7 @@
1
1
  click>=7.1
2
2
  requests>=2.23
3
3
  Pillow>=9.0.1
4
- beautifulsoup4>=4.12
4
+ beautifulsoup4>=4.14
5
5
  PyYAML>=6.0.3
6
6
  python-dateutil>=2.9.0.post0
7
7
  pyotp>=2.9
@@ -36,14 +36,12 @@ sphinx-notfound-page
36
36
  sphinx_autodoc_typehints
37
37
  mypy
38
38
  types-requests
39
- types-beautifulsoup4
40
39
  types-Pillow
41
40
  types-PyYAML
42
41
  types-python-dateutil
43
42
  sphinx-sitemap
44
43
  sphinxext-opengraph
45
44
  furo
46
- sphinxcontrib-googleanalytics
47
45
 
48
46
  [integration]
49
47
  pytest-rerunfailures
@@ -1,3 +1,3 @@
1
1
  __copyright__ = "Copyright (c) 2024-2025 Alex Laird"
2
2
  __license__ = "MIT"
3
- __version__ = "4.9.4"
3
+ __version__ = "4.9.6"
@@ -7,10 +7,11 @@ import datetime
7
7
  import logging
8
8
  import os
9
9
  import platform
10
+ import re
10
11
  import sys
11
12
  import threading
12
13
  import time
13
- from typing import Any, List, Optional
14
+ from typing import Any, List, Optional, Set, Tuple
14
15
 
15
16
  import click
16
17
  from click.core import Context
@@ -18,6 +19,7 @@ from click.core import Context
18
19
  from amazonorders import __version__, util
19
20
  from amazonorders.conf import AmazonOrdersConfig
20
21
  from amazonorders.contrib.browser.playwright import PlaywrightBrowserLauncher, PlaywrightBrowserLogin
22
+ from amazonorders.entity.invoice_pdf import InvoicePdf
21
23
  from amazonorders.exception import (
22
24
  AmazonOrdersAuthError,
23
25
  AmazonOrdersAuthRedirectError,
@@ -27,6 +29,7 @@ from amazonorders.exception import (
27
29
  from amazonorders.gift_cards import AmazonGiftCards
28
30
  from amazonorders.orders import AmazonOrders
29
31
  from amazonorders.output import OutputFormatter
32
+ from amazonorders.prime import AmazonPrime
30
33
  from amazonorders.session import AmazonSession, IODefault
31
34
  from amazonorders.transactions import AmazonTransactions
32
35
 
@@ -445,6 +448,58 @@ def invoice(ctx: Context,
445
448
  ctx.fail(str(e))
446
449
 
447
450
 
451
+ @amazon_orders_cli.command()
452
+ @click.pass_context
453
+ @click.argument("order_ids", nargs=-1, required=True)
454
+ @click.option("--download", "download_dir", type=click.Path(file_okay=False),
455
+ help="Save the documents (PDFs) to this directory, replacing any of the same name from an earlier run.")
456
+ @click.option("-o", "--output", type=click.Choice(OutputFormatter.OUTPUT_FORMATS), default="text",
457
+ help="The output format. Defaults to text.")
458
+ def invoice_pdfs(ctx: Context,
459
+ order_ids: Tuple[str, ...],
460
+ download_dir: Optional[str],
461
+ **kwargs: Any) -> None:
462
+ """
463
+ Get the invoice PDFs (invoices and credit notes) for the given Amazon Order IDs, and optionally download
464
+ them.
465
+ """
466
+ amazon_session = ctx.obj["amazon_session"]
467
+
468
+ try:
469
+ CliAuth(amazon_session).authenticate()
470
+
471
+ config = ctx.obj["conf"]
472
+ amazon_orders = AmazonOrders(amazon_session,
473
+ config=config)
474
+
475
+ output = kwargs["output"]
476
+
477
+ invoice_list = []
478
+ for order_id in order_ids:
479
+ order_invoices = amazon_orders.get_invoice_pdfs(order_id)
480
+ if not order_invoices:
481
+ click.echo(f"No invoice PDFs for Order {order_id}.", err=True)
482
+ invoice_list += order_invoices
483
+
484
+ click.echo(config.output_cls(config).format(invoice_list, output))
485
+
486
+ if download_dir:
487
+ os.makedirs(download_dir, exist_ok=True)
488
+ saved_paths: Set[str] = set()
489
+ for document in invoice_list:
490
+ path = _invoice_pdf_path(download_dir, document, saved_paths)
491
+ with open(path, "wb") as invoice_file:
492
+ invoice_file.write(amazon_orders.download_invoice_pdf(document))
493
+ click.echo(f"Saved {path}", err=True)
494
+
495
+ click.echo(f"... {len(invoice_list)} Invoice PDFs for {len(order_ids)} Orders.\n", err=True)
496
+ except AmazonOrdersAuthRedirectError:
497
+ IOClick.echo_session_expired()
498
+ except AmazonOrdersError as e:
499
+ logger.debug("An error occurred.", exc_info=True)
500
+ ctx.fail(str(e))
501
+
502
+
448
503
  @amazon_orders_cli.command("order-transactions")
449
504
  @click.pass_context
450
505
  @click.argument("order_id")
@@ -484,6 +539,39 @@ def order_transactions(ctx: Context,
484
539
  ctx.fail(str(e))
485
540
 
486
541
 
542
+ @amazon_orders_cli.command("prime-payments")
543
+ @click.pass_context
544
+ @click.option("-o", "--output", type=click.Choice(OutputFormatter.OUTPUT_FORMATS), default="text",
545
+ help="The output format. Defaults to text.")
546
+ def prime_payments(ctx: Context, **kwargs: Any) -> None:
547
+ """
548
+ Get the Prime membership payment history.
549
+ """
550
+ amazon_session = ctx.obj["amazon_session"]
551
+
552
+ try:
553
+ CliAuth(amazon_session).authenticate()
554
+
555
+ config = ctx.obj["conf"]
556
+ amazon_prime = AmazonPrime(amazon_session,
557
+ config=config)
558
+
559
+ start_time = time.time()
560
+ prime_payments = amazon_prime.get_prime_payments()
561
+ end_time = time.time()
562
+
563
+ click.echo(config.output_cls(config).format(prime_payments, kwargs["output"]))
564
+
565
+ click.echo(
566
+ "... {total} Prime payments parsed in {time} seconds.\n".format(
567
+ total=len(prime_payments), time=int(end_time - start_time)), err=True)
568
+ except AmazonOrdersAuthRedirectError:
569
+ IOClick.echo_session_expired()
570
+ except AmazonOrdersError as e:
571
+ logger.debug("An error occurred.", exc_info=True)
572
+ ctx.fail(str(e))
573
+
574
+
487
575
  @amazon_orders_cli.command()
488
576
  @click.pass_context
489
577
  @click.option("--days", default=365,
@@ -725,5 +813,20 @@ def _is_interactive_terminal() -> bool:
725
813
  return sys.stderr.isatty() and os.environ.get("TERM") != "dumb"
726
814
 
727
815
 
816
+ def _invoice_pdf_path(download_dir: str,
817
+ invoice: InvoicePdf,
818
+ saved_paths: Set[str]) -> str:
819
+ # e.g. "302-0000000-0000000_invoice-2.pdf", with a counter if the name repeats within an Order. A file from an
820
+ # earlier run is overwritten, so downloading again doesn't duplicate it.
821
+ name = re.sub(r"[^a-z0-9]+", "-", (invoice.name or "").lower()).strip("-") or "invoice"
822
+ path = os.path.join(download_dir, f"{invoice.order_number}_{name}.pdf")
823
+ i = 2
824
+ while path in saved_paths:
825
+ path = os.path.join(download_dir, f"{invoice.order_number}_{name}-{i}.pdf")
826
+ i += 1
827
+ saved_paths.add(path)
828
+ return path
829
+
830
+
728
831
  if __name__ == "__main__":
729
832
  amazon_orders_cli(obj={})
@@ -83,6 +83,17 @@ class Constants:
83
83
  TRACKING_ORDER_ID_QUERY_PARAM = "orderId"
84
84
  SHIPMENT_ID_QUERY_PARAM = "shipmentId"
85
85
  TRACKING_PACKAGE_INDEX_QUERY_PARAM = "packageIndex"
86
+ INVOICE_PDFS_ROUTE = "/your-orders/invoice/popover"
87
+ INVOICE_PDFS_URL = f"{BASE_URL}{INVOICE_PDFS_ROUTE}"
88
+ INVOICE_PDFS_ORDER_ID_QUERY_PARAM = "orderId"
89
+ INVOICE_PDF_CONTENT_TYPE = "application/pdf"
90
+
91
+ ##########################################################################
92
+ # URLs for Prime
93
+ ##########################################################################
94
+
95
+ PRIME_PAYMENTS_ROUTE = "/mc/payments"
96
+ PRIME_PAYMENTS_URL = f"{BASE_URL}{PRIME_PAYMENTS_ROUTE}"
86
97
 
87
98
  ##########################################################################
88
99
  # URLs for Transactions
@@ -92,6 +103,8 @@ class Constants:
92
103
  TRANSACTION_HISTORY_URL = f"{BASE_URL}{TRANSACTION_HISTORY_ROUTE}"
93
104
  TRANSACTION_DATA_ROUTE = "/payments-portal/data/iris/live/v1/data/manage/get-transactions"
94
105
  TRANSACTION_DATA_URL = f"{BASE_URL}{TRANSACTION_DATA_ROUTE}"
106
+ #: The widget further pages of Transactions are requested for, when the page doesn't name it (e.g. amazon.de).
107
+ TRANSACTION_DATA_WIDGET_NAME = "ViewTransactions"
95
108
 
96
109
  ##########################################################################
97
110
  # URLs for Gift Cards
@@ -371,6 +384,8 @@ class Constants:
371
384
  self.ORDER_DETAILS_URL = f"{base_url}/gp/your-account/order-details"
372
385
  self.ORDER_INVOICE_URL = f"{base_url}/gp/css/summary/print.html"
373
386
  self.TRACKING_URL = f"{base_url}{self.TRACKING_ROUTE}"
387
+ self.INVOICE_PDFS_URL = f"{base_url}{self.INVOICE_PDFS_ROUTE}"
388
+ self.PRIME_PAYMENTS_URL = f"{base_url}{self.PRIME_PAYMENTS_ROUTE}"
374
389
  self.TRANSACTION_HISTORY_URL = f"{base_url}{self.TRANSACTION_HISTORY_ROUTE}"
375
390
  self.TRANSACTION_DATA_URL = f"{base_url}{self.TRANSACTION_DATA_ROUTE}"
376
391
  self.GIFT_CARD_BALANCE_URL = f"{base_url}{self.GIFT_CARD_BALANCE_ROUTE}"
@@ -0,0 +1,58 @@
1
+ __copyright__ = "Copyright (c) 2024-2025 Alex Laird"
2
+ __license__ = "MIT"
3
+
4
+ import logging
5
+ from typing import Optional
6
+
7
+ from bs4 import Tag
8
+
9
+ from amazonorders.conf import AmazonOrdersConfig
10
+ from amazonorders.entity.parsable import Parsable
11
+
12
+ logger = logging.getLogger(__name__)
13
+
14
+
15
+ class InvoicePdf(Parsable):
16
+ """
17
+ An invoice PDF of an Amazon :class:`~amazonorders.entity.order.Order`, such as an invoice or a credit
18
+ note, parsed from the Order's invoice list. See :func:`~amazonorders.orders.AmazonOrders.get_invoice_pdfs`, and
19
+ :func:`~amazonorders.orders.AmazonOrders.download_invoice_pdf` for the document itself.
20
+ """
21
+
22
+ def __init__(self,
23
+ parsed: Tag,
24
+ config: AmazonOrdersConfig,
25
+ order_number: Optional[str] = None) -> None:
26
+ super().__init__(parsed, config)
27
+
28
+ #: The Order number the document belongs to.
29
+ self.order_number: Optional[str] = order_number
30
+ #: The document's name, as Amazon lists it, e.g. ``Invoice``, ``Invoice 2``, or ``Credit note``.
31
+ self.name: Optional[str] = self.safe_parse(self._parse_name)
32
+ #: The link to download the document. Amazon generates a new one on each request, so don't store it, get the
33
+ #: Order's invoices again instead.
34
+ self.link: Optional[str] = self.safe_parse(self._parse_link)
35
+ #: ``True`` if the document is a credit note (a refund) rather than an invoice.
36
+ self.is_credit_note: bool = self.safe_parse(self._parse_is_credit_note) or False
37
+
38
+ def __repr__(self) -> str:
39
+ return f"<InvoicePdf #{self.order_number}: \"{self.name}\">"
40
+
41
+ def __str__(self) -> str: # pragma: no cover
42
+ return f"InvoicePdf #{self.order_number}: {self.name}\n Link: {self.link}"
43
+
44
+ def _parse_name(self) -> Optional[str]:
45
+ return " ".join(self.parsed.text.split()) or None
46
+
47
+ def _parse_link(self) -> Optional[str]:
48
+ href = self.parsed.get("href")
49
+ if not href:
50
+ return None
51
+
52
+ return self.with_base_url(str(href))
53
+
54
+ def _parse_is_credit_note(self) -> bool:
55
+ if not self.name:
56
+ return False
57
+
58
+ return self.config.selectors.FIELD_INVOICE_PDF_CREDIT_NOTE_TEXT.lower() in self.name.lower()
@@ -252,7 +252,8 @@ class Order(Parsable):
252
252
  tag = util.select_one(self.parsed, self.config.selectors.FIELD_ORDER_PAYMENT_METHOD_SELECTOR)
253
253
  if tag is None:
254
254
  return None
255
- return tag.attrs.get("alt") or self._without_masked_digits(tag.text).strip()
255
+ alt = tag.attrs.get("alt")
256
+ return util.attribute_text(alt) if alt else self._without_masked_digits(tag.text).strip()
256
257
 
257
258
  def _without_masked_digits(self,
258
259
  text: str) -> str:
@@ -132,7 +132,7 @@ class Parsable:
132
132
  for tag in self.parsed.select(s):
133
133
  if tag:
134
134
  if attr_name:
135
- value = tag.attrs[attr_name]
135
+ value = util.attribute_text(tag.attrs[attr_name])
136
136
 
137
137
  if attr_name == "href" or attr_name == "src":
138
138
  value = self.with_base_url(value)
@@ -0,0 +1,108 @@
1
+ __copyright__ = "Copyright (c) 2024-2025 Alex Laird"
2
+ __license__ = "MIT"
3
+
4
+ import logging
5
+ from datetime import date
6
+ from typing import Optional, Union
7
+
8
+ from bs4 import Tag
9
+
10
+ from amazonorders import util
11
+ from amazonorders.conf import AmazonOrdersConfig
12
+ from amazonorders.entity.parsable import Parsable
13
+ from amazonorders.exception import AmazonOrdersError
14
+ from amazonorders.selectors import Selector
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+
19
+ class PrimePayment(Parsable):
20
+ """
21
+ A charge in the Prime membership payment history: the membership fee Amazon billed on a sign-up or
22
+ renewal date.
23
+
24
+ Each charge is a digital Order (a ``D01-`` ID) that neither the Order history nor the Digital Orders tab
25
+ lists, so this entity is the index to it. The Order itself is fetched by :attr:`order_number` with
26
+ :func:`~amazonorders.orders.AmazonOrders.get_order`, which renders the standard Order details layout for
27
+ these IDs.
28
+ """
29
+
30
+ def __init__(self,
31
+ parsed: Tag,
32
+ config: AmazonOrdersConfig) -> None:
33
+ super().__init__(parsed, config)
34
+
35
+ #: The date the membership fee was charged, not the start of the membership period it covers.
36
+ self.payment_date: Optional[date] = self.safe_simple_parse(
37
+ selector=self.config.selectors.FIELD_PRIME_PAYMENT_DATE_SELECTOR,
38
+ parse_date=True)
39
+ #: The amount charged, tax included.
40
+ self.grand_total: Optional[float] = self.safe_parse(self._parse_grand_total)
41
+ #: The digital Order number (``D01-…``) of the charge.
42
+ self.order_number: Optional[str] = self.safe_parse(self._parse_order_number)
43
+ #: The Order details link. ``None`` when :attr:`order_number` is ``None``.
44
+ self.order_details_link: Optional[str] = self.safe_parse(self._parse_order_details_link)
45
+ #: The "View Receipt" link, the digital Order summary's print view. ``None`` when the card has none.
46
+ self.receipt_link: Optional[str] = self.safe_parse(self._parse_receipt_link)
47
+
48
+ def __repr__(self) -> str:
49
+ return f"<PrimePayment {self.payment_date}: \"Order #{self.order_number}, Grand Total: {self.grand_total}\">"
50
+
51
+ def __str__(self) -> str:
52
+ return f"PrimePayment {self.payment_date}: Order #{self.order_number}, Grand Total: {self.grand_total}"
53
+
54
+ def _parse_labeled_row(self,
55
+ label_selector: Selector) -> Optional[Tag]:
56
+ label_tag = util.select_one(self.parsed, label_selector)
57
+
58
+ return label_tag.parent if label_tag else None
59
+
60
+ def _parse_labeled_value(self,
61
+ label_selector: Selector) -> Optional[str]:
62
+ row_tag = self._parse_labeled_row(label_selector)
63
+ value_tag = util.select_one(row_tag, self.config.selectors.FIELD_PRIME_PAYMENT_VALUE_SELECTOR) \
64
+ if row_tag else None
65
+
66
+ return value_tag.text.strip() if value_tag else None
67
+
68
+ def _parse_grand_total(self) -> Union[float, int, None]:
69
+ text = self._parse_labeled_value(self.config.selectors.FIELD_PRIME_PAYMENT_TOTAL_LABEL_SELECTOR)
70
+ value = self.to_currency(text) if text else None
71
+
72
+ if value is None:
73
+ err_msg = ("PrimePayment.grand_total could not be parsed, but it's required. "
74
+ "Check if Amazon changed the HTML")
75
+ if not self.config.warn_on_missing_required_field:
76
+ raise AmazonOrdersError(f"{err_msg} or set warn_on_missing_required_field=True in config.")
77
+
78
+ logger.warning(f"{err_msg}.")
79
+
80
+ return value
81
+
82
+ def _parse_order_number(self) -> Optional[str]:
83
+ value = self._parse_labeled_value(self.config.selectors.FIELD_PRIME_PAYMENT_ORDER_NUMBER_LABEL_SELECTOR)
84
+ order_number = self.config.constants.parse_order_number(value) if value else None
85
+
86
+ if order_number is None:
87
+ err_msg = ("PrimePayment.order_number could not be parsed, but it's required. "
88
+ "Check if Amazon changed the HTML")
89
+ if not self.config.warn_on_missing_required_field:
90
+ raise AmazonOrdersError(f"{err_msg} or set warn_on_missing_required_field=True in config.")
91
+
92
+ logger.warning(f"{err_msg}.")
93
+
94
+ return order_number
95
+
96
+ def _parse_order_details_link(self) -> Optional[str]:
97
+ if not self.order_number:
98
+ return None
99
+
100
+ constants = self.config.constants
101
+ return f"{constants.ORDER_DETAILS_URL}?{constants.ORDER_ID_QUERY_PARAM}={self.order_number}"
102
+
103
+ def _parse_receipt_link(self) -> Optional[str]:
104
+ row_tag = self._parse_labeled_row(self.config.selectors.FIELD_PRIME_PAYMENT_RECEIPTS_LABEL_SELECTOR)
105
+ link_tag = util.select_one(row_tag, self.config.selectors.FIELD_PRIME_PAYMENT_RECEIPT_LINK_SELECTOR) \
106
+ if row_tag else None
107
+
108
+ return self.with_base_url(str(link_tag["href"])) if link_tag else None
@@ -2,10 +2,12 @@ __copyright__ = "Copyright (c) 2024-2025 Alex Laird"
2
2
  __license__ = "MIT"
3
3
 
4
4
  import logging
5
- from typing import Optional
5
+ import re
6
+ from typing import List, Optional
6
7
 
7
8
  from bs4 import Tag
8
9
 
10
+ from amazonorders import util
9
11
  from amazonorders.conf import AmazonOrdersConfig
10
12
  from amazonorders.entity.parsable import Parsable
11
13
 
@@ -46,6 +48,17 @@ class Recipient(Parsable):
46
48
  ]
47
49
  value = "\n".join(filter(None, values))
48
50
  else:
49
- value = self.simple_parse(self.config.selectors.FIELD_RECIPIENT_ADDRESS_FALLBACK_SELECTOR)
51
+ value = (self._parse_address_lines() or
52
+ self.simple_parse(self.config.selectors.FIELD_RECIPIENT_ADDRESS_FALLBACK_SELECTOR))
50
53
 
51
54
  return value
55
+
56
+ def _parse_address_lines(self) -> Optional[str]:
57
+ lines: List[str] = []
58
+ for tag in util.select(self.parsed, self.config.selectors.FIELD_RECIPIENT_ADDRESS_LINES_SELECTOR):
59
+ # A list item may hold several lines, separated by <br> or, when Amazon renders the address inline, by
60
+ # commas
61
+ for line in tag.get_text("\n").split("\n"):
62
+ lines += re.split(self.config.selectors.FIELD_RECIPIENT_ADDRESS_INLINE_SEPARATOR_REGEX, line.strip())
63
+
64
+ return "\n".join(line.strip() for line in lines if line.strip()) or None
@@ -110,8 +110,15 @@ class AuthForm(ABC):
110
110
  ) # pragma: no cover
111
111
 
112
112
  method = str(self.form.get("method", "GET")).upper()
113
+ if method == "GET" and "password" in self.data:
114
+ raise AmazonOrdersAuthError("Sign-in was stopped, and your password was not sent: the sign-in form tried "
115
+ "to send it in plain text in the URL, which should never happen. This is "
116
+ "either a bug in amazon-orders or something altering the page, so check your "
117
+ "network and environment, and report it at "
118
+ "https://github.com/alexdlaird/amazon-orders/issues.")
119
+
113
120
  url = self._get_form_action(last_response)
114
- request_data = {"params" if method == "GET" else "data": self.data}
121
+ request_data: Dict[str, Any] = {"params" if method == "GET" else "data": self.data}
115
122
  form_response = self.amazon_session.request(method,
116
123
  url,
117
124
  persist_cookies=True,