effective_orders 3.0.4 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/effective/providers/moneris.rb +23 -17
- data/app/models/effective/order.rb +10 -1
- data/app/models/effective/providers/moneris_charge.rb +114 -0
- data/app/views/effective/orders/_checkout_step2.html.haml +12 -11
- data/app/views/effective/orders/_order_actions.html.haml +1 -1
- data/app/views/effective/orders/moneris/_form.html.haml +4 -43
- data/lib/effective_orders/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8a648d7e8218c51c4733d02e64c542fcebf91d04d5bb78c457a1fa835e2b319
|
4
|
+
data.tar.gz: f062fbd9fd8973ea30c1c62e470a327d6d4cac533606a65cfbe43fbc19fd7418
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 317b8781f567e20c92ed714b7f7aa823b4de332722fb7d054eaa4134888f95495b5ac138e4677ae746a0566a522e9f346279f53b950bb129c5dd188fe3c3cd50
|
7
|
+
data.tar.gz: 931166730fdbed8d51a34fc3bea22b8d791644050a2673ba74093c7f158b7a187b7de8b5580f94d0b23448d2e9427bf1feda17c89bd5ca83cd65d4caca9a16a3
|
@@ -17,33 +17,39 @@ 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
|
-
order_purchased(details: params, provider: 'moneris', card: params[:card], purchased_url: purchased_url)
|
21
|
-
return
|
20
|
+
return order_purchased(details: params, provider: 'moneris', card: params[:card], purchased_url: purchased_url)
|
22
21
|
end
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
# Invalid Result
|
24
|
+
if params[:result].to_s != '1' || params[:transactionKey].blank?
|
25
|
+
return order_declined(details: params, provider: 'moneris', card: params[:card], declined_url: declined_url)
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
+
payment = params.merge(verify_moneris_transaction(params[:transactionKey]))
|
29
|
+
valid = (1..49).include?(payment[:response_code].to_i) # Must be > 0 and < 50 to be valid. Sometimes we get the string 'null'
|
28
30
|
|
29
|
-
|
30
|
-
|
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)
|
31
|
+
if valid == false
|
32
|
+
return order_declined(details: payment, provider: 'moneris', card: params[:card], declined_url: declined_url)
|
36
33
|
end
|
34
|
+
|
35
|
+
order_purchased(details: payment, provider: 'moneris', card: params[:card], purchased_url: purchased_url)
|
37
36
|
end
|
38
37
|
|
39
38
|
private
|
40
39
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
40
|
+
def verify_moneris_transaction(transactionKey)
|
41
|
+
# Send a verification POST request
|
42
|
+
uri = URI.parse(EffectiveOrders.moneris[:verify_url])
|
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
|
44
50
|
|
45
|
-
|
46
|
-
|
51
|
+
# Parse response into a Hash
|
52
|
+
body.split('<br>').inject({}) { |h, i| h[i.split(' ').first.to_sym] = i.split(' ').last; h }
|
47
53
|
end
|
48
54
|
|
49
55
|
end
|
@@ -310,7 +310,16 @@ module Effective
|
|
310
310
|
self.purchase_state = EffectiveOrders::PURCHASED
|
311
311
|
self.purchased_at ||= Time.zone.now
|
312
312
|
|
313
|
-
self.payment =
|
313
|
+
self.payment = (
|
314
|
+
if details.kind_of?(Hash)
|
315
|
+
details
|
316
|
+
elsif details.respond_to?(:to_unsafe_h)
|
317
|
+
details.to_unsafe_h
|
318
|
+
else
|
319
|
+
{ details: details.to_s }
|
320
|
+
end
|
321
|
+
)
|
322
|
+
|
314
323
|
self.payment_provider = provider.to_s
|
315
324
|
self.payment_card = card.to_s.presence || 'none'
|
316
325
|
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Effective
|
4
|
+
module Providers
|
5
|
+
class MonerisCharge
|
6
|
+
attr_accessor :order, :purchased_url, :declined_url
|
7
|
+
attr_accessor :hpp_id, :ticket # return values
|
8
|
+
|
9
|
+
def initialize(order:, purchased_url: nil, declined_url: nil)
|
10
|
+
@order = order
|
11
|
+
@purchased_url = purchased_url
|
12
|
+
@declined_url = declined_url
|
13
|
+
|
14
|
+
moneris_preload!
|
15
|
+
end
|
16
|
+
|
17
|
+
def present?
|
18
|
+
ticket.present? && hpp_id.present?
|
19
|
+
end
|
20
|
+
|
21
|
+
def moneris_preload!
|
22
|
+
# Make the moneris preload request
|
23
|
+
uri = URI.parse(EffectiveOrders.moneris[:hpp_url])
|
24
|
+
params = moneris_preload_payload.to_query
|
25
|
+
headers = {}
|
26
|
+
|
27
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
28
|
+
http.use_ssl = true
|
29
|
+
|
30
|
+
body = http.post(uri.path, params, headers).body
|
31
|
+
doc = ::Nokogiri::XML(body)
|
32
|
+
|
33
|
+
# Parse preload request
|
34
|
+
moneris = [:hpp_id, :ticket, :order_id, :response_code].inject({}) do |h, key|
|
35
|
+
h[key] = doc.xpath("//#{key}").children.first.to_s; h
|
36
|
+
end
|
37
|
+
|
38
|
+
# Transaction Response Code: < 50: data successfully loaded, >= 50: data not loaded
|
39
|
+
moneris[:response_code] = (moneris[:response_code].to_i rescue 50)
|
40
|
+
|
41
|
+
raise 'data not loaded' unless moneris[:response_code] < 50
|
42
|
+
|
43
|
+
# Our return value
|
44
|
+
@hpp_id = moneris[:hpp_id]
|
45
|
+
@ticket = moneris[:ticket]
|
46
|
+
end
|
47
|
+
|
48
|
+
def moneris_preload_payload
|
49
|
+
payload = {
|
50
|
+
ps_store_id: EffectiveOrders.moneris[:ps_store_id],
|
51
|
+
hpp_key: EffectiveOrders.moneris[:hpp_key],
|
52
|
+
hpp_preload: '',
|
53
|
+
charge_total: ('%.2f' % (order.total / 100.0)),
|
54
|
+
|
55
|
+
# Optional
|
56
|
+
order_id: order_id,
|
57
|
+
lang: 'en-ca',
|
58
|
+
email: order.user.email,
|
59
|
+
|
60
|
+
rvar_purchased_url: purchased_url,
|
61
|
+
rvar_declined_url: declined_url
|
62
|
+
}.compact
|
63
|
+
|
64
|
+
if order.tax.present?
|
65
|
+
payload[:gst] = ('%.2f' % (order.tax / 100.0))
|
66
|
+
end
|
67
|
+
|
68
|
+
if order.billing_name.present?
|
69
|
+
payload[:bill_first_name] = order.billing_name.split(' ')[0]
|
70
|
+
payload[:bill_last_name] = order.billing_name.split(' ')[1..-1].join(' ')
|
71
|
+
end
|
72
|
+
|
73
|
+
if order.billing_address.present?
|
74
|
+
address = order.billing_address
|
75
|
+
payload[:bill_address_one] = address.address1
|
76
|
+
payload[:bill_city] = address.city
|
77
|
+
payload[:bill_state_or_province] = address.state
|
78
|
+
payload[:bill_postal_code] = address.postal_code
|
79
|
+
payload[:bill_country] = address.country
|
80
|
+
end
|
81
|
+
|
82
|
+
if order.shipping_address.present?
|
83
|
+
address = order.shipping_address
|
84
|
+
payload[:ship_address_one] = address.address1
|
85
|
+
payload[:ship_city] = address.city
|
86
|
+
payload[:ship_state_or_province] = address.state
|
87
|
+
payload[:ship_postal_code] = address.postal_code
|
88
|
+
payload[:ship_country] = address.country
|
89
|
+
end
|
90
|
+
|
91
|
+
order.order_items.each_with_index do |item, index|
|
92
|
+
payload["id#{index}"] = index
|
93
|
+
payload["description#{index}"] = item.title
|
94
|
+
payload["quantity#{index}"] = item.quantity
|
95
|
+
payload["price#{index}"] = ('%.2f' % (item.price / 100.0))
|
96
|
+
payload["subtotal#{index}"] = ('%.2f' % (item.subtotal / 100.0))
|
97
|
+
end
|
98
|
+
|
99
|
+
payload
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def order_id
|
105
|
+
[
|
106
|
+
order.to_param,
|
107
|
+
(order.billing_name.to_s.parameterize.presence if EffectiveOrders.moneris[:include_billing_name_in_order_id])
|
108
|
+
].compact.join('-')
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
@@ -1,36 +1,37 @@
|
|
1
1
|
= render partial: 'effective/orders/order', locals: { order: order }
|
2
|
+
- form_locals = { order: order, purchased_url: purchased_url, declined_url: declined_url }
|
2
3
|
|
3
4
|
.effective-order.effective-order-purchase-actions
|
4
5
|
- if EffectiveOrders.allow_free_orders && order.free?
|
5
|
-
= render partial: '/effective/orders/free/form', locals:
|
6
|
+
= render partial: '/effective/orders/free/form', locals: form_locals
|
6
7
|
|
7
8
|
- elsif EffectiveOrders.allow_refunds && order.refund?
|
8
9
|
-# Nothing
|
9
10
|
|
10
11
|
- else
|
11
12
|
- if EffectiveOrders.allow_pretend_purchase_in_development && !Rails.env.production?
|
12
|
-
= render partial: '/effective/orders/pretend/form', locals:
|
13
|
+
= render partial: '/effective/orders/pretend/form', locals: form_locals
|
13
14
|
|
14
15
|
- if EffectiveOrders.allow_pretend_purchase_in_production && Rails.env.production?
|
15
|
-
= render partial: '/effective/orders/pretend/form', locals:
|
16
|
+
= render partial: '/effective/orders/pretend/form', locals: form_locals
|
16
17
|
|
17
18
|
- if EffectiveOrders.moneris_enabled
|
18
|
-
= render partial: '/effective/orders/moneris/form', locals:
|
19
|
+
= render partial: '/effective/orders/moneris/form', locals: form_locals
|
19
20
|
|
20
21
|
- if EffectiveOrders.paypal_enabled
|
21
|
-
= render partial: '/effective/orders/paypal/form', locals:
|
22
|
+
= render partial: '/effective/orders/paypal/form', locals: form_locals
|
22
23
|
|
23
24
|
- if EffectiveOrders.stripe_enabled
|
24
|
-
= render partial: '/effective/orders/stripe/form', locals:
|
25
|
+
= render partial: '/effective/orders/stripe/form', locals: form_locals
|
25
26
|
|
26
27
|
- if EffectiveOrders.ccbill_enabled
|
27
|
-
= render partial: '/effective/orders/ccbill/form', locals:
|
28
|
+
= render partial: '/effective/orders/ccbill/form', locals: form_locals
|
28
29
|
|
29
30
|
- if EffectiveOrders.app_checkout_enabled && EffectiveOrders.authorized?(controller, :app_checkout, order)
|
30
|
-
= render partial: '/effective/orders/app_checkout/form', locals:
|
31
|
+
= render partial: '/effective/orders/app_checkout/form', locals: form_locals
|
31
32
|
|
32
33
|
- if EffectiveOrders.cheque_enabled && order.user == current_user
|
33
|
-
= render partial: '/effective/orders/cheque/form', locals:
|
34
|
+
= render partial: '/effective/orders/cheque/form', locals: form_locals
|
34
35
|
|
35
36
|
- if EffectiveOrders.allow_pretend_purchase_in_production && Rails.env.production? && EffectiveOrders.allow_pretend_purchase_in_production_message.present?
|
36
37
|
%br
|
@@ -39,8 +40,8 @@
|
|
39
40
|
- if EffectiveOrders.authorized?(controller, :admin, :effective_orders) && order.user != current_user
|
40
41
|
- if EffectiveOrders.allow_refunds && order.refund?
|
41
42
|
.effective-order.effective-order-admin-purchase-actions
|
42
|
-
= render partial: '/effective/orders/refund/form', locals:
|
43
|
+
= render partial: '/effective/orders/refund/form', locals: form_locals
|
43
44
|
- elsif EffectiveOrders.mark_as_paid_enabled
|
44
45
|
.effective-order.effective-order-admin-purchase-actions
|
45
|
-
= render partial: '/effective/orders/mark_as_paid/form', locals:
|
46
|
+
= render partial: '/effective/orders/mark_as_paid/form', locals: form_locals
|
46
47
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
- if order.purchased?
|
5
5
|
= link_to 'Resend Receipt', effective_orders.send_buyer_receipt_order_path(order), class: 'btn btn-default', data: { confirm: 'This action will email the buyer a copy of the original email receipt. Send receipt now?', disable_with: 'Resending...' }
|
6
6
|
|
7
|
-
- elsif EffectiveOrders.authorized?(controller, :admin, :effective_orders)
|
7
|
+
- elsif EffectiveOrders.authorized?(controller, :admin, :effective_orders) && order.user != current_user
|
8
8
|
- if order.pending?
|
9
9
|
= link_to 'Admin: Send Payment Request', effective_orders.send_payment_request_admin_order_path(order), class: 'btn btn-default', data: { method: :post, confirm: 'This action will email buyer a payment request. Send it now?', disable_with: 'Sending...' }
|
10
10
|
= link_to 'Admin: Delete', effective_orders.admin_order_path(order), class: 'btn btn-default', data: { method: :delete, confirm: 'Are you sure you want to delete? This cannot be undone.', disable_with: 'Deleting...' }
|
@@ -1,47 +1,8 @@
|
|
1
1
|
= form_tag(EffectiveOrders.moneris[:hpp_url], method: :post) do
|
2
|
-
=
|
3
|
-
= hidden_field_tag(:hpp_key, EffectiveOrders.moneris[:hpp_key])
|
4
|
-
= hidden_field_tag(:lang, 'en-ca')
|
5
|
-
= hidden_field_tag(:rvar_authenticity_token, form_authenticity_token)
|
2
|
+
- moneris = Effective::Providers::MonerisCharge.new(order: order, purchased_url: purchased_url, declined_url: declined_url)
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
- if declined_url.present?
|
11
|
-
= hidden_field_tag(:rvar_declined_url, declined_url)
|
12
|
-
|
13
|
-
= hidden_field_tag(:email, order.user.try(:email))
|
14
|
-
= hidden_field_tag(:cust_id, order.user.to_param)
|
15
|
-
|
16
|
-
= hidden_field_tag(:order_id, [order.to_param, order.billing_name.try(:parameterize).presence, Time.zone.now.to_i].compact.join('-'))
|
17
|
-
= hidden_field_tag(:gst, '%.2f' % (order.tax / 100.0))
|
18
|
-
= hidden_field_tag(:charge_total, '%.2f' % (order.total / 100.0))
|
19
|
-
|
20
|
-
- order.order_items.each_with_index do |item, x|
|
21
|
-
= hidden_field_tag("id#{x}", x)
|
22
|
-
= hidden_field_tag("description#{x}", item.title)
|
23
|
-
= hidden_field_tag("quantity#{x}", item.quantity)
|
24
|
-
= hidden_field_tag("price#{x}", '%.2f' % (item.price / 100.0))
|
25
|
-
= hidden_field_tag("subtotal#{x}", '%.2f' % (item.subtotal / 100.0))
|
26
|
-
|
27
|
-
- if order.billing_address.present?
|
28
|
-
- address = order.billing_address
|
29
|
-
= hidden_field_tag(:bill_first_name, address.first_name || order.try(:user).try(:first_name))
|
30
|
-
= hidden_field_tag(:bill_last_name, address.last_name || order.try(:user).try(:last_name))
|
31
|
-
= hidden_field_tag(:bill_address_one, address.address1)
|
32
|
-
= hidden_field_tag(:bill_city, address.city)
|
33
|
-
= hidden_field_tag(:bill_state_or_province, address.state)
|
34
|
-
= hidden_field_tag(:bill_postal_code, address.postal_code)
|
35
|
-
= hidden_field_tag(:bill_country, address.country)
|
36
|
-
|
37
|
-
- if order.shipping_address.present?
|
38
|
-
- address = order.shipping_address
|
39
|
-
= hidden_field_tag(:ship_first_name, address.first_name || order.try(:user).try(:first_name))
|
40
|
-
= hidden_field_tag(:ship_last_name, address.last_name || order.try(:user).try(:last_name))
|
41
|
-
= hidden_field_tag(:ship_address_one, address.address1)
|
42
|
-
= hidden_field_tag(:ship_city, address.city)
|
43
|
-
= hidden_field_tag(:ship_state_or_province, address.state)
|
44
|
-
= hidden_field_tag(:ship_postal_code, address.postal_code)
|
45
|
-
= hidden_field_tag(:ship_country, address.country)
|
4
|
+
= hidden_field_tag :hpp_preload, ''
|
5
|
+
= hidden_field_tag :hpp_id, moneris.hpp_id
|
6
|
+
= hidden_field_tag :ticket, moneris.ticket
|
46
7
|
|
47
8
|
= submit_tag order_checkout_label(:moneris), class: 'btn btn-primary', data: { disable_with: 'Continuing...' }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_orders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- app/models/effective/order_item.rb
|
168
168
|
- app/models/effective/product.rb
|
169
169
|
- app/models/effective/providers/ccbill_postback.rb
|
170
|
+
- app/models/effective/providers/moneris_charge.rb
|
170
171
|
- app/models/effective/providers/stripe_charge.rb
|
171
172
|
- app/models/effective/subscripter.rb
|
172
173
|
- app/models/effective/subscription.rb
|