Class: ActiveMerchant::Fulfillment::AmazonService
- Defined in:
- lib/active_fulfillment/fulfillment/services/amazon.rb
Constant Summary collapse
- SERVICES =
{ :outbound => { :url => 'https://fba-outbound.amazonaws.com', :xmlns => 'http://fba-outbound.amazonaws.com/doc/2007-08-02/', :version => '2007-08-02' }, :inventory => { :url => 'https://fba-inventory.amazonaws.com', :xmlns => 'http://fba-inventory.amazonaws.com/doc/2009-07-31/', :version => '2009-07-31' } }
- MESSAGES =
{ :status => { 'Accepted' => 'Success', 'Failure' => 'Failed', 'Error' => 'An error occurred' }, :create => { 'Accepted' => 'Successfully submitted the order', 'Failure' => 'Failed to submit the order', 'Error' => 'An error occurred while submitting the order' }, :list => { 'Accepted' => 'Successfully submitted request', 'Failure' => 'Failed to submit request', 'Error' => 'An error occurred while submitting request' } }
- ENV_NAMESPACES =
{ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema', 'xmlns:env' => 'http://schemas.xmlsoap.org/soap/envelope/', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' }
- AWS_SECURITY_ATTRIBUTES =
{ "env:actor" => "http://schemas.xmlsoap.org/soap/actor/next", "env:mustUnderstand" => "0", "xmlns:aws" => "http://security.amazonaws.com/doc/2007-01-01/" }
- OPERATIONS =
{ :outbound => { :status => 'GetServiceStatus', :create => 'CreateFulfillmentOrder', :list => 'ListAllFulfillmentOrders', :tracking => 'GetFulfillmentOrder' }, :inventory => { :get => 'GetInventorySupply', :list => 'ListUpdatedInventorySupply', :list_next => 'ListUpdatedInventorySupplyByNextToken' } }
- @@digest =
OpenSSL::Digest::Digest.new("sha1")
Class Method Summary collapse
-
.shipping_methods ⇒ Object
The first is the label, and the last is the code Standard: 3-5 business days Expedited: 2 business days Priority: 1 business day.
- .sign(aws_secret_access_key, auth_string) ⇒ Object
Instance Method Summary collapse
- #fetch_current_orders ⇒ Object
- #fetch_stock_levels(options = {}) ⇒ Object
- #fetch_tracking_numbers(order_ids, options = {}) ⇒ Object
- #fulfill(order_id, shipping_address, line_items, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ AmazonService
constructor
A new instance of AmazonService.
- #status ⇒ Object
- #test_mode? ⇒ Boolean
- #valid_credentials? ⇒ Boolean
Methods inherited from Service
Constructor Details
#initialize(options = {}) ⇒ AmazonService
Returns a new instance of AmazonService.
83 84 85 86 |
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 83 def initialize( = {}) requires!(, :login, :password) super end |
Class Method Details
.shipping_methods ⇒ Object
The first is the label, and the last is the code Standard: 3-5 business days Expedited: 2 business days Priority: 1 business day
71 72 73 74 75 76 77 |
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 71 def self.shipping_methods [ [ 'Standard Shipping', 'Standard' ], [ 'Expedited Shipping', 'Expedited' ], [ 'Priority Shipping', 'Priority' ] ].inject(ActiveSupport::OrderedHash.new){|h, (k,v)| h[k] = v; h} end |
.sign(aws_secret_access_key, auth_string) ⇒ Object
79 80 81 |
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 79 def self.sign(aws_secret_access_key, auth_string) Base64.encode64(OpenSSL::HMAC.digest(@@digest, aws_secret_access_key, auth_string)).strip end |
Instance Method Details
#fetch_current_orders ⇒ Object
97 98 99 |
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 97 def fetch_current_orders commit :outbound, :list, build_get_current_fulfillment_orders_request end |
#fetch_stock_levels(options = {}) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 101 def fetch_stock_levels( = {}) if [:sku] commit :inventory, :get, build_inventory_get_request() else response = commit :inventory, :list, build_inventory_list_request() while token = response.params['next_token'] do next_page = commit :inventory, :list_next, build_next_inventory_list_request(token) next_page.stock_levels.merge!(response.stock_levels) response = next_page end response end end |
#fetch_tracking_numbers(order_ids, options = {}) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 118 def fetch_tracking_numbers(order_ids, = {}) order_ids.inject(nil) do |previous, o_id| response = commit :outbound, :tracking, build_tracking_request(o_id, ) if !response.success? if response.faultstring =~ /Reason: requested order not found./ response = Response.new(true, nil, { :status => SUCCESS, :tracking_numbers => {} }) else return response end end response.tracking_numbers.merge!(previous.tracking_numbers) if previous response end end |
#fulfill(order_id, shipping_address, line_items, options = {}) ⇒ Object
92 93 94 95 |
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 92 def fulfill(order_id, shipping_address, line_items, = {}) requires!(, :order_date, :comment, :shipping_method) commit :outbound, :create, build_fulfillment_request(order_id, shipping_address, line_items, ) end |
#status ⇒ Object
88 89 90 |
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 88 def status commit :outbound, :status, build_status_request end |
#test_mode? ⇒ Boolean
142 143 144 |
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 142 def test_mode? false end |
#valid_credentials? ⇒ Boolean
138 139 140 |
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 138 def valid_credentials? status.success? end |