harpiya_api 4.3.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE +26 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/harpiya/api/main.js +36 -0
- data/app/assets/javascripts/harpiya/api/storefront/cart.js +49 -0
- data/app/controllers/concerns/harpiya/api/v2/storefront/order_concern.rb +52 -0
- data/app/controllers/harpiya/api/base_controller.rb +171 -0
- data/app/controllers/harpiya/api/errors_controller.rb +9 -0
- data/app/controllers/harpiya/api/v1/addresses_controller.rb +46 -0
- data/app/controllers/harpiya/api/v1/checkouts_controller.rb +106 -0
- data/app/controllers/harpiya/api/v1/classifications_controller.rb +20 -0
- data/app/controllers/harpiya/api/v1/countries_controller.rb +22 -0
- data/app/controllers/harpiya/api/v1/credit_cards_controller.rb +26 -0
- data/app/controllers/harpiya/api/v1/customer_returns_controller.rb +25 -0
- data/app/controllers/harpiya/api/v1/images_controller.rb +58 -0
- data/app/controllers/harpiya/api/v1/inventory_units_controller.rb +54 -0
- data/app/controllers/harpiya/api/v1/line_items_controller.rb +70 -0
- data/app/controllers/harpiya/api/v1/option_types_controller.rb +60 -0
- data/app/controllers/harpiya/api/v1/option_values_controller.rb +62 -0
- data/app/controllers/harpiya/api/v1/orders_controller.rb +156 -0
- data/app/controllers/harpiya/api/v1/payments_controller.rb +82 -0
- data/app/controllers/harpiya/api/v1/product_properties_controller.rb +73 -0
- data/app/controllers/harpiya/api/v1/products_controller.rb +131 -0
- data/app/controllers/harpiya/api/v1/promotions_controller.rb +30 -0
- data/app/controllers/harpiya/api/v1/properties_controller.rb +70 -0
- data/app/controllers/harpiya/api/v1/reimbursements_controller.rb +25 -0
- data/app/controllers/harpiya/api/v1/return_authorizations_controller.rb +70 -0
- data/app/controllers/harpiya/api/v1/shipments_controller.rb +196 -0
- data/app/controllers/harpiya/api/v1/states_controller.rb +36 -0
- data/app/controllers/harpiya/api/v1/stock_items_controller.rb +82 -0
- data/app/controllers/harpiya/api/v1/stock_locations_controller.rb +53 -0
- data/app/controllers/harpiya/api/v1/stock_movements_controller.rb +45 -0
- data/app/controllers/harpiya/api/v1/stores_controller.rb +56 -0
- data/app/controllers/harpiya/api/v1/taxonomies_controller.rb +67 -0
- data/app/controllers/harpiya/api/v1/taxons_controller.rb +100 -0
- data/app/controllers/harpiya/api/v1/users_controller.rb +97 -0
- data/app/controllers/harpiya/api/v1/variants_controller.rb +81 -0
- data/app/controllers/harpiya/api/v1/zones_controller.rb +55 -0
- data/app/controllers/harpiya/api/v2/base_controller.rb +167 -0
- data/app/controllers/harpiya/api/v2/platform/addresses_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/countries_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/menu_items_controller.rb +35 -0
- data/app/controllers/harpiya/api/v2/platform/menus_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/option_types_controller.rb +15 -0
- data/app/controllers/harpiya/api/v2/platform/option_values_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/products_controller.rb +27 -0
- data/app/controllers/harpiya/api/v2/platform/resource_controller.rb +102 -0
- data/app/controllers/harpiya/api/v2/platform/taxons_controller.rb +27 -0
- data/app/controllers/harpiya/api/v2/platform/users_controller.rb +23 -0
- data/app/controllers/harpiya/api/v2/resource_controller.rb +59 -0
- data/app/controllers/harpiya/api/v2/storefront/account/addresses_controller.rb +75 -0
- data/app/controllers/harpiya/api/v2/storefront/account/credit_cards_controller.rb +39 -0
- data/app/controllers/harpiya/api/v2/storefront/account/orders_controller.rb +46 -0
- data/app/controllers/harpiya/api/v2/storefront/account_controller.rb +52 -0
- data/app/controllers/harpiya/api/v2/storefront/cart_controller.rb +195 -0
- data/app/controllers/harpiya/api/v2/storefront/checkout_controller.rb +136 -0
- data/app/controllers/harpiya/api/v2/storefront/countries_controller.rb +50 -0
- data/app/controllers/harpiya/api/v2/storefront/menus_controller.rb +42 -0
- data/app/controllers/harpiya/api/v2/storefront/order_status_controller.rb +34 -0
- data/app/controllers/harpiya/api/v2/storefront/products_controller.rb +55 -0
- data/app/controllers/harpiya/api/v2/storefront/stores_controller.rb +23 -0
- data/app/controllers/harpiya/api/v2/storefront/taxons_controller.rb +47 -0
- data/app/helpers/harpiya/api/api_helpers.rb +190 -0
- data/app/helpers/harpiya/api/v2/collection_options_helpers.rb +46 -0
- data/app/helpers/harpiya/api/v2/display_money_helper.rb +43 -0
- data/app/models/concerns/harpiya/user_api_authentication.rb +19 -0
- data/app/models/concerns/harpiya/user_api_methods.rb +7 -0
- data/app/models/harpiya/api_configuration.rb +8 -0
- data/app/models/harpiya/api_dependencies.rb +98 -0
- data/app/serializers/concerns/harpiya/api/v2/resource_serializer_concern.rb +16 -0
- data/app/serializers/harpiya/api/v2/base_serializer.rb +32 -0
- data/app/serializers/harpiya/api/v2/platform/address_serializer.rb +15 -0
- data/app/serializers/harpiya/api/v2/platform/base_serializer.rb +10 -0
- data/app/serializers/harpiya/api/v2/platform/country_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/image_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/menu_item_serializer.rb +22 -0
- data/app/serializers/harpiya/api/v2/platform/menu_serializer.rb +14 -0
- data/app/serializers/harpiya/api/v2/platform/option_type_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/option_value_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/product_property_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/product_serializer.rb +28 -0
- data/app/serializers/harpiya/api/v2/platform/state_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/store_serializer.rb +14 -0
- data/app/serializers/harpiya/api/v2/platform/taxon_image_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/taxon_serializer.rb +37 -0
- data/app/serializers/harpiya/api/v2/platform/taxonomy_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/user_serializer.rb +21 -0
- data/app/serializers/harpiya/api/v2/platform/variant_serializer.rb +15 -0
- data/app/serializers/harpiya/v2/storefront/address_serializer.rb +20 -0
- data/app/serializers/harpiya/v2/storefront/base_serializer.rb +10 -0
- data/app/serializers/harpiya/v2/storefront/cart_serializer.rb +36 -0
- data/app/serializers/harpiya/v2/storefront/country_serializer.rb +24 -0
- data/app/serializers/harpiya/v2/storefront/credit_card_serializer.rb +13 -0
- data/app/serializers/harpiya/v2/storefront/estimated_shipping_rate_serializer.rb +29 -0
- data/app/serializers/harpiya/v2/storefront/image_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/line_item_serializer.rb +19 -0
- data/app/serializers/harpiya/v2/storefront/menu_item_serializer.rb +38 -0
- data/app/serializers/harpiya/v2/storefront/menu_serializer.rb +14 -0
- data/app/serializers/harpiya/v2/storefront/option_type_serializer.rb +13 -0
- data/app/serializers/harpiya/v2/storefront/option_value_serializer.rb +13 -0
- data/app/serializers/harpiya/v2/storefront/payment_method_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/payment_serializer.rb +15 -0
- data/app/serializers/harpiya/v2/storefront/product_property_serializer.rb +19 -0
- data/app/serializers/harpiya/v2/storefront/product_serializer.rb +67 -0
- data/app/serializers/harpiya/v2/storefront/promotion_serializer.rb +12 -0
- data/app/serializers/harpiya/v2/storefront/shipment_serializer.rb +20 -0
- data/app/serializers/harpiya/v2/storefront/shipping_rate_serializer.rb +16 -0
- data/app/serializers/harpiya/v2/storefront/state_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/stock_location_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_category_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_event_serializer.rb +15 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_serializer.rb +17 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_type_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/store_serializer.rb +23 -0
- data/app/serializers/harpiya/v2/storefront/taxon_image_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/taxon_serializer.rb +36 -0
- data/app/serializers/harpiya/v2/storefront/taxonomy_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/user_serializer.rb +31 -0
- data/app/serializers/harpiya/v2/storefront/variant_serializer.rb +49 -0
- data/app/services/harpiya/api/error_handler.rb +40 -0
- data/app/views/harpiya/api/errors/gateway_error.rabl +2 -0
- data/app/views/harpiya/api/errors/invalid_api_key.rabl +2 -0
- data/app/views/harpiya/api/errors/invalid_resource.rabl +3 -0
- data/app/views/harpiya/api/errors/must_specify_api_key.rabl +2 -0
- data/app/views/harpiya/api/errors/not_found.rabl +2 -0
- data/app/views/harpiya/api/errors/unauthorized.rabl +2 -0
- data/app/views/harpiya/api/v1/addresses/show.rabl +10 -0
- data/app/views/harpiya/api/v1/adjustments/show.rabl +4 -0
- data/app/views/harpiya/api/v1/countries/index.rabl +7 -0
- data/app/views/harpiya/api/v1/countries/show.rabl +5 -0
- data/app/views/harpiya/api/v1/credit_cards/index.rabl +7 -0
- data/app/views/harpiya/api/v1/credit_cards/show.rabl +3 -0
- data/app/views/harpiya/api/v1/customer_returns/index.rabl +7 -0
- data/app/views/harpiya/api/v1/images/index.rabl +4 -0
- data/app/views/harpiya/api/v1/images/new.rabl +3 -0
- data/app/views/harpiya/api/v1/images/show.rabl +6 -0
- data/app/views/harpiya/api/v1/inventory_units/show.rabl +2 -0
- data/app/views/harpiya/api/v1/line_items/new.rabl +3 -0
- data/app/views/harpiya/api/v1/line_items/show.rabl +14 -0
- data/app/views/harpiya/api/v1/option_types/index.rabl +3 -0
- data/app/views/harpiya/api/v1/option_types/new.rabl +3 -0
- data/app/views/harpiya/api/v1/option_types/show.rabl +5 -0
- data/app/views/harpiya/api/v1/option_values/index.rabl +3 -0
- data/app/views/harpiya/api/v1/option_values/new.rabl +3 -0
- data/app/views/harpiya/api/v1/option_values/show.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/address.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/canceled.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/cart.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/complete.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/could_not_apply_coupon.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/could_not_transition.rabl +3 -0
- data/app/views/harpiya/api/v1/orders/index.rabl +7 -0
- data/app/views/harpiya/api/v1/orders/insufficient_quantity.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/invalid_shipping_method.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/mine.rabl +9 -0
- data/app/views/harpiya/api/v1/orders/order.rabl +10 -0
- data/app/views/harpiya/api/v1/orders/payment.rabl +3 -0
- data/app/views/harpiya/api/v1/orders/show.rabl +51 -0
- data/app/views/harpiya/api/v1/payments/credit_over_limit.rabl +2 -0
- data/app/views/harpiya/api/v1/payments/index.rabl +7 -0
- data/app/views/harpiya/api/v1/payments/new.rabl +5 -0
- data/app/views/harpiya/api/v1/payments/show.rabl +2 -0
- data/app/views/harpiya/api/v1/payments/update_forbidden.rabl +2 -0
- data/app/views/harpiya/api/v1/product_properties/index.rabl +7 -0
- data/app/views/harpiya/api/v1/product_properties/new.rabl +2 -0
- data/app/views/harpiya/api/v1/product_properties/show.rabl +2 -0
- data/app/views/harpiya/api/v1/products/index.rabl +9 -0
- data/app/views/harpiya/api/v1/products/new.rabl +3 -0
- data/app/views/harpiya/api/v1/products/product.rabl +1 -0
- data/app/views/harpiya/api/v1/products/show.rabl +36 -0
- data/app/views/harpiya/api/v1/promotions/handler.rabl +5 -0
- data/app/views/harpiya/api/v1/promotions/show.rabl +2 -0
- data/app/views/harpiya/api/v1/properties/index.rabl +7 -0
- data/app/views/harpiya/api/v1/properties/new.rabl +2 -0
- data/app/views/harpiya/api/v1/properties/show.rabl +2 -0
- data/app/views/harpiya/api/v1/reimbursements/index.rabl +7 -0
- data/app/views/harpiya/api/v1/return_authorizations/index.rabl +7 -0
- data/app/views/harpiya/api/v1/return_authorizations/new.rabl +3 -0
- data/app/views/harpiya/api/v1/return_authorizations/show.rabl +2 -0
- data/app/views/harpiya/api/v1/shared/stock_location_required.rabl +2 -0
- data/app/views/harpiya/api/v1/shipments/big.rabl +48 -0
- data/app/views/harpiya/api/v1/shipments/cannot_ready_shipment.rabl +2 -0
- data/app/views/harpiya/api/v1/shipments/mine.rabl +9 -0
- data/app/views/harpiya/api/v1/shipments/show.rabl +32 -0
- data/app/views/harpiya/api/v1/shipments/small.rabl +37 -0
- data/app/views/harpiya/api/v1/shipping_rates/show.rabl +2 -0
- data/app/views/harpiya/api/v1/states/index.rabl +12 -0
- data/app/views/harpiya/api/v1/states/show.rabl +2 -0
- data/app/views/harpiya/api/v1/stock_items/index.rabl +7 -0
- data/app/views/harpiya/api/v1/stock_items/show.rabl +5 -0
- data/app/views/harpiya/api/v1/stock_locations/index.rabl +7 -0
- data/app/views/harpiya/api/v1/stock_locations/show.rabl +8 -0
- data/app/views/harpiya/api/v1/stock_movements/index.rabl +7 -0
- data/app/views/harpiya/api/v1/stock_movements/show.rabl +5 -0
- data/app/views/harpiya/api/v1/stores/index.rabl +4 -0
- data/app/views/harpiya/api/v1/stores/show.rabl +2 -0
- data/app/views/harpiya/api/v1/tags/index.rabl +9 -0
- data/app/views/harpiya/api/v1/taxonomies/index.rabl +7 -0
- data/app/views/harpiya/api/v1/taxonomies/jstree.rabl +7 -0
- data/app/views/harpiya/api/v1/taxonomies/nested.rabl +11 -0
- data/app/views/harpiya/api/v1/taxonomies/new.rabl +3 -0
- data/app/views/harpiya/api/v1/taxonomies/show.rabl +15 -0
- data/app/views/harpiya/api/v1/taxons/index.rabl +10 -0
- data/app/views/harpiya/api/v1/taxons/jstree.rabl +7 -0
- data/app/views/harpiya/api/v1/taxons/new.rabl +3 -0
- data/app/views/harpiya/api/v1/taxons/show.rabl +6 -0
- data/app/views/harpiya/api/v1/taxons/taxons.rabl +5 -0
- data/app/views/harpiya/api/v1/users/index.rabl +7 -0
- data/app/views/harpiya/api/v1/users/new.rabl +3 -0
- data/app/views/harpiya/api/v1/users/show.rabl +11 -0
- data/app/views/harpiya/api/v1/variants/big.rabl +14 -0
- data/app/views/harpiya/api/v1/variants/index.rabl +9 -0
- data/app/views/harpiya/api/v1/variants/new.rabl +2 -0
- data/app/views/harpiya/api/v1/variants/show.rabl +3 -0
- data/app/views/harpiya/api/v1/variants/small.rabl +18 -0
- data/app/views/harpiya/api/v1/zones/index.rabl +7 -0
- data/app/views/harpiya/api/v1/zones/show.rabl +6 -0
- data/config/initializers/doorkeeper.rb +48 -0
- data/config/initializers/json_api_mime_types.rb +8 -0
- data/config/initializers/rabl.rb +9 -0
- data/config/initializers/user_class_extensions.rb +7 -0
- data/config/locales/en.yml +36 -0
- data/config/routes.rb +295 -0
- data/db/migrate/20100107141738_add_api_key_to_harpiya_users.rb +7 -0
- data/db/migrate/20120411123334_resize_api_key_field.rb +7 -0
- data/db/migrate/20120530054546_rename_api_key_to_harpiya_api_key.rb +7 -0
- data/db/migrate/20131017162334_add_index_to_user_harpiya_api_key.rb +7 -0
- data/db/migrate/20180320110726_create_doorkeeper_tables.rb +69 -0
- data/docs/oauth/index.yml +140 -0
- data/docs/v2/platform/index.yaml +599 -0
- data/docs/v2/storefront/index.yaml +5585 -0
- data/harpiya_api.gemspec +36 -0
- data/lib/harpiya/api.rb +11 -0
- data/lib/harpiya/api/controller_setup.rb +19 -0
- data/lib/harpiya/api/engine.rb +30 -0
- data/lib/harpiya/api/responders.rb +11 -0
- data/lib/harpiya/api/responders/rabl_template.rb +28 -0
- data/lib/harpiya/api/testing_support/caching.rb +10 -0
- data/lib/harpiya/api/testing_support/helpers.rb +44 -0
- data/lib/harpiya/api/testing_support/setup.rb +16 -0
- data/lib/harpiya/api/testing_support/v2/base.rb +13 -0
- data/lib/harpiya/api/testing_support/v2/current_order.rb +79 -0
- data/lib/harpiya/api/testing_support/v2/platform_contexts.rb +213 -0
- data/lib/harpiya_api.rb +4 -0
- data/script/rails +9 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- metadata +418 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
class CheckoutController < ::Harpiya::Api::V2::BaseController
|
6
|
+
include Harpiya::Api::V2::Storefront::OrderConcern
|
7
|
+
before_action :ensure_order
|
8
|
+
|
9
|
+
def next
|
10
|
+
harpiya_authorize! :update, harpiya_current_order, order_token
|
11
|
+
|
12
|
+
result = next_service.call(order: harpiya_current_order)
|
13
|
+
|
14
|
+
render_order(result)
|
15
|
+
end
|
16
|
+
|
17
|
+
def advance
|
18
|
+
harpiya_authorize! :update, harpiya_current_order, order_token
|
19
|
+
|
20
|
+
result = advance_service.call(order: harpiya_current_order)
|
21
|
+
|
22
|
+
render_order(result)
|
23
|
+
end
|
24
|
+
|
25
|
+
def complete
|
26
|
+
harpiya_authorize! :update, harpiya_current_order, order_token
|
27
|
+
|
28
|
+
result = complete_service.call(order: harpiya_current_order)
|
29
|
+
|
30
|
+
render_order(result)
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
harpiya_authorize! :update, harpiya_current_order, order_token
|
35
|
+
|
36
|
+
result = update_service.call(
|
37
|
+
order: harpiya_current_order,
|
38
|
+
params: params,
|
39
|
+
# defined in https://github.com/harpiya/harpiya/blob/master/core/lib/harpiya/core/controller_helpers/strong_parameters.rb#L19
|
40
|
+
permitted_attributes: permitted_checkout_attributes,
|
41
|
+
request_env: request.headers.env
|
42
|
+
)
|
43
|
+
|
44
|
+
render_order(result)
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_store_credit
|
48
|
+
harpiya_authorize! :update, harpiya_current_order, order_token
|
49
|
+
|
50
|
+
result = add_store_credit_service.call(
|
51
|
+
order: harpiya_current_order,
|
52
|
+
amount: params[:amount].try(:to_f)
|
53
|
+
)
|
54
|
+
|
55
|
+
render_order(result)
|
56
|
+
end
|
57
|
+
|
58
|
+
def remove_store_credit
|
59
|
+
harpiya_authorize! :update, harpiya_current_order, order_token
|
60
|
+
|
61
|
+
result = remove_store_credit_service.call(order: harpiya_current_order)
|
62
|
+
render_order(result)
|
63
|
+
end
|
64
|
+
|
65
|
+
def shipping_rates
|
66
|
+
result = shipping_rates_service.call(order: harpiya_current_order)
|
67
|
+
|
68
|
+
if result.success?
|
69
|
+
render_serialized_payload { serialize_shipping_rates(result.value) }
|
70
|
+
else
|
71
|
+
render_error_payload(result.error)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def payment_methods
|
76
|
+
render_serialized_payload { serialize_payment_methods(harpiya_current_order.available_payment_methods) }
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def resource_serializer
|
82
|
+
Harpiya::Api::Dependencies.storefront_cart_serializer.constantize
|
83
|
+
end
|
84
|
+
|
85
|
+
def next_service
|
86
|
+
Harpiya::Api::Dependencies.storefront_checkout_next_service.constantize
|
87
|
+
end
|
88
|
+
|
89
|
+
def advance_service
|
90
|
+
Harpiya::Api::Dependencies.storefront_checkout_advance_service.constantize
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_store_credit_service
|
94
|
+
Harpiya::Api::Dependencies.storefront_checkout_add_store_credit_service.constantize
|
95
|
+
end
|
96
|
+
|
97
|
+
def remove_store_credit_service
|
98
|
+
Harpiya::Api::Dependencies.storefront_checkout_remove_store_credit_service.constantize
|
99
|
+
end
|
100
|
+
|
101
|
+
def complete_service
|
102
|
+
Harpiya::Api::Dependencies.storefront_checkout_complete_service.constantize
|
103
|
+
end
|
104
|
+
|
105
|
+
def update_service
|
106
|
+
Harpiya::Api::Dependencies.storefront_checkout_update_service.constantize
|
107
|
+
end
|
108
|
+
|
109
|
+
def payment_methods_serializer
|
110
|
+
Harpiya::Api::Dependencies.storefront_payment_method_serializer.constantize
|
111
|
+
end
|
112
|
+
|
113
|
+
def shipping_rates_service
|
114
|
+
Harpiya::Api::Dependencies.storefront_checkout_get_shipping_rates_service.constantize
|
115
|
+
end
|
116
|
+
|
117
|
+
def shipping_rates_serializer
|
118
|
+
Harpiya::Api::Dependencies.storefront_shipment_serializer.constantize
|
119
|
+
end
|
120
|
+
|
121
|
+
def serialize_payment_methods(payment_methods)
|
122
|
+
payment_methods_serializer.new(payment_methods, params: serializer_params).serializable_hash
|
123
|
+
end
|
124
|
+
|
125
|
+
def serialize_shipping_rates(shipments)
|
126
|
+
shipping_rates_serializer.new(
|
127
|
+
shipments,
|
128
|
+
params: serializer_params,
|
129
|
+
include: [:shipping_rates, :stock_location]
|
130
|
+
).serializable_hash
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
class CountriesController < ::Harpiya::Api::V2::ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def serialize_collection(collection)
|
9
|
+
collection_serializer.new(
|
10
|
+
collection,
|
11
|
+
collection_options(collection).merge(params: collection_serializer_params)
|
12
|
+
).serializable_hash
|
13
|
+
end
|
14
|
+
|
15
|
+
def serializer_params
|
16
|
+
super.merge(include_states: true)
|
17
|
+
end
|
18
|
+
|
19
|
+
def collection_serializer_params
|
20
|
+
serializer_params.merge(include_states: false)
|
21
|
+
end
|
22
|
+
|
23
|
+
def resource
|
24
|
+
return scope.default if params[:iso] == 'default'
|
25
|
+
|
26
|
+
scope.find_by(iso: params[:iso]&.upcase) ||
|
27
|
+
scope.find_by(id: params[:iso]&.upcase) ||
|
28
|
+
scope.find_by(iso3: params[:iso]&.upcase)
|
29
|
+
end
|
30
|
+
|
31
|
+
def resource_serializer
|
32
|
+
Harpiya::Api::Dependencies.storefront_country_serializer.constantize
|
33
|
+
end
|
34
|
+
|
35
|
+
def collection_serializer
|
36
|
+
Harpiya::Api::Dependencies.storefront_country_serializer.constantize
|
37
|
+
end
|
38
|
+
|
39
|
+
def collection_finder
|
40
|
+
Harpiya::Api::Dependencies.storefront_country_finder.constantize
|
41
|
+
end
|
42
|
+
|
43
|
+
def model_class
|
44
|
+
Harpiya::Country
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
class MenusController < ::Harpiya::Api::V2::ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def serialize_collection(collection)
|
9
|
+
collection_serializer.new(
|
10
|
+
collection,
|
11
|
+
collection_options(collection).merge(params: serializer_params)
|
12
|
+
).serializable_hash
|
13
|
+
end
|
14
|
+
|
15
|
+
def resource
|
16
|
+
@resource ||= scope.find_by(location: params[:location])
|
17
|
+
end
|
18
|
+
|
19
|
+
def resource_serializer
|
20
|
+
Harpiya::Api::Dependencies.storefront_menu_serializer.constantize
|
21
|
+
end
|
22
|
+
|
23
|
+
def collection_serializer
|
24
|
+
Harpiya::Api::Dependencies.storefront_menu_serializer.constantize
|
25
|
+
end
|
26
|
+
|
27
|
+
def collection_finder
|
28
|
+
Harpiya::Api::Dependencies.storefront_menu_finder.constantize
|
29
|
+
end
|
30
|
+
|
31
|
+
def model_class
|
32
|
+
Harpiya::Menu
|
33
|
+
end
|
34
|
+
|
35
|
+
def scope
|
36
|
+
super.by_store(current_store).by_locale(I18n.locale)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
class OrderStatusController < ::Harpiya::Api::V2::ResourceController
|
6
|
+
include Harpiya::Api::V2::Storefront::OrderConcern
|
7
|
+
|
8
|
+
before_action :ensure_order_token
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def resource
|
13
|
+
resource = resource_finder.new(number: params[:number], token: order_token).execute.take
|
14
|
+
raise ActiveRecord::RecordNotFound if resource.nil?
|
15
|
+
|
16
|
+
resource
|
17
|
+
end
|
18
|
+
|
19
|
+
def resource_finder
|
20
|
+
Harpiya::Api::Dependencies.storefront_completed_order_finder.constantize
|
21
|
+
end
|
22
|
+
|
23
|
+
def resource_serializer
|
24
|
+
Harpiya::Api::Dependencies.storefront_cart_serializer.constantize
|
25
|
+
end
|
26
|
+
|
27
|
+
def ensure_order_token
|
28
|
+
raise ActiveRecord::RecordNotFound unless order_token.present?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
class ProductsController < ::Harpiya::Api::V2::ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def sorted_collection
|
9
|
+
collection_sorter.new(collection, current_currency, params, allowed_sort_attributes).call
|
10
|
+
end
|
11
|
+
|
12
|
+
def collection
|
13
|
+
@collection ||= collection_finder.new(scope: scope, params: params, current_currency: current_currency).execute
|
14
|
+
end
|
15
|
+
|
16
|
+
def resource
|
17
|
+
@resource ||= scope.find_by(slug: params[:id]) || scope.find(params[:id])
|
18
|
+
end
|
19
|
+
|
20
|
+
def collection_sorter
|
21
|
+
Harpiya::Api::Dependencies.storefront_products_sorter.constantize
|
22
|
+
end
|
23
|
+
|
24
|
+
def collection_finder
|
25
|
+
Harpiya::Api::Dependencies.storefront_products_finder.constantize
|
26
|
+
end
|
27
|
+
|
28
|
+
def collection_serializer
|
29
|
+
Harpiya::Api::Dependencies.storefront_product_serializer.constantize
|
30
|
+
end
|
31
|
+
|
32
|
+
def resource_serializer
|
33
|
+
Harpiya::Api::Dependencies.storefront_product_serializer.constantize
|
34
|
+
end
|
35
|
+
|
36
|
+
def model_class
|
37
|
+
Harpiya::Product
|
38
|
+
end
|
39
|
+
|
40
|
+
def scope_includes
|
41
|
+
{
|
42
|
+
master: :default_price,
|
43
|
+
variants: [],
|
44
|
+
variant_images: [],
|
45
|
+
taxons: [],
|
46
|
+
product_properties: :property,
|
47
|
+
option_types: :option_values,
|
48
|
+
variants_including_master: %i[default_price option_values]
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
class StoresController < ::Harpiya::Api::V2::ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def model_class
|
9
|
+
Harpiya::Store
|
10
|
+
end
|
11
|
+
|
12
|
+
def resource
|
13
|
+
@resource ||= scope.find_by!(code: params[:code])
|
14
|
+
end
|
15
|
+
|
16
|
+
def resource_serializer
|
17
|
+
Harpiya::Api::Dependencies.storefront_store_serializer.constantize
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
module Storefront
|
5
|
+
class TaxonsController < ::Harpiya::Api::V2::ResourceController
|
6
|
+
private
|
7
|
+
|
8
|
+
def collection_serializer
|
9
|
+
Harpiya::Api::Dependencies.storefront_taxon_serializer.constantize
|
10
|
+
end
|
11
|
+
|
12
|
+
def resource_serializer
|
13
|
+
Harpiya::Api::Dependencies.storefront_taxon_serializer.constantize
|
14
|
+
end
|
15
|
+
|
16
|
+
def collection_finder
|
17
|
+
Harpiya::Api::Dependencies.storefront_taxon_finder.constantize
|
18
|
+
end
|
19
|
+
|
20
|
+
def paginated_collection
|
21
|
+
@paginated_collection ||= collection_paginator.new(collection, params).call
|
22
|
+
end
|
23
|
+
|
24
|
+
def resource
|
25
|
+
@resource ||= scope.find_by(permalink: params[:id]) || scope.find(params[:id])
|
26
|
+
end
|
27
|
+
|
28
|
+
def model_class
|
29
|
+
Harpiya::Taxon
|
30
|
+
end
|
31
|
+
|
32
|
+
def scope_includes
|
33
|
+
node_includes = %i[icon products parent taxonomy]
|
34
|
+
|
35
|
+
{
|
36
|
+
parent: node_includes,
|
37
|
+
children: node_includes,
|
38
|
+
taxonomy: [root: node_includes],
|
39
|
+
products: [],
|
40
|
+
icon: [attachment_attachment: :blob]
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module ApiHelpers
|
4
|
+
ATTRIBUTES = [
|
5
|
+
:product_attributes,
|
6
|
+
:product_property_attributes,
|
7
|
+
:variant_attributes,
|
8
|
+
:image_attributes,
|
9
|
+
:option_value_attributes,
|
10
|
+
:order_attributes,
|
11
|
+
:line_item_attributes,
|
12
|
+
:option_type_attributes,
|
13
|
+
:payment_attributes,
|
14
|
+
:payment_method_attributes,
|
15
|
+
:shipment_attributes,
|
16
|
+
:taxonomy_attributes,
|
17
|
+
:taxon_attributes,
|
18
|
+
:address_attributes,
|
19
|
+
:country_attributes,
|
20
|
+
:state_attributes,
|
21
|
+
:adjustment_attributes,
|
22
|
+
:inventory_unit_attributes,
|
23
|
+
:return_authorization_attributes,
|
24
|
+
:creditcard_attributes,
|
25
|
+
:payment_source_attributes,
|
26
|
+
:user_attributes,
|
27
|
+
:property_attributes,
|
28
|
+
:stock_location_attributes,
|
29
|
+
:stock_movement_attributes,
|
30
|
+
:stock_item_attributes,
|
31
|
+
:promotion_attributes,
|
32
|
+
:store_attributes,
|
33
|
+
:tag_attributes,
|
34
|
+
:customer_return_attributes,
|
35
|
+
:reimbursement_attributes
|
36
|
+
]
|
37
|
+
|
38
|
+
mattr_reader *ATTRIBUTES
|
39
|
+
|
40
|
+
def required_fields_for(model)
|
41
|
+
required_fields = model._validators.select do |_field, validations|
|
42
|
+
validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
|
43
|
+
end.map(&:first) # get fields that are invalid
|
44
|
+
# Permalinks presence is validated, but are really automatically generated
|
45
|
+
# Therefore we shouldn't tell API clients that they MUST send one through
|
46
|
+
required_fields.map!(&:to_s).delete('permalink')
|
47
|
+
# Do not require slugs, either
|
48
|
+
required_fields.delete('slug')
|
49
|
+
required_fields
|
50
|
+
end
|
51
|
+
|
52
|
+
@@product_attributes = [
|
53
|
+
:id, :name, :description, :price, :display_price, :available_on,
|
54
|
+
:slug, :meta_description, :meta_keywords, :shipping_category_id,
|
55
|
+
:taxon_ids, :total_on_hand
|
56
|
+
]
|
57
|
+
|
58
|
+
@@product_property_attributes = [
|
59
|
+
:id, :product_id, :property_id, :value, :property_name
|
60
|
+
]
|
61
|
+
|
62
|
+
@@variant_attributes = [
|
63
|
+
:id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master,
|
64
|
+
:slug, :description, :track_inventory
|
65
|
+
]
|
66
|
+
|
67
|
+
@@image_attributes = [
|
68
|
+
:id, :position, :attachment_content_type, :attachment_file_name, :type,
|
69
|
+
:attachment_updated_at, :attachment_width, :attachment_height, :alt
|
70
|
+
]
|
71
|
+
|
72
|
+
@@option_value_attributes = [
|
73
|
+
:id, :name, :presentation, :option_type_name, :option_type_id,
|
74
|
+
:option_type_presentation
|
75
|
+
]
|
76
|
+
|
77
|
+
@@order_attributes = [
|
78
|
+
:id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,
|
79
|
+
:user_id, :created_at, :updated_at, :completed_at, :payment_total,
|
80
|
+
:shipment_state, :payment_state, :email, :special_instructions, :channel,
|
81
|
+
:included_tax_total, :additional_tax_total, :display_included_tax_total,
|
82
|
+
:display_additional_tax_total, :tax_total, :currency, :considered_risky,
|
83
|
+
:canceler_id
|
84
|
+
]
|
85
|
+
|
86
|
+
@@line_item_attributes = [:id, :quantity, :price, :variant_id]
|
87
|
+
|
88
|
+
@@option_type_attributes = [:id, :name, :presentation, :position]
|
89
|
+
|
90
|
+
@@payment_attributes = [
|
91
|
+
:id, :source_type, :source_id, :amount, :display_amount,
|
92
|
+
:payment_method_id, :state, :avs_response, :created_at,
|
93
|
+
:updated_at, :number
|
94
|
+
]
|
95
|
+
|
96
|
+
@@payment_method_attributes = [:id, :name, :description]
|
97
|
+
|
98
|
+
@@shipment_attributes = [:id, :tracking, :number, :cost, :shipped_at, :state]
|
99
|
+
|
100
|
+
@@taxonomy_attributes = [:id, :name]
|
101
|
+
|
102
|
+
@@taxon_attributes = [
|
103
|
+
:id, :name, :pretty_name, :permalink, :parent_id,
|
104
|
+
:taxonomy_id, :meta_title, :meta_description
|
105
|
+
]
|
106
|
+
|
107
|
+
@@inventory_unit_attributes = [
|
108
|
+
:id, :lock_version, :state, :variant_id, :shipment_id,
|
109
|
+
:return_authorization_id
|
110
|
+
]
|
111
|
+
|
112
|
+
@@return_authorization_attributes = [
|
113
|
+
:id, :number, :state, :order_id, :memo, :created_at, :updated_at
|
114
|
+
]
|
115
|
+
|
116
|
+
@@address_attributes = [
|
117
|
+
:id, :firstname, :lastname, :full_name, :address1, :address2, :city,
|
118
|
+
:zipcode, :phone, :company, :alternative_phone, :country_id, :state_id,
|
119
|
+
:label, :state_name, :state_text
|
120
|
+
]
|
121
|
+
|
122
|
+
@@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]
|
123
|
+
|
124
|
+
@@state_attributes = [:id, :name, :abbr, :country_id]
|
125
|
+
|
126
|
+
@@adjustment_attributes = [
|
127
|
+
:id, :source_type, :source_id, :adjustable_type, :adjustable_id,
|
128
|
+
:originator_type, :originator_id, :amount, :label, :mandatory,
|
129
|
+
:locked, :eligible, :created_at, :updated_at
|
130
|
+
]
|
131
|
+
|
132
|
+
@@creditcard_attributes = [
|
133
|
+
:id, :month, :year, :cc_type, :last_digits, :name,
|
134
|
+
:gateway_customer_profile_id, :gateway_payment_profile_id
|
135
|
+
]
|
136
|
+
|
137
|
+
@@payment_source_attributes = [
|
138
|
+
:id, :month, :year, :cc_type, :last_digits, :name
|
139
|
+
]
|
140
|
+
|
141
|
+
@@user_attributes = [:id, :email, :created_at, :updated_at]
|
142
|
+
|
143
|
+
@@property_attributes = [:id, :name, :presentation]
|
144
|
+
|
145
|
+
@@stock_location_attributes = [
|
146
|
+
:id, :name, :address1, :address2, :city, :state_id, :state_name,
|
147
|
+
:country_id, :zipcode, :phone, :active
|
148
|
+
]
|
149
|
+
|
150
|
+
@@stock_movement_attributes = [:id, :quantity, :stock_item_id]
|
151
|
+
|
152
|
+
@@stock_item_attributes = [
|
153
|
+
:id, :count_on_hand, :backorderable, :lock_version, :stock_location_id,
|
154
|
+
:variant_id
|
155
|
+
]
|
156
|
+
|
157
|
+
@@promotion_attributes = [
|
158
|
+
:id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
|
159
|
+
:match_policy, :code, :advertise, :path
|
160
|
+
]
|
161
|
+
|
162
|
+
@@store_attributes = [
|
163
|
+
:id, :name, :url, :meta_description, :meta_keywords, :seo_title,
|
164
|
+
:mail_from_address, :customer_support_email, :default_currency,
|
165
|
+
:code, :default, :facebook, :twitter, :instagram,
|
166
|
+
:supported_currencies, :default_locale, :supported_locales
|
167
|
+
]
|
168
|
+
|
169
|
+
@@tag_attributes = [:id, :name]
|
170
|
+
|
171
|
+
@@customer_return_attributes = [
|
172
|
+
:id, :number, :order_id, :fully_reimbursed?, :pre_tax_total,
|
173
|
+
:created_at, :updated_at
|
174
|
+
]
|
175
|
+
|
176
|
+
@@reimbursement_attributes = [
|
177
|
+
:id, :reimbursement_status, :customer_return_id, :order_id,
|
178
|
+
:number, :total, :created_at, :updated_at
|
179
|
+
]
|
180
|
+
|
181
|
+
def variant_attributes
|
182
|
+
if @current_user_roles&.include?('admin')
|
183
|
+
@@variant_attributes + [:cost_price]
|
184
|
+
else
|
185
|
+
@@variant_attributes
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|