wordjelly-auth 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/images/payumoney.png +0 -0
- data/app/assets/javascripts/auth/auth_dependencies.js +20 -1
- data/app/assets/stylesheets/auth/common-styles.scss +15 -0
- data/app/controllers/auth/concerns/shopping/cart_controller_concern.rb +2 -2
- data/app/controllers/auth/concerns/shopping/cart_item_controller_concern.rb +24 -0
- data/app/controllers/auth/concerns/shopping/discount_controller_concern.rb +2 -2
- data/app/controllers/auth/concerns/shopping/payment_controller_concern.rb +5 -2
- data/app/controllers/auth/concerns/shopping/personality_controller_concern.rb +88 -0
- data/app/controllers/auth/concerns/shopping/place_controller_concern.rb +96 -0
- data/app/controllers/auth/concerns/shopping/product_controller_concern.rb +53 -42
- data/app/controllers/auth/concerns/token_concern.rb +3 -1
- data/app/controllers/auth/search_controller.rb +3 -3
- data/app/controllers/auth/shopping/personalities_controller.rb +14 -0
- data/app/controllers/auth/shopping/places_controller.rb +11 -0
- data/app/controllers/auth/shopping/shopping_controller.rb +26 -0
- data/app/helpers/auth/shopping/payments/pay_u_money_helper.rb +1 -1
- data/app/helpers/auth/shopping/personalities/personalities_helper.rb +26 -0
- data/app/helpers/auth/shopping/places/places_helper.rb +26 -0
- data/app/helpers/auth/shopping/products/products_helper.rb +2 -2
- data/app/models/auth/concerns/chief_model_concern.rb +0 -4
- data/app/models/auth/concerns/shopping/cart_concern.rb +31 -4
- data/app/models/auth/concerns/shopping/cart_item_concern.rb +4 -7
- data/app/models/auth/concerns/shopping/discount_concern.rb +0 -7
- data/app/models/auth/concerns/shopping/pay_u_money_concern.rb +2 -2
- data/app/models/auth/concerns/shopping/payment_concern.rb +25 -8
- data/app/models/auth/concerns/shopping/personality_concern.rb +91 -0
- data/app/models/auth/concerns/shopping/place_concern.rb +134 -0
- data/app/models/auth/concerns/shopping/product_concern.rb +57 -1
- data/app/models/auth/shopping/personality.rb +3 -0
- data/app/models/auth/shopping/place.rb +3 -0
- data/app/views/auth/search/authenticated_user_search.js.erb +5 -31
- data/app/views/auth/shopping/personalities/_form.html.erb +32 -0
- data/app/views/auth/shopping/personalities/_search.html.erb +6 -0
- data/app/views/auth/shopping/personalities/_search_results_holder.html.erb +3 -0
- data/app/views/auth/shopping/personalities/new.html.erb +1 -0
- data/app/views/auth/shopping/places/_form.html.erb +62 -0
- data/app/views/auth/shopping/places/_search.html.erb +6 -0
- data/app/views/auth/shopping/places/_search_results_holder.html.erb +3 -0
- data/app/views/auth/shopping/places/new.html.erb +1 -0
- data/app/views/auth/shopping/products/index/_show.html.erb +1 -1
- data/app/views/auth/shopping/products/show/_content.html.erb +2 -1
- data/lib/assets/javascripts/search.js +0 -2
- data/lib/auth/engine.rb +15 -0
- data/lib/auth/rails/routes.rb +7 -1
- data/lib/auth/search/main.rb +20 -8
- data/lib/auth/version.rb +1 -1
- data/lib/wordjelly-auth.rb +1 -0
- data/spec/dummy/app/assets/time_hashes.json +1 -1
- data/spec/dummy/config/initializers/preinitializer.rb +8 -1
- data/spec/dummy/config/routes.rb +1 -1
- metadata +37 -4
@@ -112,9 +112,11 @@ module Auth::Concerns::TokenConcern
|
|
112
112
|
|
113
113
|
|
114
114
|
def lookup_resource
|
115
|
+
puts "came to lookup resource."
|
115
116
|
## if the current signed in resource si not an admin, just return it, because the concept of proxy arises only if the current_signed in resource is an admin.
|
117
|
+
puts "current signed in resource : #{current_signed_in_resource}"
|
116
118
|
return current_signed_in_resource unless current_signed_in_resource.is_admin?
|
117
|
-
|
119
|
+
puts "crossed resource."
|
118
120
|
## else.
|
119
121
|
|
120
122
|
## first check the session or the params for a proxy resource.
|
@@ -27,18 +27,18 @@ class Auth::SearchController < ApplicationController
|
|
27
27
|
## @html => currently does not support html request.
|
28
28
|
def authenticated_user_search
|
29
29
|
|
30
|
+
|
30
31
|
## m client will be available at this stage.
|
31
32
|
## the problem is that it is hard to pass it forward to the mongoid elasticsearch object.
|
32
33
|
## because while initializing the user it will have to first be set on the user.
|
33
34
|
## is there any other way to achieve this?
|
34
35
|
query = permitted_params[:query]
|
35
36
|
query[:resource_id] = lookup_resource.id.to_s if !current_signed_in_resource.is_admin?
|
37
|
+
|
36
38
|
|
37
39
|
@search_results = Auth::Search::Main.search(query)
|
38
40
|
|
39
|
-
|
40
|
-
puts @search_results.to_s
|
41
|
-
|
41
|
+
|
42
42
|
#dummy_product = Auth.configuration.product_class.constantize.new
|
43
43
|
#dummy_product.name = "test product"
|
44
44
|
#dummy_product.price = 100.20
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Auth::Shopping::PersonalitiesController < Auth::Shopping::ShoppingController
|
2
|
+
include Auth::Concerns::Shopping::PersonalityControllerConcern
|
3
|
+
|
4
|
+
## only these actions need an authenticated user to be present for them to be executed.
|
5
|
+
CONDITIONS_FOR_TOKEN_AUTH = [:create,:update,:destroy,:edit,:new,:index,:show,:create_multiple]
|
6
|
+
|
7
|
+
TCONDITIONS = {:only => CONDITIONS_FOR_TOKEN_AUTH}
|
8
|
+
##this ensures api access to this controller.
|
9
|
+
include Auth::Concerns::DeviseConcern
|
10
|
+
include Auth::Concerns::TokenConcern
|
11
|
+
before_filter :do_before_request , TCONDITIONS
|
12
|
+
before_filter :initialize_vars , TCONDITIONS
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Auth::Shopping::PlacesController < Auth::Shopping::ShoppingController
|
2
|
+
include Auth::Concerns::Shopping::PlaceControllerConcern
|
3
|
+
## only these actions need an authenticated user to be present for them to be executed.
|
4
|
+
CONDITIONS_FOR_TOKEN_AUTH = [:create,:update,:destroy,:edit,:new,:index,:show,:create_multiple]
|
5
|
+
TCONDITIONS = {:only => CONDITIONS_FOR_TOKEN_AUTH}
|
6
|
+
##this ensures api access to this controller.
|
7
|
+
include Auth::Concerns::DeviseConcern
|
8
|
+
include Auth::Concerns::TokenConcern
|
9
|
+
before_filter :do_before_request , TCONDITIONS
|
10
|
+
before_filter :initialize_vars , TCONDITIONS
|
11
|
+
end
|
@@ -12,6 +12,30 @@ class Auth::Shopping::ShoppingController < Auth::ApplicationController
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def instantiate_place_class
|
16
|
+
if @auth_shopping_place_class = Auth.configuration.place_class
|
17
|
+
begin
|
18
|
+
@auth_shopping_place_class = @auth_shopping_place_class.constantize
|
19
|
+
rescue
|
20
|
+
not_found("error instantiating class from place class")
|
21
|
+
end
|
22
|
+
else
|
23
|
+
not_found("place class not specified in configuration")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def instantiate_personality_class
|
28
|
+
if @auth_shopping_personality_class = Auth.configuration.personality_class
|
29
|
+
begin
|
30
|
+
@auth_shopping_personality_class = @auth_shopping_personality_class.constantize
|
31
|
+
rescue
|
32
|
+
not_found("error instantiating class from personality class")
|
33
|
+
end
|
34
|
+
else
|
35
|
+
not_found("personality class not specified in configuration")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
15
39
|
|
16
40
|
def instantiate_cart_class
|
17
41
|
if @auth_shopping_cart_class = Auth.configuration.cart_class
|
@@ -79,6 +103,8 @@ class Auth::Shopping::ShoppingController < Auth::ApplicationController
|
|
79
103
|
instantiate_cart_item_class
|
80
104
|
instantiate_product_class
|
81
105
|
instantiate_discount_class
|
106
|
+
instantiate_personality_class
|
107
|
+
instantiate_place_class
|
82
108
|
end
|
83
109
|
|
84
110
|
|
@@ -31,7 +31,7 @@ module Auth::Shopping::Payments::PayUMoneyHelper
|
|
31
31
|
result << hidden_field_tag(field == "hast" ? "hash" : field, value)
|
32
32
|
end
|
33
33
|
|
34
|
-
result << '<input type=
|
34
|
+
result << '<input type="image" src="/assets/payumoney.png" >'
|
35
35
|
result << '</form>'
|
36
36
|
result = result.join("\n")
|
37
37
|
concat(result.respond_to?(:html_safe) ? result.html_safe : result)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Auth::Shopping::Personalities::PersonalitiesHelper
|
2
|
+
|
3
|
+
## get /new
|
4
|
+
def new_personality_path
|
5
|
+
main_app.send(Auth::OmniAuth::Path.new_path(Auth.configuration.personality_class))
|
6
|
+
end
|
7
|
+
|
8
|
+
## (PUT/PATCH/GET) - individual personality
|
9
|
+
def personality_path(personality)
|
10
|
+
|
11
|
+
main_app.send(Auth::OmniAuth::Path.show_or_update_or_delete_path(Auth.configuration.personality_class),personality)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
##/personalities (GET - all personalities /CREATE - individual personality)
|
16
|
+
def personalities_path
|
17
|
+
main_app.send(Auth::OmniAuth::Path.create_or_index_path(Auth.configuration.personality_class))
|
18
|
+
end
|
19
|
+
|
20
|
+
##/shopping/personalities/:id/edit
|
21
|
+
def edit_personality_path(personality)
|
22
|
+
main_app.send(Auth::OmniAuth::Path.edit_path(Auth.configuration.personality_class),personality)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Auth::Shopping::Places::PlacesHelper
|
2
|
+
|
3
|
+
## get /new
|
4
|
+
def new_place_path
|
5
|
+
main_app.send(Auth::OmniAuth::Path.new_path(Auth.configuration.place_class))
|
6
|
+
end
|
7
|
+
|
8
|
+
## (PUT/PATCH/GET) - individual place
|
9
|
+
def place_path(place)
|
10
|
+
|
11
|
+
main_app.send(Auth::OmniAuth::Path.show_or_update_or_delete_path(Auth.configuration.place_class),place)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
##/places (GET - all places /CREATE - individual place)
|
16
|
+
def places_path
|
17
|
+
main_app.send(Auth::OmniAuth::Path.create_or_index_path(Auth.configuration.place_class))
|
18
|
+
end
|
19
|
+
|
20
|
+
##/shopping/places/:id/edit
|
21
|
+
def edit_place_path(place)
|
22
|
+
main_app.send(Auth::OmniAuth::Path.edit_path(Auth.configuration.place_class),place)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
@@ -40,8 +40,8 @@ module Auth::Shopping::Products::ProductsHelper
|
|
40
40
|
|
41
41
|
|
42
42
|
##/products (GET - all products /CREATE - individual product)
|
43
|
-
def products_path
|
44
|
-
main_app.send(Auth::OmniAuth::Path.create_or_index_path(Auth.configuration.product_class))
|
43
|
+
def products_path(params={})
|
44
|
+
main_app.send(Auth::OmniAuth::Path.create_or_index_path(Auth.configuration.product_class),params)
|
45
45
|
end
|
46
46
|
|
47
47
|
##/shopping/products/:id/edit
|
@@ -9,9 +9,11 @@ module Auth::Concerns::Shopping::CartConcern
|
|
9
9
|
included do
|
10
10
|
field :name, type: String
|
11
11
|
field :notes, type: String
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
## location of the user for this cart
|
14
|
+
field :place_id, type: String
|
15
|
+
## name, age, sex of the user for this cart.
|
16
|
+
field :personality_id, type: String
|
15
17
|
|
16
18
|
|
17
19
|
## 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.
|
@@ -52,6 +54,10 @@ module Auth::Concerns::Shopping::CartConcern
|
|
52
54
|
|
53
55
|
attr_accessor :discount
|
54
56
|
|
57
|
+
attr_accessor :personality
|
58
|
+
|
59
|
+
attr_accessor :place
|
60
|
+
|
55
61
|
before_destroy do |document|
|
56
62
|
document.prepare_cart
|
57
63
|
if document.cart_items.keep_if{|c| c.accepted == true}.size > 0
|
@@ -76,7 +82,7 @@ module Auth::Concerns::Shopping::CartConcern
|
|
76
82
|
## @param[Payment] : a payment object can be passed in.
|
77
83
|
## 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
84
|
def prepare_cart
|
79
|
-
|
85
|
+
|
80
86
|
find_cart_items
|
81
87
|
|
82
88
|
set_cart_price
|
@@ -91,12 +97,17 @@ module Auth::Concerns::Shopping::CartConcern
|
|
91
97
|
|
92
98
|
set_discount
|
93
99
|
|
100
|
+
set_personality
|
101
|
+
|
102
|
+
set_place
|
103
|
+
|
94
104
|
end
|
95
105
|
|
96
106
|
################ ATTR ACCESSOR SETTERS & GETTERS ##############
|
97
107
|
|
98
108
|
## set the cart items, [Array] of cart items.
|
99
109
|
def find_cart_items
|
110
|
+
puts "find cart items."
|
100
111
|
conditions = {:resource_id => get_resource.id.to_s, :parent_id => self.id.to_s}
|
101
112
|
self.cart_items = Auth.configuration.cart_item_class.constantize.where(conditions).order(:created_at => 'asc')
|
102
113
|
|
@@ -109,6 +120,7 @@ module Auth::Concerns::Shopping::CartConcern
|
|
109
120
|
|
110
121
|
## =>
|
111
122
|
def set_cart_price
|
123
|
+
puts "set cart price"
|
112
124
|
self.cart_price = total_value_of_all_items_in_cart = get_cart_items.map{|c| c = c.price*c.quantity}.sum
|
113
125
|
self.cart_price
|
114
126
|
end
|
@@ -119,6 +131,7 @@ module Auth::Concerns::Shopping::CartConcern
|
|
119
131
|
|
120
132
|
|
121
133
|
def set_cart_payments
|
134
|
+
puts "set cart payments."
|
122
135
|
self.cart_payments = []
|
123
136
|
payments_made_to_this_cart = Auth.configuration.payment_class.constantize.find_payments(get_resource,self)
|
124
137
|
|
@@ -135,6 +148,7 @@ module Auth::Concerns::Shopping::CartConcern
|
|
135
148
|
end
|
136
149
|
|
137
150
|
def set_cart_paid_amount
|
151
|
+
puts "set cart paid amount"
|
138
152
|
total_paid = 0
|
139
153
|
payments = get_cart_payments
|
140
154
|
price = get_cart_price
|
@@ -249,6 +263,7 @@ module Auth::Concerns::Shopping::CartConcern
|
|
249
263
|
## then returns a hash with these two instead of the original values.
|
250
264
|
## @used_in : Shopping::PaymentConcern.set_receipt.
|
251
265
|
def prepare_receipt
|
266
|
+
puts "PREPARE RECEIPT-----------------------------------"
|
252
267
|
cart_item_ids = cart_items.map{|c| c = c.id.to_s}
|
253
268
|
cart_payment_ids = cart_payments.map{|c| c = c.id.to_s}
|
254
269
|
receipt = self.attributes.merge({:cart_items => cart_item_ids, :cart_payments => cart_payment_ids})
|
@@ -326,4 +341,16 @@ module Auth::Concerns::Shopping::CartConcern
|
|
326
341
|
|
327
342
|
end
|
328
343
|
|
344
|
+
def set_personality
|
345
|
+
return unless self.personality_id
|
346
|
+
puts "self personality id is: #{self.personality_id}"
|
347
|
+
self.personality = Auth.configuration.personality_class.constantize.find(self.personality_id)
|
348
|
+
end
|
349
|
+
|
350
|
+
def set_place
|
351
|
+
return unless self.place_id
|
352
|
+
puts "Self place id is: #{self.place_id}"
|
353
|
+
self.place = Auth.configuration.place_class.constantize.find(self.place_id)
|
354
|
+
end
|
355
|
+
|
329
356
|
end
|
@@ -162,7 +162,6 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
162
162
|
end
|
163
163
|
|
164
164
|
|
165
|
-
|
166
165
|
validate :user_cannot_change_anything_if_payment_accepted
|
167
166
|
validate :product_id_exists?
|
168
167
|
|
@@ -170,8 +169,6 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
170
169
|
document.public = "no"
|
171
170
|
end
|
172
171
|
|
173
|
-
|
174
|
-
|
175
172
|
end
|
176
173
|
|
177
174
|
|
@@ -193,7 +190,7 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
193
190
|
### this is an internal method, cannot be set by admin or anyone, it is done after validation, since it is not necessary for someone to be admin, even the user can call refresh on the record to get the new state of the acceptence.
|
194
191
|
## just checks if the accepted by payment id exists, and if yes, then doesnt do anything, otherwise will update the cart item status as false.
|
195
192
|
def refresh_accepted
|
196
|
-
|
193
|
+
puts "CALLED REFRESH accepted-----------------------"
|
197
194
|
if self.accepted_by_payment_id
|
198
195
|
|
199
196
|
begin
|
@@ -202,6 +199,7 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
202
199
|
## if the payment status is approved, then dont do anything to the cart item.(we don't retro check payment to cart item.)
|
203
200
|
## if the payment status is not approved, then make the cart item accepted as false.
|
204
201
|
if (payment.payment_status.nil? || payment.payment_status == 0)
|
202
|
+
puts "FOUND THE PAYMENT STATUS TO BE NIL or 0"
|
205
203
|
self.accepted = false
|
206
204
|
end
|
207
205
|
rescue Mongoid::Errors::DocumentNotFound
|
@@ -234,8 +232,7 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
234
232
|
## does not SAVE.
|
235
233
|
def set_accepted(payment,override)
|
236
234
|
|
237
|
-
|
238
|
-
#puts self.accepted.to_s
|
235
|
+
|
239
236
|
|
240
237
|
if cart_has_sufficient_credit_for_item?(payment.cart)
|
241
238
|
|
@@ -371,7 +368,7 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
371
368
|
|
372
369
|
return if self.new_record?
|
373
370
|
|
374
|
-
|
371
|
+
|
375
372
|
|
376
373
|
return if self.accepted_changed?
|
377
374
|
|
@@ -166,7 +166,6 @@ module Auth::Concerns::Shopping::DiscountConcern
|
|
166
166
|
document.add_verified_ids ||= []
|
167
167
|
document.add_declined_ids ||= []
|
168
168
|
|
169
|
-
|
170
169
|
|
171
170
|
document.pending = document.pending - ([document.add_declined_ids + document.add_verified_ids].flatten)
|
172
171
|
|
@@ -189,10 +188,6 @@ module Auth::Concerns::Shopping::DiscountConcern
|
|
189
188
|
module ClassMethods
|
190
189
|
|
191
190
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
191
|
def find_discounts(options)
|
197
192
|
conditions = {:resource_id => nil}
|
198
193
|
conditions[:resource_id] = options[:resource].id.to_s if options[:resource]
|
@@ -200,8 +195,6 @@ module Auth::Concerns::Shopping::DiscountConcern
|
|
200
195
|
end
|
201
196
|
|
202
197
|
|
203
|
-
|
204
|
-
|
205
198
|
## @called_from : payment_concern.rb
|
206
199
|
## @param[String] payment_id
|
207
200
|
## @return[BSON::Document] the document after the update or nil, in case nothing was updated.
|
@@ -25,7 +25,6 @@ module Auth::Concerns::Shopping::PayUMoneyConcern
|
|
25
25
|
##remember to set the default_url_options in the dummy app routes file.
|
26
26
|
before_create do |document|
|
27
27
|
if document.is_gateway?
|
28
|
-
|
29
28
|
document.surl = document.furl = Rails.application.routes.url_helpers.shopping_payment_url(document.id.to_s)
|
30
29
|
document.txnid = document.id.to_s
|
31
30
|
#document.txnid = "a#{Random.new.rand(1..50)}"
|
@@ -93,8 +92,9 @@ module Auth::Concerns::Shopping::PayUMoneyConcern
|
|
93
92
|
self.payment_status = 0 if transaction_details["status"].to_s.downcase =~/pending|failure/
|
94
93
|
if payment_status_changed?
|
95
94
|
## prevents recursive callbacks, after save.
|
95
|
+
## actually this may not be necessary here.
|
96
96
|
self.is_verify_payment = "false"
|
97
|
-
|
97
|
+
## so only if is_verify_payment is true,
|
98
98
|
else
|
99
99
|
self.errors.add(:payment_status,"transaction status was something other than failed|success|pending")
|
100
100
|
end
|
@@ -115,7 +115,7 @@ module Auth::Concerns::Shopping::PaymentConcern
|
|
115
115
|
|
116
116
|
|
117
117
|
before_validation do |document|
|
118
|
-
|
118
|
+
|
119
119
|
document.set_cart(document.cart_id)
|
120
120
|
|
121
121
|
document.payment_callback(document.payment_type,document.payment_params)
|
@@ -123,7 +123,10 @@ module Auth::Concerns::Shopping::PaymentConcern
|
|
123
123
|
## we can hook the refresh into this.
|
124
124
|
document.refresh_refund
|
125
125
|
|
126
|
+
## here the call goes to save it inside
|
127
|
+
## that will again trigger.
|
126
128
|
document.verify_payment
|
129
|
+
|
127
130
|
end
|
128
131
|
|
129
132
|
## because the validation will not allow the payment status to be changed in case this is not an admin user, and we need to allow the user to refresh the payment state, in case of refunds which need to set as failed because some later refund was accepted but in that callback the nil refund was for some reason not set as failed.
|
@@ -143,6 +146,7 @@ module Auth::Concerns::Shopping::PaymentConcern
|
|
143
146
|
|
144
147
|
## when a refund is accepted, any pening refund requests are considered to have failed, since this one has succeeded.
|
145
148
|
after_save do |document|
|
149
|
+
|
146
150
|
if !document.skip_callback?("after_save")
|
147
151
|
|
148
152
|
|
@@ -170,10 +174,12 @@ module Auth::Concerns::Shopping::PaymentConcern
|
|
170
174
|
end
|
171
175
|
|
172
176
|
## set the payment receipt
|
177
|
+
|
173
178
|
document.set_payment_receipt
|
174
179
|
|
175
180
|
end
|
176
181
|
end
|
182
|
+
|
177
183
|
end
|
178
184
|
|
179
185
|
|
@@ -249,12 +255,16 @@ module Auth::Concerns::Shopping::PaymentConcern
|
|
249
255
|
## called in show action of controller.
|
250
256
|
## return[Array]
|
251
257
|
def set_payment_receipt
|
258
|
+
puts "CAME TO SET PAYMENT RECEIPT ------------------------"
|
252
259
|
self.payment_receipt = {:current_payment => [], :cart => {}}
|
253
260
|
Auth.configuration.cart_item_class.constantize.where(:accepted_by_payment_id => self.id.to_s).each do |c_item|
|
261
|
+
puts "THIS ITEM IS C_ITEM: #{c_item.id.to_s}"
|
254
262
|
self.payment_receipt[:current_payment] << c_item
|
255
263
|
end
|
256
264
|
set_cart(self.cart_id) if self.cart.nil?
|
257
265
|
self.payment_receipt[:cart] = self.cart.prepare_receipt
|
266
|
+
puts self.payment_receipt.to_s
|
267
|
+
puts "finished set payment receipt."
|
258
268
|
end
|
259
269
|
|
260
270
|
##res : 59a5405c421aa90f732c9059
|
@@ -369,7 +379,12 @@ module Auth::Concerns::Shopping::PaymentConcern
|
|
369
379
|
end
|
370
380
|
|
371
381
|
def discount_callback(params,&block)
|
372
|
-
|
382
|
+
|
383
|
+
## so now what next ?
|
384
|
+
## what about refunds ?
|
385
|
+
## and what about discount coupons for companies ?
|
386
|
+
## can i handle that right now as well ?
|
387
|
+
|
373
388
|
## the callback should fire on create/update, so new_record checking is not required.
|
374
389
|
|
375
390
|
## first check if the discount id exists -> get the discount object.
|
@@ -398,7 +413,7 @@ module Auth::Concerns::Shopping::PaymentConcern
|
|
398
413
|
self.amount = self.discount.discount_amount
|
399
414
|
|
400
415
|
elsif self.discount.discount_percentage > 0
|
401
|
-
self.amount = self.cart.cart_pending_balance*self.discount.discount_percentage
|
416
|
+
self.amount = self.cart.cart_pending_balance*(self.discount.discount_percentage/100.0)
|
402
417
|
else
|
403
418
|
self.amount = 0
|
404
419
|
end
|
@@ -458,8 +473,9 @@ module Auth::Concerns::Shopping::PaymentConcern
|
|
458
473
|
def update_cart_items_accepted
|
459
474
|
|
460
475
|
if payment_status_changed?
|
461
|
-
|
476
|
+
puts "payment status was changed---------------------"
|
462
477
|
if payment_status == 1
|
478
|
+
puts "PAYMENT STATUS IS 1"
|
463
479
|
self.cart.cart_credit+= self.amount
|
464
480
|
elsif payment_status == 0 && payment_status_was == 1
|
465
481
|
|
@@ -469,8 +485,8 @@ module Auth::Concerns::Shopping::PaymentConcern
|
|
469
485
|
end
|
470
486
|
|
471
487
|
|
472
|
-
|
473
488
|
cart_item_update_results = self.cart.get_cart_items.map{|cart_item|
|
489
|
+
puts "CART ITEM OF THE CART IS FOUND"
|
474
490
|
cart_item.signed_in_resource = self.signed_in_resource
|
475
491
|
## first all the expected cart items should exist
|
476
492
|
## then they should all get saved
|
@@ -486,12 +502,13 @@ module Auth::Concerns::Shopping::PaymentConcern
|
|
486
502
|
cart_item.set_accepted(self,nil)
|
487
503
|
}.compact.uniq
|
488
504
|
self.errors.add(:cart,"cart item status could not be updated") if cart_item_update_results[0] == false
|
489
|
-
|
505
|
+
puts "self errors are:"
|
506
|
+
puts self.errors.size
|
490
507
|
else
|
491
508
|
if (payment_status == 0 || payment_status == 1)
|
492
509
|
cart_item_update_results = self.cart.get_cart_items.map{|cart_item|
|
493
|
-
|
494
|
-
|
510
|
+
puts "VALIDATING IT WITH PAYMENT AT NULL."
|
511
|
+
puts cart_item.id.to_s
|
495
512
|
cart_item.signed_in_resource = self.signed_in_resource
|
496
513
|
res = cart_item.set_accepted(self,nil)
|
497
514
|
res
|