effective_orders 3.2.3 → 4.0.0beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/MIT-LICENSE +1 -1
- data/README.md +11 -99
- data/app/assets/stylesheets/effective_orders.scss +1 -0
- data/app/assets/stylesheets/effective_orders/_cart.scss +4 -0
- data/app/assets/stylesheets/effective_orders/_order.scss +6 -2
- data/app/controllers/admin/orders_controller.rb +17 -17
- data/app/controllers/effective/carts_controller.rb +4 -2
- data/app/controllers/effective/orders_controller.rb +50 -105
- data/app/controllers/effective/providers/cheque.rb +1 -1
- data/app/controllers/effective/providers/moneris.rb +17 -23
- data/app/controllers/effective/providers/stripe.rb +2 -37
- data/app/datatables/effective_customers_datatable.rb +1 -5
- data/app/datatables/effective_order_items_datatable.rb +10 -10
- data/app/datatables/effective_orders_datatable.rb +23 -46
- data/app/helpers/effective_carts_helper.rb +5 -25
- data/app/helpers/effective_orders_helper.rb +29 -61
- data/app/helpers/effective_paypal_helper.rb +10 -8
- data/app/helpers/effective_stripe_helper.rb +2 -33
- data/app/models/concerns/acts_as_purchasable.rb +26 -37
- data/app/models/concerns/acts_as_subscribable.rb +1 -1
- data/app/models/effective/cart.rb +4 -5
- data/app/models/effective/customer.rb +1 -4
- data/app/models/effective/order.rb +132 -163
- data/app/models/effective/order_item.rb +2 -21
- data/app/models/{effective → validators/effective}/sold_out_validator.rb +0 -0
- data/app/views/admin/customers/index.html.haml +1 -4
- data/app/views/admin/order_items/index.html.haml +1 -4
- data/app/views/admin/orders/_actions.html.haml +18 -9
- data/app/views/admin/orders/_form.html.haml +12 -14
- data/app/views/admin/orders/_form_note_internal.html.haml +2 -2
- data/app/views/admin/orders/_order_actions.html.haml +8 -5
- data/app/views/admin/orders/_order_item_fields.html.haml +9 -8
- data/app/views/admin/orders/checkout.html.haml +3 -0
- data/app/views/admin/orders/edit.html.haml +3 -1
- data/app/views/admin/orders/new.html.haml +2 -1
- data/app/views/admin/orders/show.html.haml +2 -5
- data/app/views/effective/carts/_cart.html.haml +1 -1
- data/app/views/effective/carts/_cart_actions.html.haml +3 -4
- data/app/views/effective/carts/show.html.haml +4 -4
- data/app/views/effective/orders/_checkout_actions.html.haml +3 -0
- data/app/views/effective/orders/_checkout_step1.html.haml +20 -27
- data/app/views/effective/orders/_checkout_step2.html.haml +26 -30
- data/app/views/effective/orders/_order.html.haml +1 -2
- data/app/views/effective/orders/_order_actions.html.haml +14 -6
- data/app/views/effective/orders/_order_header.html.haml +2 -2
- data/app/views/effective/orders/_order_note_fields.html.haml +6 -4
- data/app/views/effective/orders/_order_notes.html.haml +15 -0
- data/app/views/effective/orders/_order_payment_details.html.haml +1 -1
- data/app/views/effective/orders/_order_shipping.html.haml +6 -6
- data/app/views/effective/orders/_order_terms_and_conditions_fields.html.haml +5 -6
- data/app/views/effective/orders/_order_user_fields.html.haml +5 -11
- data/app/views/effective/orders/_orders_table.html.haml +2 -6
- data/app/views/effective/orders/index.html.haml +2 -1
- data/app/views/effective/orders/mark_as_paid/_form.html.haml +8 -14
- data/app/views/effective/orders/moneris/_form.html.haml +43 -4
- data/app/views/effective/orders/pretend/_form.html.haml +1 -3
- data/app/views/effective/orders/refund/_form.html.haml +8 -12
- data/app/views/effective/orders/show.html.haml +2 -2
- data/app/views/effective/orders/stripe/_form.html.haml +4 -4
- data/app/views/effective/orders_mailer/payment_request_to_buyer.html.haml +1 -1
- data/app/views/effective/orders_mailer/pending_order_invoice_to_buyer.html.haml +1 -1
- data/config/effective_orders.rb +116 -182
- data/config/routes.rb +16 -27
- data/db/migrate/01_create_effective_orders.rb.erb +6 -5
- data/lib/effective_orders.rb +72 -76
- data/lib/effective_orders/engine.rb +8 -80
- data/lib/effective_orders/version.rb +1 -1
- data/lib/generators/templates/effective_orders_mailer_preview.rb +4 -4
- metadata +26 -38
- data/Rakefile +0 -21
- data/app/assets/config/effective_orders_manifest.js +0 -3
- data/app/assets/images/effective_orders/stripe_connect.png +0 -0
- data/app/controllers/effective/providers/app_checkout.rb +0 -38
- data/app/controllers/effective/providers/ccbill.rb +0 -34
- data/app/controllers/effective/providers/stripe_connect.rb +0 -47
- data/app/helpers/effective_ccbill_helper.rb +0 -25
- data/app/models/effective/providers/ccbill_postback.rb +0 -85
- data/app/models/effective/providers/moneris_charge.rb +0 -115
- data/app/views/effective/orders/_order_note.html.haml +0 -5
- data/app/views/effective/orders/_order_note_to_buyer.html.haml +0 -9
- data/app/views/effective/orders/app_checkout/_form.html.haml +0 -2
- data/app/views/effective/orders/ccbill/_form.html.haml +0 -24
- data/app/views/effective/orders/my_purchases.html.haml +0 -3
- data/app/views/effective/orders/my_sales.html.haml +0 -25
- data/app/views/effective/orders_mailer/order_receipt_to_seller.html.haml +0 -25
- data/lib/effective_orders/app_checkout_service.rb +0 -26
@@ -17,39 +17,33 @@ module Effective
|
|
17
17
|
declined_url = params.delete(:rvar_declined_url)
|
18
18
|
|
19
19
|
if @order.purchased? # Fallback to a success condition of the Order is already purchased
|
20
|
-
|
20
|
+
order_purchased(details: params, provider: 'moneris', card: params[:card], purchased_url: purchased_url)
|
21
|
+
return
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
return order_declined(details: params, provider: 'moneris', card: params[:card], declined_url: declined_url)
|
26
|
-
end
|
24
|
+
if params[:result].to_s == '1' && params[:transactionKey].present?
|
25
|
+
verify_params = parse_moneris_response(send_moneris_verify_request(params[:transactionKey])) || {}
|
27
26
|
|
28
|
-
|
29
|
-
valid = (1..49).include?(payment[:response_code].to_i) # Must be > 0 and < 50 to be valid. Sometimes we get the string 'null'
|
27
|
+
response_code = verify_params[:response_code].to_i # Sometimes moneris sends us the string 'null'
|
30
28
|
|
31
|
-
|
32
|
-
|
29
|
+
if response_code > 0 && response_code < 50 # Less than 50 means a successful validation
|
30
|
+
order_purchased(details: params.merge(verify_params), provider: 'moneris', card: params[:card], purchased_url: purchased_url)
|
31
|
+
else
|
32
|
+
order_declined(details: params.merge(verify_params), provider: 'moneris', card: params[:card], declined_url: declined_url)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
order_declined(details: params, provider: 'moneris', card: params[:card], declined_url: declined_url)
|
33
36
|
end
|
34
|
-
|
35
|
-
order_purchased(details: payment, provider: 'moneris', card: params[:card], purchased_url: purchased_url)
|
36
37
|
end
|
37
38
|
|
38
39
|
private
|
39
40
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
params = { ps_store_id: EffectiveOrders.moneris[:ps_store_id], hpp_key: EffectiveOrders.moneris[:hpp_key], transactionKey: transactionKey }
|
44
|
-
headers = { 'Referer': effective_orders.orders_url }
|
45
|
-
|
46
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
47
|
-
http.use_ssl = true
|
48
|
-
|
49
|
-
body = http.post(uri.path, params.to_query, headers).body
|
41
|
+
def parse_moneris_response(text)
|
42
|
+
text.split("<br>").inject(Hash.new()) { |h, i| h[i.split(' ').first.to_sym] = i.split(' ').last ; h } rescue {response: text}
|
43
|
+
end
|
50
44
|
|
51
|
-
|
52
|
-
|
45
|
+
def send_moneris_verify_request(verify_key)
|
46
|
+
`curl -F ps_store_id='#{EffectiveOrders.moneris[:ps_store_id]}' -F hpp_key='#{EffectiveOrders.moneris[:hpp_key]}' -F transactionKey='#{verify_key}' --referer #{effective_orders.moneris_postback_orders_url} #{EffectiveOrders.moneris[:verify_url]}`
|
53
47
|
end
|
54
48
|
|
55
49
|
end
|
@@ -16,7 +16,7 @@ module Effective
|
|
16
16
|
if @stripe_charge.valid? && (response = process_stripe_charge(@stripe_charge)) != false
|
17
17
|
order_purchased(
|
18
18
|
details: response,
|
19
|
-
provider:
|
19
|
+
provider: 'stripe',
|
20
20
|
card: (response[:charge]['source']['brand'] rescue nil)
|
21
21
|
)
|
22
22
|
else
|
@@ -34,11 +34,7 @@ module Effective
|
|
34
34
|
subscripter = Effective::Subscripter.new(user: charge.order.user, stripe_token: charge.stripe_token)
|
35
35
|
subscripter.save!
|
36
36
|
|
37
|
-
|
38
|
-
return charge_with_stripe_connect(charge, subscripter.customer)
|
39
|
-
else
|
40
|
-
return charge_with_stripe(charge, subscripter.customer)
|
41
|
-
end
|
37
|
+
return charge_with_stripe(charge, subscripter.customer)
|
42
38
|
rescue => e
|
43
39
|
charge.errors.add(:base, "Unable to process order with Stripe. Your credit card has not been charged. Message: \"#{e.message}\".")
|
44
40
|
raise ActiveRecord::Rollback
|
@@ -63,37 +59,6 @@ module Effective
|
|
63
59
|
results
|
64
60
|
end
|
65
61
|
|
66
|
-
def charge_with_stripe_connect(charge, buyer)
|
67
|
-
# Go through and create Stripe::Tokens for each seller
|
68
|
-
items = charge.order_items.group_by { |oi| oi.seller }
|
69
|
-
results = {}
|
70
|
-
|
71
|
-
# We do all these Tokens first, so if one throws an exception no charges are made
|
72
|
-
items.each do |seller, _|
|
73
|
-
seller.token = ::Stripe::Token.create({customer: buyer.stripe_customer.id}, seller.stripe_connect_access_token)
|
74
|
-
end
|
75
|
-
|
76
|
-
# Make one charge per seller, for all his order_items
|
77
|
-
items.each do |seller, order_items|
|
78
|
-
amount = order_items.map { |oi| oi.total }.sum
|
79
|
-
description = "Charge for Order ##{charge.order.to_param} with OrderItems ##{order_items.map(&:id).join(', #')}"
|
80
|
-
application_fee = order_items.sum(&:stripe_connect_application_fee)
|
81
|
-
|
82
|
-
results[seller.id] = JSON.parse(::Stripe::Charge.create(
|
83
|
-
{
|
84
|
-
amount: amount,
|
85
|
-
currency: EffectiveOrders.stripe[:currency],
|
86
|
-
card: seller.token.id,
|
87
|
-
description: description,
|
88
|
-
application_fee: application_fee
|
89
|
-
},
|
90
|
-
seller.stripe_connect_access_token
|
91
|
-
).to_json)
|
92
|
-
end
|
93
|
-
|
94
|
-
results
|
95
|
-
end
|
96
|
-
|
97
62
|
# StrongParameters
|
98
63
|
def stripe_charge_params
|
99
64
|
params.require(:effective_providers_stripe_charge).permit(:stripe_token, :effective_order_id)
|
@@ -4,15 +4,11 @@ class EffectiveCustomersDatatable < Effective::Datatable
|
|
4
4
|
col :id, visible: false
|
5
5
|
#col 'user.email'
|
6
6
|
|
7
|
-
if EffectiveOrders.
|
7
|
+
if EffectiveOrders.stripe?
|
8
8
|
col :stripe_customer_id
|
9
9
|
col :active_card
|
10
10
|
end
|
11
11
|
|
12
|
-
if EffectiveOrders.stripe_connect_enabled
|
13
|
-
col :stripe_connect_access_token
|
14
|
-
end
|
15
|
-
|
16
12
|
actions_col do |customer|
|
17
13
|
link_to('Manage', "https://dashboard.stripe.com/#{'test/' if Rails.env.development?}customers/#{customer.stripe_customer_id}")
|
18
14
|
end
|
@@ -27,14 +27,14 @@ class EffectiveOrderItemsDatatable < Effective::Datatable
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
if EffectiveOrders.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
30
|
+
# if EffectiveOrders.billing_address && attributes[:user_id].blank?
|
31
|
+
# col :buyer_name, sort: false, label: 'Buyer Name' do |order_item|
|
32
|
+
# (order_item[:buyer_name] || '').split('!!SEP!!').find(&:present?)
|
33
|
+
# end
|
34
|
+
# end
|
35
35
|
|
36
|
-
col :
|
37
|
-
order_item[:
|
36
|
+
col :state, sql_column: 'orders.state', search: { collection: [%w(abandoned abandoned), [EffectiveOrders::PURCHASED, EffectiveOrders::PURCHASED], [EffectiveOrders::DECLINED, EffectiveOrders::DECLINED]], selected: EffectiveOrders::PURCHASED } do |order_item|
|
37
|
+
order_item[:state] || 'abandoned'
|
38
38
|
end
|
39
39
|
|
40
40
|
col :title do |order_item|
|
@@ -56,7 +56,7 @@ class EffectiveOrderItemsDatatable < Effective::Datatable
|
|
56
56
|
.select("#{query_subtotal} AS subtotal, #{query_tax} AS tax, #{query_total} AS total")
|
57
57
|
.group('order_items.id, orders.id, users.email')
|
58
58
|
|
59
|
-
if EffectiveOrders.
|
59
|
+
if EffectiveOrders.billing_address && defined?(EffectiveAddresses)
|
60
60
|
addresses_tbl = EffectiveAddresses.addresses_table_name
|
61
61
|
|
62
62
|
collection = collection
|
@@ -83,8 +83,8 @@ class EffectiveOrderItemsDatatable < Effective::Datatable
|
|
83
83
|
# def search_column(collection, table_column, search_term)
|
84
84
|
# if table_column[:name] == 'order'
|
85
85
|
# collection.where("#{EffectiveOrders.order_items_table_name.to_s}.order_id = ?", Effective::Order.deobfuscate(search_term))
|
86
|
-
# elsif table_column[:name] == '
|
87
|
-
# collection.where("#{EffectiveOrders.orders_table_name.to_s}.
|
86
|
+
# elsif table_column[:name] == 'state' && search_term == 'abandoned'
|
87
|
+
# collection.where("#{EffectiveOrders.orders_table_name.to_s}.state IS NULL")
|
88
88
|
# elsif table_column[:name] == 'subtotal'
|
89
89
|
# collection.having("#{query_subtotal} = ?", (search_term.gsub(/[^0-9.]/, '').to_f * 100.0).to_i)
|
90
90
|
# elsif table_column[:name] == 'tax'
|
@@ -16,57 +16,45 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
16
16
|
end
|
17
17
|
|
18
18
|
filters do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
19
|
+
scope :purchased, default: true
|
20
|
+
scope :not_purchased
|
21
|
+
scope :all
|
23
22
|
end
|
24
23
|
|
25
24
|
datatable do
|
26
|
-
order :
|
25
|
+
order :id
|
27
26
|
|
28
27
|
bulk_actions_col
|
29
28
|
|
30
|
-
col :
|
29
|
+
col :created_at, visible: false
|
30
|
+
col :updated_at, visible: false
|
31
|
+
col :id, visible: false
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
obfuscated_id = order.to_param
|
35
|
-
link_to(obfuscated_id, (admin_namespace? ? effective_orders.admin_order_path(obfuscated_id) : effective_orders.order_path(obfuscated_id)))
|
36
|
-
end.search do |collection, term|
|
37
|
-
collection.where(id: Effective::Order.deobfuscate(term))
|
38
|
-
end
|
39
|
-
else
|
40
|
-
col :id
|
33
|
+
col :purchased_at do |order|
|
34
|
+
order.purchased_at&.strftime('%F %H:%M') || 'not purchased'
|
41
35
|
end
|
42
36
|
|
43
37
|
if attributes[:user_id].blank?
|
44
|
-
col :user
|
38
|
+
col :user
|
39
|
+
|
40
|
+
col :email, label: 'Email', visible: false, search: :string, sort: :email do |order|
|
45
41
|
link_to order.user.email, (edit_admin_user_path(order.user) rescue admin_user_path(order.user) rescue '#')
|
46
42
|
end
|
47
43
|
|
48
|
-
|
49
|
-
val :buyer_name, visible: false do |order|
|
50
|
-
order.billing_address.try(:full_name)
|
51
|
-
end
|
52
|
-
else
|
53
|
-
val :buyer_name, visible: false do |order|
|
54
|
-
order.user.to_s
|
55
|
-
end
|
56
|
-
end
|
44
|
+
col :billing_name, visible: false
|
57
45
|
end
|
58
46
|
|
59
|
-
if EffectiveOrders.
|
60
|
-
col :billing_address
|
47
|
+
if EffectiveOrders.billing_address
|
48
|
+
col :billing_address, visible: false
|
61
49
|
end
|
62
50
|
|
63
|
-
if EffectiveOrders.
|
64
|
-
col :shipping_address
|
51
|
+
if EffectiveOrders.shipping_address
|
52
|
+
col :shipping_address, visible: false
|
65
53
|
end
|
66
54
|
|
67
|
-
col :
|
68
|
-
|
69
|
-
end
|
55
|
+
# col :state, label: 'State', search: { collection: EffectiveOrders::STATES.invert } do |order|
|
56
|
+
# EffectiveOrders::STATES[order.state]
|
57
|
+
# end
|
70
58
|
|
71
59
|
col :order_items, search: { as: :string }
|
72
60
|
|
@@ -79,16 +67,13 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
79
67
|
|
80
68
|
col :total, as: :price
|
81
69
|
|
82
|
-
col :payment_provider, label: 'Provider', visible: false, search: { collection:
|
83
|
-
col :payment_card, label: 'Card'
|
70
|
+
col :payment_provider, label: 'Provider', visible: false, search: { collection: EffectiveOrders.payment_providers }
|
71
|
+
col :payment_card, label: 'Card', visible: false
|
84
72
|
|
85
|
-
col :note, visible:
|
73
|
+
col :note, visible: EffectiveOrders.collect_note
|
86
74
|
col :note_to_buyer, visible: false
|
87
75
|
col :note_internal, visible: false
|
88
76
|
|
89
|
-
col :created_at, visible: false
|
90
|
-
col :updated_at, visible: false
|
91
|
-
|
92
77
|
actions_col partial: 'admin/orders/actions', partial_as: :order
|
93
78
|
|
94
79
|
aggregate :total
|
@@ -101,14 +86,6 @@ class EffectiveOrdersDatatable < Effective::Datatable
|
|
101
86
|
scope = EffectiveOrders.orders_collection_scope.call(scope)
|
102
87
|
end
|
103
88
|
|
104
|
-
if filters[:start_date].present?
|
105
|
-
scope = scope.where('created_at > ?', Time.zone.parse(filters[:start_date]).beginning_of_day)
|
106
|
-
end
|
107
|
-
|
108
|
-
if filters[:end_date].present?
|
109
|
-
scope = scope.where('created_at < ?', Time.zone.parse(filters[:end_date]).end_of_day)
|
110
|
-
end
|
111
|
-
|
112
89
|
attributes[:user_id].present? ? scope.where(user_id: attributes[:user_id]) : scope
|
113
90
|
end
|
114
91
|
|
@@ -47,14 +47,7 @@ module EffectiveCartsHelper
|
|
47
47
|
def link_to_add_to_cart(purchasable, opts = {})
|
48
48
|
raise 'expecting an acts_as_purchasable object' unless purchasable.kind_of?(ActsAsPurchasable)
|
49
49
|
|
50
|
-
options = {
|
51
|
-
label: 'Add to Cart',
|
52
|
-
class: 'btn btn-primary',
|
53
|
-
rel: :nofollow,
|
54
|
-
data: {
|
55
|
-
disable_with: 'Adding...'
|
56
|
-
}
|
57
|
-
}.merge(opts)
|
50
|
+
options = { label: 'Add to Cart', class: 'btn btn-primary', rel: :nofollow }.merge(opts)
|
58
51
|
|
59
52
|
label = options.delete(:label)
|
60
53
|
options[:class] = ((options[:class] || '') + ' btn-add-to-cart')
|
@@ -69,10 +62,7 @@ module EffectiveCartsHelper
|
|
69
62
|
label: 'Remove',
|
70
63
|
class: 'btn btn-primary',
|
71
64
|
rel: :nofollow,
|
72
|
-
data: {
|
73
|
-
confirm: 'Are you sure? This cannot be undone!',
|
74
|
-
disable_with: 'Removing...'
|
75
|
-
},
|
65
|
+
data: { confirm: 'Are you sure? This cannot be undone!' },
|
76
66
|
method: :delete
|
77
67
|
}.merge(opts)
|
78
68
|
|
@@ -87,10 +77,7 @@ module EffectiveCartsHelper
|
|
87
77
|
label: 'Empty Cart',
|
88
78
|
class: 'btn btn-danger',
|
89
79
|
rel: :nofollow,
|
90
|
-
data: {
|
91
|
-
confirm: 'This will clear your entire cart. Are you sure?',
|
92
|
-
disable_with: 'Emptying...'
|
93
|
-
},
|
80
|
+
data: { confirm: 'This will clear your entire cart. Are you sure?' },
|
94
81
|
method: :delete
|
95
82
|
}.merge(opts)
|
96
83
|
|
@@ -101,14 +88,7 @@ module EffectiveCartsHelper
|
|
101
88
|
end
|
102
89
|
|
103
90
|
def link_to_checkout(opts = {})
|
104
|
-
options = {
|
105
|
-
label: 'Checkout',
|
106
|
-
class: 'btn btn-primary',
|
107
|
-
rel: :nofollow,
|
108
|
-
data: {
|
109
|
-
disable_with: 'Continuing...'
|
110
|
-
},
|
111
|
-
}.merge(opts)
|
91
|
+
options = { label: 'Checkout', class: 'btn btn-primary', rel: :nofollow }.merge(opts)
|
112
92
|
|
113
93
|
order = options.delete(:order)
|
114
94
|
label = options.delete(:label)
|
@@ -127,7 +107,7 @@ module EffectiveCartsHelper
|
|
127
107
|
end
|
128
108
|
|
129
109
|
def render_purchasables(*purchasables)
|
130
|
-
render(partial: 'effective/orders/order_items', locals: { order: Effective::Order.new(
|
110
|
+
render(partial: 'effective/orders/order_items', locals: { order: Effective::Order.new(purchasables) })
|
131
111
|
end
|
132
112
|
|
133
113
|
end
|
@@ -36,22 +36,22 @@ module EffectiveOrdersHelper
|
|
36
36
|
return 'Checkout' if (EffectiveOrders.single_payment_processor? && ![:pretend, :mark_as_paid, :free, :refund].include?(processor))
|
37
37
|
|
38
38
|
case processor
|
39
|
-
when :
|
40
|
-
'
|
39
|
+
when :cheque
|
40
|
+
'Pay by cheque'
|
41
41
|
when :free
|
42
42
|
'Checkout free'
|
43
|
-
when :
|
44
|
-
'
|
45
|
-
when :moneris
|
43
|
+
when :mark_as_paid
|
44
|
+
'Mark as paid'
|
45
|
+
when :moneris
|
46
46
|
'Checkout with credit card'
|
47
47
|
when :paypal
|
48
48
|
'Checkout with PayPal'
|
49
49
|
when :pretend
|
50
|
-
EffectiveOrders.
|
51
|
-
when :
|
52
|
-
'
|
53
|
-
when :
|
54
|
-
|
50
|
+
EffectiveOrders.pretend_purchase_in_production_enabled ? 'Purchase Order' : 'Purchase Order (development only)'
|
51
|
+
when :refund
|
52
|
+
'Complete refund'
|
53
|
+
when :stripe
|
54
|
+
'Checkout with credit card'
|
55
55
|
else
|
56
56
|
'Checkout'
|
57
57
|
end
|
@@ -63,25 +63,8 @@ module EffectiveOrdersHelper
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def order_payment_to_html(order)
|
66
|
-
payment = order.payment
|
67
|
-
|
68
|
-
if order.purchased?(:stripe_connect) && order.payment.kind_of?(Hash)
|
69
|
-
payment = Hash[
|
70
|
-
order.payment.map do |seller_id, v|
|
71
|
-
if (user = Effective::Customer.find(seller_id).try(:user))
|
72
|
-
[link_to(user, admin_user_path(user)), order.payment[seller_id]]
|
73
|
-
else
|
74
|
-
[seller_id, order.payment[seller_id]]
|
75
|
-
end
|
76
|
-
end
|
77
|
-
]
|
78
|
-
end
|
79
|
-
|
80
66
|
content_tag(:pre) do
|
81
|
-
raw JSON.pretty_generate(payment).html_safe
|
82
|
-
.gsub('\"', '')
|
83
|
-
.gsub("[\n\n ]", '[]')
|
84
|
-
.gsub("{\n }", '{}')
|
67
|
+
raw JSON.pretty_generate(order.payment).html_safe.gsub('\"', '').gsub("[\n\n ]", '[]').gsub("{\n }", '{}')
|
85
68
|
end
|
86
69
|
end
|
87
70
|
|
@@ -89,28 +72,28 @@ module EffectiveOrdersHelper
|
|
89
72
|
render(partial: 'effective/orders/order', locals: { order: order })
|
90
73
|
end
|
91
74
|
|
92
|
-
def
|
75
|
+
def render_checkout(order, namespace: nil, purchased_url: nil, declined_url: nil)
|
93
76
|
raise 'unable to checkout an order without a user' unless order && order.user
|
94
77
|
|
95
78
|
locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, namespace: namespace }
|
96
79
|
|
97
|
-
|
80
|
+
if order.purchased?
|
81
|
+
render(partial: 'effective/orders/order', locals: locals)
|
82
|
+
elsif order.confirmed? && order.errors.blank?
|
83
|
+
render(partial: 'effective/orders/checkout_step2', locals: locals)
|
84
|
+
else
|
85
|
+
render(partial: 'effective/orders/checkout_step1', locals: locals)
|
86
|
+
end
|
98
87
|
end
|
99
|
-
alias_method :render_checkout, :render_checkout_step1
|
100
|
-
|
101
|
-
def render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil)
|
102
|
-
raise 'unable to checkout an order without a user' unless order && order.user
|
103
|
-
|
104
|
-
purchased_url ||= session["effective_orders_#{order.id}_purchased_url"]
|
105
|
-
declined_url ||= session["effective_orders_#{order.id}_declined_url"]
|
106
88
|
|
89
|
+
def render_checkout_step1(order, namespace: nil, purchased_url: nil, declined_url: nil)
|
107
90
|
locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, namespace: namespace }
|
91
|
+
render(partial: 'effective/orders/checkout_step1', locals: locals)
|
92
|
+
end
|
108
93
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
render(partial: 'effective/orders/checkout_step2', locals: locals)
|
113
|
-
end
|
94
|
+
def render_checkout_step2(order, namespace: nil, purchased_url: nil, declined_url: nil)
|
95
|
+
locals = { order: order, purchased_url: purchased_url, declined_url: declined_url, namespace: namespace }
|
96
|
+
render(partial: 'effective/orders/checkout_step2', locals: locals)
|
114
97
|
end
|
115
98
|
|
116
99
|
def checkout_step1_form_url(order, namespace = nil)
|
@@ -124,21 +107,6 @@ module EffectiveOrdersHelper
|
|
124
107
|
end
|
125
108
|
end
|
126
109
|
|
127
|
-
def link_to_my_purchases(opts = {})
|
128
|
-
options = {
|
129
|
-
label: 'My Purchases',
|
130
|
-
class: 'btn btn-default',
|
131
|
-
rel: :nofollow
|
132
|
-
}.merge(opts)
|
133
|
-
|
134
|
-
label = options.delete(:label)
|
135
|
-
options[:class] = ((options[:class] || '') + ' btn-my-purchases')
|
136
|
-
|
137
|
-
link_to(label, effective_orders.my_purchases_orders_path, options)
|
138
|
-
end
|
139
|
-
alias_method :link_to_order_history, :link_to_my_purchases
|
140
|
-
|
141
|
-
|
142
110
|
def render_orders(obj, opts = {})
|
143
111
|
orders = Array(obj.kind_of?(User) ? Effective::Order.purchased_by(obj) : obj)
|
144
112
|
|
@@ -149,10 +117,6 @@ module EffectiveOrdersHelper
|
|
149
117
|
render(partial: 'effective/orders/orders_table', locals: { orders: orders }.merge(opts))
|
150
118
|
end
|
151
119
|
|
152
|
-
alias_method :render_purchases, :render_orders
|
153
|
-
alias_method :render_my_purchases, :render_orders
|
154
|
-
alias_method :render_order_history, :render_orders
|
155
|
-
|
156
120
|
def payment_card_label(card)
|
157
121
|
card = card.to_s.downcase.gsub(' ', '').strip
|
158
122
|
|
@@ -172,4 +136,8 @@ module EffectiveOrdersHelper
|
|
172
136
|
end
|
173
137
|
end
|
174
138
|
|
139
|
+
def checkout_icon_to(path, options = {})
|
140
|
+
icon_to('shopping-cart', path, { title: 'Checkout' }.merge(options))
|
141
|
+
end
|
142
|
+
|
175
143
|
end
|