effective_orders 3.2.3 → 4.0.0beta1

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.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +11 -99
  4. data/app/assets/stylesheets/effective_orders.scss +1 -0
  5. data/app/assets/stylesheets/effective_orders/_cart.scss +4 -0
  6. data/app/assets/stylesheets/effective_orders/_order.scss +6 -2
  7. data/app/controllers/admin/orders_controller.rb +17 -17
  8. data/app/controllers/effective/carts_controller.rb +4 -2
  9. data/app/controllers/effective/orders_controller.rb +50 -105
  10. data/app/controllers/effective/providers/cheque.rb +1 -1
  11. data/app/controllers/effective/providers/moneris.rb +17 -23
  12. data/app/controllers/effective/providers/stripe.rb +2 -37
  13. data/app/datatables/effective_customers_datatable.rb +1 -5
  14. data/app/datatables/effective_order_items_datatable.rb +10 -10
  15. data/app/datatables/effective_orders_datatable.rb +23 -46
  16. data/app/helpers/effective_carts_helper.rb +5 -25
  17. data/app/helpers/effective_orders_helper.rb +29 -61
  18. data/app/helpers/effective_paypal_helper.rb +10 -8
  19. data/app/helpers/effective_stripe_helper.rb +2 -33
  20. data/app/models/concerns/acts_as_purchasable.rb +26 -37
  21. data/app/models/concerns/acts_as_subscribable.rb +1 -1
  22. data/app/models/effective/cart.rb +4 -5
  23. data/app/models/effective/customer.rb +1 -4
  24. data/app/models/effective/order.rb +132 -163
  25. data/app/models/effective/order_item.rb +2 -21
  26. data/app/models/{effective → validators/effective}/sold_out_validator.rb +0 -0
  27. data/app/views/admin/customers/index.html.haml +1 -4
  28. data/app/views/admin/order_items/index.html.haml +1 -4
  29. data/app/views/admin/orders/_actions.html.haml +18 -9
  30. data/app/views/admin/orders/_form.html.haml +12 -14
  31. data/app/views/admin/orders/_form_note_internal.html.haml +2 -2
  32. data/app/views/admin/orders/_order_actions.html.haml +8 -5
  33. data/app/views/admin/orders/_order_item_fields.html.haml +9 -8
  34. data/app/views/admin/orders/checkout.html.haml +3 -0
  35. data/app/views/admin/orders/edit.html.haml +3 -1
  36. data/app/views/admin/orders/new.html.haml +2 -1
  37. data/app/views/admin/orders/show.html.haml +2 -5
  38. data/app/views/effective/carts/_cart.html.haml +1 -1
  39. data/app/views/effective/carts/_cart_actions.html.haml +3 -4
  40. data/app/views/effective/carts/show.html.haml +4 -4
  41. data/app/views/effective/orders/_checkout_actions.html.haml +3 -0
  42. data/app/views/effective/orders/_checkout_step1.html.haml +20 -27
  43. data/app/views/effective/orders/_checkout_step2.html.haml +26 -30
  44. data/app/views/effective/orders/_order.html.haml +1 -2
  45. data/app/views/effective/orders/_order_actions.html.haml +14 -6
  46. data/app/views/effective/orders/_order_header.html.haml +2 -2
  47. data/app/views/effective/orders/_order_note_fields.html.haml +6 -4
  48. data/app/views/effective/orders/_order_notes.html.haml +15 -0
  49. data/app/views/effective/orders/_order_payment_details.html.haml +1 -1
  50. data/app/views/effective/orders/_order_shipping.html.haml +6 -6
  51. data/app/views/effective/orders/_order_terms_and_conditions_fields.html.haml +5 -6
  52. data/app/views/effective/orders/_order_user_fields.html.haml +5 -11
  53. data/app/views/effective/orders/_orders_table.html.haml +2 -6
  54. data/app/views/effective/orders/index.html.haml +2 -1
  55. data/app/views/effective/orders/mark_as_paid/_form.html.haml +8 -14
  56. data/app/views/effective/orders/moneris/_form.html.haml +43 -4
  57. data/app/views/effective/orders/pretend/_form.html.haml +1 -3
  58. data/app/views/effective/orders/refund/_form.html.haml +8 -12
  59. data/app/views/effective/orders/show.html.haml +2 -2
  60. data/app/views/effective/orders/stripe/_form.html.haml +4 -4
  61. data/app/views/effective/orders_mailer/payment_request_to_buyer.html.haml +1 -1
  62. data/app/views/effective/orders_mailer/pending_order_invoice_to_buyer.html.haml +1 -1
  63. data/config/effective_orders.rb +116 -182
  64. data/config/routes.rb +16 -27
  65. data/db/migrate/01_create_effective_orders.rb.erb +6 -5
  66. data/lib/effective_orders.rb +72 -76
  67. data/lib/effective_orders/engine.rb +8 -80
  68. data/lib/effective_orders/version.rb +1 -1
  69. data/lib/generators/templates/effective_orders_mailer_preview.rb +4 -4
  70. metadata +26 -38
  71. data/Rakefile +0 -21
  72. data/app/assets/config/effective_orders_manifest.js +0 -3
  73. data/app/assets/images/effective_orders/stripe_connect.png +0 -0
  74. data/app/controllers/effective/providers/app_checkout.rb +0 -38
  75. data/app/controllers/effective/providers/ccbill.rb +0 -34
  76. data/app/controllers/effective/providers/stripe_connect.rb +0 -47
  77. data/app/helpers/effective_ccbill_helper.rb +0 -25
  78. data/app/models/effective/providers/ccbill_postback.rb +0 -85
  79. data/app/models/effective/providers/moneris_charge.rb +0 -115
  80. data/app/views/effective/orders/_order_note.html.haml +0 -5
  81. data/app/views/effective/orders/_order_note_to_buyer.html.haml +0 -9
  82. data/app/views/effective/orders/app_checkout/_form.html.haml +0 -2
  83. data/app/views/effective/orders/ccbill/_form.html.haml +0 -24
  84. data/app/views/effective/orders/my_purchases.html.haml +0 -3
  85. data/app/views/effective/orders/my_sales.html.haml +0 -25
  86. data/app/views/effective/orders_mailer/order_receipt_to_seller.html.haml +0 -25
  87. data/lib/effective_orders/app_checkout_service.rb +0 -26
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrders
2
- VERSION = '3.2.3'.freeze
2
+ VERSION = '4.0.0beta1'.freeze
3
3
  end
@@ -68,10 +68,10 @@ class EffectiveOrdersMailerPreview < ActionMailer::Preview
68
68
  # so that this mailer will not have to guess at your app's acts_as_purchasable objects
69
69
  def preview_order_items
70
70
  [
71
- {title: 'Item One', quantity: 2, price: 999, tax_exempt: false},
72
- {title: 'Item Two', quantity: 1, price: 25000, tax_exempt: false},
73
- {title: 'Item Three', quantity: 1, price: 8999, tax_exempt: false},
74
- {title: 'Item Four', quantity: 1, price: 100000, tax_exempt: false}
71
+ { title: 'Item One', quantity: 2, price: 999, tax_exempt: false },
72
+ { title: 'Item Two', quantity: 1, price: 25000, tax_exempt: false },
73
+ { title: 'Item Three', quantity: 1, price: 8999, tax_exempt: false },
74
+ { title: 'Item Four', quantity: 1, price: 100000, tax_exempt: false }
75
75
  ]
76
76
  end
77
77
 
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.2.3
4
+ version: 4.0.0beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-17 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.0
19
+ version: 4.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.0
26
+ version: 4.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: coffee-rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: jquery-rails
56
+ name: sass-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,21 +67,21 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: sass-rails
70
+ name: effective_datatables
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 4.0.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 4.0.0
83
83
  - !ruby/object:Gem::Dependency
84
- name: effective_addresses
84
+ name: effective_bootstrap
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,19 +95,19 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: effective_datatables
98
+ name: effective_resources
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '3.0'
103
+ version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '3.0'
110
+ version: '0'
111
111
  description: Quickly build an online store with carts, orders, automatic email receipts
112
112
  and payment collection via Stripe, StripeConnect, PayPal and Moneris.
113
113
  email:
@@ -118,14 +118,12 @@ extra_rdoc_files: []
118
118
  files:
119
119
  - MIT-LICENSE
120
120
  - README.md
121
- - Rakefile
122
- - app/assets/config/effective_orders_manifest.js
123
- - app/assets/images/effective_orders/stripe_connect.png
124
121
  - app/assets/javascripts/effective_orders.js
125
122
  - app/assets/javascripts/effective_orders/customers.js.coffee
126
123
  - app/assets/javascripts/effective_orders/providers/stripe.js.coffee
127
124
  - app/assets/javascripts/effective_orders/subscriptions.js.coffee
128
125
  - app/assets/stylesheets/effective_orders.scss
126
+ - app/assets/stylesheets/effective_orders/_cart.scss
129
127
  - app/assets/stylesheets/effective_orders/_order.scss
130
128
  - app/assets/stylesheets/effective_orders/_subscriptions.scss
131
129
  - app/controllers/admin/customers_controller.rb
@@ -135,8 +133,6 @@ files:
135
133
  - app/controllers/effective/concerns/purchase.rb
136
134
  - app/controllers/effective/customers_controller.rb
137
135
  - app/controllers/effective/orders_controller.rb
138
- - app/controllers/effective/providers/app_checkout.rb
139
- - app/controllers/effective/providers/ccbill.rb
140
136
  - app/controllers/effective/providers/cheque.rb
141
137
  - app/controllers/effective/providers/free.rb
142
138
  - app/controllers/effective/providers/mark_as_paid.rb
@@ -145,13 +141,11 @@ files:
145
141
  - app/controllers/effective/providers/pretend.rb
146
142
  - app/controllers/effective/providers/refund.rb
147
143
  - app/controllers/effective/providers/stripe.rb
148
- - app/controllers/effective/providers/stripe_connect.rb
149
144
  - app/controllers/effective/webhooks_controller.rb
150
145
  - app/datatables/effective_customers_datatable.rb
151
146
  - app/datatables/effective_order_items_datatable.rb
152
147
  - app/datatables/effective_orders_datatable.rb
153
148
  - app/helpers/effective_carts_helper.rb
154
- - app/helpers/effective_ccbill_helper.rb
155
149
  - app/helpers/effective_orders_helper.rb
156
150
  - app/helpers/effective_paypal_helper.rb
157
151
  - app/helpers/effective_stripe_helper.rb
@@ -167,13 +161,11 @@ files:
167
161
  - app/models/effective/order.rb
168
162
  - app/models/effective/order_item.rb
169
163
  - app/models/effective/product.rb
170
- - app/models/effective/providers/ccbill_postback.rb
171
- - app/models/effective/providers/moneris_charge.rb
172
164
  - app/models/effective/providers/stripe_charge.rb
173
- - app/models/effective/sold_out_validator.rb
174
165
  - app/models/effective/subscripter.rb
175
166
  - app/models/effective/subscription.rb
176
167
  - app/models/effective/tax_rate_calculator.rb
168
+ - app/models/validators/effective/sold_out_validator.rb
177
169
  - app/views/admin/customers/_actions.html.haml
178
170
  - app/views/admin/customers/index.html.haml
179
171
  - app/views/admin/customers/show.html.haml
@@ -183,6 +175,7 @@ files:
183
175
  - app/views/admin/orders/_form_note_internal.html.haml
184
176
  - app/views/admin/orders/_order_actions.html.haml
185
177
  - app/views/admin/orders/_order_item_fields.html.haml
178
+ - app/views/admin/orders/checkout.html.haml
186
179
  - app/views/admin/orders/edit.html.haml
187
180
  - app/views/admin/orders/index.html.haml
188
181
  - app/views/admin/orders/new.html.haml
@@ -194,6 +187,7 @@ files:
194
187
  - app/views/effective/customers/_fields.html.haml
195
188
  - app/views/effective/customers/_form.html.haml
196
189
  - app/views/effective/customers/edit.html.haml
190
+ - app/views/effective/orders/_checkout_actions.html.haml
197
191
  - app/views/effective/orders/_checkout_step1.html.haml
198
192
  - app/views/effective/orders/_checkout_step2.html.haml
199
193
  - app/views/effective/orders/_order.html.haml
@@ -201,16 +195,13 @@ files:
201
195
  - app/views/effective/orders/_order_footer.html.haml
202
196
  - app/views/effective/orders/_order_header.html.haml
203
197
  - app/views/effective/orders/_order_items.html.haml
204
- - app/views/effective/orders/_order_note.html.haml
205
198
  - app/views/effective/orders/_order_note_fields.html.haml
206
- - app/views/effective/orders/_order_note_to_buyer.html.haml
199
+ - app/views/effective/orders/_order_notes.html.haml
207
200
  - app/views/effective/orders/_order_payment_details.html.haml
208
201
  - app/views/effective/orders/_order_shipping.html.haml
209
202
  - app/views/effective/orders/_order_terms_and_conditions_fields.html.haml
210
203
  - app/views/effective/orders/_order_user_fields.html.haml
211
204
  - app/views/effective/orders/_orders_table.html.haml
212
- - app/views/effective/orders/app_checkout/_form.html.haml
213
- - app/views/effective/orders/ccbill/_form.html.haml
214
205
  - app/views/effective/orders/cheque/_form.html.haml
215
206
  - app/views/effective/orders/cheque/pay_by_cheque.html.haml
216
207
  - app/views/effective/orders/declined.html.haml
@@ -219,8 +210,6 @@ files:
219
210
  - app/views/effective/orders/index.html.haml
220
211
  - app/views/effective/orders/mark_as_paid/_form.html.haml
221
212
  - app/views/effective/orders/moneris/_form.html.haml
222
- - app/views/effective/orders/my_purchases.html.haml
223
- - app/views/effective/orders/my_sales.html.haml
224
213
  - app/views/effective/orders/new.html.haml
225
214
  - app/views/effective/orders/paypal/_form.html.haml
226
215
  - app/views/effective/orders/pretend/_form.html.haml
@@ -231,7 +220,6 @@ files:
231
220
  - app/views/effective/orders_mailer/order_error.html.haml
232
221
  - app/views/effective/orders_mailer/order_receipt_to_admin.html.haml
233
222
  - app/views/effective/orders_mailer/order_receipt_to_buyer.html.haml
234
- - app/views/effective/orders_mailer/order_receipt_to_seller.html.haml
235
223
  - app/views/effective/orders_mailer/payment_request_to_buyer.html.haml
236
224
  - app/views/effective/orders_mailer/pending_order_invoice_to_buyer.html.haml
237
225
  - app/views/effective/orders_mailer/subscription_canceled.html.haml
@@ -246,7 +234,6 @@ files:
246
234
  - config/routes.rb
247
235
  - db/migrate/01_create_effective_orders.rb.erb
248
236
  - lib/effective_orders.rb
249
- - lib/effective_orders/app_checkout_service.rb
250
237
  - lib/effective_orders/engine.rb
251
238
  - lib/effective_orders/version.rb
252
239
  - lib/generators/effective_orders/install_generator.rb
@@ -256,7 +243,7 @@ homepage: https://github.com/code-and-effect/effective_orders
256
243
  licenses:
257
244
  - MIT
258
245
  metadata: {}
259
- post_install_message:
246
+ post_install_message:
260
247
  rdoc_options: []
261
248
  require_paths:
262
249
  - lib
@@ -267,12 +254,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
267
254
  version: '0'
268
255
  required_rubygems_version: !ruby/object:Gem::Requirement
269
256
  requirements:
270
- - - ">="
257
+ - - ">"
271
258
  - !ruby/object:Gem::Version
272
- version: '0'
259
+ version: 1.3.1
273
260
  requirements: []
274
- rubygems_version: 3.1.2
275
- signing_key:
261
+ rubyforge_project:
262
+ rubygems_version: 2.4.5.1
263
+ signing_key:
276
264
  specification_version: 4
277
265
  summary: Quickly build an online store with carts, orders, automatic email receipts
278
266
  and payment collection via Stripe, StripeConnect, PayPal and Moneris.
data/Rakefile DELETED
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
-
8
- # Testing tasks
9
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
10
- load 'rails/tasks/engine.rake'
11
-
12
- require "bundler/vendored_thor"
13
- Bundler::GemHelper.install_tasks
14
-
15
- require 'rspec/core'
16
- require 'rspec/core/rake_task'
17
-
18
- desc "Run all specs in spec directory (excluding plugin specs)"
19
- RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
20
-
21
- task :default => :spec
@@ -1,3 +0,0 @@
1
- //= link_directory ../javascripts .js
2
- //= link_directory ../stylesheets .css
3
- //= link_directory ../images/effective_orders
@@ -1,38 +0,0 @@
1
- module Effective
2
- module Providers
3
- module AppCheckout
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- end
8
-
9
- # TODO: Make app checkout work with admin checkout workflow
10
-
11
- def app_checkout
12
- @order = Order.find(params[:id])
13
-
14
- (EffectiveOrders.authorize!(self, :update, @order) rescue false)
15
-
16
- checkout = EffectiveOrders.app_checkout[:service].call(order: @order)
17
- if checkout.success?
18
- order_purchased(details: payment_details(checkout), provider: 'app_checkout', card: 'none')
19
- else
20
- flash = EffectiveOrders.app_checkout[:declined_flash]
21
- order_declined(details: payment_details(checkout), message: flash, provider: 'app_checkout', card: 'none')
22
- end
23
- end
24
-
25
- private
26
-
27
- def payment_details(checkout)
28
- default = 'App Checkout'
29
- if checkout.respond_to?(:payment_details)
30
- checkout.payment_details.presence || default
31
- else
32
- default
33
- end
34
- end
35
- end
36
- end
37
- end
38
-
@@ -1,34 +0,0 @@
1
- module Effective
2
- module Providers
3
- module Ccbill
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- skip_before_action :verify_authenticity_token, only: [:ccbill_postback]
8
- end
9
-
10
- # TODO: Make ccbill work with admin checkout workflow
11
-
12
- def ccbill_postback
13
- postback = Effective::Providers::CcbillPostback.new(params)
14
- @order ||= Effective::Order.find(postback.order_id)
15
-
16
- (EffectiveOrders.authorize!(self, :update, @order) rescue false)
17
-
18
- if @order.present? && postback.verified?
19
- if @order.purchased?
20
- order_purchased(details: postback.order_details, provider: 'ccbill')
21
- elsif postback.approval? && postback.matches?(@order)
22
- order_purchased(details: postback.order_details, provider: 'ccbill')
23
- else
24
- order_declined(details: postback.order_details, provider: 'ccbill')
25
- end
26
- end
27
-
28
- head(:ok)
29
- end
30
- end
31
-
32
- end
33
- end
34
-
@@ -1,47 +0,0 @@
1
- module Effective
2
- module Providers
3
- module StripeConnect
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- prepend_before_action :set_stripe_connect_state_params, only: [:stripe_connect_redirect_uri]
8
- end
9
-
10
- # So this is the postback after Stripe does its oAuth authentication
11
- def stripe_connect_redirect_uri
12
- if params[:code].present?
13
- token_params = request_access_token(params[:code]) # We got a code, so now we make a curl request for the access_token
14
- customer = Effective::Customer.for_user(current_user)
15
-
16
- if token_params['access_token'].present? && customer.present?
17
- if customer.update_attributes(stripe_connect_access_token: token_params['access_token'])
18
- flash[:success] = 'Successfully Connected with Stripe Connect'
19
- else
20
- flash[:danger] = "Unable to update customer: #{customer.errors[:base].first}"
21
- end
22
- else
23
- flash[:danger] = "Error when connecting to Stripe /oauth/token: #{token_params[:error]}. Please try again."
24
- end
25
- else
26
- flash[:danger] = "Error when connecting to Stripe /oauth/authorize: #{params[:error]}. Please try again."
27
- end
28
-
29
- redirect_to URI.parse(@stripe_state_params['redirect_to']).path rescue effective_orders.orders_path
30
- end
31
-
32
- private
33
-
34
- def request_access_token(code)
35
- stripe_response = `curl -F client_secret='#{EffectiveOrders.stripe[:secret_key]}' -F code='#{code}' -F grant_type='authorization_code' #{EffectiveStripeHelper::STRIPE_CONNECT_TOKEN_URL}`
36
- JSON.parse(stripe_response) rescue {}
37
- end
38
-
39
- def set_stripe_connect_state_params
40
- @stripe_state_params = (JSON.parse(params[:state]) rescue {})
41
- @stripe_state_params = {} unless @stripe_state_params.kind_of?(Hash)
42
-
43
- params[:authenticity_token] = @stripe_state_params['form_authenticity_token']
44
- end
45
- end
46
- end
47
- end
@@ -1,25 +0,0 @@
1
- module EffectiveCcbillHelper
2
- def ccbill_form_digest(order)
3
- digested_variables = [
4
- ccbill_price(order.total),
5
- EffectiveOrders.ccbill[:form_period],
6
- EffectiveOrders.ccbill[:currency_code],
7
- EffectiveOrders.ccbill[:dynamic_pricing_salt]
8
- ]
9
- string = digested_variables.join('')
10
- Digest::MD5.hexdigest(string)
11
- end
12
-
13
- def ccbill_price(price)
14
- number_to_currency(price/100.0, unit: '')
15
- end
16
-
17
- def ccbill_customer_name(order, name = :full_name)
18
- if order.user.present? && order.user.try(name).present?
19
- order.user.public_send(name)
20
- elsif order.billing_address.present?
21
- order.billing_address.public_send(name)
22
- end
23
- end
24
- end
25
-
@@ -1,85 +0,0 @@
1
- # https://www.ccbill.com/cs/wiki/tiki-index.php?page=Background+Post
2
- class Effective::Providers::CcbillPostback
3
- attr_reader :params
4
-
5
- def initialize(params)
6
- @params = params
7
- end
8
-
9
- def verified?
10
- params[:responseDigest] == digest(digest_value)
11
- end
12
-
13
- def matches?(order)
14
- price == order.total && order_id == order.to_param
15
- end
16
-
17
- def approval?
18
- !denial?
19
- end
20
-
21
- def denial?
22
- # denialId is for subscriptions only
23
- [:reasonForDeclineCode, :reasonForDecline, :denialId].any? { |key| params[key].present? }
24
- end
25
-
26
- def order_details
27
- @order_details ||= get_order_details
28
- end
29
-
30
- def order_id
31
- params[:order_id]
32
- end
33
-
34
- private
35
-
36
- # https://www.ccbill.com/cs/wiki/tiki-index.php?page=Dynamic+Pricing+User+Guide#Postback
37
- def digest_value
38
- if approval?
39
- "#{params[:subscription_id]}1#{salt}" # the `subscriptionId` param in the linked docs is a typo
40
- else
41
- "#{params[:denialId]}0#{salt}"
42
- end
43
- end
44
-
45
- def digest(value)
46
- Digest::MD5.hexdigest(value)
47
- end
48
-
49
- def salt
50
- EffectiveOrders.ccbill[:dynamic_pricing_salt]
51
- end
52
-
53
- # in cents
54
- def price
55
- return @price if @price.present?
56
- formatted_price = params[:initialFormattedPrice] # example: "&#36;10.00"
57
- formatted_price = Nokogiri::HTML::DocumentFragment.parse(formatted_price).to_s # => "$10.00"
58
- match = formatted_price.match(/^\D(\d*.\d\d)$/) # {a currency symbol}(digits.two digits)
59
- return false unless match.present?
60
- formatted_price = match[1] # => "10.00"
61
- @price = formatted_price.sub('.', '').to_i # => 1000
62
- end
63
-
64
- def get_order_details
65
- # ignore some params
66
- keepable = params.except(*ignorable_params)
67
- # remove blanks
68
- keepable.inject({}) do |details, kv_pair|
69
- details[kv_pair[0]] = kv_pair[1] if kv_pair[1].present?
70
- details
71
- end
72
- end
73
-
74
- def ignorable_params
75
- [
76
- # we have these already
77
- :clientAccnum,
78
- :clientSubacc,
79
- :productDesc,
80
- # a hash of billing information which CCBill doesn't share the format of (afaik)
81
- :paymentAccount
82
- ]
83
- end
84
- end
85
-