Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.

Merchant Fulfillment API MWS#50

Merged
GriceTurrble merged 13 commits intopython-amazon-mws:developfrom
cesarfmacario:master
Mar 10, 2018
Merged

Merchant Fulfillment API MWS#50
GriceTurrble merged 13 commits intopython-amazon-mws:developfrom
cesarfmacario:master

Conversation

@cesarfmacario
Copy link
Copy Markdown

No description provided.

GriceTurrble and others added 8 commits February 4, 2018 10:42
* Added Finances API Feature

* .setup.py: bump version to 0.7.5-dev0

* Split out request_description building from make_request()

So that it can be tested more easily, and refactored

* Split out building the initial params dict from make_request()

So that it can be tested more easily

* Add fake MWS credentials pytest fixture

* test_service_status() should use the pytest fake credentials fixture

* Add more pytest fixtures (access_key, secret_key, account_id, timestamp)

* Add test for calc_request_description()

* Split out calc_request_description() into more statements

So that it is easier to debug

* Fix calc_request_description - don't include leading ampersand

* Don't do automated deployments via Travis (for the moment)

* Update README.md badges

* InboundShipments, next_token_action decorator, and some style cleanups. (python-amazon-mws#33)

* Testing out git commits from VS Code

* Reverting the test commit

* Adding VS Code settings to gitignore.

* Style fixes

* MWS.enumerate_param deprecated: now using utils.enumerate_param and utils.enumerate_params

* InboundShipments fleshed out; added `utils.next_token_action` decorator; deprecated separate methods for `...by_next_token()`

* Bugfix, rename `_enumerate_param` to `enumerate_param` (no need for private)

* Fix for next_token issues.

* TravisCI flake8 complaining, fixes.

* Minor flake8 complaint.

* Hack to get flake8 to stop complaining.

* Strip pylint disables to clear line length issue.

* Correction to keyed params, now tests every item in values sequence to ensure all are dicts.

* Add tests for param methods in utils.

* Add test for next token decorator.

* Adding 'InboundShipments' to `__all__`

* Assigning response a default in __init__ for DictWrapper and DataWrapper

* Unneeded line breaks removed + docstring formatting

* Comment corrected. They're tuples, not sets.

* Finances methods updated to use next_token_action decorator

* Create .travis.yaml

* Update .gitignore

* Removing deploy code from local travis

* Delete .travis.yaml

* Pushed to 0.8.0-dev0

Recently added functionality to InboundShipments, as well as Finances API. These constitute feature additions with backwards compatibility, which calls for a minor version update.

* Adding Python 3.6 category

We are testing in 3.6 in Travis anyway. May as well include the note.

* Specified master and develop branches for badges

Ensured the badges for Travis and Codecov are pointing to the appropriate branches (used to be pointing to default, which was master in both cases).

* Updated comments throughout module

No substantial code changes, comment changes only. Also ensured all docstrings follow same format.

* Fixed docstring formatting

Also made slight update to docstring for ObjectDict to more clearly note what it does, vs what the original code did.

* Fix for flake8 (trailing whitespace)

* Fix for flake8 (trailing whitespace)

* Bump to 0.8.0 (drop dev tag) for release

* Bug: Incorrect use of `super` for back-compat

Using the old-style `super` syntax to comply with Python 2.7 compatibility. Not revealed in tests, because current tests don't touch the APIs. Whoops!

* Added back old object names in case needed

Old names `object_dict` and `xml2dict` added back in case the old objects are being used directly by some users.

To be removed in 1.0.0 release down the road.
Remove old-style string formatting for sake of clarity.
@GriceTurrble GriceTurrble self-assigned this Mar 1, 2018
@codecov-io
Copy link
Copy Markdown

codecov-io commented Mar 1, 2018

Codecov Report

Merging #50 into develop will decrease coverage by 0.96%.
The diff coverage is 29.41%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #50      +/-   ##
===========================================
- Coverage    46.67%   45.71%   -0.97%     
===========================================
  Files            4        4              
  Lines          632      665      +33     
  Branches        64       65       +1     
===========================================
+ Hits           295      304       +9     
- Misses         324      346      +22     
- Partials        13       15       +2
Impacted Files Coverage Δ
mws/mws.py 43.73% <28.57%> (-0.87%) ⬇️
mws/utils.py 69.44% <33.33%> (-2.41%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29f5c5c...0aced96. Read the comment docs.

@GriceTurrble
Copy link
Copy Markdown
Member

Code coverage issue is something I'm working on separately, so no need to worry about the coverage decrease in this PR. Post-0.9 we will have a better standard for coverage of new features.

@GriceTurrble
Copy link
Copy Markdown
Member

@Bobspadger, can you independently verify this code working in your production? As before, I have no seller account, so I cannot test it against MWS.

@Bobspadger
Copy link
Copy Markdown
Member

@GriceTurrble I'll try, I need to read the docs and work out if my account is activated for this and that I won't cause our order process / customers any issues.

@Bobspadger
Copy link
Copy Markdown
Member

Testing - got stuck:

import mws
from credentials import creds
# Make some easier to read globals
SECRET_KEY = creds['amazon']['secret_key']
AWS_ACCESS_KEY = creds['amazon']['AWS_access_id']
SELLER_ID = creds['amazon']['sellerid']
MARKETPLACE_ID = creds['amazon']['marketplaceids']['UK']

shipping = mws.MerchantFulfillment(access_key=AWS_ACCESS_KEY, secret_key=SECRET_KEY, account_id=SELLER_ID, region='UK')



###
# Get service status
###

service_status = shipping.get_service_status()
print(service_status.parsed)

"""
Passes, status green good to carry on
"""


###
# Get eligible shipping services
###

"""
I'm using real order items and id's here

Note: Quantity : 1 fails, Quantity: '1' works and allows params to be encoded. Not sure if this is expected?

"""

item_list = [{'OrderItemId': 'REDACTED', 'Quantity': '1'}]
ship_fron = {
    'Name': 'Absolute Music',
    'AddressLine1': 'REDACTED',
    'AddressLine2': 'REDACTED',
    'City': 'REDACTED',
    'Email': 'REDACTED',
    'PostalCode': 'REDACTED',
    'Phone': 'REDACTED'
}
package = {'Length': '10',
           'Width': '10',
           'Height': '10',
           'Unit': 'Centimetres'
           }
weight = {'Value': '1',
          'Unit': 'g'}
ship_service = {'DeliveryExperience': 'DeliveryConfirmationWithSignature',
                'CarrierWillPickUp': 'true'}

services = shipping.get_eligible_shipping_services("XXX-XXXXXXX-XXXXXXX", item_list=item_list, ship_from_address=ship_fron,
                                                   package_dimensions=package, weight=weight, shipping_service_options=ship_service)
print(services.parsed)

and I get


<ErrorResponse xmlns="https://mws.amazonservices.com/MerchantFulfillment/2015-06-01">
  <Error>
    <Type>Sender</Type>
    <Code>MalformedInput</Code>
    <Message>Unexpected complex element termination</Message>
  </Error>
  <RequestId>9bcacad8-bd4d-495b-b863-1ffc86fb7c5e</RequestId>
</ErrorResponse>

Can't see anything immediately incorrect - do you have any info with regards to my inputs?? @cmchecha

@GriceTurrble GriceTurrble changed the base branch from master to develop March 2, 2018 16:37
@GriceTurrble
Copy link
Copy Markdown
Member

Just noticed this PR was targeting master. Target changed to develop to coincide with our workflow.

node_tree[key] = val
# Save childrens
for child in node.getchildren():
for child in node:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fairly basic upstream process that seems to have been working so far. Changing this now could have some nasty aftereffects without extensive testing.

@cmchecha , can you provide some detail here, please?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output in my production:
DeprecationWarning: This method will be removed in future versions. Use 'list(elem)' or iteration over elem instead.
for child in node.getchildren():

But we can return to the previous version.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I see that now. Did some digging: getchildren is deprecated as of 2.7 (doc) and 3.2 (doc).

Spot-checked the change locally, and I confirm it works that same as original. We can accept that change. Good catch, thank you. :)

@cesarfmacario
Copy link
Copy Markdown
Author

@Bobspadger I found the error, it was the list of items.
Correction in your body:
Centimetres to centimeters in package and add ContryCode in your ship_from, this is required

    item_list = [{'OrderItemId': 'REDACTED', 'Quantity': '1'}]
        ship_fron = {
            'Name': 'REDACTED',
            'AddressLine1': 'REDACTED',
            'AddressLine2': 'REDACTED',
            'City': 'REDACTED',
            'Email': '[email protected]',
            'PostalCode': 'REDACTED',
            'Phone': 'REDACTED',
            'CountryCode': "REDACTED"
        }
        package = {'Length': '10',
                'Width': '10',
                'Height': '10',
                'Unit': 'centimeters'
                }
        weight = {'Value': '1',
                'Unit': 'g'}
        ship_service = {'DeliveryExperience': 'DeliveryConfirmationWithSignature',
                        'CarrierWillPickUp': 'true'}

@Bobspadger
Copy link
Copy Markdown
Member

Those last updates are providing me with better error codes, working through a test now

@Bobspadger
Copy link
Copy Markdown
Member

<ErrorResponse xmlns="https://mws.amazonservices.com/MerchantFulfillment/2015-06-01">
  <Error>
    <Type>Sender</Type>
    <Code>TermsAndConditionsNotAccepted</Code>
  </Error>
  <RequestId>7d3d2cf5-6686-4a7e-8713-8791d824fc8b</RequestId>
</ErrorResponse>

Not sure if this is because I need to accept terms and conditions, documentation @amazon is lacking on this

@GriceTurrble
Copy link
Copy Markdown
Member

GriceTurrble commented Mar 2, 2018

Docs cover this somewhat:

http://docs.developer.amazonservices.com/en_UK/merch_fulfill/MerchFulfill_ErrorCodes.html

TermsAndConditionsNotAccepted: The seller has not yet agreed to Amazon's or the carrier's terms and conditions. You can accept terms and condition in Seller Central (Europe) (US).

That is something the seller needs to take care of. I would assume at this stage that getting that error means the rest of the request is solid.

@Bobspadger
Copy link
Copy Markdown
Member

@cmchecha

I found you updates provided me with those error messages to fix, so thanks, it was that list items. Its returning proper responses now

@GriceTurrble Yep, I just found that too - being a bit slow today :(

I now have responses from Amazon, but not quite as they are giving me with their seller central.

I'm just trying to work out why this is at present but the communications aspect of it is looking good :)

@Bobspadger
Copy link
Copy Markdown
Member

I have a support request open with Amazon on this.

To me, it looks like we are ok for the communications part of it (only tested on GetEligibleShippingServices
However, the API is returning to me that everything is currently Temporarily unavailable.

Once I've got confirmation from Amazon that its actually them needing to activate the services on my account and doing so, I can test and confirm the rest of the label creation etc.

Looks good so far though.

@GriceTurrble GriceTurrble merged commit 60a4556 into python-amazon-mws:develop Mar 10, 2018
@Bobspadger
Copy link
Copy Markdown
Member

Just an update on this.

I now have the full merchant fulfilment API working and returning labels.

I'm happy this is fully working now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants