effective_orders 5.7.4 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccd5fb4a32b778af10466e4b8eab1fd40de1c9c7bf6033960ae1b72ea8254ea8
4
- data.tar.gz: c32de9af51826855c96fc33364be02fb0c7efbeee78206de5268dd1636f388fe
3
+ metadata.gz: 7ef5017c01d659fbcc95d0f7b69568175c7bbe76540b2d57ec6f0ea6ac87d44d
4
+ data.tar.gz: 570d1894364ff47516f213d9fa29b139597c8f702de4da8277857eac9fe8140a
5
5
  SHA512:
6
- metadata.gz: e191aad0d3e26a3f0f1f221c196e3351c269cd3f7dc19d21f77b45de3a8b52f65a6f5428099d376f59d9463d03720828c0634b1c3bea40aed482cc99e983e3c3
7
- data.tar.gz: d97326c36979460db32c854ee210fdec62eb1ff21a2e344163040f66dff1cc163241ac344af41e4e58dae2a3e203aeaa77e244e755cd6e3c63df4fee8fdf277e
6
+ metadata.gz: 66297faebffcc406116d3bb394a5572e5127796bd34bbaabb7832785061280bd0e6fd4e06b3509013ab98f6c3a88a47c36eec27e12f20b6859970d5f7dc18a55
7
+ data.tar.gz: 92dc17259f946aa1ff2d49521e40ab2db17f0d6888f52ff6d7567ded95f6d022532f13959b408bbe9ccfb905066fe05adcee2919e2063684da43ce3fe2965233
@@ -4,6 +4,7 @@ module Effective
4
4
  include Concerns::Purchase
5
5
 
6
6
  include Providers::Cheque
7
+ include Providers::Etransfer
7
8
  include Providers::Free
8
9
  include Providers::MarkAsPaid
9
10
  include Providers::Moneris
@@ -0,0 +1,24 @@
1
+ module Effective
2
+ module Providers
3
+ module Etransfer
4
+ extend ActiveSupport::Concern
5
+
6
+ def etransfer
7
+ raise('etransfer provider is not available') unless EffectiveOrders.etransfer?
8
+
9
+ @order ||= Order.find(params[:id])
10
+
11
+ EffectiveResources.authorize!(self, :update, @order)
12
+
13
+ flash[:success] = EffectiveOrders.etransfer[:success]
14
+
15
+ order_deferred(provider: 'etransfer', deferred_url: etransfer_params[:deferred_url])
16
+ end
17
+
18
+ def etransfer_params
19
+ params.require(:etransfer).permit(:deferred_url)
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -38,7 +38,8 @@ module Effective
38
38
 
39
39
  def validate_stripe_payment(payment_intent_id)
40
40
  begin
41
- intent = ::Stripe::PaymentIntent.retrieve(payment_intent_id)
41
+ intent = EffectiveOrders.with_stripe { ::Stripe::PaymentIntent.retrieve(payment_intent_id) }
42
+
42
43
  raise('status is not succeeded') unless intent.status == 'succeeded'
43
44
  raise('charges are not present') unless intent.charges.present?
44
45
 
@@ -16,7 +16,8 @@ module Effective
16
16
  after_action :run_subscribable_buyer_callbacks!
17
17
 
18
18
  def stripe
19
- @event = (Stripe::Webhook.construct_event(request.body.read, request.env['HTTP_STRIPE_SIGNATURE'], EffectiveOrders.subscriptions[:webhook_secret]) rescue nil)
19
+ @event = EffectiveOrders.with_stripe { ::Stripe::Webhook.construct_event(request.body.read, request.env['HTTP_STRIPE_SIGNATURE'], EffectiveOrders.subscriptions[:webhook_secret]) rescue nil }
20
+
20
21
  (head(:ok) and return) if request.get? && @event.blank?
21
22
  (head(:bad_request) and return) unless @event
22
23
 
@@ -63,6 +63,8 @@ class Admin::EffectiveOrdersDatatable < Effective::Datatable
63
63
  collection.where(id: Effective::OrderItem.where('name ILIKE ?', "%#{term}%").select('order_id'))
64
64
  end
65
65
 
66
+ col :payment_method
67
+
66
68
  col :subtotal, as: :price, visible: false
67
69
  col :tax, as: :price, visible: false
68
70
 
@@ -36,6 +36,8 @@ module EffectiveOrdersHelper
36
36
  case processor
37
37
  when :cheque
38
38
  'Pay by Cheque'
39
+ when :etransfer
40
+ 'Pay by E-transfer'
39
41
  when :free
40
42
  'Checkout Free'
41
43
  when :mark_as_paid
@@ -75,11 +75,11 @@ module EffectiveStripeHelper
75
75
 
76
76
  intent = begin
77
77
  Rails.logger.info "[STRIPE] create payment intent : #{payment}"
78
- Stripe::PaymentIntent.create(payment)
78
+ EffectiveOrders.with_stripe { ::Stripe::PaymentIntent.create(payment) }
79
79
  rescue Stripe::CardError => e
80
80
  token_required = true
81
81
  Rails.logger.info "[STRIPE] (error) get payment intent : #{e.error.payment_intent.id}"
82
- Stripe::PaymentIntent.retrieve(e.error.payment_intent.id)
82
+ EffectiveOrders.with_stripe { ::Stripe::PaymentIntent.retrieve(e.error.payment_intent.id) }
83
83
  end
84
84
 
85
85
  payload = {
@@ -39,7 +39,7 @@ module Effective
39
39
 
40
40
  Rails.logger.info "[STRIPE] create customer: #{user.email}"
41
41
 
42
- self.stripe_customer = Stripe::Customer.create(email: user.email, description: user.to_s, metadata: { user_id: user.id })
42
+ self.stripe_customer = EffectiveOrders.with_stripe { ::Stripe::Customer.create(email: user.email, description: user.to_s, metadata: { user_id: user.id }) }
43
43
  self.stripe_customer_id = stripe_customer.id
44
44
 
45
45
  save!
@@ -48,21 +48,21 @@ module Effective
48
48
  def stripe_customer
49
49
  @stripe_customer ||= if stripe_customer_id.present?
50
50
  Rails.logger.info "[STRIPE] get customer: #{stripe_customer_id}"
51
- ::Stripe::Customer.retrieve(stripe_customer_id)
51
+ EffectiveOrders.with_stripe { ::Stripe::Customer.retrieve(stripe_customer_id) }
52
52
  end
53
53
  end
54
54
 
55
55
  def invoices
56
56
  @invoices ||= if stripe_customer_id.present?
57
57
  Rails.logger.info "[STRIPE] list invoices: #{stripe_customer_id}"
58
- ::Stripe::Invoice.list(customer: stripe_customer_id) rescue nil
58
+ EffectiveOrders.with_stripe { ::Stripe::Invoice.list(customer: stripe_customer_id) rescue nil }
59
59
  end
60
60
  end
61
61
 
62
62
  def upcoming_invoice
63
63
  @upcoming_invoice ||= if stripe_customer_id.present?
64
64
  Rails.logger.info "[STRIPE] get upcoming invoice: #{stripe_customer_id}"
65
- ::Stripe::Invoice.upcoming(customer: stripe_customer_id) rescue nil
65
+ EffectiveOrders.with_stripe { ::Stripe::Invoice.upcoming(customer: stripe_customer_id) rescue nil }
66
66
  end
67
67
  end
68
68
 
@@ -89,5 +89,6 @@ module Effective
89
89
  'Please update or confirm your card details to continue.'
90
90
  end.html_safe
91
91
  end
92
+
92
93
  end
93
94
  end
@@ -326,7 +326,7 @@ module Effective
326
326
  def payment_method
327
327
  return nil unless purchased?
328
328
 
329
- provider = payment_provider if ['cheque', 'phone'].include?(payment_provider)
329
+ provider = payment_provider if ['cheque', 'etransfer', 'phone'].include?(payment_provider)
330
330
 
331
331
  # Normalize payment card
332
332
  card = case payment_card.to_s.downcase.gsub(' ', '').strip
@@ -0,0 +1,4 @@
1
+ = effective_form_with(scope: :etransfer, url: effective_orders.etransfer_order_path(order), method: :post) do |f|
2
+ = f.hidden_field :deferred_url, value: deferred_url
3
+
4
+ = f.submit order_checkout_label(:etransfer), center: true, border: false, 'data-confirm': EffectiveOrders.etransfer[:confirm]
@@ -10,14 +10,13 @@
10
10
  = f.select :payment_provider, EffectiveOrders.admin_payment_providers, required: true
11
11
 
12
12
  = f.text_field :payment_card,
13
- label: 'Payment card type, cheque or transaction number',
13
+ label: 'Payment card type, cheque, e-transfer or transaction number',
14
14
  hint: 'Do not enter credit card numbers here, or anywhere.'
15
15
 
16
16
  = f.check_box :send_mark_as_paid_email_to_buyer,
17
17
  label: 'Yes, send a receipt email to the buyer.',
18
18
  input_html: { checked: (f.object.send_mark_as_paid_email_to_buyer.nil? ? EffectiveOrders.send_order_receipts_when_mark_as_paid : f.object.send_mark_as_paid_email_to_buyer?) }
19
19
 
20
-
21
20
  .row
22
21
  .col
23
22
  = f.text_area :note_to_buyer, hint: 'This message will be displayed to the buyer on the receipt.'
@@ -6,8 +6,8 @@
6
6
 
7
7
  %p #{link_to('Click here', effective_orders.order_url(@order))} to review your order and pay online with a credit card.
8
8
 
9
- - if EffectiveOrders.cheque?
10
- %p We also accept cheques via the mail, and we will manually mark your order paid upon receiving it.
9
+ - if EffectiveOrders.deferred_providers.present?
10
+ - providers = EffectiveOrders.deferred_providers.to_sentence()
11
+ %p We also accept #{providers}. We will mark your order paid upon receiving it.
11
12
 
12
13
  = render(@order, no_order_actions: true)
13
-
@@ -6,8 +6,8 @@
6
6
 
7
7
  %p #{link_to('Click here', effective_orders.order_url(@order))} to review your order online.
8
8
 
9
- - if EffectiveOrders.cheque?
10
- %p When we receive your cheque in the mail we will mark your order paid.
9
+ - if EffectiveOrders.deferred_providers.present?
10
+ - providers = EffectiveOrders.deferred_providers.to_sentence(last_word_connector: ', or', two_words_connector: ' or ')
11
+ %p When we receive your #{providers} we will mark your order paid.
11
12
 
12
13
  = render(@order, no_order_actions: true)
13
-
@@ -61,6 +61,7 @@ EffectiveOrders.setup do |config|
61
61
  # Mark as Paid
62
62
  # Mark an order as paid without going through a processor
63
63
  # This is accessed via the admin screens only. Must have can?(:admin, :effective_orders)
64
+ # Should be true when using deferred payment providers
64
65
  config.mark_as_paid_enabled = false
65
66
 
66
67
  # Pretend Purchase
@@ -117,6 +118,15 @@ EffectiveOrders.setup do |config|
117
118
  # success: 'Thank you! You have indicated that this order will be purchased by cheque. Please send us a cheque and a copy of this invoice at your earliest convenience.'
118
119
  # }
119
120
 
121
+ # E-transfer
122
+ # This is an deferred payment
123
+ config.etransfer = false
124
+
125
+ # config.etransfer = {
126
+ # confirm: 'Proceed with pay by e-transfer?',
127
+ # success: 'Thank you! You have indicated that this order will be purchased by e-transfer. Please send us an e-transfer to "payments@example.com" with password "example" at your earliest convenience'
128
+ # }
129
+
120
130
  # Moneris
121
131
  config.moneris = false
122
132
 
data/config/routes.rb CHANGED
@@ -7,9 +7,10 @@ EffectiveOrders::Engine.routes.draw do
7
7
  get :declined
8
8
  post :send_buyer_receipt
9
9
 
10
+ post :cheque
11
+ post :etransfer
10
12
  post :free
11
13
  post :mark_as_paid
12
- post :cheque
13
14
  post :moneris_checkout
14
15
  post :phone
15
16
  post :pretend
@@ -33,7 +33,6 @@ module EffectiveOrders
33
33
  if EffectiveOrders.stripe?
34
34
  begin
35
35
  require 'stripe'
36
- ::Stripe.api_key = EffectiveOrders.stripe[:secret_key]
37
36
  rescue Exception
38
37
  raise "unable to load stripe. Plese add gem 'stripe' to your Gemfile and then 'bundle install'"
39
38
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '5.7.4'.freeze
2
+ VERSION = '5.8.0'.freeze
3
3
  end
@@ -7,7 +7,7 @@ module EffectiveOrders
7
7
  # Order states
8
8
  PENDING = 'pending' # New orders are created in a pending state
9
9
  CONFIRMED = 'confirmed' # Once the order has passed checkout step 1
10
- DEFERRED = 'deferred' # Deferred providers. Cheque or Phone was selected.
10
+ DEFERRED = 'deferred' # Deferred providers. cheque, etransfer or phone was selected.
11
11
  PURCHASED = 'purchased' # Purchased by provider
12
12
  DECLINED = 'declined' # Declined by provider
13
13
  ABANDONED = 'abandoned' # Not set by this gem. Can be set outside it.
@@ -53,7 +53,7 @@ module EffectiveOrders
53
53
  :free_enabled, :mark_as_paid_enabled, :pretend_enabled, :pretend_message,
54
54
 
55
55
  # Payment processors. false or Hash
56
- :cheque, :moneris, :moneris_checkout, :paypal, :phone, :refund, :stripe, :subscriptions, :trial
56
+ :cheque, :etransfer, :moneris, :moneris_checkout, :paypal, :phone, :refund, :stripe, :subscriptions, :trial
57
57
  ]
58
58
  end
59
59
 
@@ -72,6 +72,10 @@ module EffectiveOrders
72
72
  cheque.kind_of?(Hash)
73
73
  end
74
74
 
75
+ def self.etransfer?
76
+ etransfer.kind_of?(Hash)
77
+ end
78
+
75
79
  def self.free?
76
80
  free_enabled == true
77
81
  end
@@ -129,6 +133,7 @@ module EffectiveOrders
129
133
  [
130
134
  ('cheque' if cheque?),
131
135
  ('credit card' if mark_as_paid?),
136
+ ('etransfer' if etransfer?),
132
137
  ('free' if free?),
133
138
  ('moneris' if moneris?),
134
139
  ('moneris_checkout' if moneris_checkout?),
@@ -147,6 +152,7 @@ module EffectiveOrders
147
152
  [
148
153
  ('cheque' if mark_as_paid?),
149
154
  ('credit card' if mark_as_paid?),
155
+ ('etransfer' if etransfer?),
150
156
  #('free' if free?),
151
157
  ('moneris' if moneris?),
152
158
  ('moneris_checkout' if moneris_checkout?),
@@ -161,7 +167,7 @@ module EffectiveOrders
161
167
  end
162
168
 
163
169
  def self.deferred_providers
164
- [('cheque' if cheque?), ('phone' if phone?)].compact
170
+ [('cheque' if cheque?), ('etransfer' if etransfer?), ('phone' if phone?)].compact
165
171
  end
166
172
 
167
173
  def self.qb_sync?
@@ -184,6 +190,17 @@ module EffectiveOrders
184
190
  true
185
191
  end
186
192
 
193
+ def self.with_stripe(&block)
194
+ raise('expected stripe to be enabled') unless stripe?
195
+
196
+ begin
197
+ ::Stripe.api_key = stripe[:secret_key]
198
+ yield
199
+ ensure
200
+ ::Stripe.api_key = nil
201
+ end
202
+ end
203
+
187
204
  def self.stripe_plans
188
205
  return [] unless (stripe? && subscriptions?)
189
206
 
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: 5.7.4
4
+ version: 5.8.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: 2022-06-27 00:00:00.000000000 Z
11
+ date: 2022-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -193,6 +193,7 @@ files:
193
193
  - app/controllers/effective/customers_controller.rb
194
194
  - app/controllers/effective/orders_controller.rb
195
195
  - app/controllers/effective/providers/cheque.rb
196
+ - app/controllers/effective/providers/etransfer.rb
196
197
  - app/controllers/effective/providers/free.rb
197
198
  - app/controllers/effective/providers/mark_as_paid.rb
198
199
  - app/controllers/effective/providers/moneris.rb
@@ -271,6 +272,7 @@ files:
271
272
  - app/views/effective/orders/deferred.html.haml
272
273
  - app/views/effective/orders/deferred/_form.html.haml
273
274
  - app/views/effective/orders/edit.html.haml
275
+ - app/views/effective/orders/etransfer/_form.html.haml
274
276
  - app/views/effective/orders/free/_form.html.haml
275
277
  - app/views/effective/orders/index.html.haml
276
278
  - app/views/effective/orders/mark_as_paid/_form.html.haml