Skip to content

Commit 956a947

Browse files
author
rubensanchez
committed
Recover amazon shipping from marketplace
1 parent a6e76cc commit 956a947

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

sp_api/api/shipping/shippingV2.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import enum
2+
import os
23
import urllib.parse
34
from datetime import datetime
45

5-
from sp_api.base import Client, sp_endpoint, fill_query_params, ApiResponse
6+
from sp_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Marketplaces
67

78

89
class AmznShippingBusiness(str, enum.Enum):
9-
AmazonShipping_US = "AmazonShipping_US"
10-
AmazonShipping_IN = "AmazonShipping_IN"
11-
AmazonShipping_UK = "AmazonShipping_UK"
12-
AmazonShipping_UAE = "AmazonShipping_UAE"
13-
AmazonShipping_SA = "AmazonShipping_SA"
14-
AmazonShipping_EG = "AmazonShipping_EG"
15-
AmazonShipping_IT = "AmazonShipping_IT"
16-
AmazonShipping_ES = "AmazonShipping_ES"
17-
AmazonShipping_FR = "AmazonShipping_FR"
18-
AmazonShipping_JP = "AmazonShipping_JP"
10+
US = "AmazonShipping_US"
11+
IN = "AmazonShipping_IN"
12+
UK = "AmazonShipping_UK"
13+
AE = "AmazonShipping_UAE"
14+
SA = "AmazonShipping_SA"
15+
IT = "AmazonShipping_IT"
16+
EG = "AmazonShipping_EG"
17+
ES = "AmazonShipping_ES"
18+
FR = "AmazonShipping_FR"
19+
JP = "AmazonShipping_JP"
20+
21+
@classmethod
22+
def has_key(cls, name):
23+
return name in cls.__members__
1924

2025

2126
class Shipping(Client):
@@ -26,11 +31,19 @@ class Shipping(Client):
2631
Provides programmatic access to Amazon Shipping APIs.
2732
"""
2833

29-
amzn_shipping_business: AmznShippingBusiness = AmznShippingBusiness.AmazonShipping_UK
34+
amzn_shipping_business: AmznShippingBusiness = AmznShippingBusiness.US
3035

3136
def __init__(self, *args, **kwargs):
3237
if 'amzn_shipping_business' in kwargs:
33-
self.amzn_shipping_business = kwargs.pop('amzn_shipping_business', AmznShippingBusiness.AmazonShipping_UK)
38+
self.amzn_shipping_business = kwargs.pop('amzn_shipping_business', AmznShippingBusiness.US)
39+
else:
40+
marketplace = args[0] if len(args) > 0 else Marketplaces.US
41+
if os.environ.get('SP_API_DEFAULT_MARKETPLACE', None):
42+
marketplace = Marketplaces[os.environ.get('SP_API_DEFAULT_MARKETPLACE')]
43+
44+
if AmznShippingBusiness.has_key(marketplace.name):
45+
self.amzn_shipping_business = AmznShippingBusiness[marketplace.name]
46+
3447
super().__init__(*args, **kwargs)
3548

3649
@property

tests/api/shipping/test_shipping_v2.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def test_get_rates():
8-
res = Shipping().get_rates(
8+
res = Shipping(amzn_shipping_business=AmznShippingBusiness.UK).get_rates(
99
**{
1010
"shipTo": {
1111
"name": "Arlene Purdy",
@@ -25,7 +25,6 @@ def test_get_rates():
2525
"email": "seller@test.com",
2626
"phoneNumber": "662-302-7817",
2727
},
28-
"shipDate": "2024-09-11T14:15:22Z",
2928
"shipperInstruction": {
3029
"deliveryNotes": "TEST"
3130
},
@@ -184,7 +183,7 @@ def test_get_access_points():
184183

185184

186185
def test_one_click_shipment():
187-
res = Shipping().one_click_shipment(
186+
res = Shipping(amzn_shipping_business=AmznShippingBusiness.UK).one_click_shipment(
188187
**{
189188
"shipTo": {
190189
"name": "Arlene Purdy",
@@ -204,7 +203,6 @@ def test_one_click_shipment():
204203
"email": "seller@test.com",
205204
"phoneNumber": "662-302-7817",
206205
},
207-
"shipDate": "2024-09-11T14:15:22Z",
208206
"shipperInstruction": {
209207
"deliveryNotes": "TEST"
210208
},
@@ -261,4 +259,4 @@ def test_one_click_shipment():
261259
assert res.errors is None
262260
assert res.payload.get('shipmentId')
263261
assert res.payload.get('packageDocumentDetails')[0]['trackingId']
264-
assert len(res.payload.get('packageDocumentDetails')[0]['packageDocuments']) > 0
262+
assert len(res.payload.get('packageDocumentDetails')[0]['packageDocuments']) > 0

0 commit comments

Comments
 (0)