Class: ActiveMerchant::Fulfillment::AmazonService
- Inherits:
-
Service
- Object
- Service
- ActiveMerchant::Fulfillment::AmazonService
show all
- 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.new("sha1")
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Service
#fetch_tracking_numbers, #test?
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(options = {})
requires!(options, :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(options = {})
if options[:sku]
commit :inventory, :get, build_inventory_get_request(options)
else
response = commit :inventory, :list, build_inventory_list_request(options)
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_data(order_ids, options = {}) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 118
def fetch_tracking_data(order_ids, options = {})
order_ids.inject(nil) do |previous, o_id|
response = commit :outbound, :tracking, build_tracking_request(o_id, options)
return response unless response.success?
if previous
response.tracking_numbers.merge!(previous.tracking_numbers)
response.tracking_companies.merge!(previous.tracking_companies)
response.tracking_urls.merge!(previous.tracking_urls)
end
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, options = {})
requires!(options, :order_date, :comment, :shipping_method)
commit :outbound, :create, build_fulfillment_request(order_id, shipping_address, line_items, options)
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
137
138
139
|
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 137
def test_mode?
false
end
|
#valid_credentials? ⇒ Boolean
133
134
135
|
# File 'lib/active_fulfillment/fulfillment/services/amazon.rb', line 133
def valid_credentials?
status.success?
end
|