wordjelly-auth 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +35 -0
- data/app/assets/images/auth/activity.jpg +0 -0
- data/app/assets/images/auth/facebook.svg +1 -0
- data/app/assets/images/auth/google_oauth2.svg +1 -0
- data/app/assets/images/auth/js_pic3.jpg +0 -0
- data/app/assets/images/auth/profile.jpg +0 -0
- data/app/assets/javascripts/auth/admin_create_users.js +2 -0
- data/app/assets/javascripts/auth/application.js +20 -0
- data/app/assets/javascripts/auth/auth_dependencies.js +12 -0
- data/app/assets/javascripts/auth/auth_modals_and_navbar.js +218 -0
- data/app/assets/javascripts/auth/clients.js +2 -0
- data/app/assets/javascripts/auth/search.js +2 -0
- data/app/assets/javascripts/auth/shopping/discounts.js +2 -0
- data/app/assets/javascripts/auth/users/profiles.js +188 -0
- data/app/assets/stylesheets/auth/admin_create_users.css +4 -0
- data/app/assets/stylesheets/auth/application.scss +14 -0
- data/app/assets/stylesheets/auth/auth_default_css.scss +13 -0
- data/app/assets/stylesheets/auth/common-styles.scss +579 -0
- data/app/assets/stylesheets/auth/overrides.scss +26 -0
- data/app/assets/stylesheets/auth/search.css +4 -0
- data/app/assets/stylesheets/auth/shopping/discounts.css +4 -0
- data/app/assets/stylesheets/auth/users/profiles.scss +40 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/controllers/auth/admin_create_users_controller.rb +89 -0
- data/app/controllers/auth/application_controller.rb +97 -0
- data/app/controllers/auth/clients_controller.rb +105 -0
- data/app/controllers/auth/concerns/activity_controller_concern.rb +32 -0
- data/app/controllers/auth/concerns/devise_concern.rb +193 -0
- data/app/controllers/auth/concerns/omni_concern.rb +310 -0
- data/app/controllers/auth/concerns/otp_concern.rb +251 -0
- data/app/controllers/auth/concerns/shopping/cart_controller_concern.rb +105 -0
- data/app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb +150 -0
- data/app/controllers/auth/concerns/shopping/discount_controller_concern.rb +97 -0
- data/app/controllers/auth/concerns/shopping/pay_u_money_controller_concern.rb +38 -0
- data/app/controllers/auth/concerns/shopping/payment_controller_concern.rb +101 -0
- data/app/controllers/auth/concerns/shopping/product_controller_concern.rb +68 -0
- data/app/controllers/auth/concerns/token_concern.rb +187 -0
- data/app/controllers/auth/confirmations_controller.rb +3 -0
- data/app/controllers/auth/mailgun_controller.rb +8 -0
- data/app/controllers/auth/omniauth_callbacks_controller.rb +6 -0
- data/app/controllers/auth/passwords_controller.rb +4 -0
- data/app/controllers/auth/profiles_controller.rb +156 -0
- data/app/controllers/auth/registrations_controller.rb +99 -0
- data/app/controllers/auth/search_controller.rb +61 -0
- data/app/controllers/auth/sessions_controller.rb +20 -0
- data/app/controllers/auth/shopping/cart_items_controller.rb +14 -0
- data/app/controllers/auth/shopping/carts_controller.rb +13 -0
- data/app/controllers/auth/shopping/discounts_controller.rb +19 -0
- data/app/controllers/auth/shopping/payments_controller.rb +13 -0
- data/app/controllers/auth/shopping/products_controller.rb +17 -0
- data/app/controllers/auth/shopping/shopping_controller.rb +86 -0
- data/app/controllers/auth/unlocks_controller.rb +3 -0
- data/app/controllers/auth/webhooks_controller.rb +3 -0
- data/app/helpers/auth/admin_create_users_helper.rb +2 -0
- data/app/helpers/auth/application_helper.rb +136 -0
- data/app/helpers/auth/clients_helper.rb +4 -0
- data/app/helpers/auth/resource_helper.rb +10 -0
- data/app/helpers/auth/search_helper.rb +2 -0
- data/app/helpers/auth/shopping/cart_items/cart_items_helper.rb +29 -0
- data/app/helpers/auth/shopping/carts/carts_helper.rb +25 -0
- data/app/helpers/auth/shopping/discounts/discounts_helper.rb +39 -0
- data/app/helpers/auth/shopping/payments/pay_u_money_helper.rb +56 -0
- data/app/helpers/auth/shopping/payments/payments_helper.rb +54 -0
- data/app/helpers/auth/shopping/products/products_helper.rb +52 -0
- data/app/helpers/auth/shopping/shopping_helper.rb +3 -0
- data/app/helpers/auth/users/profiles_helper.rb +12 -0
- data/app/jobs/otp_job.rb +92 -0
- data/app/mailers/application_mailer.rb +4 -0
- data/app/mailers/auth/notifier.rb +9 -0
- data/app/models/auth/admin_create_user.rb +3 -0
- data/app/models/auth/client.rb +52 -0
- data/app/models/auth/concerns/activity_concern.rb +112 -0
- data/app/models/auth/concerns/chief_model_concern.rb +73 -0
- data/app/models/auth/concerns/es_concern.rb +21 -0
- data/app/models/auth/concerns/notification_concern.rb +232 -0
- data/app/models/auth/concerns/notification_response_concern.rb +71 -0
- data/app/models/auth/concerns/owner_concern.rb +81 -0
- data/app/models/auth/concerns/shopping/cart_concern.rb +329 -0
- data/app/models/auth/concerns/shopping/cart_item_concern.rb +437 -0
- data/app/models/auth/concerns/shopping/discount_concern.rb +482 -0
- data/app/models/auth/concerns/shopping/discount_flow.txt +11 -0
- data/app/models/auth/concerns/shopping/pay_u_money_concern.rb +184 -0
- data/app/models/auth/concerns/shopping/payment_concern.rb +613 -0
- data/app/models/auth/concerns/shopping/product_concern.rb +102 -0
- data/app/models/auth/concerns/sms_otp_concern.rb +68 -0
- data/app/models/auth/concerns/user_concern.rb +788 -0
- data/app/models/auth/identity.rb +23 -0
- data/app/models/auth/shopping/cart.rb +3 -0
- data/app/models/auth/shopping/cart_item.rb +6 -0
- data/app/models/auth/shopping/cart_item_payment_result.rb +7 -0
- data/app/models/auth/shopping/discount.rb +4 -0
- data/app/models/auth/shopping/payment.rb +5 -0
- data/app/models/auth/shopping/product.rb +5 -0
- data/app/models/auth/user.rb +3 -0
- data/app/views/auth/admin_create_users/_admin_actions.html.erb +46 -0
- data/app/views/auth/admin_create_users/_form.html.erb +19 -0
- data/app/views/auth/admin_create_users/edit.html.erb +6 -0
- data/app/views/auth/admin_create_users/index.html.erb +25 -0
- data/app/views/auth/admin_create_users/new.html.erb +5 -0
- data/app/views/auth/admin_create_users/show.html.erb +8 -0
- data/app/views/auth/clients/_form.html.erb +41 -0
- data/app/views/auth/clients/edit.html.erb +6 -0
- data/app/views/auth/clients/index.html.erb +33 -0
- data/app/views/auth/clients/new.html.erb +5 -0
- data/app/views/auth/clients/show.html.erb +21 -0
- data/app/views/auth/confirmations/_enter_otp.html.erb +27 -0
- data/app/views/auth/confirmations/_get_otp_status.html.erb +25 -0
- data/app/views/auth/confirmations/_new_otp_input.js.erb +11 -0
- data/app/views/auth/confirmations/_resend_otp.js.erb +8 -0
- data/app/views/auth/confirmations/_resend_sms_otp.html.erb +18 -0
- data/app/views/auth/confirmations/_verify_otp.js.erb +64 -0
- data/app/views/auth/confirmations/create.js.erb +8 -0
- data/app/views/auth/confirmations/enter_otp.html.erb +7 -0
- data/app/views/auth/confirmations/get_otp_status.html.erb +3 -0
- data/app/views/auth/confirmations/new.html.erb +1 -0
- data/app/views/auth/confirmations/new.js.erb +16 -0
- data/app/views/auth/confirmations/otp_status_result.html.erb +20 -0
- data/app/views/auth/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/auth/mailer/password_change.html.erb +3 -0
- data/app/views/auth/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/auth/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/auth/modals/_ajax_error_modal.html.erb +3 -0
- data/app/views/auth/modals/_ajax_error_modal_content.html.erb +0 -0
- data/app/views/auth/modals/_edit_account_content.html.erb +68 -0
- data/app/views/auth/modals/_edit_account_success_content.html.erb +5 -0
- data/app/views/auth/modals/_error_notification.html.erb +8 -0
- data/app/views/auth/modals/_forgot_password_content.html.erb +18 -0
- data/app/views/auth/modals/_forgot_password_success_content.html.erb +8 -0
- data/app/views/auth/modals/_login_default_content.html.erb +3 -0
- data/app/views/auth/modals/_login_forms.html.erb +13 -0
- data/app/views/auth/modals/_login_navigation_options.html.erb +12 -0
- data/app/views/auth/modals/_new_otp_input.html.erb +28 -0
- data/app/views/auth/modals/_oauth_and_submit.html.erb +21 -0
- data/app/views/auth/modals/_recaptcha_tags.html.erb +4 -0
- data/app/views/auth/modals/_resend_confirmation_content.html.erb +17 -0
- data/app/views/auth/modals/_resend_confirmation_success_content.html.erb +8 -0
- data/app/views/auth/modals/_resend_otp.html.erb +23 -0
- data/app/views/auth/modals/_resource_errors.js.erb +24 -0
- data/app/views/auth/modals/_sign_in_inputs.html.erb +10 -0
- data/app/views/auth/modals/_sign_in_needed_modal.html.erb +3 -0
- data/app/views/auth/modals/_sign_in_success_content.html.erb +5 -0
- data/app/views/auth/modals/_sign_up_inputs.html.erb +9 -0
- data/app/views/auth/modals/_sign_up_success_content.html.erb +1 -0
- data/app/views/auth/modals/_sign_up_success_inactive_content.html.erb +2 -0
- data/app/views/auth/modals/_unlock_content.html.erb +17 -0
- data/app/views/auth/modals/_verify_otp.html.erb +1 -0
- data/app/views/auth/modals/base_modal/_base.html.erb +25 -0
- data/app/views/auth/modals/login.js.erb +120 -0
- data/app/views/auth/modals/unlock_success_content.html.erb +8 -0
- data/app/views/auth/notifier/_email.html.erb +3 -0
- data/app/views/auth/notifier/notification.html.erb +2 -0
- data/app/views/auth/notifier/notification.text.erb +1 -0
- data/app/views/auth/omniauth_callbacks/failure.html.erb +4 -0
- data/app/views/auth/passwords/create.js.erb +12 -0
- data/app/views/auth/passwords/edit.html.erb +25 -0
- data/app/views/auth/passwords/new.html.erb +16 -0
- data/app/views/auth/passwords/new.js.erb +19 -0
- data/app/views/auth/profiles/_proxy_resource.html.erb +5 -0
- data/app/views/auth/profiles/set_proxy_resource.js.erb +1 -0
- data/app/views/auth/profiles/show.html.erb +8 -0
- data/app/views/auth/registrations/create.js.erb +40 -0
- data/app/views/auth/registrations/edit.html.erb +2 -0
- data/app/views/auth/registrations/edit.js.erb +5 -0
- data/app/views/auth/registrations/new.html.erb +33 -0
- data/app/views/auth/registrations/update.js.erb +47 -0
- data/app/views/auth/search/_search_bar.html.erb +11 -0
- data/app/views/auth/search/_search_result.html.erb +7 -0
- data/app/views/auth/search/_search_results.html.erb +4 -0
- data/app/views/auth/search/authenticated_user_search.js.erb +45 -0
- data/app/views/auth/search/authenticated_user_search.json +7 -0
- data/app/views/auth/sessions/create.js.erb +5 -0
- data/app/views/auth/sessions/new.html.erb +4 -0
- data/app/views/auth/sessions/new.js.erb +20 -0
- data/app/views/auth/shared/_devise_error_messages.html.erb +9 -0
- data/app/views/auth/shared/_links.html.erb +25 -0
- data/app/views/auth/shared/_object_errors.html.erb +12 -0
- data/app/views/auth/shared/_proxy_resource.html.erb +18 -0
- data/app/views/auth/shopping/cart_items/_form.html.erb +34 -0
- data/app/views/auth/shopping/cart_items/_show_cart_items_collection.html.erb +31 -0
- data/app/views/auth/shopping/cart_items/create_multiple.html.erb +6 -0
- data/app/views/auth/shopping/cart_items/create_multiple.json.erb +9 -0
- data/app/views/auth/shopping/cart_items/edit.html.erb +6 -0
- data/app/views/auth/shopping/cart_items/index.html.erb +52 -0
- data/app/views/auth/shopping/cart_items/new.html.erb +5 -0
- data/app/views/auth/shopping/cart_items/show.html.erb +13 -0
- data/app/views/auth/shopping/carts/_form.html.erb +35 -0
- data/app/views/auth/shopping/carts/_payment_links.html.erb +27 -0
- data/app/views/auth/shopping/carts/_remove_cart_item.html.erb +11 -0
- data/app/views/auth/shopping/carts/_show_cart_balance_info.html.erb +35 -0
- data/app/views/auth/shopping/carts/edit.html.erb +6 -0
- data/app/views/auth/shopping/carts/index.html.erb +43 -0
- data/app/views/auth/shopping/carts/new.html.erb +5 -0
- data/app/views/auth/shopping/carts/show.html.erb +46 -0
- data/app/views/auth/shopping/discounts/_form.html.erb +18 -0
- data/app/views/auth/shopping/discounts/_form_for_create_multiple_cart_items.html.erb +17 -0
- data/app/views/auth/shopping/discounts/_show_pending_discount_request.html.erb +17 -0
- data/app/views/auth/shopping/discounts/destroy.html.erb +2 -0
- data/app/views/auth/shopping/discounts/edit.html.erb +29 -0
- data/app/views/auth/shopping/discounts/index.html.erb +40 -0
- data/app/views/auth/shopping/discounts/new.html.erb +1 -0
- data/app/views/auth/shopping/discounts/show.html.erb +18 -0
- data/app/views/auth/shopping/discounts/update.html.erb +2 -0
- data/app/views/auth/shopping/payments/_approve_payment.html.erb +7 -0
- data/app/views/auth/shopping/payments/_cash_card_cheque.html.erb +24 -0
- data/app/views/auth/shopping/payments/_create_discount_coupon.html.erb +5 -0
- data/app/views/auth/shopping/payments/_form.html.erb +19 -0
- data/app/views/auth/shopping/payments/_gateway.html.erb +21 -0
- data/app/views/auth/shopping/payments/_proceed_to_gateway_or_verify_payment.html.erb +18 -0
- data/app/views/auth/shopping/payments/_refresh_payment.html.erb +7 -0
- data/app/views/auth/shopping/payments/_refund.html.erb +10 -0
- data/app/views/auth/shopping/payments/_show_payment_receipt.html.erb +12 -0
- data/app/views/auth/shopping/payments/edit.html.erb +6 -0
- data/app/views/auth/shopping/payments/index.html.erb +43 -0
- data/app/views/auth/shopping/payments/new.html.erb +13 -0
- data/app/views/auth/shopping/payments/show.html.erb +36 -0
- data/app/views/auth/shopping/products/_form.html.erb +27 -0
- data/app/views/auth/shopping/products/edit.html.erb +6 -0
- data/app/views/auth/shopping/products/index.html.erb +48 -0
- data/app/views/auth/shopping/products/index.json.erb +7 -0
- data/app/views/auth/shopping/products/new.html.erb +5 -0
- data/app/views/auth/shopping/products/show.html.erb +12 -0
- data/app/views/auth/shopping/products/show.json.erb +1 -0
- data/app/views/auth/unlocks/create.js.erb +12 -0
- data/app/views/auth/unlocks/new.html.erb +14 -0
- data/app/views/auth/unlocks/new.js.erb +17 -0
- data/app/views/auth/users/_search_result.html.erb +8 -0
- data/app/views/auth/users/profiles/_user_data.html.erb +4 -0
- data/app/views/auth/users/profiles/show.html.erb +54 -0
- data/app/views/layouts/auth/_modals.html.erb +2 -0
- data/app/views/layouts/auth/application.html.erb +17 -0
- data/app/views/layouts/auth/navbar/_navbar.html.erb +49 -0
- data/app/views/layouts/auth/navbar/_personalization.html.erb +17 -0
- data/app/views/layouts/auth/navbar/_progress_spinner.html.erb +11 -0
- data/app/views/layouts/mailer.html.erb +5 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/config/initializers/active_model.rb +36 -0
- data/config/initializers/devise.rb +623 -0
- data/config/initializers/json.rb +10 -0
- data/config/initializers/omniauth.rb +447 -0
- data/config/initializers/redis.rb +2 -0
- data/config/initializers/redis.yml +14 -0
- data/config/locales/devise.en.yml +63 -0
- data/config/routes.rb +1 -0
- data/lib/assets/javascripts/data.js +126 -0
- data/lib/assets/javascripts/jquery.calendario.js +394 -0
- data/lib/assets/javascripts/jquery.tagcloud.js +92 -0
- data/lib/assets/javascripts/leanModal.js +236 -0
- data/lib/assets/javascripts/main.js +668 -0
- data/lib/assets/javascripts/modernizr.custom.63321.js +4 -0
- data/lib/assets/javascripts/payumoney.js +9 -0
- data/lib/assets/javascripts/search.js +36 -0
- data/lib/assets/javascripts/spinner.js +77 -0
- data/lib/assets/javascripts/trianglify.min.js +2 -0
- data/lib/assets/javascripts/you_need_to_sign_in.js.erb +478 -0
- data/lib/assets/stylesheets/calendar.css +111 -0
- data/lib/assets/stylesheets/calendar_modifications.scss +276 -0
- data/lib/auth.rb +32 -0
- data/lib/auth/custom_failure.rb +3 -0
- data/lib/auth/engine.rb +231 -0
- data/lib/auth/job_exception_handler.rb +7 -0
- data/lib/auth/mailgun.rb +28 -0
- data/lib/auth/notify.rb +8 -0
- data/lib/auth/omniauth/path.rb +104 -0
- data/lib/auth/partials.rb +12 -0
- data/lib/auth/rails/routes.rb +169 -0
- data/lib/auth/search/main.rb +97 -0
- data/lib/auth/sidekiq_up.rb +16 -0
- data/lib/auth/two_factor_otp.rb +202 -0
- data/lib/auth/url_shortener.rb +29 -0
- data/lib/auth/version.rb +3 -0
- data/lib/tasks/auth_tasks.rake +4 -0
- metadata +863 -0
@@ -0,0 +1,232 @@
|
|
1
|
+
module Auth::Concerns::NotificationConcern
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include Auth::Concerns::ChiefModelConcern
|
5
|
+
|
6
|
+
included do
|
7
|
+
|
8
|
+
include GlobalID::Identification
|
9
|
+
|
10
|
+
|
11
|
+
## email subject.
|
12
|
+
## the subject for email notifications.
|
13
|
+
field :email_subject, type: String, default: "Notification from #{Auth.configuration.brand_name}"
|
14
|
+
|
15
|
+
|
16
|
+
## short message : displayed in notification popup
|
17
|
+
field :callout_message, type: String
|
18
|
+
|
19
|
+
|
20
|
+
## a collapse id, for gcm messages.
|
21
|
+
field :collapse_id, type: String
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
## to topics
|
26
|
+
## the topics to which this notification is being sent.
|
27
|
+
## this will only be applicable to gcm.
|
28
|
+
field :topics, type: Array
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
## resource class
|
33
|
+
## the class of the resource to which this notification should be sent.
|
34
|
+
field :resource_class, type: String
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
## to resource_ids
|
39
|
+
## hash of resource_ids to which this notification is being sent.
|
40
|
+
## key -> class_name
|
41
|
+
## value -> array of resource ids.
|
42
|
+
## JSON encoded string.
|
43
|
+
field :resource_ids, type: String, default: JSON.generate({})
|
44
|
+
|
45
|
+
|
46
|
+
## a hash with query conditions determining to which resources this notification should be sent.
|
47
|
+
## key -> class name
|
48
|
+
## value -> query hash
|
49
|
+
## JSON encoded string.
|
50
|
+
field :resources_by_query, type: String, default: JSON.generate({})
|
51
|
+
|
52
|
+
|
53
|
+
## reply_to_email
|
54
|
+
## an email address to which the user can reply in case of any issues
|
55
|
+
field :reply_to_email, type: String
|
56
|
+
|
57
|
+
|
58
|
+
## reply_to_number
|
59
|
+
## a mobile phone number to which the user can reply in case of any issues.
|
60
|
+
field :reply_to_number, type: String
|
61
|
+
|
62
|
+
## objects related to this notification.
|
63
|
+
## a hash of object ids, that refer to any objects that this notification deals with.
|
64
|
+
## key -> string[preferably the class name, but can be anything if more than two objects of the same class are used.]
|
65
|
+
## value -> bson::objectid of the instance of that class
|
66
|
+
## these can be used to refer to , or pull up objects , pertaining to this notification.
|
67
|
+
## eg, suppose you are sending a notification regarding an order object, then this would be a good place to store a key->value like: object_id: object.id.to_s
|
68
|
+
## this can later be used when sending the notification, in the email/sms etc.
|
69
|
+
field :objects, type: Hash, default: {}
|
70
|
+
|
71
|
+
|
72
|
+
##################### RETRY COUNTS ######################
|
73
|
+
|
74
|
+
field :sms_send_count, type: Integer, default: 0
|
75
|
+
field :email_send_count, type: Integer, default: 0
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
######################### FORMAT METHODS ####################
|
83
|
+
|
84
|
+
## returns the name of a partial to be rendered.
|
85
|
+
def email_partial
|
86
|
+
"auth/notifier/email.html.erb"
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def format_for_sms(resource)
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def format_for_android(resource)
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
def format_for_ios(resource)
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
def format_for_web(resource)
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
################ default max retry count ###################
|
107
|
+
|
108
|
+
def max_retry_count
|
109
|
+
2
|
110
|
+
end
|
111
|
+
|
112
|
+
######################### SEND METHODS ####################
|
113
|
+
|
114
|
+
|
115
|
+
## if the notification should be sent by email or not.
|
116
|
+
## override in the implementing model.
|
117
|
+
## default is true
|
118
|
+
def send_by_email?(resource)
|
119
|
+
true
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
## if the notification should be sent by sms or not.
|
124
|
+
## override in the implementing model.
|
125
|
+
## default is true
|
126
|
+
def send_by_sms?(resource)
|
127
|
+
true
|
128
|
+
end
|
129
|
+
|
130
|
+
## if the notification should be sent by mobile or not.
|
131
|
+
## override in the implementing model.
|
132
|
+
## default is true
|
133
|
+
def send_by_mobile?(resource)
|
134
|
+
true
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
## if the notification should be sent by desktop or not.
|
139
|
+
## override in the implementing model.
|
140
|
+
## default is true
|
141
|
+
def send_by_desktop?(resource)
|
142
|
+
true
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
def send_notification
|
147
|
+
recipients = send_to
|
148
|
+
recipients[:resources].map{|r|
|
149
|
+
send_email_background(r) if send_by_email?(r)
|
150
|
+
send_sms_background(r) if send_by_sms?(r)
|
151
|
+
#r.send_mobile_notification(self) if send_by_mobile?(r)
|
152
|
+
#r.send_desktop_notification(self) if send_by_desktop?(r)
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
156
|
+
################### SEND SMS NOTIFICATION ####################
|
157
|
+
|
158
|
+
|
159
|
+
## defaults to just sending the sms direclty.
|
160
|
+
## override using a background job to actually call the send_sms method.
|
161
|
+
def send_sms_background(resource)
|
162
|
+
send_sms(resource)
|
163
|
+
end
|
164
|
+
|
165
|
+
## creates a notification response object using the yield block from calling this method.
|
166
|
+
## block passed if any must return a string as the yield.
|
167
|
+
def send_sms(resource)
|
168
|
+
if self.sms_send_count < max_retry_count
|
169
|
+
self.sms_send_count+=1
|
170
|
+
create_notification_response(yield,"sms")
|
171
|
+
self.save
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
################## SEND EMAIL NOTIFICATION ##################
|
176
|
+
|
177
|
+
## defaults to sending the email directly.
|
178
|
+
## override to send email in a background job.
|
179
|
+
def send_email_background(resource)
|
180
|
+
send_email(resource)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Auth.configuration.mailer_class.constantize.notification(resource,notification).deliver_later if resource.email
|
184
|
+
|
185
|
+
def send_email(resource)
|
186
|
+
if self.email_send_count < max_retry_count
|
187
|
+
self.email_send_count+=1
|
188
|
+
create_notification_response(yield,"email")
|
189
|
+
self.save
|
190
|
+
end
|
191
|
+
end
|
192
|
+
################## NOTIFICATION RESPONSE CREATE ##############
|
193
|
+
|
194
|
+
## @response[String] : a response received after sending a notification.
|
195
|
+
## webhook identifier is called before_create by a callback.
|
196
|
+
def create_notification_response(response,type)
|
197
|
+
notification_response = Auth.configuration.notification_response_class.constantize.new(notification_type: type, parent_notification_id: self.id.to_s)
|
198
|
+
notification_response.add_response(response)
|
199
|
+
notification_response.set_webhook_identifier(response)
|
200
|
+
notification_response.save
|
201
|
+
end
|
202
|
+
|
203
|
+
######################## UTILITY METHODS ##################
|
204
|
+
|
205
|
+
## @return [Array] of resource objects.
|
206
|
+
def get_resources
|
207
|
+
resources = []
|
208
|
+
|
209
|
+
JSON.parse(resource_ids).each do |class_name,ids|
|
210
|
+
resources << ids.map{|c|
|
211
|
+
class_name.capitalize.constantize.find(c)
|
212
|
+
}
|
213
|
+
end
|
214
|
+
JSON.parse(resources_by_query).each do |class_name,query|
|
215
|
+
resources << class_name.capitalize.constantize.where(query)
|
216
|
+
end
|
217
|
+
resources.flatten
|
218
|
+
end
|
219
|
+
|
220
|
+
def get_topics
|
221
|
+
topics || []
|
222
|
+
end
|
223
|
+
|
224
|
+
def send_to
|
225
|
+
{:resources => get_resources, :topics => get_topics}
|
226
|
+
end
|
227
|
+
|
228
|
+
def resource_class_constantized
|
229
|
+
self.class.name.capitalize.constantize
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Auth::Concerns::NotificationResponseConcern
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
|
5
|
+
included do
|
6
|
+
include Auth::Concerns::ChiefModelConcern
|
7
|
+
include Auth::Concerns::OwnerConcern
|
8
|
+
include GlobalID::Identification
|
9
|
+
field :notification_type, type: String
|
10
|
+
validates_presence_of :notification_type
|
11
|
+
## array of json responses.
|
12
|
+
## example from the webhook, or the initial notification send response.
|
13
|
+
field :responses, type: Array, default: []
|
14
|
+
field :parent_notification_id, type: String
|
15
|
+
validates_presence_of :parent_notification_id
|
16
|
+
|
17
|
+
## field to search for during the webhook callback.
|
18
|
+
## the webhook should search for where(:webhook_identifier => something provided by the webhook.)
|
19
|
+
field :webhook_identifier
|
20
|
+
validates_presence_of :webhook_identifier
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
## the idea here is the process the response by means of a block.
|
26
|
+
## json response should be a string representation of a valid json object.
|
27
|
+
def add_response(json_response)
|
28
|
+
self.responses << json_response
|
29
|
+
yield if block_given?
|
30
|
+
end
|
31
|
+
|
32
|
+
## returns the parent notificatino object of this notification response.
|
33
|
+
def get_parent_notification
|
34
|
+
Auth.configuration.notification_class.constantize.find(self.parent_notification_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
## fixes the identifier by which this response can be identified during webhook calls.
|
40
|
+
## @param response[String] : the json string that contains the response that was obtained by sending the notification.
|
41
|
+
def set_webhook_identifier(response)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
module ClassMethods
|
47
|
+
|
48
|
+
## @param webhook_identifier[String] : an identifier by which to search for a notification response object
|
49
|
+
## @param params[String] : a JSON string of whatever was received from the webhook request.
|
50
|
+
## &block, optional block.
|
51
|
+
## return the notification_response object, after adding the response to it and saving it, if it was found
|
52
|
+
## yields the provided block after calling save.
|
53
|
+
## check the notification_response to see if it was successfully saved.
|
54
|
+
## return nil otherwise, and logs a rails error.
|
55
|
+
def find_and_update_notification_response(webhook_identifier,params,&block)
|
56
|
+
puts "webhook identifier is: #{webhook_identifier}"
|
57
|
+
if notification_response = Auth.configuration.notification_response_class.constantize.where(:webhook_identifier => webhook_identifier)
|
58
|
+
notification_response = notification_response.first
|
59
|
+
notification_response.add_response(params)
|
60
|
+
notification_response.save
|
61
|
+
yield(notification_response) if block_given?
|
62
|
+
notification_response
|
63
|
+
else
|
64
|
+
Rails.logger.error("webhook identifier not found: #{webhook_identifier}")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Auth::Concerns::OwnerConcern
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include Auth::Concerns::ChiefModelConcern
|
5
|
+
included do
|
6
|
+
|
7
|
+
## resource id is not essential for the creation of a cart.
|
8
|
+
|
9
|
+
## but if a resource id is present, then a resource class must be provided.
|
10
|
+
|
11
|
+
field :resource_id, type: String
|
12
|
+
field :resource_class, type: String
|
13
|
+
|
14
|
+
## THERE ARE BASICALLY THREE KINDS OF USERS THAT WE MAY NEED.
|
15
|
+
|
16
|
+
## ONE : The resource that is considered as the owner of the object . this uses the resource_id and resource_class. It is got by calling get_resource on the object.
|
17
|
+
|
18
|
+
attr_accessor :owner_resource
|
19
|
+
|
20
|
+
## SIGNED_IN_RESOURCE : the resource that is currently signed in, and should be assigned to this model instance, in the controller. In the controller this can be got by calling the method currently_signed_in_resource, provided that the controller implements the token_concern.
|
21
|
+
|
22
|
+
attr_accessor :signed_in_resource
|
23
|
+
|
24
|
+
|
25
|
+
validates_presence_of :resource_class, if: Proc.new{|c| !c.resource_id.nil?}
|
26
|
+
|
27
|
+
## you cannot change the resource_id or owner of the object once it is set.
|
28
|
+
validate :resource_id_not_changed
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
|
34
|
+
## used in cart_item_controller_concern#show
|
35
|
+
## if the resource is nil, will look for a cart item, which has a resource of nil, otherwise will look for a cart item, with the provided resource id.
|
36
|
+
##
|
37
|
+
def find_self(_id,resource)
|
38
|
+
conditions = {:_id => _id}
|
39
|
+
conditions[:resource_id] = resource.id.to_s if !resource.is_admin?
|
40
|
+
puts "conditions are:"
|
41
|
+
puts conditions.to_s
|
42
|
+
all = self.where(conditions)
|
43
|
+
puts "the resultant size:"
|
44
|
+
puts all.size.to_s
|
45
|
+
return all.first if all.size > 0
|
46
|
+
return nil
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
## returns the resource that was associated with the object when the object was created.
|
52
|
+
## it basically uses the resource_id and resource_class that were saved, when creating the resource.
|
53
|
+
## since resources can be created without the resource_class and resource_id being provided, it may return nil if these two are not present.
|
54
|
+
def get_resource
|
55
|
+
return unless (self.resource_class && self.resource_id)
|
56
|
+
unless owner_resource
|
57
|
+
|
58
|
+
owner_resource = self.resource_class.capitalize.constantize.find(self.resource_id)
|
59
|
+
end
|
60
|
+
owner_resource
|
61
|
+
end
|
62
|
+
|
63
|
+
## checks if the owner of the current object is the same as the owner of the other object passed in.
|
64
|
+
## this is currently used in payment_concern, in a before_save validation def.
|
65
|
+
## this is also used in the cart_item_concern, as a before_update validation , if the parent_id is changing, where we check if the cart_item owner is the same as that of the cart.
|
66
|
+
def owner_matches(other_object)
|
67
|
+
return false unless other_object.respond_to? :resource_id
|
68
|
+
return false if self.resource_id != other_object.resource_id
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def resource_id_not_changed
|
74
|
+
##this method will give you access to be able to reset the resource_id in case the admin is modifying the resource.
|
75
|
+
##need to check if that can be done?
|
76
|
+
if resource_id_changed? && resource_id_was
|
77
|
+
errors.add(:resource_id, "You cannot change the ownership of this entity")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,329 @@
|
|
1
|
+
##NEED A SEPERATE MODEL THAT IMPLEMENTS IT
|
2
|
+
module Auth::Concerns::Shopping::CartConcern
|
3
|
+
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
include Auth::Concerns::ChiefModelConcern
|
7
|
+
include Auth::Concerns::OwnerConcern
|
8
|
+
|
9
|
+
included do
|
10
|
+
field :name, type: String
|
11
|
+
field :notes, type: String
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
## debit is calculated live, by first getting all the items already dispatched and their value, and then getting the total payments made and their value, so it infact becomes something at the validation level of the cart item.
|
18
|
+
|
19
|
+
## add cart item ids
|
20
|
+
attr_accessor :add_cart_item_ids
|
21
|
+
|
22
|
+
|
23
|
+
## remove cart item ids
|
24
|
+
attr_accessor :remove_cart_item_ids
|
25
|
+
|
26
|
+
|
27
|
+
## the total price of all the items in the cart
|
28
|
+
attr_accessor :cart_price
|
29
|
+
|
30
|
+
## the array of payment objects made upto now to this cart
|
31
|
+
attr_accessor :cart_payments
|
32
|
+
|
33
|
+
## the array of cart items in this cart.
|
34
|
+
attr_accessor :cart_items
|
35
|
+
|
36
|
+
## the amount the customer owes to us.
|
37
|
+
attr_accessor :cart_pending_balance
|
38
|
+
|
39
|
+
## the cumulative amount paid into this cart(sum of all successfull payments.)
|
40
|
+
attr_accessor :cart_paid_amount
|
41
|
+
|
42
|
+
## the credit the customer has pending in the cart.
|
43
|
+
## this is used for sequentially debiting money from the cart_paid amount.
|
44
|
+
attr_accessor :cart_credit
|
45
|
+
|
46
|
+
## the minimum amount payable for all the cart items in the cart that are not yet accepted
|
47
|
+
attr_accessor :cart_minimum_payable_amount
|
48
|
+
|
49
|
+
|
50
|
+
## the discount object id, passed in so that it can be rendered in the show_cart action where we provide a link to create a payment.
|
51
|
+
field :discount_id, type: String
|
52
|
+
|
53
|
+
attr_accessor :discount
|
54
|
+
|
55
|
+
before_destroy do |document|
|
56
|
+
document.prepare_cart
|
57
|
+
if document.cart_items.keep_if{|c| c.accepted == true}.size > 0
|
58
|
+
false
|
59
|
+
elsif document.get_cart_payments.size > 0
|
60
|
+
false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
validate :add_or_remove_validation
|
66
|
+
|
67
|
+
|
68
|
+
## how to handle discount exceeds cart balance.
|
69
|
+
## how to handle discount origin cart id, is same as this cart.
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
## sets all the attribute accessors of the cart.
|
76
|
+
## @param[Payment] : a payment object can be passed in.
|
77
|
+
## this is used in case there is a new payment which is calling prepare_cart. in that case the new payment has to be also added to the cart_payments. this is alwasy the case when a new payment is made with a status directly set as accepted, i.e for eg a cashier makes a payment on behalf of the customer.
|
78
|
+
def prepare_cart
|
79
|
+
|
80
|
+
find_cart_items
|
81
|
+
|
82
|
+
set_cart_price
|
83
|
+
|
84
|
+
set_cart_payments
|
85
|
+
|
86
|
+
set_cart_paid_amount
|
87
|
+
|
88
|
+
set_cart_pending_balance
|
89
|
+
|
90
|
+
set_cart_minimum_payable_amount
|
91
|
+
|
92
|
+
set_discount
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
################ ATTR ACCESSOR SETTERS & GETTERS ##############
|
97
|
+
|
98
|
+
## set the cart items, [Array] of cart items.
|
99
|
+
def find_cart_items
|
100
|
+
conditions = {:resource_id => get_resource.id.to_s, :parent_id => self.id.to_s}
|
101
|
+
self.cart_items = Auth.configuration.cart_item_class.constantize.where(conditions).order(:created_at => 'asc')
|
102
|
+
|
103
|
+
self.cart_items
|
104
|
+
end
|
105
|
+
|
106
|
+
def get_cart_items
|
107
|
+
self.cart_items
|
108
|
+
end
|
109
|
+
|
110
|
+
## =>
|
111
|
+
def set_cart_price
|
112
|
+
self.cart_price = total_value_of_all_items_in_cart = get_cart_items.map{|c| c = c.price*c.quantity}.sum
|
113
|
+
self.cart_price
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_cart_price
|
117
|
+
self.cart_price
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
def set_cart_payments
|
122
|
+
self.cart_payments = []
|
123
|
+
payments_made_to_this_cart = Auth.configuration.payment_class.constantize.find_payments(get_resource,self)
|
124
|
+
|
125
|
+
payments_made_to_this_cart.each do |payment|
|
126
|
+
|
127
|
+
self.cart_payments << payment
|
128
|
+
end
|
129
|
+
|
130
|
+
self.cart_payments
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_cart_payments
|
134
|
+
self.cart_payments
|
135
|
+
end
|
136
|
+
|
137
|
+
def set_cart_paid_amount
|
138
|
+
total_paid = 0
|
139
|
+
payments = get_cart_payments
|
140
|
+
price = get_cart_price
|
141
|
+
payments.each do |payment|
|
142
|
+
|
143
|
+
total_paid += payment.amount if (payment.payment_success)
|
144
|
+
end
|
145
|
+
self.cart_paid_amount = total_paid
|
146
|
+
|
147
|
+
self.cart_credit = self.cart_paid_amount
|
148
|
+
self.cart_paid_amount
|
149
|
+
end
|
150
|
+
|
151
|
+
## sum total of all payments made to the cart.
|
152
|
+
def get_cart_paid_amount
|
153
|
+
self.cart_paid_amount
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def set_cart_pending_balance
|
158
|
+
self.cart_pending_balance = get_cart_price - get_cart_paid_amount
|
159
|
+
end
|
160
|
+
|
161
|
+
def get_cart_pending_balance
|
162
|
+
self.cart_pending_balance
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
## takes all the cart items that are not accepted, and sums their "minimum_price_required_to_accept_cart_item" methods.
|
167
|
+
def set_cart_minimum_payable_amount
|
168
|
+
|
169
|
+
pending_or_unaccepted_cart_items = self.cart_items.select{|c| c.accepted.nil? || c.accepted == false}
|
170
|
+
|
171
|
+
accepted_cart_items = self.cart_items.select{|c| c.accepted == true}
|
172
|
+
|
173
|
+
if pending_or_unaccepted_cart_items.size > 0
|
174
|
+
|
175
|
+
self.cart_minimum_payable_amount = pending_or_unaccepted_cart_items.map{|c| c = c.minimum_price_required_to_accept_cart_item}.inject(:+)
|
176
|
+
|
177
|
+
## it can happen that he has payed somewhere halfway between the required amount and the full price of the cart -> see the tests.
|
178
|
+
self.cart_minimum_payable_amount = self.cart_pending_balance if (self.cart_pending_balance < self.cart_minimum_payable_amount)
|
179
|
+
|
180
|
+
elsif accepted_cart_items.size > 0
|
181
|
+
|
182
|
+
self.cart_minimum_payable_amount = 0
|
183
|
+
|
184
|
+
else
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
## we can add more stuff here like the credit score of the user.
|
190
|
+
## so that is a function of the cart_owner.
|
191
|
+
## so everytime a cart is fully paid, it can add to the credit score of the user, and that can further titrate this..
|
192
|
+
## so we have discount and all this.
|
193
|
+
end
|
194
|
+
|
195
|
+
## will do first check if the discount id exists, and then if it requires
|
196
|
+
def set_discount
|
197
|
+
begin
|
198
|
+
self.discount = Auth.configuration.discount_class.constantize.find(discount_id)
|
199
|
+
|
200
|
+
rescue => e
|
201
|
+
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
## initially is the same as cart_paid_amount, by calling debit, we can debit from credit, the costs of various items.
|
206
|
+
def get_cart_credit
|
207
|
+
self.cart_credit
|
208
|
+
end
|
209
|
+
|
210
|
+
## debits the @amount from the cart credit.
|
211
|
+
## returns the current credit.
|
212
|
+
def debit(amount)
|
213
|
+
#puts "want to debit: #{amount}"
|
214
|
+
#puts "current credit is: #{self.cart_credit}"
|
215
|
+
self.cart_credit-=amount
|
216
|
+
|
217
|
+
#puts "after debiting: #{self.cart_credit}"
|
218
|
+
self.cart_credit
|
219
|
+
end
|
220
|
+
|
221
|
+
############# PAYMENT BALANCE CONVENIENCE METHODS #############
|
222
|
+
|
223
|
+
## not fully paid, there is some amount to be taken from the customer yet.
|
224
|
+
def has_pending
|
225
|
+
get_cart_pending_balance > 0
|
226
|
+
end
|
227
|
+
|
228
|
+
## fully paid.
|
229
|
+
def fully_paid
|
230
|
+
get_cart_pending_balance == 0
|
231
|
+
end
|
232
|
+
|
233
|
+
## not paid a penny.
|
234
|
+
def not_paid_at_all
|
235
|
+
get_cart_pending_balance == get_cart_price
|
236
|
+
end
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
## returns the amount that needs to be refunded to the customer from this cart.
|
241
|
+
## @return : 0 if the pending_balance is greater than 0,otherwise returns the pending balance.
|
242
|
+
def refund_amount
|
243
|
+
return 0 unless get_cart_pending_balance < 0
|
244
|
+
return get_cart_pending_balance
|
245
|
+
end
|
246
|
+
|
247
|
+
## just replaces the cart_items with an array of cart_item_ids
|
248
|
+
## replaces the cart_payments with an array of cart_payment_ids
|
249
|
+
## then returns a hash with these two instead of the original values.
|
250
|
+
## @used_in : Shopping::PaymentConcern.set_receipt.
|
251
|
+
def prepare_receipt
|
252
|
+
cart_item_ids = cart_items.map{|c| c = c.id.to_s}
|
253
|
+
cart_payment_ids = cart_payments.map{|c| c = c.id.to_s}
|
254
|
+
receipt = self.attributes.merge({:cart_items => cart_item_ids, :cart_payments => cart_payment_ids})
|
255
|
+
receipt
|
256
|
+
end
|
257
|
+
|
258
|
+
## checks if there are any items in the cart.
|
259
|
+
## expected that prepare_cart has been called in advance.
|
260
|
+
## return[Boolean] true if there is one or more items in the cart
|
261
|
+
## @used_in: payment_concern validation cart_not_empty
|
262
|
+
def has_items?
|
263
|
+
get_cart_items.size > 0
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
def as_json(options={})
|
268
|
+
super.merge({:cart_items => self.cart_items, :cart_payments => self.cart_payments, :cart_price => self.cart_price, :cart_paid_amount => self.cart_paid_amount, :cart_pending_balance => self.cart_pending_balance, :cart_credit => self.cart_credit, :cart_minimum_payable_amount => self.cart_minimum_payable_amount})
|
269
|
+
end
|
270
|
+
|
271
|
+
def add_or_remove_validation
|
272
|
+
add_or_remove(add_cart_item_ids,1) if add_cart_item_ids
|
273
|
+
add_or_remove(remove_cart_item_ids,-1) if remove_cart_item_ids
|
274
|
+
end
|
275
|
+
|
276
|
+
##adds a validation error if the cart items could not be successfully added or removed.
|
277
|
+
##called from the controller.
|
278
|
+
##TODO: you should change this to be called before_validation instead, so that all code remains in the model.
|
279
|
+
def add_or_remove(item_ids,add_or_remove)
|
280
|
+
item_ids.map {|id|
|
281
|
+
begin
|
282
|
+
#puts "the signed in resource is:"
|
283
|
+
#puts self.signed_in_resource
|
284
|
+
|
285
|
+
cart_item = Auth.configuration.cart_item_class.constantize.find_self(id,self.signed_in_resource)
|
286
|
+
|
287
|
+
cart_item.signed_in_resource = self.signed_in_resource
|
288
|
+
|
289
|
+
puts "Add or remove is: #{add_or_remove}"
|
290
|
+
|
291
|
+
resp = (add_or_remove == 1) ? cart_item.set_cart_and_resource(self) : cart_item.unset_cart
|
292
|
+
|
293
|
+
puts "unset cart is:#{resp.to_s}"
|
294
|
+
|
295
|
+
|
296
|
+
resp
|
297
|
+
rescue Mongoid::Errors::DocumentNotFound => error
|
298
|
+
#puts "--------------------------------------------DIDNT FIND THE CART ITEM"
|
299
|
+
#puts error.to_s
|
300
|
+
#puts "--------------------------------------------"
|
301
|
+
true
|
302
|
+
end
|
303
|
+
}
|
304
|
+
#self.errors.add(:cart_items,"some cart items could not be added or removed successfully") if ((add_remove_results.size > 1) || (add_remove_results[0] == false))
|
305
|
+
|
306
|
+
end
|
307
|
+
|
308
|
+
## used in initialize vars in cart_controlller_concern.
|
309
|
+
## override this method to allow an admin to also interact with all the actions of the controller.
|
310
|
+
def self.find_cart(cart_id,resource)
|
311
|
+
if cart_collection = self.where(:id => cart_id, :resource_id => resource_id)
|
312
|
+
cart_collection.size > 0 ? cart_collection.first : nil
|
313
|
+
else
|
314
|
+
nil
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
## @return[Boolean] true/false : override to decide how the cart decides if it can create discount coupons for its contents or not.
|
319
|
+
## the current implementation returns true if all items have been fully paid for.
|
320
|
+
def can_create_discount_coupons?
|
321
|
+
#return (self.cart_items.select{|c| c.accepted.nil? || c.accepted == false}.size == 0)
|
322
|
+
puts "CAME TO CAN CREATE DISCOUNT COUPONS."
|
323
|
+
prepare_cart
|
324
|
+
|
325
|
+
self.cart_pending_balance == 0
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
end
|