bws 0.2.1.pre
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.
- data/.document +5 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +36 -0
- data/LICENSE +20 -0
- data/README.rdoc +116 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/bws.gemspec +133 -0
- data/lib/bws.rb +13 -0
- data/lib/bws/acknowledge_order.rb +11 -0
- data/lib/bws/active_isbn_report.rb +27 -0
- data/lib/bws/checkout.rb +30 -0
- data/lib/bws/client.rb +807 -0
- data/lib/bws/create_shipment.rb +11 -0
- data/lib/bws/fillable_orders.rb +15 -0
- data/lib/bws/inventory.rb +58 -0
- data/lib/bws/order.rb +10 -0
- data/lib/bws/order_events.rb +28 -0
- data/lib/bws/orders.rb +14 -0
- data/lib/bws/reject_line_item.rb +11 -0
- data/lib/bws/response.rb +8 -0
- data/lib/bws/unacknowledged_orders.rb +23 -0
- data/test/fixtures/acknowledge_success.xml +11 -0
- data/test/fixtures/active_isbn_report_with_one_isbn_request_body.xml +13 -0
- data/test/fixtures/active_isbn_report_with_one_isbn_success.xml +38 -0
- data/test/fixtures/active_isbn_report_with_two_isbns_request_body.xml +16 -0
- data/test/fixtures/active_isbn_report_with_two_isbns_success.xml +57 -0
- data/test/fixtures/cancel_line_item_success.xml +11 -0
- data/test/fixtures/create_order_request_body.xml +70 -0
- data/test/fixtures/create_order_response_success.xml +14 -0
- data/test/fixtures/create_shipment_success.xml +11 -0
- data/test/fixtures/fillable_success.xml +127 -0
- data/test/fixtures/inventory_by_isbn_success.xml +36 -0
- data/test/fixtures/inventory_success.xml +54 -0
- data/test/fixtures/order_events_by_order_success.xml +68 -0
- data/test/fixtures/order_events_success.xml +65 -0
- data/test/fixtures/order_success.xml +37 -0
- data/test/fixtures/orders_show_success.xml +37 -0
- data/test/fixtures/price_order_request_body.xml +46 -0
- data/test/fixtures/price_order_response_success.xml +63 -0
- data/test/fixtures/single_post_create_order_request_body.xml +62 -0
- data/test/fixtures/single_post_create_order_response_success.xml +13 -0
- data/test/fixtures/unacknowledged_success.xml +122 -0
- data/test/fixtures/unacknowledged_success_0_orders.xml +12 -0
- data/test/fixtures/unacknowledged_success_1_order.xml +37 -0
- data/test/fixtures/validate_credit_card_request_body.xml +39 -0
- data/test/fixtures/validate_credit_card_response_success.xml +14 -0
- data/test/helper.rb +23 -0
- data/test/integration/test_bws_active_isbn_report.rb +28 -0
- data/test/integration/test_bws_retrieve_inventory.rb +31 -0
- data/test/unit/test_bws_acknowledge_order.rb +24 -0
- data/test/unit/test_bws_active_isbn_report.rb +45 -0
- data/test/unit/test_bws_checkout.rb +117 -0
- data/test/unit/test_bws_client.rb +370 -0
- data/test/unit/test_bws_create_shipment.rb +26 -0
- data/test/unit/test_bws_fillable_orders.rb +41 -0
- data/test/unit/test_bws_order.rb +25 -0
- data/test/unit/test_bws_reject_line_item.rb +26 -0
- data/test/unit/test_bws_response.rb +7 -0
- data/test/unit/test_bws_retrieve_inventory.rb +42 -0
- data/test/unit/test_bws_retrieve_inventory_by_isbn.rb +25 -0
- data/test/unit/test_bws_retrieve_order_events.rb +42 -0
- data/test/unit/test_bws_retrieve_order_events_by_order.rb +37 -0
- data/test/unit/test_bws_unacknowledged_orders.rb +74 -0
- data/test/unit/test_retrieve_orders_show.rb +27 -0
- metadata +293 -0
data/lib/bws/checkout.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
class BWS::Checkout < BWS::Response
|
2
|
+
def result
|
3
|
+
base.nil?
|
4
|
+
end
|
5
|
+
|
6
|
+
def price_order
|
7
|
+
base['checkout_price_order']
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate_credit_card
|
11
|
+
base['checkout_validate_credit_card']
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_order
|
15
|
+
base['checkout_create_order']
|
16
|
+
end
|
17
|
+
|
18
|
+
def single_post_create_order
|
19
|
+
base['checkout_single_post_create_order']
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_store_order
|
23
|
+
base['checkout_create_store_order']
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def base
|
28
|
+
response.parsed_response['envelope']['body']
|
29
|
+
end
|
30
|
+
end
|
data/lib/bws/client.rb
ADDED
@@ -0,0 +1,807 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'builder'
|
4
|
+
|
5
|
+
module BWS
|
6
|
+
class Client
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
format :xml
|
10
|
+
headers 'Content-Type' => 'application/xml'
|
11
|
+
|
12
|
+
attr_reader :api_key, :base_uri, :timeout
|
13
|
+
|
14
|
+
class MissingApiKey < StandardError;
|
15
|
+
end
|
16
|
+
class BadParams < StandardError;
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(api_key = nil, base_uri = 'https://bws.bookrenter.com/v1', options = {})
|
20
|
+
raise MissingApiKey if api_key.nil?
|
21
|
+
@api_key = api_key
|
22
|
+
@base_uri = base_uri
|
23
|
+
@timeout = options[:timeout] || 5
|
24
|
+
end
|
25
|
+
|
26
|
+
def unacknowledged_orders(page = 1)
|
27
|
+
BWS::UnacknowledgedOrders.new(get("/distributor_orders/unacknowledged.xml?page=#{page}"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def fillable_orders(page = 1)
|
31
|
+
BWS::FillableOrders.new(get("/distributor_orders/fillable.xml?page=#{page}"))
|
32
|
+
end
|
33
|
+
|
34
|
+
def order(public_id = nil)
|
35
|
+
raise BadParams unless public_id
|
36
|
+
BWS::Order.new(get("/distributor_orders/#{public_id}.xml"))
|
37
|
+
end
|
38
|
+
|
39
|
+
def acknowledge_order(order_hash = nil)
|
40
|
+
raise BadParams unless order_hash
|
41
|
+
public_id = order_hash['public_id']
|
42
|
+
|
43
|
+
line_items = order_hash['distributor_line_items']['distributor_line_item']
|
44
|
+
line_items = [line_items] unless line_items.is_a?(Array)
|
45
|
+
|
46
|
+
xml_target = ''
|
47
|
+
xml = Builder::XmlMarkup.new :target => xml_target
|
48
|
+
xml.envelope do
|
49
|
+
xml.body do
|
50
|
+
xml.distributor_orders_acknowledge do
|
51
|
+
xml.distributor_order do
|
52
|
+
xml.public_id order_hash['public_id']
|
53
|
+
xml.distributor_identifier order_hash['distributor_identifier'] if order_hash['distributor_identifier']
|
54
|
+
xml.distributor_line_items do
|
55
|
+
line_items.each do |li_hash|
|
56
|
+
xml.distributor_line_item do
|
57
|
+
xml.public_id li_hash['public_id']
|
58
|
+
xml.estimated_ship_date li_hash['estimated_ship_date'] if li_hash['estimated_ship_date']
|
59
|
+
xml.distributor_identifier li_hash['distributor_identifier'] if li_hash['distributor_identifier']
|
60
|
+
xml.status li_hash['status']
|
61
|
+
xml.reject_reason li_hash['reject_reason'] if li_hash['reject_reason']
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
BWS::AcknowledgeOrder.new(post("/distributor_orders/#{public_id}/acknowledge.xml", xml_target))
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_shipment(shipment_hash = nil)
|
73
|
+
raise BadParams unless shipment_hash
|
74
|
+
public_id = shipment_hash['public_id']
|
75
|
+
xml_target = ''
|
76
|
+
xml = Builder::XmlMarkup.new :target => xml_target
|
77
|
+
xml.envelope do
|
78
|
+
xml.body do
|
79
|
+
xml.distributor_outbound_shipments_create do
|
80
|
+
xml.distributor_outbound_shipment do
|
81
|
+
xml.estimated_delivery_date shipment_hash['estimated_delivery_date'] if shipment_hash['estimated_delivery_date']
|
82
|
+
xml.shipping_method shipment_hash['shipping_method']
|
83
|
+
xml.shipped_at shipment_hash['shipped_at'] if shipment_hash['shipped_at']
|
84
|
+
xml.cost_cents shipment_hash['cost_cents'] if shipment_hash['cost_cents']
|
85
|
+
xml.carrier shipment_hash['carrier']
|
86
|
+
xml.tracking_number shipment_hash['tracking_number'] if shipment_hash['tracking_number']
|
87
|
+
xml.distributor_line_items do
|
88
|
+
shipment_hash['distributor_line_items'].each do |dli|
|
89
|
+
xml.distributor_line_item do
|
90
|
+
xml.public_id dli['public_id']
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
BWS::CreateShipment.new(post("/distributor_orders/#{public_id}/distributor_outbound_shipments.xml", xml_target))
|
99
|
+
end
|
100
|
+
|
101
|
+
def reject_line_item(reject_hash = nil)
|
102
|
+
raise BadParams unless reject_hash
|
103
|
+
public_id = reject_hash['public_id']
|
104
|
+
xml_target = ''
|
105
|
+
xml = Builder::XmlMarkup.new :target => xml_target
|
106
|
+
xml.envelope do
|
107
|
+
xml.body do
|
108
|
+
xml.distributor_line_items_reject do
|
109
|
+
xml.distributor_line_item do
|
110
|
+
xml.public_id reject_hash['public_id']
|
111
|
+
xml.status 'rejected'
|
112
|
+
xml.reject_reason reject_hash['reject_reason']
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
BWS::RejectLineItem.new(post("/distributor_line_items/#{public_id}/reject.xml", xml_target))
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# Retrieves multiple book with pricing and available rental terms. Books requested that are out-of-stock will be returned with a quantity zero, and no prices. The two main scenarios for the use of this API are:
|
122
|
+
#
|
123
|
+
# 1) retrieving inventory information on a specific set of books
|
124
|
+
# 2) retrieving inventory changes for all books (Delta result set)
|
125
|
+
# Parameters:
|
126
|
+
# isbns - (optional) A list of comma separated ISBN13's for the book requesting inventory. If this parameter is not include, all books will be returned
|
127
|
+
# segment - (optional) Your inventory specific segmentation. If your inventory is segmented, this may affect the price and rental periods available.
|
128
|
+
# page - (optional) The page number to request. Page numbers start at 1.
|
129
|
+
# per_page - (optional) The number of results per page. The maximum number of books per page is 100. This is also the default.
|
130
|
+
# delta_range_start_date - (optional) This date range limits the result set to inventory_books that were last modified within the given time period. The delta_range_start_date is included in the date range. Delta result records will represent out of stock inventory with quantities of zero. All date formats must be based on the RFC3339 profile of ISO8601.
|
131
|
+
# delta_range_end_date - (optional) End date for the delta result set being requested. If this element is omitted, the current date/time will be used. The delta_range_end_date is excluded in the date range.
|
132
|
+
# in_store - (optional) Defaults to false. Set to true to get rental prices for in-store inventory. Set to false to get online prices from BookRenter.com.
|
133
|
+
#
|
134
|
+
def retrieve_inventory(isbns = nil, segment = nil, page = nil, per_page = nil, delta_range_start_date = nil, delta_range_end_date = nil, in_store = nil)
|
135
|
+
|
136
|
+
service_url = ""
|
137
|
+
|
138
|
+
if (isbns.present? && isbns.length > 0)
|
139
|
+
service_url << "isbns=" << isbns.join(',') << '&'
|
140
|
+
end
|
141
|
+
|
142
|
+
if (segment.present?)
|
143
|
+
service_url << "segment=" << segment << "&"
|
144
|
+
end
|
145
|
+
|
146
|
+
if (page.present?)
|
147
|
+
service_url << "page=" << page << "&"
|
148
|
+
end
|
149
|
+
|
150
|
+
if (per_page.present?)
|
151
|
+
service_url << "per_page=" << per_page << "&"
|
152
|
+
end
|
153
|
+
|
154
|
+
if (delta_range_start_date.present?)
|
155
|
+
service_url << "delta_range_start_date=" << delta_range_start_date << "&"
|
156
|
+
end
|
157
|
+
|
158
|
+
if (delta_range_end_date.present?)
|
159
|
+
service_url << "delta_range_end_date=" << delta_range_end_date << "&"
|
160
|
+
end
|
161
|
+
|
162
|
+
if (in_store.present?)
|
163
|
+
service_url << "in_store=#{in_store}&"
|
164
|
+
end
|
165
|
+
|
166
|
+
url = '/inventory_books.xml'
|
167
|
+
if (service_url != "")
|
168
|
+
service_url = service_url[0..-2]
|
169
|
+
url = "/inventory_books.xml?#{service_url}"
|
170
|
+
end
|
171
|
+
|
172
|
+
BWS::Inventory.new(get(url))
|
173
|
+
end
|
174
|
+
|
175
|
+
#
|
176
|
+
# Retrieves a single book with pricing and available rental terms.
|
177
|
+
#
|
178
|
+
# Parameters:
|
179
|
+
# BOOK_ISBN_13 - The ISBN13 for the book requesting inventory.
|
180
|
+
# segment - (optional) Your inventory specific segmentation. If your inventory is segmented, this may affect the price and periods available.
|
181
|
+
# in_store - (optional) Defaults to false. Set to true to get rental prices for in-store inventory. Set to false to prices for online offers fulfilled by BookRenter.
|
182
|
+
#
|
183
|
+
def retrieve_inventory_by_isbn(isbn = nil, segment = nil, in_store = nil)
|
184
|
+
raise BadParams unless isbn
|
185
|
+
|
186
|
+
service_url = ""
|
187
|
+
|
188
|
+
if (segment.present?)
|
189
|
+
service_url << "segment=" << segment << "&"
|
190
|
+
end
|
191
|
+
|
192
|
+
if (in_store.present?)
|
193
|
+
service_url << "in_store=#{in_store}&"
|
194
|
+
end
|
195
|
+
|
196
|
+
url = "/inventory_books/#{isbn}.xml"
|
197
|
+
if (service_url != "")
|
198
|
+
service_url = service_url[0..-2]
|
199
|
+
url = "/inventory_books/#{isbn}.xml?#{service_url}"
|
200
|
+
end
|
201
|
+
|
202
|
+
BWS::Inventory.new(get(url))
|
203
|
+
end
|
204
|
+
|
205
|
+
#
|
206
|
+
# Retrieves order events for for a specified time period.
|
207
|
+
#
|
208
|
+
# Parameters:
|
209
|
+
# start_time - (optional) The start time of events to retrieve. If not specified, starts at first event.
|
210
|
+
# end_time - (optional) The start time of events to retrieve. If not specified, starts at first event.
|
211
|
+
# types - (optional) Include only the types of events specified. If not specified, all events are included. Valid events types are order_created, order_charged, order_frozen_for_fraud_check, order_failed_fraud_check, line_item_cancelled, line_item_shipment_to_customer_created, line_item_replaced, line_item_refunded, line_item_extended, line_item_purchased, line_item_shipment_to_receiving_facility_created, line_item_checked_in.
|
212
|
+
# page - (optional) The page number to request. Page numbers start at 1.
|
213
|
+
# per_page - (optional) The number of results per page. The maximum number of events per page is 25. This is also the default.
|
214
|
+
#
|
215
|
+
def retrieve_order_events(types = nil, start_time = nil, end_time = nil, page = nil, per_page = nil)
|
216
|
+
|
217
|
+
service_url = ""
|
218
|
+
|
219
|
+
if (start_time)
|
220
|
+
service_url << "start_time=" << start_time << "&"
|
221
|
+
end
|
222
|
+
|
223
|
+
if (end_time)
|
224
|
+
service_url << "end_time=" << end_time << "&"
|
225
|
+
end
|
226
|
+
|
227
|
+
if (types && types.length > 0)
|
228
|
+
service_url << "types=" << types.join(',') << '&'
|
229
|
+
end
|
230
|
+
|
231
|
+
if (page)
|
232
|
+
service_url << "page=" << page << "&"
|
233
|
+
end
|
234
|
+
|
235
|
+
if (per_page)
|
236
|
+
service_url << "per_page=" << per_page << "&"
|
237
|
+
end
|
238
|
+
|
239
|
+
url = '/order_events.xml'
|
240
|
+
if (service_url != "")
|
241
|
+
service_url = service_url[0..-2]
|
242
|
+
url = "/order_events.xml?#{service_url}"
|
243
|
+
end
|
244
|
+
|
245
|
+
BWS::OrderEvents.new(get(url))
|
246
|
+
end
|
247
|
+
|
248
|
+
#
|
249
|
+
# Retrieves all events for a specific order.
|
250
|
+
#
|
251
|
+
# Parameters:
|
252
|
+
# BR-ORDER-ID - The Bookrenter Order ID.
|
253
|
+
# types - (optional) Include only the types of events specified. If not specified, all events are included. Valid events types are order_created, order_charged, order_frozen_for_fraud_check, order_failed_fraud_check, line_item_cancelled, line_item_shipment_to_customer_created, line_item_replaced, line_item_refunded, line_item_extended, line_item_purchased, line_item_shipment_to_receiving_facility_created, line_item_checked_in.
|
254
|
+
#
|
255
|
+
def retrieve_order_events_by_order(types = nil, br_order_id = nil)
|
256
|
+
raise BadParams unless br_order_id
|
257
|
+
|
258
|
+
service_url = ""
|
259
|
+
|
260
|
+
if (types && types.length > 0)
|
261
|
+
service_url << "types=" << types.join(',') << '&'
|
262
|
+
end
|
263
|
+
|
264
|
+
url = "/order_events/#{br_order_id}.xml"
|
265
|
+
if (service_url != "")
|
266
|
+
service_url = service_url[0..-2]
|
267
|
+
url = "/order_events/#{br_order_id}.xml?#{service_url}"
|
268
|
+
end
|
269
|
+
|
270
|
+
BWS::OrderEvents.new(get(url))
|
271
|
+
end
|
272
|
+
|
273
|
+
#
|
274
|
+
# View a customer's order data on BookRenter. This service displays most order information necessary to gather status and shipment detail for a given order.
|
275
|
+
#
|
276
|
+
# Parameters:
|
277
|
+
# public_id* - (optional) BookRenter's unique identifier for this order
|
278
|
+
# external_order_id* - (optional) Partner's unique identifier for this order
|
279
|
+
#
|
280
|
+
# * either BookRenter public_id or Partner external_order_id must be provided in the url.
|
281
|
+
#
|
282
|
+
# order_id can receive public_id or external_order_id
|
283
|
+
#
|
284
|
+
def retrieve_orders_show(order_id = nil)
|
285
|
+
raise BadParams unless order_id
|
286
|
+
|
287
|
+
url = "/orders/#{order_id}.xml"
|
288
|
+
|
289
|
+
BWS::Orders.new(get(url))
|
290
|
+
end
|
291
|
+
|
292
|
+
#
|
293
|
+
# The first step of order checkout. From a user's phone number, product list, shipping information, billing information, gets the product price, subtotal, subtotal tax, and available shipping options. Shipping options include price and tax information for each available shipping method.
|
294
|
+
#
|
295
|
+
# Note: If customer, billing address, shipping address or products changes, you will need to re-price the order.
|
296
|
+
#
|
297
|
+
def checkout_price_order(checkout_price_order_hash = nil)
|
298
|
+
raise BadParams unless checkout_price_order_hash
|
299
|
+
|
300
|
+
xml_target = ''
|
301
|
+
xml = Builder::XmlMarkup.new :target => xml_target
|
302
|
+
xml.envelope do
|
303
|
+
xml.body do
|
304
|
+
xml.checkout_price_order do
|
305
|
+
if checkout_price_order_hash['customer']
|
306
|
+
xml.customer do
|
307
|
+
xml.email checkout_price_order_hash['customer']['email'] if checkout_price_order_hash['customer']['email']
|
308
|
+
xml.external_user_id checkout_price_order_hash['customer']['external_user_id'] if checkout_price_order_hash['customer']['external_user_id']
|
309
|
+
xml.mobile_phone_number checkout_price_order_hash['customer']['mobile_phone_number'] if checkout_price_order_hash['customer']['mobile_phone_number']
|
310
|
+
end
|
311
|
+
end
|
312
|
+
if checkout_price_order_hash['product_list']
|
313
|
+
xml.product_list do
|
314
|
+
xml.segment checkout_price_order_hash['product_list']['segment'] if checkout_price_order_hash['product_list']['segment']
|
315
|
+
if checkout_price_order_hash['product_list']['products']
|
316
|
+
xml.products do
|
317
|
+
if checkout_price_order_hash['product_list']['products']['product'].class == Array
|
318
|
+
checkout_price_order_hash['product_list']['products']['product'].each do |product|
|
319
|
+
xml.product do
|
320
|
+
xml.product_id product['product_id'] if product['product_id']
|
321
|
+
xml.product_type product['product_type'] if product['product_type']
|
322
|
+
xml.quantity product['quantity'] if product['quantity']
|
323
|
+
xml.rental_period product['rental_period'] if product['rental_period']
|
324
|
+
end
|
325
|
+
end
|
326
|
+
else
|
327
|
+
product = checkout_price_order_hash['product_list']['products']['product']
|
328
|
+
xml.product do
|
329
|
+
xml.product_id product['product_id'] if product['product_id']
|
330
|
+
xml.product_type product['product_type'] if product['product_type']
|
331
|
+
xml.quantity product['quantity'] if product['quantity']
|
332
|
+
xml.rental_period product['rental_period'] if product['rental_period']
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
if checkout_price_order_hash['billing_address']
|
340
|
+
xml.billing_address do
|
341
|
+
xml.first_name checkout_price_order_hash['billing_address']['first_name'] if checkout_price_order_hash['billing_address']['first_name']
|
342
|
+
xml.last_name checkout_price_order_hash['billing_address']['last_name'] if checkout_price_order_hash['billing_address']['last_name']
|
343
|
+
xml.street_address checkout_price_order_hash['billing_address']['street_address'] if checkout_price_order_hash['billing_address']['street_address']
|
344
|
+
xml.street_address_2 checkout_price_order_hash['billing_address']['street_address_2'] if checkout_price_order_hash['billing_address']['street_address_2']
|
345
|
+
xml.city checkout_price_order_hash['billing_address']['city'] if checkout_price_order_hash['billing_address']['city']
|
346
|
+
xml.state checkout_price_order_hash['billing_address']['state'] if checkout_price_order_hash['billing_address']['state']
|
347
|
+
xml.zip checkout_price_order_hash['billing_address']['zip'] if checkout_price_order_hash['billing_address']['zip']
|
348
|
+
xml.country checkout_price_order_hash['billing_address']['country'] if checkout_price_order_hash['billing_address']['country']
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
if checkout_price_order_hash['shipping_address']
|
353
|
+
xml.shipping_address do
|
354
|
+
xml.first_name checkout_price_order_hash['shipping_address']['first_name'] if checkout_price_order_hash['shipping_address']['first_name']
|
355
|
+
xml.last_name checkout_price_order_hash['shipping_address']['last_name'] if checkout_price_order_hash['shipping_address']['last_name']
|
356
|
+
xml.street_address checkout_price_order_hash['shipping_address']['street_address'] if checkout_price_order_hash['shipping_address']['street_address']
|
357
|
+
xml.street_address_2 checkout_price_order_hash['shipping_address']['street_address_2'] if checkout_price_order_hash['shipping_address']['street_address_2']
|
358
|
+
xml.city checkout_price_order_hash['shipping_address']['city'] if checkout_price_order_hash['shipping_address']['city']
|
359
|
+
xml.state checkout_price_order_hash['shipping_address']['state'] if checkout_price_order_hash['shipping_address']['state']
|
360
|
+
xml.zip checkout_price_order_hash['shipping_address']['zip'] if checkout_price_order_hash['shipping_address']['zip']
|
361
|
+
xml.country checkout_price_order_hash['shipping_address']['country'] if checkout_price_order_hash['shipping_address']['country']
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
BWS::Checkout.new(post("/checkout/price_order.xml", xml_target))
|
368
|
+
end
|
369
|
+
|
370
|
+
#
|
371
|
+
# The second step of order checkout. Ensures that the credit card is valid. Renting books requires that the card expiration extend beyond the date of the latest return date for the books being rented.
|
372
|
+
#
|
373
|
+
# Note: If billing address or products changes, you will need to re-validate the credit card information.
|
374
|
+
#
|
375
|
+
def checkout_validate_credit_card(checkout_validate_credit_card_hash = nil)
|
376
|
+
raise BadParams unless checkout_validate_credit_card_hash
|
377
|
+
|
378
|
+
xml_target = ''
|
379
|
+
xml = Builder::XmlMarkup.new :target => xml_target
|
380
|
+
xml.envelope do
|
381
|
+
xml.body do
|
382
|
+
xml.checkout_validate_credit_card do
|
383
|
+
xml.checkout_verification_code checkout_validate_credit_card_hash['checkout_verification_code'] if checkout_validate_credit_card_hash['checkout_verification_code']
|
384
|
+
if checkout_validate_credit_card_hash['product_list']
|
385
|
+
xml.product_list do
|
386
|
+
xml.product_list_verification_code checkout_validate_credit_card_hash['product_list']['product_list_verification_code'] if checkout_validate_credit_card_hash['product_list']['product_list_verification_code']
|
387
|
+
xml.segment checkout_validate_credit_card_hash['product_list']['segment'] if checkout_validate_credit_card_hash['product_list']['segment']
|
388
|
+
if checkout_validate_credit_card_hash['product_list']['products']
|
389
|
+
xml.products do
|
390
|
+
if checkout_validate_credit_card_hash['product_list']['products']['product'].class == Array
|
391
|
+
checkout_validate_credit_card_hash['product_list']['products']['product'].each do |product|
|
392
|
+
xml.product do
|
393
|
+
xml.product_id product['product_id'] if product['product_id']
|
394
|
+
xml.product_type product['product_type'] if product['product_type']
|
395
|
+
xml.quantity product['quantity'] if product['quantity']
|
396
|
+
xml.rental_period product['rental_period'] if product['rental_period']
|
397
|
+
end
|
398
|
+
end
|
399
|
+
else
|
400
|
+
product = checkout_validate_credit_card_hash['product_list']['products']['product']
|
401
|
+
xml.product do
|
402
|
+
xml.product_id product['product_id'] if product['product_id']
|
403
|
+
xml.product_type product['product_type'] if product['product_type']
|
404
|
+
xml.quantity product['quantity'] if product['quantity']
|
405
|
+
xml.rental_period product['rental_period'] if product['rental_period']
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
if checkout_validate_credit_card_hash['billing_address']
|
413
|
+
xml.billing_address do
|
414
|
+
xml.billing_address_verification_code checkout_validate_credit_card_hash['billing_address']['billing_address_verification_code'] if checkout_validate_credit_card_hash['billing_address']['billing_address_verification_code']
|
415
|
+
xml.first_name checkout_validate_credit_card_hash['billing_address']['first_name'] if checkout_validate_credit_card_hash['billing_address']['first_name']
|
416
|
+
xml.last_name checkout_validate_credit_card_hash['billing_address']['last_name'] if checkout_validate_credit_card_hash['billing_address']['last_name']
|
417
|
+
xml.street_address checkout_validate_credit_card_hash['billing_address']['street_address'] if checkout_validate_credit_card_hash['billing_address']['street_address']
|
418
|
+
xml.street_address_2 checkout_validate_credit_card_hash['billing_address']['street_address_2'] if checkout_validate_credit_card_hash['billing_address']['street_address_2']
|
419
|
+
xml.city checkout_validate_credit_card_hash['billing_address']['city'] if checkout_validate_credit_card_hash['billing_address']['city']
|
420
|
+
xml.state checkout_validate_credit_card_hash['billing_address']['state'] if checkout_validate_credit_card_hash['billing_address']['state']
|
421
|
+
xml.zip checkout_validate_credit_card_hash['billing_address']['zip'] if checkout_validate_credit_card_hash['billing_address']['zip']
|
422
|
+
xml.country checkout_validate_credit_card_hash['billing_address']['country'] if checkout_validate_credit_card_hash['billing_address']['country']
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
if checkout_validate_credit_card_hash['credit_card']
|
427
|
+
xml.credit_card do
|
428
|
+
xml.number checkout_validate_credit_card_hash['credit_card']['number'] if checkout_validate_credit_card_hash['credit_card']['number']
|
429
|
+
xml.month checkout_validate_credit_card_hash['credit_card']['month'] if checkout_validate_credit_card_hash['credit_card']['month']
|
430
|
+
xml.year checkout_validate_credit_card_hash['credit_card']['year'] if checkout_validate_credit_card_hash['credit_card']['year']
|
431
|
+
xml.verification_value checkout_validate_credit_card_hash['credit_card']['verification_value'] if checkout_validate_credit_card_hash['credit_card']['verification_value']
|
432
|
+
xml.type checkout_validate_credit_card_hash['credit_card']['type'] if checkout_validate_credit_card_hash['credit_card']['type']
|
433
|
+
end
|
434
|
+
end
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|
438
|
+
BWS::Checkout.new(post("/checkout/validate_credit_card.xml", xml_target))
|
439
|
+
end
|
440
|
+
|
441
|
+
#
|
442
|
+
# The second step of order checkout. Ensures that the credit card is valid. Renting books requires that the card expiration extend beyond the date of the latest return date for the books being rented.
|
443
|
+
#
|
444
|
+
# Note: If billing address or products changes, you will need to re-validate the credit card information.
|
445
|
+
#
|
446
|
+
def checkout_create_order(checkout_create_order_hash = nil)
|
447
|
+
raise BadParams unless checkout_create_order_hash
|
448
|
+
|
449
|
+
xml_target = ''
|
450
|
+
xml = Builder::XmlMarkup.new :target => xml_target
|
451
|
+
xml.envelope do
|
452
|
+
xml.body do
|
453
|
+
xml.checkout_create_order do
|
454
|
+
xml.checkout_verification_code checkout_create_order_hash['checkout_verification_code'] if checkout_create_order_hash['checkout_verification_code']
|
455
|
+
xml.charge_amount_cents checkout_create_order_hash['charge_amount_cents'] if checkout_create_order_hash['charge_amount_cents']
|
456
|
+
xml.external_order_id checkout_create_order_hash['external_order_id'] if checkout_create_order_hash['external_order_id']
|
457
|
+
if checkout_create_order_hash['customer']
|
458
|
+
xml.customer do
|
459
|
+
xml.customer_verification_code checkout_create_order_hash['customer']['customer_verification_code'] if checkout_create_order_hash['customer']['customer_verification_code']
|
460
|
+
xml.email checkout_create_order_hash['customer']['email'] if checkout_create_order_hash['customer']['email']
|
461
|
+
xml.external_user_id checkout_create_order_hash['customer']['external_user_id'] if checkout_create_order_hash['customer']['external_user_id']
|
462
|
+
xml.mobile_phone_number checkout_create_order_hash['customer']['mobile_phone_number'] if checkout_create_order_hash['customer']['mobile_phone_number']
|
463
|
+
end
|
464
|
+
end
|
465
|
+
if checkout_create_order_hash['product_list']
|
466
|
+
xml.product_list do
|
467
|
+
xml.product_list_verification_code checkout_create_order_hash['product_list']['product_list_verification_code'] if checkout_create_order_hash['product_list']['product_list_verification_code']
|
468
|
+
xml.segment checkout_create_order_hash['product_list']['segment'] if checkout_create_order_hash['product_list']['segment']
|
469
|
+
if checkout_create_order_hash['product_list']['products']
|
470
|
+
xml.products do
|
471
|
+
if checkout_create_order_hash['product_list']['products']['product'].class == Array
|
472
|
+
checkout_create_order_hash['product_list']['products']['product'].each do |product|
|
473
|
+
xml.product do
|
474
|
+
xml.product_id product['product_id'] if product['product_id']
|
475
|
+
xml.product_type product['product_type'] if product['product_type']
|
476
|
+
xml.quantity product['quantity'] if product['quantity']
|
477
|
+
xml.rental_due_date product['rental_due_date'] if product['rental_due_date']
|
478
|
+
xml.rental_period product['rental_period'] if product['rental_period']
|
479
|
+
if product['external_line_item_ids']
|
480
|
+
xml.external_line_item_ids do
|
481
|
+
if product['external_line_item_ids']['external_line_item_id'].class == Array
|
482
|
+
product['external_line_item_ids']['external_line_item_id'].each do |external_line_item_id|
|
483
|
+
xml.external_line_item_id external_line_item_id
|
484
|
+
end
|
485
|
+
else
|
486
|
+
external_line_item_id = product['external_line_item_ids']['external_line_item_id']
|
487
|
+
xml.external_line_item_id external_line_item_id
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
end
|
492
|
+
end
|
493
|
+
else
|
494
|
+
product = checkout_create_order_hash['product_list']['products']['product']
|
495
|
+
xml.product do
|
496
|
+
xml.product_id product['product_id'] if product['product_id']
|
497
|
+
xml.product_type product['product_type'] if product['product_type']
|
498
|
+
xml.quantity product['quantity'] if product['quantity']
|
499
|
+
xml.rental_due_date product['rental_due_date'] if product['rental_due_date']
|
500
|
+
xml.rental_period product['rental_period'] if product['rental_period']
|
501
|
+
if product['external_line_item_ids']
|
502
|
+
xml.external_line_item_ids do
|
503
|
+
if product['external_line_item_ids']['external_line_item_id'].class == Array
|
504
|
+
product['external_line_item_ids']['external_line_item_id'].each do |external_line_item_id|
|
505
|
+
xml.external_line_item_id external_line_item_id
|
506
|
+
end
|
507
|
+
else
|
508
|
+
external_line_item_id = product['external_line_item_ids']['external_line_item_id']
|
509
|
+
xml.external_line_item_id external_line_item_id
|
510
|
+
end
|
511
|
+
end
|
512
|
+
end
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|
516
|
+
end
|
517
|
+
end
|
518
|
+
end
|
519
|
+
if checkout_create_order_hash['billing_address']
|
520
|
+
xml.billing_address do
|
521
|
+
xml.billing_address_verification_code checkout_create_order_hash['billing_address']['billing_address_verification_code'] if checkout_create_order_hash['billing_address']['billing_address_verification_code']
|
522
|
+
xml.first_name checkout_create_order_hash['billing_address']['first_name'] if checkout_create_order_hash['billing_address']['first_name']
|
523
|
+
xml.last_name checkout_create_order_hash['billing_address']['last_name'] if checkout_create_order_hash['billing_address']['last_name']
|
524
|
+
xml.street_address checkout_create_order_hash['billing_address']['street_address'] if checkout_create_order_hash['billing_address']['street_address']
|
525
|
+
xml.street_address_2 checkout_create_order_hash['billing_address']['street_address_2'] if checkout_create_order_hash['billing_address']['street_address_2']
|
526
|
+
xml.city checkout_create_order_hash['billing_address']['city'] if checkout_create_order_hash['billing_address']['city']
|
527
|
+
xml.state checkout_create_order_hash['billing_address']['state'] if checkout_create_order_hash['billing_address']['state']
|
528
|
+
xml.zip checkout_create_order_hash['billing_address']['zip'] if checkout_create_order_hash['billing_address']['zip']
|
529
|
+
xml.country checkout_create_order_hash['billing_address']['country'] if checkout_create_order_hash['billing_address']['country']
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
if checkout_create_order_hash['shipping_address']
|
534
|
+
xml.shipping_address do
|
535
|
+
xml.shipping_address_verification_code checkout_create_order_hash['shipping_address']['shipping_address_verification_code'] if checkout_create_order_hash['shipping_address']['shipping_address_verification_code']
|
536
|
+
xml.first_name checkout_create_order_hash['shipping_address']['first_name'] if checkout_create_order_hash['shipping_address']['first_name']
|
537
|
+
xml.last_name checkout_create_order_hash['shipping_address']['last_name'] if checkout_create_order_hash['shipping_address']['last_name']
|
538
|
+
xml.street_address checkout_create_order_hash['shipping_address']['street_address'] if checkout_create_order_hash['shipping_address']['street_address']
|
539
|
+
xml.street_address_2 checkout_create_order_hash['shipping_address']['street_address_2'] if checkout_create_order_hash['shipping_address']['street_address_2']
|
540
|
+
xml.city checkout_create_order_hash['shipping_address']['city'] if checkout_create_order_hash['shipping_address']['city']
|
541
|
+
xml.state checkout_create_order_hash['shipping_address']['state'] if checkout_create_order_hash['shipping_address']['state']
|
542
|
+
xml.zip checkout_create_order_hash['shipping_address']['zip'] if checkout_create_order_hash['shipping_address']['zip']
|
543
|
+
xml.country checkout_create_order_hash['shipping_address']['country'] if checkout_create_order_hash['shipping_address']['country']
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
if checkout_create_order_hash['credit_card']
|
548
|
+
xml.credit_card do
|
549
|
+
xml.credit_card_verification_code checkout_create_order_hash['credit_card']['credit_card_verification_code'] if checkout_create_order_hash['credit_card']['credit_card_verification_code']
|
550
|
+
xml.number checkout_create_order_hash['credit_card']['number'] if checkout_create_order_hash['credit_card']['number']
|
551
|
+
xml.month checkout_create_order_hash['credit_card']['month'] if checkout_create_order_hash['credit_card']['month']
|
552
|
+
xml.year checkout_create_order_hash['credit_card']['year'] if checkout_create_order_hash['credit_card']['year']
|
553
|
+
xml.verification_value checkout_create_order_hash['credit_card']['verification_value'] if checkout_create_order_hash['credit_card']['verification_value']
|
554
|
+
xml.type checkout_create_order_hash['credit_card']['type'] if checkout_create_order_hash['credit_card']['type']
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
if checkout_create_order_hash['shipping_option']
|
559
|
+
xml.shipping_option do
|
560
|
+
xml.shipping_option_verification_code checkout_create_order_hash['shipping_option']['shipping_option_verification_code'] if checkout_create_order_hash['shipping_option']['shipping_option_verification_code']
|
561
|
+
xml.method_name checkout_create_order_hash['shipping_option']['method_name'] if checkout_create_order_hash['shipping_option']['method_name']
|
562
|
+
end
|
563
|
+
end
|
564
|
+
end
|
565
|
+
end
|
566
|
+
end
|
567
|
+
BWS::Checkout.new(post("/checkout/create_order.xml", xml_target))
|
568
|
+
end
|
569
|
+
|
570
|
+
#
|
571
|
+
# Creates an order from the information provided in the Request Body. Used as an alternative to the 3 step create order process. It can be utilized when all required information is available on the partner site at request time
|
572
|
+
#
|
573
|
+
# Note: All input data will be validated prior to order creation. See Errors section for details on possible failed validation responses.
|
574
|
+
#
|
575
|
+
def checkout_single_post_create_order(checkout_single_post_create_order_hash = nil)
|
576
|
+
raise BadParams unless checkout_single_post_create_order_hash
|
577
|
+
|
578
|
+
xml_target = ''
|
579
|
+
xml = Builder::XmlMarkup.new :target => xml_target
|
580
|
+
xml.envelope do
|
581
|
+
xml.body do
|
582
|
+
xml.checkout_single_post_create_order do
|
583
|
+
xml.date_ordered checkout_single_post_create_order_hash['date_ordered'] if checkout_single_post_create_order_hash['date_ordered']
|
584
|
+
xml.charge_amount_cents checkout_single_post_create_order_hash['charge_amount_cents'] if checkout_single_post_create_order_hash['charge_amount_cents']
|
585
|
+
xml.external_order_id checkout_single_post_create_order_hash['external_order_id'] if checkout_single_post_create_order_hash['external_order_id']
|
586
|
+
if checkout_single_post_create_order_hash['customer']
|
587
|
+
xml.customer do
|
588
|
+
xml.customer_verification_code checkout_single_post_create_order_hash['customer']['customer_verification_code'] if checkout_single_post_create_order_hash['customer']['customer_verification_code']
|
589
|
+
xml.email checkout_single_post_create_order_hash['customer']['email'] if checkout_single_post_create_order_hash['customer']['email']
|
590
|
+
xml.external_user_id checkout_single_post_create_order_hash['customer']['external_user_id'] if checkout_single_post_create_order_hash['customer']['external_user_id']
|
591
|
+
xml.mobile_phone_number checkout_single_post_create_order_hash['customer']['mobile_phone_number'] if checkout_single_post_create_order_hash['customer']['mobile_phone_number']
|
592
|
+
end
|
593
|
+
end
|
594
|
+
if checkout_single_post_create_order_hash['product_list']
|
595
|
+
xml.product_list do
|
596
|
+
xml.subtotal_cents checkout_single_post_create_order_hash['product_list']['subtotal_cents'] if checkout_single_post_create_order_hash['product_list']['subtotal_cents']
|
597
|
+
xml.subtotal_tax_cents checkout_single_post_create_order_hash['product_list']['subtotal_tax_cents'] if checkout_single_post_create_order_hash['product_list']['subtotal_tax_cents']
|
598
|
+
|
599
|
+
if checkout_single_post_create_order_hash['product_list']['products']
|
600
|
+
xml.products do
|
601
|
+
|
602
|
+
xml.segment checkout_single_post_create_order_hash['product_list']['products']['segment'] if checkout_single_post_create_order_hash['product_list']['products']['segment']
|
603
|
+
if checkout_single_post_create_order_hash['product_list']['products']['product'].class == Array
|
604
|
+
checkout_single_post_create_order_hash['product_list']['products']['product'].each do |product|
|
605
|
+
xml.product do
|
606
|
+
xml.product_id product['product_id'] if product['product_id']
|
607
|
+
xml.product_type product['product_type'] if product['product_type']
|
608
|
+
xml.quantity product['quantity'] if product['quantity']
|
609
|
+
xml.rental_due_date product['rental_due_date'] if product['rental_due_date']
|
610
|
+
xml.rental_period product['rental_period'] if product['rental_period']
|
611
|
+
if product['external_line_item_ids']
|
612
|
+
xml.external_line_item_ids do
|
613
|
+
if product['external_line_item_ids']['external_line_item_id'].class == Array
|
614
|
+
product['external_line_item_ids']['external_line_item_id'].each do |external_line_item_id|
|
615
|
+
xml.external_line_item_id external_line_item_id
|
616
|
+
end
|
617
|
+
else
|
618
|
+
external_line_item_id = product['external_line_item_ids']['external_line_item_id']
|
619
|
+
xml.external_line_item_id external_line_item_id
|
620
|
+
end
|
621
|
+
end
|
622
|
+
end
|
623
|
+
xml.price_cents product['price_cents'] if product['price_cents']
|
624
|
+
xml.retail_price_cents product['retail_price_cents'] if product['retail_price_cents']
|
625
|
+
|
626
|
+
if product['line_item_extension']
|
627
|
+
xml.line_item_extension do
|
628
|
+
xml.external_line_item_id product['line_item_extension']['external_line_item_id'] if product['line_item_extension']['external_line_item_id']
|
629
|
+
xml.period product['line_item_extension']['period'] if product['line_item_extension']['period']
|
630
|
+
end
|
631
|
+
end
|
632
|
+
|
633
|
+
end
|
634
|
+
end
|
635
|
+
else
|
636
|
+
product = checkout_single_post_create_order_hash['product_list']['products']['product']
|
637
|
+
xml.product do
|
638
|
+
xml.product_id product['product_id'] if product['product_id']
|
639
|
+
xml.product_type product['product_type'] if product['product_type']
|
640
|
+
xml.quantity product['quantity'] if product['quantity']
|
641
|
+
xml.rental_due_date product['rental_due_date'] if product['rental_due_date']
|
642
|
+
xml.rental_period product['rental_period'] if product['rental_period']
|
643
|
+
if product['external_line_item_ids']
|
644
|
+
xml.external_line_item_ids do
|
645
|
+
if product['external_line_item_ids']['external_line_item_id'].class == Array
|
646
|
+
product['external_line_item_ids']['external_line_item_id'].each do |external_line_item_id|
|
647
|
+
xml.external_line_item_id external_line_item_id
|
648
|
+
end
|
649
|
+
else
|
650
|
+
external_line_item_id = product['external_line_item_ids']['external_line_item_id']
|
651
|
+
xml.external_line_item_id external_line_item_id
|
652
|
+
end
|
653
|
+
end
|
654
|
+
end
|
655
|
+
xml.price_cents product['price_cents'] if product['price_cents']
|
656
|
+
xml.retail_price_cents product['retail_price_cents'] if product['retail_price_cents']
|
657
|
+
|
658
|
+
if product['line_item_extension']
|
659
|
+
xml.line_item_extension do
|
660
|
+
xml.external_line_item_id product['line_item_extension']['external_line_item_id'] if product['line_item_extension']['external_line_item_id']
|
661
|
+
xml.period product['line_item_extension']['period'] if product['line_item_extension']['period']
|
662
|
+
end
|
663
|
+
end
|
664
|
+
|
665
|
+
end
|
666
|
+
end
|
667
|
+
end
|
668
|
+
end
|
669
|
+
end
|
670
|
+
end
|
671
|
+
if checkout_single_post_create_order_hash['billing_address']
|
672
|
+
xml.billing_address do
|
673
|
+
xml.billing_address_verification_code checkout_single_post_create_order_hash['billing_address']['billing_address_verification_code'] if checkout_single_post_create_order_hash['billing_address']['billing_address_verification_code']
|
674
|
+
xml.first_name checkout_single_post_create_order_hash['billing_address']['first_name'] if checkout_single_post_create_order_hash['billing_address']['first_name']
|
675
|
+
xml.last_name checkout_single_post_create_order_hash['billing_address']['last_name'] if checkout_single_post_create_order_hash['billing_address']['last_name']
|
676
|
+
xml.street_address checkout_single_post_create_order_hash['billing_address']['street_address'] if checkout_single_post_create_order_hash['billing_address']['street_address']
|
677
|
+
if checkout_single_post_create_order_hash['billing_address']['street_address_2']
|
678
|
+
xml.street_address_2 checkout_single_post_create_order_hash['billing_address']['street_address_2']
|
679
|
+
else
|
680
|
+
xml.street_address_2 ""
|
681
|
+
end
|
682
|
+
xml.city checkout_single_post_create_order_hash['billing_address']['city'] if checkout_single_post_create_order_hash['billing_address']['city']
|
683
|
+
xml.state checkout_single_post_create_order_hash['billing_address']['state'] if checkout_single_post_create_order_hash['billing_address']['state']
|
684
|
+
xml.zip checkout_single_post_create_order_hash['billing_address']['zip'] if checkout_single_post_create_order_hash['billing_address']['zip']
|
685
|
+
xml.country checkout_single_post_create_order_hash['billing_address']['country'] if checkout_single_post_create_order_hash['billing_address']['country']
|
686
|
+
end
|
687
|
+
end
|
688
|
+
|
689
|
+
if checkout_single_post_create_order_hash['shipping_address']
|
690
|
+
xml.shipping_address do
|
691
|
+
xml.shipping_address_verification_code checkout_single_post_create_order_hash['shipping_address']['shipping_address_verification_code'] if checkout_single_post_create_order_hash['shipping_address']['shipping_address_verification_code']
|
692
|
+
xml.first_name checkout_single_post_create_order_hash['shipping_address']['first_name'] if checkout_single_post_create_order_hash['shipping_address']['first_name']
|
693
|
+
xml.last_name checkout_single_post_create_order_hash['shipping_address']['last_name'] if checkout_single_post_create_order_hash['shipping_address']['last_name']
|
694
|
+
xml.street_address checkout_single_post_create_order_hash['shipping_address']['street_address'] if checkout_single_post_create_order_hash['shipping_address']['street_address']
|
695
|
+
xml.street_address_2 checkout_single_post_create_order_hash['shipping_address']['street_address_2'] if checkout_single_post_create_order_hash['shipping_address']['street_address_2']
|
696
|
+
xml.city checkout_single_post_create_order_hash['shipping_address']['city'] if checkout_single_post_create_order_hash['shipping_address']['city']
|
697
|
+
xml.state checkout_single_post_create_order_hash['shipping_address']['state'] if checkout_single_post_create_order_hash['shipping_address']['state']
|
698
|
+
xml.zip checkout_single_post_create_order_hash['shipping_address']['zip'] if checkout_single_post_create_order_hash['shipping_address']['zip']
|
699
|
+
xml.country checkout_single_post_create_order_hash['shipping_address']['country'] if checkout_single_post_create_order_hash['shipping_address']['country']
|
700
|
+
end
|
701
|
+
end
|
702
|
+
|
703
|
+
if checkout_single_post_create_order_hash['credit_card']
|
704
|
+
xml.credit_card do
|
705
|
+
xml.credit_card_verification_code checkout_single_post_create_order_hash['credit_card']['credit_card_verification_code'] if checkout_single_post_create_order_hash['credit_card']['credit_card_verification_code']
|
706
|
+
xml.number checkout_single_post_create_order_hash['credit_card']['number'] if checkout_single_post_create_order_hash['credit_card']['number']
|
707
|
+
xml.month checkout_single_post_create_order_hash['credit_card']['month'] if checkout_single_post_create_order_hash['credit_card']['month']
|
708
|
+
xml.year checkout_single_post_create_order_hash['credit_card']['year'] if checkout_single_post_create_order_hash['credit_card']['year']
|
709
|
+
xml.verification_value checkout_single_post_create_order_hash['credit_card']['verification_value'] if checkout_single_post_create_order_hash['credit_card']['verification_value']
|
710
|
+
xml.type checkout_single_post_create_order_hash['credit_card']['type'] if checkout_single_post_create_order_hash['credit_card']['type']
|
711
|
+
end
|
712
|
+
end
|
713
|
+
|
714
|
+
if checkout_single_post_create_order_hash['shipping_option']
|
715
|
+
xml.shipping_option do
|
716
|
+
xml.method_name checkout_single_post_create_order_hash['shipping_option']['method_name'] if checkout_single_post_create_order_hash['shipping_option']['method_name']
|
717
|
+
xml.shipping_price_cents checkout_single_post_create_order_hash['shipping_option']['shipping_price_cents'] if checkout_single_post_create_order_hash['shipping_option']['shipping_price_cents']
|
718
|
+
xml.tax_cost_cents checkout_single_post_create_order_hash['shipping_option']['tax_cost_cents'] if checkout_single_post_create_order_hash['shipping_option']['tax_cost_cents']
|
719
|
+
end
|
720
|
+
end
|
721
|
+
end
|
722
|
+
end
|
723
|
+
end
|
724
|
+
BWS::Checkout.new(post("/checkout/single_post_create_order.xml", xml_target))
|
725
|
+
end
|
726
|
+
|
727
|
+
#
|
728
|
+
# TODO Implement this method following https://bws.demo.bookrenter.com/v1/retail_docs/create_store_order
|
729
|
+
# A file called test_sequoia_main_use_case.rb has that structure. It was sent by email.
|
730
|
+
#
|
731
|
+
def checkout_create_store_order(checkout_create_store_order_hash = nil)
|
732
|
+
raise BadParams unless checkout_single_post_create_order_hash
|
733
|
+
|
734
|
+
|
735
|
+
end
|
736
|
+
|
737
|
+
#
|
738
|
+
# This report produces a list of active ISBNs forecasted to be in the BookRenter eco-system.
|
739
|
+
# Each active_isbn record will include the elements listed in the response if they are available.
|
740
|
+
#
|
741
|
+
def retrieve_active_isbn_report(active_isbn_report_hash = nil)
|
742
|
+
raise BadParams unless active_isbn_report_hash
|
743
|
+
|
744
|
+
xml_target = ''
|
745
|
+
xml = Builder::XmlMarkup.new :target => xml_target
|
746
|
+
xml.envelope do
|
747
|
+
xml.body do
|
748
|
+
xml.reports_active_isbn_report do
|
749
|
+
if active_isbn_report_hash['pagination'] then
|
750
|
+
xml.pagination do
|
751
|
+
xml.page active_isbn_report_hash['pagination']['page'] if active_isbn_report_hash['pagination']['page']
|
752
|
+
xml.items_per_page active_isbn_report_hash['pagination']['items_per_page'] if active_isbn_report_hash['pagination']['items_per_page']
|
753
|
+
end
|
754
|
+
end
|
755
|
+
if active_isbn_report_hash['active_isbn_report'] then
|
756
|
+
xml.active_isbn_report do
|
757
|
+
if active_isbn_report_hash['active_isbn_report']['active_isbns'] then
|
758
|
+
xml.active_isbns do
|
759
|
+
if active_isbn_report_hash['active_isbn_report']['active_isbns']['active_isbn'] then
|
760
|
+
if active_isbn_report_hash['active_isbn_report']['active_isbns']['active_isbn'].class == Array then
|
761
|
+
active_isbns = active_isbn_report_hash['active_isbn_report']['active_isbns']['active_isbn']
|
762
|
+
else
|
763
|
+
active_isbns = [ active_isbn_report_hash['active_isbn_report']['active_isbns']['active_isbn'] ]
|
764
|
+
end
|
765
|
+
active_isbns.each do |active_isbn|
|
766
|
+
if active_isbn['isbn'] then
|
767
|
+
xml.active_isbn do
|
768
|
+
xml.isbn active_isbn['isbn']
|
769
|
+
end
|
770
|
+
end
|
771
|
+
end
|
772
|
+
end
|
773
|
+
end
|
774
|
+
end
|
775
|
+
end
|
776
|
+
end
|
777
|
+
end
|
778
|
+
end
|
779
|
+
end
|
780
|
+
BWS::ActiveIsbnReport.new(post("/reports/active_isbn_report.xml", xml_target))
|
781
|
+
end
|
782
|
+
|
783
|
+
private
|
784
|
+
def get(url)
|
785
|
+
full_url = url.match(/\?/) ? "#{base_uri}#{url}&api_key=#{api_key}" : "#{base_uri}#{url}?api_key=#{api_key}"
|
786
|
+
if(defined? Rails)
|
787
|
+
Rails.logger.debug("----------------------------------------------------------------------------------------")
|
788
|
+
Rails.logger.debug("BWS GET call")
|
789
|
+
Rails.logger.debug("URL: #{full_url}")
|
790
|
+
Rails.logger.debug("----------------------------------------------------------------------------------------")
|
791
|
+
end
|
792
|
+
self.class.get(full_url, :timeout => @timeout)
|
793
|
+
end
|
794
|
+
|
795
|
+
def post(url, data)
|
796
|
+
full_url = "#{base_uri}#{url}?api_key=#{api_key}"
|
797
|
+
if(defined? Rails)
|
798
|
+
Rails.logger.debug("----------------------------------------------------------------------------------------")
|
799
|
+
Rails.logger.debug("BWS POST call")
|
800
|
+
Rails.logger.debug("URL: #{full_url}")
|
801
|
+
Rails.logger.debug("XML: #{data}")
|
802
|
+
Rails.logger.debug("----------------------------------------------------------------------------------------")
|
803
|
+
end
|
804
|
+
self.class.post(full_url, :body => data, :timeout => @timeout)
|
805
|
+
end
|
806
|
+
end
|
807
|
+
end
|