Class: BeyondApi::Carts
- Includes:
- Utils
- Defined in:
- lib/beyond_api/resources/carts.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#add_line_item(cart_id, body) ⇒ OpenStruct
A
POST
request is used to add a line item to the cart. -
#create ⇒ OpenStruct
A
POST
request is used to create a cart. -
#create_order(cart_id, body) ⇒ OpenStruct
A
POST
request is used to create an order from the cart. -
#create_payment(cart_id, body) ⇒ OpenStruct
A
POST
request is used to initiate the creation of a payment. -
#create_payment_and_order(cart_id, body) ⇒ OpenStruct
A
POST
request is used to create an order from a cart and initiate the payment. -
#delete(cart_id) ⇒ Object
A
DELETE
request is used to delete a cart. -
#delete_line_item(cart_id, line_item_id) ⇒ Object
A
DELETE
request is used to delete a line item from the cart. -
#delete_shipping_address(cart_id) ⇒ Object
A
DELETE
request is used to remove the shipping address of the cart. -
#find(cart_id) ⇒ OpenStruct
A
GET
request is used to retrieve the details of a cart. -
#payment_method(cart_id) ⇒ OpenStruct
A
GET
request is used to retrieve the current payment method. -
#payment_methods(cart_id) ⇒ OpenStruct
A
GET
request is used to get the applicable payment methods of a cart. -
#replace_line_item(cart_id, line_item_id, body) ⇒ OpenStruct
A
PUT
request is used to replace only one line item in the cart. -
#replace_line_items(cart_id, body) ⇒ OpenStruct
A
PUT
request is used to replace the current line items in the cart with the given list. -
#set_billing_address(cart_id, body) ⇒ OpenStruct
A
PUT
request is used to set the billing address of the cart. -
#set_payment_method(cart_id, payment_method_id) ⇒ OpenStruct
A
PUT
request is used to set the current payment method of the cart. -
#set_payment_method_to_default(cart_id) ⇒ OpenStruct
A
PUT
request is used to set the payment method to the current default payment method. -
#set_shipping_address(cart_id, body) ⇒ OpenStruct
A
PUT
request is used to set the shipping address of the cart. -
#set_shipping_method(cart_id, shipping_zone_id, shipping_method_id) ⇒ OpenStruct
A
PUT
request is used to set the current shipping method of the cart. -
#set_shipping_method_to_default(cart_id) ⇒ OpenStruct
A
PUT
request is used to set the shipping method to the current default shipping method. -
#shipping_method(cart_id) ⇒ OpenStruct
A
GET
request is used to get the current shipping method. -
#shipping_methods(cart_id) ⇒ OpenStruct
A
GET
request is used to get the applicable shipping method of a cart.
Methods included from Utils
#file_content_type, #handle_all_request, #handle_error, #handle_response, #sanitize_key, #sanitize_response, #to_object_struct
Methods inherited from Base
Constructor Details
This class inherits a constructor from BeyondApi::Base
Instance Method Details
#add_line_item(cart_id, body) ⇒ OpenStruct
A POST
request is used to add a line item to the cart. Currently only product line items are supported.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/6d529573-b39e-4cd4-99fe-856432ea97f3/line-items' -i -X POST \
-H 'Content-Type: application/json' \
-d '{"_type":"PRODUCT","_ref":"c3a52c19-2b43-4ceb-a7ca-00c558aec072","quantity":1}'
29 30 31 32 33 34 35 |
# File 'lib/beyond_api/resources/carts.rb', line 29 def add_line_item(cart_id, body) response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/line-items", body) handle_response(response, status) end |
#create ⇒ OpenStruct
A POST
request is used to create a cart.
$ curl 'https://api-shop.beyondshop.cloud/api/carts' -i -X POST \
-H 'Accept: application/hal+json'
48 49 50 51 52 53 |
# File 'lib/beyond_api/resources/carts.rb', line 48 def create response, status = BeyondApi::Request.post(@session, "/carts") handle_response(response, status) end |
#create_order(cart_id, body) ⇒ OpenStruct
A POST
request is used to create an order from the cart.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/986247da-b78f-422c-a273-917804896974/order' -i -X POST \
-H 'Content-Type: application/json' \
-d '{"customerComment": "send it fast please",
"salesChannel": "DifferentChannel",
"marketingChannel": "Google",
"marketingSubchannel": "Search page 2",
"testOrder": false,
"termsAndConditionsExplicitlyAccepted": true
}'
158 159 160 161 162 163 164 |
# File 'lib/beyond_api/resources/carts.rb', line 158 def create_order(cart_id, body) response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/order", body) handle_response(response, status) end |
#create_payment(cart_id, body) ⇒ OpenStruct
A POST
request is used to initiate the creation of a payment.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/158bdcee-178a-4b5f-88ff-1953f5ea8e09/create-payment' -i -X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-d '{
"returnUri" : "http://some.com/return",
"cancelUri" : "http://some.com/cancel"
}'
78 79 80 81 82 83 84 |
# File 'lib/beyond_api/resources/carts.rb', line 78 def create_payment(cart_id, body) response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/create-payment", body) handle_response(response, status) end |
#create_payment_and_order(cart_id, body) ⇒ OpenStruct
A POST
request is used to create an order from a cart and initiate the payment.
$ curl ‘api-shop.beyondshop.cloud/api/carts/f6c6615b-a9f6-420e-be1d-46339ddc5fda/create-payment-and-order’ -i -X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-d '{
"returnUri" : "http://some.com/return",
"cancelUri" : "http://some.com/cancel",
"customerComment" : "Send it fast please!",
"salesChannel" : "Storefront",
"marketingChannel" : "Google",
"marketingSubchannel" : "Search page 2",
"testOrder" : false,
"termsAndConditionsExplicitlyAccepted" : false
}'
121 122 123 124 125 126 127 |
# File 'lib/beyond_api/resources/carts.rb', line 121 def create_payment_and_order(cart_id, body) response, status = BeyondApi::Request.post(@session, "/carts/#{cart_id}/create-payment-and-order", body) handle_response(response, status) end |
#delete(cart_id) ⇒ Object
A DELETE
request is used to delete a cart.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/1a58f22f-481a-4993-9947-62c1c2857f87' -i -X DELETE
178 179 180 181 182 183 |
# File 'lib/beyond_api/resources/carts.rb', line 178 def delete(cart_id) response, status = BeyondApi::Request.delete(@session, "/carts/#{cart_id}") handle_response(response, status, respond_with_true: true) end |
#delete_line_item(cart_id, line_item_id) ⇒ Object
A DELETE
request is used to delete a line item from the cart.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/3fb55475-f6d2-471a-90ac-ccee7896b9f7/line-items/51c86195-d2b9-4073-9a14-7ddd5a76b6a7' -i -X DELETE
198 199 200 201 202 203 |
# File 'lib/beyond_api/resources/carts.rb', line 198 def delete_line_item(cart_id, line_item_id) response, status = BeyondApi::Request.delete(@session, "/carts/#{cart_id}/line-items/#{line_item_id}") handle_response(response, status, respond_with_true: true) end |
#delete_shipping_address(cart_id) ⇒ Object
A DELETE
request is used to remove the shipping address of the cart. After deletion, the shipping address will default to the billing address.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/2fa7dc36-8305-4628-b961-f2c3f7dda47d/shipping-address' -i -X DELETE \
-H 'Accept: application/hal+json'
218 219 220 221 222 223 |
# File 'lib/beyond_api/resources/carts.rb', line 218 def delete_shipping_address(cart_id) response, status = BeyondApi::Request.delete(@session, "/carts/#{cart_id}/shipping-address") handle_response(response, status, respond_with_true: true) end |
#find(cart_id) ⇒ OpenStruct
A GET
request is used to retrieve the details of a cart.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/26857145-aeab-4210-9191-3906573a14ae' -i -X GET \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json'
239 240 241 242 243 244 |
# File 'lib/beyond_api/resources/carts.rb', line 239 def find(cart_id) response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}") handle_response(response, status) end |
#payment_method(cart_id) ⇒ OpenStruct
A GET
request is used to retrieve the current payment method.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/6d9de289-d6a7-44d6-afb3-c31bb0a792ff/payment-methods/current' -i -X GET \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json'
259 260 261 262 263 264 |
# File 'lib/beyond_api/resources/carts.rb', line 259 def payment_method(cart_id) response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}/payment-methods/current") handle_response(response, status) end |
#payment_methods(cart_id) ⇒ OpenStruct
A GET
request is used to get the applicable payment methods of a cart. The selectable field indicates if a payment method is currently selectable. Non-selectable payment methods are currently restricted because of rules that apply to a cart. Trying to set such a payment method as the current one of the cart will fail.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/45f9009d-4d2f-43b1-9cd2-ea29ff0d46d6/payment-methods' -i -X GET \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json'
282 283 284 285 286 287 |
# File 'lib/beyond_api/resources/carts.rb', line 282 def payment_methods(cart_id) response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}/payment-methods") handle_response(response, status) end |
#replace_line_item(cart_id, line_item_id, body) ⇒ OpenStruct
A PUT
request is used to replace only one line item in the cart.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/f73629e5-fecf-4474-9b04-6b2fcd4663c4/line-items/2c9c0f38-0b9e-4fa7-bcbe-960098ff63aa' -i -X PUT \
-H 'Content-Type: application/json' \
-d '{"_type":"PRODUCT","_ref":"f084553c-ea77-4745-b1bd-71c64c8419fd","quantity":2}'
311 312 313 314 315 316 317 |
# File 'lib/beyond_api/resources/carts.rb', line 311 def replace_line_item(cart_id, line_item_id, body) response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/line-items/#{line_item_id}", body) handle_response(response, status) end |
#replace_line_items(cart_id, body) ⇒ OpenStruct
A PUT
request is used to replace the current line items in the cart with the given list.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/c1436110-e283-49b3-a748-0321efec6d35/line-items' -i -X PUT \
-H 'Content-Type: application/json' \
-d '[{"_type":"PRODUCT","_ref":"0612362d-9856-4b40-94c6-a36abec0cf8c","quantity":1}]'
340 341 342 343 344 345 346 |
# File 'lib/beyond_api/resources/carts.rb', line 340 def replace_line_items(cart_id, body) response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/line-items", body) handle_response(response, status) end |
#set_billing_address(cart_id, body) ⇒ OpenStruct
A PUT
request is used to set the billing address of the cart. The billing address is mandatory for a cart being ready to order.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/01da6aa7-8aa2-4383-a496-6611a14afbc9/billing-address' -i -X PUT \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-d '{"salutation":"Mrs","gender":"FEMALE","title":"","firstName":"Astrid","middleName":"Agnes","lastName":"Alster","street":"Alsterwasserweg",
"houseNumber":"2","street2":"Erdgeschoss","doorCode":"0185","addressExtension":"Hinterhof","postalCode":"20999","dependentLocality":"Seevetal",
"city":"Alsterwasser","country":"DE","state":"Hamburg","email":"[email protected]","phone":"(800) 555-0102","mobile":"(800) 555-0103",
"vatId":"123456789","taxNumber":"123-34-6789","birthDate":"1985-03-20"}'
392 393 394 395 396 397 398 |
# File 'lib/beyond_api/resources/carts.rb', line 392 def set_billing_address(cart_id, body) response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/billing-address", body) handle_response(response, status) end |
#set_payment_method(cart_id, payment_method_id) ⇒ OpenStruct
A PUT
request is used to set the current payment method of the cart.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/750c8a68-ef58-4955-b05f-29e35fa19687/payment-methods/current' -i -X PUT \
-H 'Content-Type: text/uri-list' \
-H 'Accept: application/json' \
-d 'https://api-shop.beyondshop.cloud/api/payment-methods/6498f339-7fe6-43d4-8e2a-6da68d7cdfe3'
416 417 418 419 420 421 422 |
# File 'lib/beyond_api/resources/carts.rb', line 416 def set_payment_method(cart_id, payment_method_id) response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/payment-methods/current", "#{@session.api_url}/payment-methods/#{payment_method_id}") handle_response(response, status) end |
#set_payment_method_to_default(cart_id) ⇒ OpenStruct
A PUT
request is used to set the payment method to the current default payment method. The default payment method is the one with the highest priority of the applicable payment methods.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/d1efcb74-ab96-43c5-b404-9c1f927dc3d2/payment-methods/default' -i -X PUT \
-H 'Content-Type: application/json' \
-H 'Accept: application/json'
438 439 440 441 442 443 |
# File 'lib/beyond_api/resources/carts.rb', line 438 def set_payment_method_to_default(cart_id) response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/payment-methods/default") handle_response(response, status) end |
#set_shipping_address(cart_id, body) ⇒ OpenStruct
A PUT
request is used to set the shipping address of the cart. If a shipping address is not set, it will default to the billing address.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/01da6aa7-8aa2-4383-a496-6611a14afbc9/shipping-address' -i -X PUT \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json' \
-d '{"salutation":"Mrs","gender":"FEMALE","title":"","firstName":"Astrid","middleName":"Agnes","lastName":"Alster","street":"Alsterwasserweg",
"houseNumber":"2","street2":"Erdgeschoss","doorCode":"0185","addressExtension":"Hinterhof","postalCode":"20999","dependentLocality":"Seevetal",
"city":"Alsterwasser","country":"DE","state":"Hamburg","email":"[email protected]","phone":"(800) 555-0102","mobile":"(800) 555-0103",
"vatId":"123456789","taxNumber":"123-34-6789","birthDate":"1985-03-20"}'
489 490 491 492 493 494 495 |
# File 'lib/beyond_api/resources/carts.rb', line 489 def set_shipping_address(cart_id, body) response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/shipping-address", body) handle_response(response, status) end |
#set_shipping_method(cart_id, shipping_zone_id, shipping_method_id) ⇒ OpenStruct
A PUT
request is used to set the current shipping method of the cart.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/a4e7922a-f895-4a7d-8cb1-6ecf74d7ceba/shipping-methods/current' -i -X PUT \
-H 'Content-Type: text/uri-list' \
-H 'Accept: application/json' \
-d 'https://api-shop.beyondshop.cloud/api/shipping-zones/59e26c99-ef1d-4ee8-a79f-d078cd6dfe24/shipping-methods/f3d3ce8d-eeab-44b6-81bb-67a4f1d7a57f'
514 515 516 517 518 519 520 |
# File 'lib/beyond_api/resources/carts.rb', line 514 def set_shipping_method(cart_id, shipping_zone_id, shipping_method_id) response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/shipping-methods/current", "#{session.api_url}/shipping-zones/#{shipping_zone_id}/shipping-methods/#{shipping_method_id}") handle_response(response, status) end |
#set_shipping_method_to_default(cart_id) ⇒ OpenStruct
A PUT
request is used to set the shipping method to the current default shipping method. The default shipping method is the one with the highest priority of the applicable shipping methods.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/c31c5d06-4460-4f89-9e09-47f9956dea98/shipping-methods/default' -i -X PUT \
-H 'Content-Type: application/json' \
-H 'Accept: application/json'
537 538 539 540 541 542 |
# File 'lib/beyond_api/resources/carts.rb', line 537 def set_shipping_method_to_default(cart_id) response, status = BeyondApi::Request.put(@session, "/carts/#{cart_id}/shipping-methods/default") handle_response(response, status) end |
#shipping_method(cart_id) ⇒ OpenStruct
A GET
request is used to get the current shipping method.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/9093a339-66fd-4cc1-9dcf-d23003c38b41/shipping-methods/current' -i -X GET \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json'
558 559 560 561 562 563 |
# File 'lib/beyond_api/resources/carts.rb', line 558 def shipping_method(cart_id) response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}") handle_response(response, status) end |
#shipping_methods(cart_id) ⇒ OpenStruct
A GET
request is used to get the applicable shipping method of a cart.
$ curl 'https://api-shop.beyondshop.cloud/api/carts/05a547a0-80dc-4a8c-b9b6-aa028b6ef7d8/shipping-methods' -i -X GET \
-H 'Content-Type: application/json' \
-H 'Accept: application/hal+json'
578 579 580 581 582 583 |
# File 'lib/beyond_api/resources/carts.rb', line 578 def shipping_methods(cart_id) response, status = BeyondApi::Request.get(@session, "/carts/#{cart_id}") handle_response(response, status) end |