effective_orders 2.0.1 → 2.1.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
  SHA1:
3
- metadata.gz: 793c9df1822bf63be47d98586f545f026cd5ea7d
4
- data.tar.gz: 072df510e3963f95b7e49cda4709e0f65c8a586c
3
+ metadata.gz: 0859d05abbb767645eea00e2032ffbc509fd27b7
4
+ data.tar.gz: c8394d5d17df7acd343431f3f57b49437cb59c2b
5
5
  SHA512:
6
- metadata.gz: c264b1f08954da9f38b34b3c753d46a83b859876035d64263925614b79d1ccacb6fd88e05efdda6c26694d2994984e2f425d5c8c8a54cffc3526b15dac5943f2
7
- data.tar.gz: 0835197276efa3182745d988acae1ae5eac7539a74c348a9507bb534b28079f24ea3da41d6de28f299ad0ad9c7054753bc52167de8142d52bc2054e9af64e5e7
6
+ metadata.gz: 4521494be70f5ae7d3cc306094a1a05bc1e50a1d92fc59aa50ea30603447ef7423ce32e6fa454824173874eba1714c86960fcab1c5f1d1b1b2c2ff71b3f848c3
7
+ data.tar.gz: 622e6827e569114d063340637f2029b423483a859073eacd46b1a3d750935a5b787f6fa3abea94dae592fe0dee7850cc97a660a6d3e00ce32647ab511881dfba
data/README.md CHANGED
@@ -679,9 +679,9 @@ Transaction Type: Purchase
679
679
 
680
680
  Response Method: Sent to your server as a POST
681
681
 
682
- Approved URL: http://4f972556.ngrok.com/orders/moneris_postback
682
+ Approved URL: https://myapp.herokuapp.com/orders/moneris_postback
683
683
 
684
- Declined URL: http://4f972556.ngrok.com/orders/moneris_postback
684
+ Declined URL: https://myapp.herokuapp.com/orders/moneris_postback
685
685
 
686
686
  Note: The Approved and Declined URLs must match the effective_orders.moneris_postback_path value in your application. By default it is /orders/moneris_postback
687
687
 
@@ -731,7 +731,7 @@ Display merchange name: true, if you have an SSL cert
731
731
 
732
732
  Cancel Button Text: 'Cancel'
733
733
 
734
- Cancel Button URL: http://4f972556.ngrok.com
734
+ Cancel Button URL: https://myapp.herokuapp.com/
735
735
 
736
736
  Click 'Save Appearance Settings'
737
737
 
@@ -752,16 +752,18 @@ Click 'Return to main configuration'
752
752
 
753
753
  ### Security
754
754
 
755
- Referring URL: Depends how you're using effective_orders in your application, you can add multiple URLs
756
- By default, use http://4f972556.ngrok.com/orders/new
755
+ Referring URL: https://myapp.herokuapp.com/
757
756
 
758
757
  Enable Card Verification: false, unused
759
758
 
760
759
  Enable Transaction Verification: true
760
+
761
761
  Response Method: Displayed as key/value pairs on our server.
762
+
762
763
  Response URL: leave blank
763
764
 
764
765
  Click 'Save Verification Settings'
766
+
765
767
  Click 'Return to main configuration'
766
768
 
767
769
 
@@ -777,7 +779,9 @@ If you'd prefer to use the Moneris receipt, disable email sendouts from the conf
777
779
  With this test store set up, you can make a successful purchase with:
778
780
 
779
781
  Cardholder Name: Any name
782
+
780
783
  Credit Card Number: 4242 4242 4242 4242
784
+
781
785
  Expiry Date: Any future date
782
786
 
783
787
  Some gotchas:
@@ -11,6 +11,7 @@ module Admin
11
11
  authorize_effective_order!
12
12
  end
13
13
 
14
+ # We use the show action as an edit screen too
14
15
  def show
15
16
  @order = Effective::Order.find(params[:id])
16
17
  @page_title = "Order ##{@order.to_param}"
@@ -18,6 +19,26 @@ module Admin
18
19
  authorize_effective_order!
19
20
  end
20
21
 
22
+ def update
23
+ @order = Effective::Order.find(params[:id])
24
+ @page_title = "Order ##{@order.to_param}"
25
+
26
+ authorize_effective_order!
27
+
28
+ if @order.update_attributes(order_params)
29
+ if params[:commit].to_s.downcase == 'save internal note'
30
+ flash[:success] = 'Successfully updated internal note'
31
+ else
32
+ flash[:success] = 'Successfully updated order'
33
+ end
34
+
35
+ redirect_to effective_orders.admin_order_path(@order)
36
+ else
37
+ flash.now[:danger] = 'Unable to update order'
38
+ render action: :show
39
+ end
40
+ end
41
+
21
42
  def new
22
43
  @order = Effective::Order.new
23
44
  @page_title = 'New Order'
@@ -28,17 +49,16 @@ module Admin
28
49
  def create
29
50
  @user = User.find_by_id(order_params[:user_id])
30
51
  @order = Effective::Order.new(user: @user)
31
- @order.send_payment_request_to_buyer = order_params[:send_payment_request_to_buyer]
32
52
 
33
53
  authorize_effective_order!
34
54
 
35
- if order_params[:order_items_attributes].present?
36
- order_params[:order_items_attributes].each do |_, item_attrs|
37
- purchasable = Effective::Product.new(item_attrs[:purchasable_attributes])
38
- @order.add(purchasable, quantity: item_attrs[:quantity])
39
- end
55
+ (order_params[:order_items_attributes] || {}).each do |_, item_attrs|
56
+ purchasable = Effective::Product.new(item_attrs[:purchasable_attributes])
57
+ @order.add(purchasable, quantity: item_attrs[:quantity])
40
58
  end
41
59
 
60
+ @order.attributes = order_params.except(:order_items_attributes, :user_id)
61
+
42
62
  if @order.create_as_pending
43
63
  path_for_redirect = params[:commit] == 'Save and Add New' ? effective_orders.new_admin_order_path : effective_orders.admin_order_path(@order)
44
64
  message = 'Successfully created order'
@@ -54,22 +74,33 @@ module Admin
54
74
 
55
75
  def mark_as_paid
56
76
  @order = Effective::Order.find(params[:id])
77
+ @page_title = 'Mark as Paid'
78
+
57
79
  authorize_effective_order!
58
80
 
59
- purchased = @order.purchase!(
60
- details: 'Marked as paid by admin',
61
- provider: 'admin',
62
- card: 'none',
63
- email: EffectiveOrders.mailer[:send_order_receipts_when_marked_paid_by_admin],
64
- skip_buyer_validations: true # This will allow a declined order to be marked purchased
65
- )
81
+ if request.patch? || request.post? # They are submitting the form to mark an order as paid
82
+ purchased = false
66
83
 
67
- if purchased
68
- flash[:success] = 'Order marked as paid successfully'
69
- redirect_to effective_orders.admin_order_path(@order)
70
- else
71
- flash[:danger] = 'Unable to mark order as paid'
72
- request.referrer ? (redirect_to :back) : (redirect_to effective_orders.admin_orders_path)
84
+ @order.attributes = order_params.except(:payment, :payment_provider, :payment_card)
85
+
86
+ begin
87
+ purchased = @order.purchase!(
88
+ details: order_params[:payment],
89
+ provider: order_params[:payment_provider],
90
+ card: order_params[:payment_card],
91
+ email: @order.send_mark_as_paid_email_to_buyer?,
92
+ )
93
+ rescue => e
94
+ purchased = false
95
+ end
96
+
97
+ if purchased
98
+ flash[:success] = 'Order marked as paid successfully'
99
+ redirect_to effective_orders.admin_order_path(@order)
100
+ else
101
+ flash.now[:danger] = "Unable to mark order as paid: #{@order.errors.full_messages.to_sentence}"
102
+ render action: :mark_as_paid
103
+ end
73
104
  end
74
105
  end
75
106
 
@@ -90,6 +121,8 @@ module Admin
90
121
 
91
122
  def order_params
92
123
  params.require(:effective_order).permit(:user_id, :send_payment_request_to_buyer,
124
+ :note_internal, :note_to_buyer,
125
+ :payment_provider, :payment_card, :payment, :send_mark_as_paid_email_to_buyer,
93
126
  order_items_attributes: [
94
127
  :quantity, :_destroy, purchasable_attributes: [
95
128
  :title, :price, :tax_exempt
@@ -53,44 +53,3 @@ module Effective
53
53
  end
54
54
  end
55
55
  end
56
-
57
-
58
- # Instructions to set up a Test Moneris Store
59
-
60
- # https://esqa.moneris.com/mpg/index.php
61
-
62
- # demouser
63
- # store2
64
- # password
65
-
66
- # Click on the ADMIN -> hosted config
67
-
68
- # Generate a Version3 Configuration
69
-
70
- # This should bring us to a "hosted Paypage Configuration"
71
-
72
- # == Basic Configuration ==
73
- # - Transaction Type: Purchase
74
- # - Response Method Sent to your server as a POST
75
- # - Approved URL: http://ourwebsite.com/orders/moneris_postback
76
- # - Declined URL: http://ourwebsite.com/orders/moneris_postback
77
-
78
- # == Appearance ==
79
- # - Display item details
80
- # - Display customer details
81
- # - Display billing address details
82
- # - Display merchant name
83
- # - Cancel Button Text: Cancel Transaction
84
- # - Cancel Button URL http://ourwebsite.com
85
-
86
- # == Response Fields ==
87
- # - Ignore, leave blank, the asynchronous data post
88
- # - Do not Perform an asynchronous data post. Leave Async Response URL blank
89
-
90
- # == Security ==
91
- # Add a URL http://ourwebsite.com/orders/new
92
- # Click YES Enable Transaction Verification
93
- # Sent to your server as a POST
94
- # Response URL: http://ourwebsite.com/orders/moneris_postback
95
-
96
- # Displayed as key/value pairs on our server
@@ -13,6 +13,7 @@ module Effective
13
13
 
14
14
  attr_accessor :save_billing_address, :save_shipping_address, :shipping_address_same_as_billing # save these addresses to the user if selected
15
15
  attr_accessor :send_payment_request_to_buyer # Used by the /admin/orders/new form. Should the payment request email be sent after creating an order?
16
+ attr_accessor :send_mark_as_paid_email_to_buyer # Used by the /admin/orders/mark_as_paid action
16
17
  attr_accessor :skip_buyer_validations # Enabled by the /admin/orders/create action
17
18
 
18
19
  belongs_to :user, validate: false # This is the user who purchased the order. We validate it below.
@@ -282,6 +283,10 @@ module Effective
282
283
  ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(self.send_payment_request_to_buyer)
283
284
  end
284
285
 
286
+ def send_mark_as_paid_email_to_buyer?
287
+ ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(self.send_mark_as_paid_email_to_buyer)
288
+ end
289
+
285
290
  def shipping_address_same_as_billing?
286
291
  ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(self.shipping_address_same_as_billing)
287
292
  end
@@ -322,6 +327,9 @@ module Effective
322
327
 
323
328
  success = true
324
329
  rescue => e
330
+ self.purchase_state = purchase_state_was
331
+ self.purchased_at = purchased_at_was
332
+
325
333
  raise ::ActiveRecord::Rollback
326
334
  end
327
335
  end
@@ -1,2 +1,6 @@
1
+ - if (order.purchased? == false) && (EffectiveOrders.authorized?(controller, :admin, :effective_orders) rescue false)
2
+ = link_to effective_orders.mark_as_paid_admin_order_path(order), title: 'Mark as Paid' do
3
+ %span.glyphicon.glyphicon-usd
4
+
1
5
  = link_to (datatables_admin_path? ? effective_orders.admin_order_path(order) : effective_orders.order_path(order)), title: 'View' do
2
6
  %span.glyphicon.glyphicon-eye-open
@@ -22,7 +22,11 @@
22
22
  label: 'Yes, send a payment request email to the buyer.',
23
23
  value: (f.object.send_payment_request_to_buyer.nil? ? EffectiveOrders.mailer[:send_payment_request_to_buyer] : f.object.send_payment_request_to_buyer?)
24
24
 
25
- .form-group.pull-right
25
+ %h3 Internal Note
26
+ = f.input :note_internal, label: 'Internal note', hint: 'For internal admin use only. This note will never be displayed to the buyer.'
27
+
28
+
29
+ %p.text-right
26
30
  = f.button :submit, 'Save', data: { disable_with: 'Saving...' }
27
31
  = f.button :submit, 'Save and Add New', data: { disable_with: 'Saving...' }
28
32
  = link_to 'Cancel', effective_orders.admin_orders_path
@@ -0,0 +1,33 @@
1
+ = simple_form_for [:admin, order], (EffectiveOrders.admin_simple_form_options || {}).merge(url: effective_orders.mark_as_paid_admin_order_path(order), method: :post) do |f|
2
+ %h3 Payment Details
3
+
4
+ - if order.purchased?
5
+ .alert.alert-warning Warning: This order has already been purchased
6
+ %br
7
+
8
+ = f.input :payment_provider,
9
+ as: (defined?(EffectiveFormInputs) ? :effective_select : :select),
10
+ collection: EffectiveOrders.payment_providers,
11
+ required: true
12
+
13
+ = f.input :payment_card,
14
+ label: 'Payment card type, cheque or transaction number',
15
+ placeholder: 'Visa',
16
+ hint: 'Full credit card numbers should not be entered here, or anywhere.'
17
+
18
+ = f.input :payment,
19
+ as: :text,
20
+ label: 'Additional details',
21
+ input_html: { value: f.object.payment.kind_of?(Hash) ? f.object.payment[:details] : f.object.payment.presence }
22
+
23
+ = f.input :send_mark_as_paid_email_to_buyer,
24
+ as: :boolean,
25
+ label: 'Yes, send an email receipt to the buyer.',
26
+ value: (f.object.send_mark_as_paid_email_to_buyer.nil? ? EffectiveOrders.mailer[:send_order_receipts_when_mark_as_paid_by_admin] : f.object.send_mark_as_paid_email_to_buyer?)
27
+
28
+ %h3 Note to Buyer
29
+ = f.input :note_to_buyer, label: 'Note to buyer', hint: 'This is displayed to the buyer on all order receipts.'
30
+
31
+ %p.text-right
32
+ = f.button :submit, 'Mark Order as Paid', data: { disable_with: 'Saving...' }
33
+
@@ -0,0 +1,7 @@
1
+ %h3 Internal Note
2
+
3
+ = simple_form_for [:admin, order], (EffectiveOrders.admin_simple_form_options || {}).merge(url: effective_orders.admin_order_path(order)) do |f|
4
+ = f.input :note_internal, label: 'Internal note', hint: 'For internal admin use only. This note will never be displayed to the buyer.'
5
+
6
+ %p.text-right
7
+ = f.button :submit, 'Save Internal Note', data: { disable_with: 'Saving...' }
@@ -0,0 +1,19 @@
1
+ - if order.purchased?
2
+ .effective-order-payment-details
3
+ %h3 Payment Details
4
+ %table.table
5
+ %tbody
6
+ %tr
7
+ %td Provider
8
+ %td= order.payment_provider
9
+ %tr
10
+ %td Card
11
+ %td= order.payment_card || 'none'
12
+ %tr
13
+ %td Purchased at
14
+ %td= order.purchased_at.strftime('%Y-%m-%d %H:%M')
15
+ - if order.payment.present?
16
+ %tr
17
+ %td Additional details
18
+ %td= tableize_order_payment(order.payment[:details] || order.payment, class: 'table')
19
+
@@ -0,0 +1,7 @@
1
+ %h2.effective-orders-page-title= (@page_title || 'Mark as Paid')
2
+
3
+ %p Mark the following order as paid:
4
+
5
+ = render partial: 'effective/orders/order', locals: {order: @order, no_order_actions: true}
6
+
7
+ = render partial: 'admin/orders/form_mark_as_paid', locals: { order: @order }
@@ -1,3 +1,9 @@
1
1
  %h2.effective-orders-page-title= (@order.purchased? ? 'Receipt' : 'Order')
2
2
 
3
3
  = render partial: 'effective/orders/order', locals: {order: @order}
4
+
5
+ - if (EffectiveOrders.authorized?(controller, :admin, :effective_orders) rescue false)
6
+ = render partial: 'admin/orders/form_note_internal', locals: { order: @order }
7
+
8
+ - if (EffectiveOrders.authorized?(controller, :show, :payment_details) rescue false)
9
+ = render partial: 'admin/orders/order_payment_details', locals: { order: @order }
@@ -39,7 +39,7 @@
39
39
  - unless f.object.pending? || current_cart.try(:empty?)
40
40
  = link_to_current_cart(label: 'Change Items')
41
41
 
42
- .pull-right
42
+ %p.text-right
43
43
  - if order.total == 0 && EffectiveOrders.allow_free_orders
44
44
  = f.submit order_checkout_label(:free), class: 'btn btn-primary', rel: :nofollow, data: {'disable_with' => 'Processing...' }
45
45
  - else
@@ -5,8 +5,7 @@
5
5
  = render partial: 'effective/orders/order_header', locals: {order: order}
6
6
  = render partial: 'effective/orders/order_shipping', locals: {order: order}
7
7
  = render partial: 'effective/orders/order_note', locals: {order: order}
8
+ = render partial: 'effective/orders/order_note_to_buyer', locals: {order: order}
8
9
  = render partial: 'effective/orders/order_items', locals: {order: order}
9
10
  = render partial: 'effective/orders/order_footer', locals: {order: order}
10
11
 
11
- - if (EffectiveOrders.authorized?(controller, :show, :payment_details) rescue false)
12
- = render partial: 'effective/orders/order_payment_details', locals: {order: order}
@@ -6,5 +6,5 @@
6
6
  = link_to 'Resend Receipt', effective_orders.resend_buyer_receipt_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...' }
7
7
 
8
8
  - elsif (EffectiveOrders.authorized?(controller, :admin, :effective_orders) rescue false)
9
- = link_to 'Mark as Paid', effective_orders.mark_as_paid_admin_order_path(order), class: 'btn btn-default', method: :post, data: { confirm: 'Are you sure you want to mark this order as paid?', disable_with: 'Marking as paid...' }
10
- = link_to 'Send Payment Request', effective_orders.send_payment_request_admin_order_path(order), class: 'btn btn-default', method: :post, data: { confirm: 'This action will email buyer a payment request. Send it now?', disable_with: 'Sending...' }
9
+ = link_to 'Admin: Mark as Paid', effective_orders.mark_as_paid_admin_order_path(order), class: 'btn btn-default'
10
+ = link_to 'Admin: Send Payment Request', effective_orders.send_payment_request_admin_order_path(order), class: 'btn btn-default', method: :post, data: { confirm: 'This action will email buyer a payment request. Send it now?', disable_with: 'Sending...' }
@@ -0,0 +1,8 @@
1
+ - if order.note_to_buyer.present?
2
+ %table.table
3
+ %thead
4
+ %tr
5
+ %th Receipt note
6
+ %tbody
7
+ %tr
8
+ %td= order.note_to_buyer
data/config/routes.rb CHANGED
@@ -64,10 +64,11 @@ EffectiveOrders::Engine.routes.draw do
64
64
  if !EffectiveOrders.use_active_admin? || Rails.env.test?
65
65
  namespace :admin do
66
66
  resources :customers, only: [:index]
67
- resources :orders, only: [:index, :show, :new, :create] do
67
+ resources :orders, only: [:index, :show, :update, :new, :create] do
68
68
  member do
69
- post :send_payment_request
69
+ get :mark_as_paid
70
70
  post :mark_as_paid
71
+ post :send_payment_request
71
72
  end
72
73
  end
73
74
  resources :order_items, only: [:index]
@@ -6,6 +6,8 @@ class CreateEffectiveOrders < ActiveRecord::Migration
6
6
  t.datetime :purchased_at
7
7
 
8
8
  t.text :note
9
+ t.text :note_to_buyer
10
+ t.text :note_internal
9
11
 
10
12
  t.text :payment
11
13
 
@@ -9,6 +9,9 @@ class UpgradeEffectiveOrdersFrom1x < ActiveRecord::Migration
9
9
  end
10
10
 
11
11
  add_column <%= @orders_table_name %>, :note, :text
12
+ add_column <%= @orders_table_name %>, :note_to_buyer, :text
13
+ add_column <%= @orders_table_name %>, :note_internal, :text
14
+
12
15
  add_column <%= @orders_table_name %>, :payment_provider, :string
13
16
  add_column <%= @orders_table_name %>, :payment_card, :string
14
17
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
@@ -157,7 +157,7 @@ EffectiveOrders.setup do |config|
157
157
  send_order_receipt_to_seller: true, # Only applies to StripeConnect
158
158
  send_payment_request_to_buyer: true,
159
159
  send_pending_order_invoice_to_buyer: true,
160
- send_order_receipts_when_marked_paid_by_admin: false,
160
+ send_order_receipts_when_mark_as_paid_by_admin: false,
161
161
 
162
162
  subject_prefix: '[example]',
163
163
  subject_for_order_receipt_to_admin: '',
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: 2.0.1
4
+ version: 2.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: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -316,8 +316,12 @@ files:
316
316
  - app/views/admin/order_items/index.html.haml
317
317
  - app/views/admin/orders/_actions.html.haml
318
318
  - app/views/admin/orders/_form.html.haml
319
+ - app/views/admin/orders/_form_mark_as_paid.html.haml
320
+ - app/views/admin/orders/_form_note_internal.html.haml
319
321
  - app/views/admin/orders/_order_item_fields.html.haml
322
+ - app/views/admin/orders/_order_payment_details.html.haml
320
323
  - app/views/admin/orders/index.html.haml
324
+ - app/views/admin/orders/mark_as_paid.html.haml
321
325
  - app/views/admin/orders/new.html.haml
322
326
  - app/views/admin/orders/show.html.haml
323
327
  - app/views/effective/carts/_cart.html.haml
@@ -332,7 +336,7 @@ files:
332
336
  - app/views/effective/orders/_order_items.html.haml
333
337
  - app/views/effective/orders/_order_note.html.haml
334
338
  - app/views/effective/orders/_order_note_fields.html.haml
335
- - app/views/effective/orders/_order_payment_details.html.haml
339
+ - app/views/effective/orders/_order_note_to_buyer.html.haml
336
340
  - app/views/effective/orders/_order_shipping.html.haml
337
341
  - app/views/effective/orders/_order_user_fields.html.haml
338
342
  - app/views/effective/orders/_orders_table.html.haml
@@ -1,3 +0,0 @@
1
- - if order.payment.present?
2
- .effective-order-payment-details
3
- = tableize_order_payment(order.payment, {class: 'table', title: 'Payment Details'})