harpiya_api 4.3.0.alpha
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.
- 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,62 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V1
|
|
4
|
+
class OptionValuesController < Harpiya::Api::BaseController
|
|
5
|
+
def index
|
|
6
|
+
@option_values = if params[:ids]
|
|
7
|
+
scope.where(id: params[:ids])
|
|
8
|
+
else
|
|
9
|
+
scope.ransack(params[:q]).result.distinct
|
|
10
|
+
end
|
|
11
|
+
respond_with(@option_values)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def show
|
|
15
|
+
@option_value = scope.find(params[:id])
|
|
16
|
+
respond_with(@option_value)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def new; end
|
|
20
|
+
|
|
21
|
+
def create
|
|
22
|
+
authorize! :create, Harpiya::OptionValue
|
|
23
|
+
@option_value = scope.new(option_value_params)
|
|
24
|
+
if @option_value.save
|
|
25
|
+
render :show, status: 201
|
|
26
|
+
else
|
|
27
|
+
invalid_resource!(@option_value)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def update
|
|
32
|
+
@option_value = scope.accessible_by(current_ability, :update).find(params[:id])
|
|
33
|
+
if @option_value.update(option_value_params)
|
|
34
|
+
render :show
|
|
35
|
+
else
|
|
36
|
+
invalid_resource!(@option_value)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def destroy
|
|
41
|
+
@option_value = scope.accessible_by(current_ability, :destroy).find(params[:id])
|
|
42
|
+
@option_value.destroy
|
|
43
|
+
render plain: nil, status: 204
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def scope
|
|
49
|
+
@scope ||= if params[:option_type_id]
|
|
50
|
+
Harpiya::OptionType.find(params[:option_type_id]).option_values.accessible_by(current_ability, :show)
|
|
51
|
+
else
|
|
52
|
+
Harpiya::OptionValue.accessible_by(current_ability, :show).load
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def option_value_params
|
|
57
|
+
params.require(:option_value).permit(permitted_option_value_attributes)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V1
|
|
4
|
+
class OrdersController < Harpiya::Api::BaseController
|
|
5
|
+
skip_before_action :authenticate_user, only: :apply_coupon_code
|
|
6
|
+
|
|
7
|
+
before_action :find_order, except: [:create, :mine, :current, :index, :update, :remove_coupon_code]
|
|
8
|
+
|
|
9
|
+
# Dynamically defines our stores checkout steps to ensure we check authorization on each step.
|
|
10
|
+
Order.checkout_steps.keys.each do |step|
|
|
11
|
+
define_method step do
|
|
12
|
+
find_order
|
|
13
|
+
authorize! :update, @order, params[:token]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def cancel
|
|
18
|
+
authorize! :update, @order, params[:token]
|
|
19
|
+
@order.canceled_by(current_api_user)
|
|
20
|
+
respond_with(@order, default_template: :show)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def approve
|
|
24
|
+
authorize! :approve, @order, params[:token]
|
|
25
|
+
@order.approved_by(current_api_user)
|
|
26
|
+
respond_with(@order, default_template: :show)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def create
|
|
30
|
+
authorize! :create, Harpiya::Order
|
|
31
|
+
if can?(:admin, Harpiya::Order)
|
|
32
|
+
order_user = if @current_user_roles.include?('admin') && order_params[:user_id]
|
|
33
|
+
Harpiya.user_class.find(order_params[:user_id])
|
|
34
|
+
else
|
|
35
|
+
current_api_user
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
import_params = if @current_user_roles.include?('admin')
|
|
39
|
+
params[:order].present? ? params[:order].permit! : {}
|
|
40
|
+
else
|
|
41
|
+
order_params
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
@order = Harpiya::Core::Importer::Order.import(order_user, import_params)
|
|
45
|
+
|
|
46
|
+
respond_with(@order, default_template: :show, status: 201)
|
|
47
|
+
else
|
|
48
|
+
@order = Harpiya::Order.create!(user: current_api_user, store: current_store)
|
|
49
|
+
if Cart::Update.call(order: @order, params: order_params).success?
|
|
50
|
+
respond_with(@order, default_template: :show, status: 201)
|
|
51
|
+
else
|
|
52
|
+
invalid_resource!(@order)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def empty
|
|
58
|
+
authorize! :update, @order, order_token
|
|
59
|
+
@order.empty!
|
|
60
|
+
render plain: nil, status: 204
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def index
|
|
64
|
+
authorize! :index, Order
|
|
65
|
+
@orders = Order.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
|
66
|
+
respond_with(@orders)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def show
|
|
70
|
+
authorize! :show, @order, order_token
|
|
71
|
+
respond_with(@order)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def update
|
|
75
|
+
find_order(true)
|
|
76
|
+
authorize! :update, @order, order_token
|
|
77
|
+
|
|
78
|
+
if Cart::Update.call(order: @order, params: order_params).success?
|
|
79
|
+
user_id = params[:order][:user_id]
|
|
80
|
+
if current_api_user.has_harpiya_role?('admin') && user_id
|
|
81
|
+
@order.associate_user!(Harpiya.user_class.find(user_id))
|
|
82
|
+
end
|
|
83
|
+
respond_with(@order, default_template: :show)
|
|
84
|
+
else
|
|
85
|
+
invalid_resource!(@order)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def current
|
|
90
|
+
@order = find_current_order
|
|
91
|
+
if @order
|
|
92
|
+
respond_with(@order, default_template: :show, locals: { root_object: @order })
|
|
93
|
+
else
|
|
94
|
+
head :no_content
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def mine
|
|
99
|
+
if current_api_user.persisted?
|
|
100
|
+
@orders = current_api_user.orders.reverse_chronological.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
|
101
|
+
else
|
|
102
|
+
render 'harpiya/api/errors/unauthorized', status: :unauthorized
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def apply_coupon_code
|
|
107
|
+
find_order
|
|
108
|
+
authorize! :update, @order, order_token
|
|
109
|
+
@order.coupon_code = params[:coupon_code]
|
|
110
|
+
@handler = PromotionHandler::Coupon.new(@order).apply
|
|
111
|
+
status = @handler.successful? ? 200 : 422
|
|
112
|
+
render 'harpiya/api/v1/promotions/handler', status: status
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def remove_coupon_code
|
|
116
|
+
find_order(true)
|
|
117
|
+
authorize! :update, @order, order_token
|
|
118
|
+
@handler = Harpiya::PromotionHandler::Coupon.new(@order).remove(params[:coupon_code])
|
|
119
|
+
status = @handler.successful? ? 200 : 404
|
|
120
|
+
render 'harpiya/api/v1/promotions/handler', status: status
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
|
|
125
|
+
def order_params
|
|
126
|
+
if params[:order]
|
|
127
|
+
normalize_params
|
|
128
|
+
params.require(:order).permit(permitted_order_attributes)
|
|
129
|
+
else
|
|
130
|
+
{}
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def normalize_params
|
|
135
|
+
params[:order][:payments_attributes] = params[:order].delete(:payments) if params[:order][:payments]
|
|
136
|
+
params[:order][:shipments_attributes] = params[:order].delete(:shipments) if params[:order][:shipments]
|
|
137
|
+
params[:order][:line_items_attributes] = params[:order].delete(:line_items) if params[:order][:line_items]
|
|
138
|
+
params[:order][:ship_address_attributes] = params[:order].delete(:ship_address) if params[:order][:ship_address]
|
|
139
|
+
params[:order][:bill_address_attributes] = params[:order].delete(:bill_address) if params[:order][:bill_address]
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def find_order(lock = false)
|
|
143
|
+
@order = Harpiya::Order.lock(lock).find_by!(number: params[:id])
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def find_current_order
|
|
147
|
+
current_api_user ? current_api_user.orders.incomplete.order(:created_at).last : nil
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def order_id
|
|
151
|
+
super || params[:id]
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V1
|
|
4
|
+
class PaymentsController < Harpiya::Api::BaseController
|
|
5
|
+
before_action :find_order
|
|
6
|
+
before_action :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void]
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@payments = @order.payments.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
|
10
|
+
respond_with(@payments)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def new
|
|
14
|
+
@payment_methods = Harpiya::PaymentMethod.available
|
|
15
|
+
respond_with(@payment_methods)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create
|
|
19
|
+
@order.validate_payments_attributes([payment_params])
|
|
20
|
+
@payment = @order.payments.build(payment_params)
|
|
21
|
+
if @payment.save
|
|
22
|
+
respond_with(@payment, status: 201, default_template: :show)
|
|
23
|
+
else
|
|
24
|
+
invalid_resource!(@payment)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def update
|
|
29
|
+
authorize! params[:action], @payment
|
|
30
|
+
if !@payment.editable?
|
|
31
|
+
render 'update_forbidden', status: 403
|
|
32
|
+
elsif @payment.update(payment_params)
|
|
33
|
+
respond_with(@payment, default_template: :show)
|
|
34
|
+
else
|
|
35
|
+
invalid_resource!(@payment)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def show
|
|
40
|
+
respond_with(@payment)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def authorize
|
|
44
|
+
perform_payment_action(:authorize)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def capture
|
|
48
|
+
perform_payment_action(:capture)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def purchase
|
|
52
|
+
perform_payment_action(:purchase)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def void
|
|
56
|
+
perform_payment_action(:void_transaction)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def find_order
|
|
62
|
+
@order = Harpiya::Order.find_by!(number: order_id)
|
|
63
|
+
authorize! :show, @order, order_token
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def find_payment
|
|
67
|
+
@payment = @order.payments.find_by!(number: params[:id])
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def perform_payment_action(action, *args)
|
|
71
|
+
authorize! action, Payment
|
|
72
|
+
@payment.send("#{action}!", *args)
|
|
73
|
+
respond_with(@payment, default_template: :show)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def payment_params
|
|
77
|
+
params.require(:payment).permit(permitted_payment_attributes)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V1
|
|
4
|
+
class ProductPropertiesController < Harpiya::Api::BaseController
|
|
5
|
+
before_action :find_product, :authorize_product!
|
|
6
|
+
before_action :product_property, only: [:show, :update, :destroy]
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@product_properties = @product.product_properties.accessible_by(current_ability).
|
|
10
|
+
ransack(params[:q]).result.
|
|
11
|
+
page(params[:page]).per(params[:per_page])
|
|
12
|
+
respond_with(@product_properties)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def show
|
|
16
|
+
respond_with(@product_property)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def new; end
|
|
20
|
+
|
|
21
|
+
def create
|
|
22
|
+
authorize! :create, ProductProperty
|
|
23
|
+
@product_property = @product.product_properties.new(product_property_params)
|
|
24
|
+
if @product_property.save
|
|
25
|
+
respond_with(@product_property, status: 201, default_template: :show)
|
|
26
|
+
else
|
|
27
|
+
invalid_resource!(@product_property)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def update
|
|
32
|
+
authorize! :update, @product_property
|
|
33
|
+
|
|
34
|
+
if @product_property.update(product_property_params)
|
|
35
|
+
respond_with(@product_property, status: 200, default_template: :show)
|
|
36
|
+
else
|
|
37
|
+
invalid_resource!(@product_property)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def destroy
|
|
42
|
+
authorize! :destroy, @product_property
|
|
43
|
+
@product_property.destroy
|
|
44
|
+
respond_with(@product_property, status: 204)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def find_product
|
|
50
|
+
super(params[:product_id])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def authorize_product!
|
|
54
|
+
authorize! :show, @product
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def product_property
|
|
58
|
+
if @product
|
|
59
|
+
@product_property ||= @product.product_properties.find_by(id: params[:id])
|
|
60
|
+
@product_property ||= @product.product_properties.includes(:property).where(harpiya_properties: { name: params[:id] }).first
|
|
61
|
+
raise ActiveRecord::RecordNotFound unless @product_property
|
|
62
|
+
|
|
63
|
+
authorize! :show, @product_property
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def product_property_params
|
|
68
|
+
params.require(:product_property).permit(permitted_product_properties_attributes)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
module Harpiya
|
|
2
|
+
module Api
|
|
3
|
+
module V1
|
|
4
|
+
class ProductsController < Harpiya::Api::BaseController
|
|
5
|
+
before_action :find_product, only: [:update, :show, :destroy]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@products = if params[:ids]
|
|
9
|
+
product_scope.where(id: params[:ids].split(',').flatten)
|
|
10
|
+
else
|
|
11
|
+
product_scope.ransack(params[:q]).result
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
@products = @products.distinct.page(params[:page]).per(params[:per_page])
|
|
15
|
+
expires_in 15.minutes, public: true
|
|
16
|
+
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
|
17
|
+
respond_with(@products)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def show
|
|
21
|
+
expires_in 15.minutes, public: true
|
|
22
|
+
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
|
23
|
+
headers['Surrogate-Key'] = 'product_id=1'
|
|
24
|
+
respond_with(@product)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Takes besides the products attributes either an array of variants or
|
|
28
|
+
# an array of option types.
|
|
29
|
+
#
|
|
30
|
+
# By submitting an array of variants the option types will be created
|
|
31
|
+
# using the *name* key in options hash. e.g
|
|
32
|
+
#
|
|
33
|
+
# product: {
|
|
34
|
+
# ...
|
|
35
|
+
# variants: {
|
|
36
|
+
# price: 19.99,
|
|
37
|
+
# sku: "hey_you",
|
|
38
|
+
# options: [
|
|
39
|
+
# { name: "size", value: "small" },
|
|
40
|
+
# { name: "color", value: "black" }
|
|
41
|
+
# ]
|
|
42
|
+
# }
|
|
43
|
+
# }
|
|
44
|
+
#
|
|
45
|
+
# Or just pass in the option types hash:
|
|
46
|
+
#
|
|
47
|
+
# product: {
|
|
48
|
+
# ...
|
|
49
|
+
# option_types: ['size', 'color']
|
|
50
|
+
# }
|
|
51
|
+
#
|
|
52
|
+
# By passing the shipping category name you can fetch or create that
|
|
53
|
+
# shipping category on the fly. e.g.
|
|
54
|
+
#
|
|
55
|
+
# product: {
|
|
56
|
+
# ...
|
|
57
|
+
# shipping_category: "Free Shipping Items"
|
|
58
|
+
# }
|
|
59
|
+
#
|
|
60
|
+
def new; end
|
|
61
|
+
|
|
62
|
+
def create
|
|
63
|
+
authorize! :create, Product
|
|
64
|
+
params[:product][:available_on] ||= Time.current
|
|
65
|
+
set_up_shipping_category
|
|
66
|
+
|
|
67
|
+
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
|
68
|
+
@product = Core::Importer::Product.new(nil, product_params, options).create
|
|
69
|
+
|
|
70
|
+
if @product.persisted?
|
|
71
|
+
respond_with(@product, status: 201, default_template: :show)
|
|
72
|
+
else
|
|
73
|
+
invalid_resource!(@product)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def update
|
|
78
|
+
authorize! :update, @product
|
|
79
|
+
|
|
80
|
+
options = { variants_attrs: variants_params, options_attrs: option_types_params }
|
|
81
|
+
@product = Core::Importer::Product.new(@product, product_params, options).update
|
|
82
|
+
|
|
83
|
+
if @product.errors.empty?
|
|
84
|
+
respond_with(@product.reload, status: 200, default_template: :show)
|
|
85
|
+
else
|
|
86
|
+
invalid_resource!(@product)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def destroy
|
|
91
|
+
authorize! :destroy, @product
|
|
92
|
+
@product.destroy
|
|
93
|
+
respond_with(@product, status: 204)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
|
|
98
|
+
def product_params
|
|
99
|
+
params.require(:product).permit(permitted_product_attributes)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def variants_params
|
|
103
|
+
variants_key = if params[:product].key? :variants
|
|
104
|
+
:variants
|
|
105
|
+
else
|
|
106
|
+
:variants_attributes
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
params.require(:product).permit(
|
|
110
|
+
variants_key => [permitted_variant_attributes, :id]
|
|
111
|
+
).delete(variants_key) || []
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def option_types_params
|
|
115
|
+
params[:product].fetch(:option_types, [])
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def find_product
|
|
119
|
+
super(params[:id])
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def set_up_shipping_category
|
|
123
|
+
if shipping_category = params[:product].delete(:shipping_category)
|
|
124
|
+
id = ShippingCategory.find_or_create_by(name: shipping_category).id
|
|
125
|
+
params[:product][:shipping_category_id] = id
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|