glysellin 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +100 -0
  4. data/Rakefile +29 -0
  5. data/app/assets/javascripts/glysellin/address.coffee +38 -0
  6. data/app/assets/javascripts/glysellin/async-cart.coffee +139 -0
  7. data/app/assets/javascripts/glysellin/base.js +6 -0
  8. data/app/assets/javascripts/glysellin/cart.coffee +54 -0
  9. data/app/assets/javascripts/glysellin/main.coffee +0 -0
  10. data/app/assets/javascripts/glysellin/product.coffee +0 -0
  11. data/app/assets/stylesheets/glysellin/application.css +13 -0
  12. data/app/assets/stylesheets/glysellin/orders.css +4 -0
  13. data/app/assets/stylesheets/glysellin/products.css +4 -0
  14. data/app/controllers/glysellin/cart/addresses_controller.rb +17 -0
  15. data/app/controllers/glysellin/cart/discount_code_controller.rb +10 -0
  16. data/app/controllers/glysellin/cart/payment_method_controller.rb +17 -0
  17. data/app/controllers/glysellin/cart/products_controller.rb +37 -0
  18. data/app/controllers/glysellin/cart/shipping_method_controller.rb +18 -0
  19. data/app/controllers/glysellin/cart/state_controller.rb +15 -0
  20. data/app/controllers/glysellin/cart_controller.rb +53 -0
  21. data/app/controllers/glysellin/orders_controller.rb +53 -0
  22. data/app/controllers/glysellin/products_controller.rb +12 -0
  23. data/app/helpers/glysellin/application_helper.rb +4 -0
  24. data/app/helpers/glysellin/cart_helper.rb +21 -0
  25. data/app/helpers/glysellin/orders_helper.rb +35 -0
  26. data/app/helpers/glysellin/products_helper.rb +4 -0
  27. data/app/mailers/glysellin/order_admin_mailer.rb +17 -0
  28. data/app/mailers/glysellin/order_customer_mailer.rb +27 -0
  29. data/app/models/glysellin/address.rb +35 -0
  30. data/app/models/glysellin/brand.rb +14 -0
  31. data/app/models/glysellin/discount_code.rb +36 -0
  32. data/app/models/glysellin/discount_type.rb +9 -0
  33. data/app/models/glysellin/order.rb +243 -0
  34. data/app/models/glysellin/order_adjustment.rb +19 -0
  35. data/app/models/glysellin/order_item.rb +38 -0
  36. data/app/models/glysellin/orderer.rb +28 -0
  37. data/app/models/glysellin/payment.rb +46 -0
  38. data/app/models/glysellin/payment_method.rb +36 -0
  39. data/app/models/glysellin/product.rb +136 -0
  40. data/app/models/glysellin/product_image.rb +11 -0
  41. data/app/models/glysellin/product_property.rb +22 -0
  42. data/app/models/glysellin/product_property_type.rb +11 -0
  43. data/app/models/glysellin/product_type.rb +11 -0
  44. data/app/models/glysellin/shipping_method.rb +22 -0
  45. data/app/models/glysellin/taxonomy.rb +35 -0
  46. data/app/models/glysellin/variant.rb +100 -0
  47. data/app/views/glysellin/cart/_added_to_cart_warning.html.erb +21 -0
  48. data/app/views/glysellin/cart/_cart.html.erb +13 -0
  49. data/app/views/glysellin/cart/_navigation.html.erb +11 -0
  50. data/app/views/glysellin/cart/_products.html.erb +125 -0
  51. data/app/views/glysellin/cart/_recap.html.erb +16 -0
  52. data/app/views/glysellin/cart/recap/_addresses.html.erb +13 -0
  53. data/app/views/glysellin/cart/recap/_products.html.erb +63 -0
  54. data/app/views/glysellin/cart/show.html.erb +13 -0
  55. data/app/views/glysellin/cart/states/_addresses.html.erb +25 -0
  56. data/app/views/glysellin/cart/states/_choose_payment_method.html.erb +14 -0
  57. data/app/views/glysellin/cart/states/_choose_shipping_method.html.erb +14 -0
  58. data/app/views/glysellin/cart/states/_filled.html.erb +3 -0
  59. data/app/views/glysellin/cart/states/_init.html.erb +5 -0
  60. data/app/views/glysellin/cart/states/_ready.html.erb +1 -0
  61. data/app/views/glysellin/order_admin_mailer/_order_header.text.erb +5 -0
  62. data/app/views/glysellin/order_admin_mailer/send_check_order_created_email.text.erb +8 -0
  63. data/app/views/glysellin/order_admin_mailer/send_order_paid_email.text.erb +8 -0
  64. data/app/views/glysellin/order_customer_mailer/_order_footer.text.erb +3 -0
  65. data/app/views/glysellin/order_customer_mailer/_order_header.text.erb +5 -0
  66. data/app/views/glysellin/order_customer_mailer/send_order_created_email.text.erb +7 -0
  67. data/app/views/glysellin/order_customer_mailer/send_order_paid_email.text.erb +7 -0
  68. data/app/views/glysellin/order_customer_mailer/send_order_shipped_email.text.erb +8 -0
  69. data/app/views/glysellin/orders/_addresses_fields.html.erb +29 -0
  70. data/app/views/glysellin/orders/_order.html.erb +18 -0
  71. data/app/views/glysellin/orders/_payment_canceled.html.erb +13 -0
  72. data/app/views/glysellin/orders/_payment_successful.html.erb +6 -0
  73. data/app/views/glysellin/orders/payment_response.html.erb +5 -0
  74. data/app/views/glysellin/payment_methods/_paypal-integral.html.erb +22 -0
  75. data/app/views/glysellin/products/_add_to_cart.html.erb +16 -0
  76. data/app/views/glysellin/products/_item.html.erb +21 -0
  77. data/app/views/glysellin/products/filter.html.erb +0 -0
  78. data/app/views/glysellin/products/index.html.erb +3 -0
  79. data/app/views/glysellin/products/show.html.erb +3 -0
  80. data/app/views/glysellin/shared/_address.html.erb +11 -0
  81. data/app/views/glysellin/shared/_address.text.erb +7 -0
  82. data/app/views/glysellin/shared/_order.text.erb +56 -0
  83. data/app/views/glysellin/shared/mailer/_footer.text.erb +2 -0
  84. data/app/views/layouts/glysellin/application.html.erb +14 -0
  85. data/config/locales/glysellin.en.yml +113 -0
  86. data/config/locales/glysellin.fr.yml +119 -0
  87. data/db/migrate/20120206115004_create_glysellin_orders.rb +16 -0
  88. data/db/migrate/20120206115132_create_glysellin_customers.rb +8 -0
  89. data/db/migrate/20120206115657_create_glysellin_addresses.rb +22 -0
  90. data/db/migrate/20120206124505_create_glysellin_products.rb +20 -0
  91. data/db/migrate/20120206124545_create_glysellin_order_items.rb +15 -0
  92. data/db/migrate/20120206124630_create_glysellin_product_images.rb +10 -0
  93. data/db/migrate/20120206125210_add_attachment_image_to_product_image.rb +15 -0
  94. data/db/migrate/20120206130920_create_glysellin_payments.rb +13 -0
  95. data/db/migrate/20120206131042_create_glysellin_payment_methods.rb +10 -0
  96. data/db/migrate/20120207175050_create_glysellin_taxonomies.rb +11 -0
  97. data/db/migrate/20120207175158_create_products_taxonomies_table.rb +12 -0
  98. data/db/migrate/20120515143231_create_brands.rb +9 -0
  99. data/db/migrate/20120515143233_add_attachment_image_to_brands.rb +15 -0
  100. data/db/migrate/20120620151705_create_product_properties.rb +12 -0
  101. data/db/migrate/20130204121211_create_glysellin_discount_types.rb +10 -0
  102. data/db/migrate/20130204121228_create_glysellin_discount_codes.rb +15 -0
  103. data/db/migrate/20130204125310_create_glysellin_order_adjustments.rb +13 -0
  104. data/db/migrate/20130204202102_create_glysellin_shipping_methods.rb +12 -0
  105. data/db/migrate/20130204202109_add_shipping_method_id_to_glysellin_orders.rb +5 -0
  106. data/db/migrate/20130205110036_add_weight_to_glysellin_products.rb +5 -0
  107. data/db/migrate/20130205120541_add_weight_to_glysellin_order_items.rb +5 -0
  108. data/db/migrate/20130208162813_create_glysellin_variants.rb +17 -0
  109. data/db/migrate/20130208165020_create_glysellin_product_property_types.rb +7 -0
  110. data/db/migrate/20130211105557_add_type_id_to_glysellin_product_properties.rb +5 -0
  111. data/db/migrate/20130211112302_add_variant_id_to_glysellin_product_properties.rb +13 -0
  112. data/db/migrate/20130211152651_add_product_id_to_glysellin_variants.rb +5 -0
  113. data/db/migrate/20130212131658_add_weight_to_glysellin_variants.rb +5 -0
  114. data/db/migrate/20130212132253_remove_variant_columns_from_glysellin_products.rb +15 -0
  115. data/db/migrate/20130212154943_remove_eot_price_from_glysellin_products.rb +9 -0
  116. data/db/migrate/20130214184204_create_glysellin_product_types.rb +9 -0
  117. data/db/migrate/20130214184352_create_product_type_behavior.rb +15 -0
  118. data/db/migrate/20130221102200_add_unmarked_price_to_glysellin_variants.rb +5 -0
  119. data/db/migrate/20130311135842_add_addressable_to_glysellin_addresses.rb +6 -0
  120. data/db/migrate/20130314114048_change_addressable_associations_in_glysellin_addresses.rb +15 -0
  121. data/db/migrate/20130325113903_remove_address_ids_from_glysellin_orders.rb +11 -0
  122. data/db/seeds/shipping_carrier/rates/colissimo.csv +16 -0
  123. data/db/seeds/shipping_carrier/rates/lettre-max.csv +9 -0
  124. data/lib/active_model/model.rb +101 -0
  125. data/lib/generators/glysellin/install/USAGE +8 -0
  126. data/lib/generators/glysellin/install/install_generator.rb +50 -0
  127. data/lib/generators/glysellin/install/templates/initializer.rb +119 -0
  128. data/lib/generators/glysellin/install/templates/order_observer.rb +12 -0
  129. data/lib/generators/glysellin/install/utils.rb +11 -0
  130. data/lib/glysellin.rb +124 -0
  131. data/lib/glysellin/acts_as_sellable.rb +14 -0
  132. data/lib/glysellin/cart.rb +21 -0
  133. data/lib/glysellin/cart/address.rb +16 -0
  134. data/lib/glysellin/cart/adjustment.rb +17 -0
  135. data/lib/glysellin/cart/adjustment/base.rb +41 -0
  136. data/lib/glysellin/cart/adjustment/discount_code.rb +43 -0
  137. data/lib/glysellin/cart/adjustment/shipping_method.rb +31 -0
  138. data/lib/glysellin/cart/basket.rb +482 -0
  139. data/lib/glysellin/cart/customer.rb +36 -0
  140. data/lib/glysellin/cart/model_wrapper.rb +90 -0
  141. data/lib/glysellin/cart/nested_resource.rb +39 -0
  142. data/lib/glysellin/cart/payment_method.rb +8 -0
  143. data/lib/glysellin/cart/product.rb +16 -0
  144. data/lib/glysellin/cart/select.rb +31 -0
  145. data/lib/glysellin/cart/serializable.rb +30 -0
  146. data/lib/glysellin/cart/shipping_method.rb +8 -0
  147. data/lib/glysellin/discount_type_calculator.rb +7 -0
  148. data/lib/glysellin/discount_type_calculator/base.rb +30 -0
  149. data/lib/glysellin/discount_type_calculator/order_percentage.rb +16 -0
  150. data/lib/glysellin/engine.rb +14 -0
  151. data/lib/glysellin/engine/routes.rb +61 -0
  152. data/lib/glysellin/gateway.rb +16 -0
  153. data/lib/glysellin/gateway/atos.rb +111 -0
  154. data/lib/glysellin/gateway/base.rb +43 -0
  155. data/lib/glysellin/gateway/check.rb +34 -0
  156. data/lib/glysellin/gateway/paypal_integral.rb +71 -0
  157. data/lib/glysellin/helpers.rb +15 -0
  158. data/lib/glysellin/helpers/controller.rb +22 -0
  159. data/lib/glysellin/helpers/countries.rb +261 -0
  160. data/lib/glysellin/helpers/views.rb +28 -0
  161. data/lib/glysellin/product_methods.rb +66 -0
  162. data/lib/glysellin/products_list.rb +72 -0
  163. data/lib/glysellin/property_finder.rb +13 -0
  164. data/lib/glysellin/shipping_carrier.rb +14 -0
  165. data/lib/glysellin/shipping_carrier/base.rb +55 -0
  166. data/lib/glysellin/shipping_carrier/colissimo.rb +19 -0
  167. data/lib/glysellin/shipping_carrier/flat_rate.rb +19 -0
  168. data/lib/glysellin/shipping_carrier/free_shipping.rb +14 -0
  169. data/lib/glysellin/shipping_carrier/helpers/country_weight_table.rb +65 -0
  170. data/lib/glysellin/shipping_carrier/lettre_max.rb +19 -0
  171. data/lib/glysellin/version.rb +3 -0
  172. data/lib/tasks/glysellin_tasks.rake +37 -0
  173. metadata +341 -0
@@ -0,0 +1,36 @@
1
+ module Glysellin
2
+ module Cart
3
+ class Customer
4
+ include ModelWrapper
5
+ wraps :user, class_name: "::User",
6
+ attributes: [
7
+ :id, :email, :password, :password_confirmation, :billing_address,
8
+ :shipping_address, :use_another_address_for_shipping
9
+ ]
10
+
11
+ def initialize attributes = {}
12
+ if attributes.is_a?(User) && attributes.id
13
+ @id = attributes.id
14
+ @user = attributes
15
+ elsif (id = attributes["id"].presence)
16
+ @id = id
17
+ @user = User.find(id)
18
+ else
19
+ super attributes
20
+ end
21
+ end
22
+
23
+ def as_json
24
+ # raise "As json on customer = #{ id.inspect }" if id
25
+ if id
26
+ { id: user.id }
27
+ else
28
+ %w(email password password_confirmation).reduce({}) do |hash, attr|
29
+ hash[attr] = public_send(attr)
30
+ hash
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,90 @@
1
+ module Glysellin
2
+ module Cart
3
+ module ModelWrapper
4
+ extend ActiveSupport::Concern
5
+ include ActiveModel::Model
6
+
7
+ def initialize attrs = {}
8
+ assign_fields(attrs) if attrs.length > 0
9
+ end
10
+
11
+ def assign_fields attributes
12
+ if attributes.class.to_s == model.model_name
13
+ self.wrapped_model = attributes
14
+ elsif (id = attributes[:id].presence)
15
+ @id = id
16
+ self.wrapped_model = model.find(id)
17
+ else
18
+ attributes.each do |field, value|
19
+ key = field.to_s
20
+ if attribute_names.include?(key)
21
+ self.public_send(:"#{ key }=", value)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ def method_missing method, *args, &block
28
+ reader_method = method.to_s.gsub(/\=$/, "")
29
+
30
+ # If method is an attribute of the wrapped object
31
+ if attribute_names.include?(reader_method) || reader_method == "id"
32
+ wrapped_model.send(method, *args, &block)
33
+ else
34
+ super(method, *args, &block)
35
+ end
36
+ end
37
+
38
+ def valid?
39
+ wrapped_model.valid?
40
+ end
41
+
42
+ def errors
43
+ wrapped_model.errors
44
+ end
45
+
46
+ module ClassMethods
47
+ def wraps object_name, options = {}
48
+ key = object_name.to_s
49
+ # Try infer model_name if not given
50
+ model_name = options[:class_name] || key.camelize
51
+ attrs = (options[:attributes] || []).map(&:to_s)
52
+
53
+ class_eval <<-EVAL, __FILE__, __LINE__ + 1
54
+ attr_writer :#{ key }
55
+
56
+ # Fetch wanted attributes to be serialized
57
+ def attribute_names
58
+ #{ attrs.inspect }.presence ||
59
+ model._accessible_attributes[:default].select do |attr|
60
+ attr.presence
61
+ end
62
+ end
63
+
64
+ def #{ key }
65
+ @#{ key } ||= model.new
66
+ end
67
+
68
+ def model
69
+ #{ model_name }
70
+ end
71
+
72
+ def attributes
73
+ attribute_names.reduce({}) do |attrs, attr|
74
+ begin
75
+ attrs[attr] = public_send("\#{ attr }")
76
+ rescue NoMethodError
77
+ end
78
+ attrs
79
+ end
80
+ end
81
+
82
+ # Key agnostic accessor
83
+ def wrapped_model() #{ key } end
84
+ def wrapped_model=(val) self.#{ key } = val end
85
+ EVAL
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,39 @@
1
+ module Glysellin
2
+ module Cart
3
+ module NestedResource
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def nested_resource name, options = {}
8
+ key = name.to_s
9
+ model_name = options[:class_name] || key.camelize
10
+
11
+ class_eval <<-EVAL, __FILE__, __LINE__ + 1
12
+ def #{ key }_attributes=(attributes)
13
+ self.#{ key }.assign_fields(attributes)
14
+ end
15
+
16
+ def #{ key }
17
+ @#{ key } ||= #{ model_name }.new
18
+ end
19
+
20
+ def #{ key }=(attributes)
21
+ if attributes.is_a? Hash
22
+ if (id = attributes.with_indifferent_access[:id].presence)
23
+ @#{ key } = #{ model_name }.new(id: id)
24
+ else
25
+ self.#{ key }_attributes = attributes
26
+ end
27
+ elsif attributes.is_a? #{ model_name }
28
+ @#{ key } = #{ model_name }.new(attributes)
29
+ else
30
+ @#{ key } = attributes
31
+ end
32
+ end
33
+ EVAL
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,8 @@
1
+ module Glysellin
2
+ module Cart
3
+ class PaymentMethod
4
+ include ModelWrapper
5
+ wraps :payment_method, class_name: "Glysellin::PaymentMethod"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ module Glysellin
2
+ module Cart
3
+ class Product
4
+ attr_accessor :variant, :quantity
5
+
6
+ def initialize attrs
7
+ @variant = Glysellin::Variant.find(attrs[:id])
8
+ @quantity = attrs[:quantity]
9
+ end
10
+
11
+ def as_json
12
+ { id: variant.id, quantity: quantity }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ module Glysellin
2
+ module Cart
3
+ module Select
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def select name, options = {}
8
+ key = name.to_s
9
+ model_name = options[:class_name] || key.camelize
10
+
11
+ class_eval <<-EVAL, __FILE__, __LINE__ + 1
12
+ attr_accessor :#{ key }_id
13
+
14
+ def #{ key }
15
+ if @#{ key } && @#{ key }.id == #{ key }_id
16
+ @#{ key }
17
+ elsif #{ key }_id
18
+ @#{ key } = #{ model_name }.find(#{ key }_id)
19
+ end
20
+ end
21
+
22
+ def #{ key }=(object)
23
+ self.#{ key }_id = object.id
24
+ @#{ key } = object
25
+ end
26
+ EVAL
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ module Glysellin
2
+ module Cart
3
+ module Serializable
4
+ extend ActiveSupport::Concern
5
+
6
+ def as_json
7
+ self.class.attrs.reduce({}) do |hash, attribute|
8
+ hash[attribute] = send(attribute)
9
+ hash
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+ attr_writer :attrs
15
+
16
+ def attributes *attrs
17
+ self.attrs += attrs
18
+
19
+ attrs.each do |attribute|
20
+ attr_accessor attribute
21
+ end
22
+ end
23
+
24
+ def attrs
25
+ @attrs ||= []
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,8 @@
1
+ module Glysellin
2
+ module Cart
3
+ class ShippingMethod
4
+ include ModelWrapper
5
+ wraps :shipping_method, class_name: "Glysellin::ShippingMethod"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Glysellin
2
+ module DiscountTypeCalculator
3
+ end
4
+ end
5
+
6
+ require 'glysellin/discount_type_calculator/base'
7
+ require 'glysellin/discount_type_calculator/order_percentage'
@@ -0,0 +1,30 @@
1
+ module Glysellin
2
+ def self.discount_type_calculators
3
+ Hash[
4
+ DiscountTypeCalculator.discount_type_calculators_list.map do |dtc|
5
+ [dtc[:name], dtc[:discount_type_calculator]]
6
+ end
7
+ ]
8
+ end
9
+
10
+ module DiscountTypeCalculator
11
+ # List of available discount_type_calculators in the app
12
+ mattr_accessor :discount_type_calculators_list
13
+ @@discount_type_calculators_list = []
14
+
15
+ class Base
16
+ class << self
17
+ def register name, discount_type_calculator
18
+ DiscountTypeCalculator.discount_type_calculators_list << {
19
+ :name => name,
20
+ :discount_type_calculator => discount_type_calculator
21
+ }
22
+ end
23
+
24
+ def config
25
+ yield self
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ module Glysellin
2
+ module DiscountTypeCalculator
3
+ class OrderPercentage < Glysellin::DiscountTypeCalculator::Base
4
+ register 'order-percentage', self
5
+
6
+ def initialize order, value
7
+ @order = order
8
+ @value = (value.to_f / 100.0) # Convert to percentage
9
+ end
10
+
11
+ def calculate
12
+ @order.subtotal * @value
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ require 'glysellin/helpers'
2
+ require 'glysellin/engine/routes'
3
+
4
+ module Glysellin
5
+ class Engine < ::Rails::Engine
6
+
7
+ initializer "Include Helpers" do |app|
8
+ ActiveSupport.on_load :action_controller do
9
+ Helpers.include!
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,61 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+ def glysellin_at(mount_location, options = {})
4
+
5
+ controllers = parse_controllers(options)
6
+
7
+ scope mount_location do
8
+ resources :orders, controller: controllers[:orders], :only => [] do
9
+ collection do
10
+ get 'payment_response'
11
+ post 'gateway/:gateway', :action => 'gateway_response', :as => 'named_gateway_response'
12
+ match 'gateway/response/:type', :action => 'payment_response', :as => 'typed_payment_response'
13
+ end
14
+
15
+ member do
16
+ post 'gateway-response', :action => 'gateway_response', :as => 'gateway_response'
17
+ match 'payment_response'
18
+ end
19
+ end
20
+
21
+ resources :products, controller: controllers[:products] do
22
+ collection do
23
+ get 'taxonomy/:id', action: "filter", as: "filter"
24
+ end
25
+ end
26
+
27
+ resources :taxonomies, only: [] do
28
+ resources :products, only: [:index]
29
+ end
30
+
31
+ resource :cart, controller: controllers[:cart], only: [:show, :destroy] do
32
+ resources :products, controller: "glysellin/cart/products", only: [:create, :update, :destroy] do
33
+ collection do
34
+ put "contents/validate", action: "validate", as: "validate"
35
+ end
36
+ end
37
+ resource :discount_code, controller: "glysellin/cart/discount_code", only: [:update]
38
+ resource :addresses, controller: "glysellin/cart/addresses", only: [:update]
39
+ resource :shipping_method, controller: "glysellin/cart/shipping_method", only: [:update]
40
+ resource :payment_method, controller: "glysellin/cart/payment_method", only: [:update]
41
+ resource :state, controller: "glysellin/cart/state", only: [:show] do
42
+ get "state/:state", action: "show", as: "set"
43
+ end
44
+ end
45
+
46
+ get '/' => 'glysellin/products#index', as: 'shop'
47
+ end
48
+ end
49
+
50
+ # Allows user to define app controllers to handle glysellin routes
51
+ def parse_controllers options
52
+ defaults = {
53
+ orders: 'glysellin/orders',
54
+ products: 'glysellin/products',
55
+ cart: 'glysellin/cart'
56
+ }
57
+
58
+ defaults.merge(options)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,16 @@
1
+ if File.exists? 'glysellin/engine/routes'
2
+ require 'glysellin/gateway/base'
3
+ require 'glysellin/gateway/paypal_integral'
4
+ require 'glysellin/gateway/atos'
5
+ require 'glysellin/gateway/check'
6
+ else
7
+ require File.expand_path('../gateway/base', __FILE__)
8
+ require File.expand_path('../gateway/paypal_integral', __FILE__)
9
+ require File.expand_path('../gateway/atos', __FILE__)
10
+ require File.expand_path('../gateway/check', __FILE__)
11
+ end
12
+
13
+ module Glysellin
14
+ module Gateway
15
+ end
16
+ end
@@ -0,0 +1,111 @@
1
+ module Glysellin
2
+ module Gateway
3
+ class Atos < Glysellin::Gateway::Base
4
+ register 'atos', self
5
+
6
+ mattr_accessor :bin_path
7
+ @@bin_path = ''
8
+
9
+ mattr_accessor :merchant_id
10
+ @@merchant_id = ''
11
+
12
+ mattr_accessor :pathfile_path
13
+ @@pathfile_path = ''
14
+
15
+ mattr_accessor :merchant_country
16
+ @@merchant_country = 'fr'
17
+
18
+ mattr_accessor :capture_mode
19
+ @@capture_mode = 'AUTHOR_CAPTURE'
20
+
21
+ mattr_accessor :capture_days
22
+ @@capture_days = nil
23
+
24
+ attr_accessor :errors, :order
25
+
26
+ def initialize order
27
+ @order = order
28
+ @errors = []
29
+ end
30
+
31
+ class << self
32
+ # Extract order id from response data since it cannot be dynamically given via get URL
33
+ def parse_order_id data
34
+ data_param = Rack::Utils.parse_nested_query(data)['DATA']
35
+ log "Parse id from RAW POST : #{ data }"
36
+ log "Data param : #{ data_param }"
37
+ parse_atos_resp(data_param)[32].to_i
38
+ end
39
+
40
+ def parse_atos_resp data
41
+ # Prepare arguments
42
+ exec_chain = "message=#{ data } pathfile=#{ @@pathfile_path }"
43
+ bin_path = "#{ @@bin_path }/response"
44
+ # Call response program to get exclamation point separated payment response details
45
+ resp = `#{ bin_path } #{ exec_chain }`.split('!')
46
+ log "Reponse de atos : #{ resp } / Order id : #{ resp[32] }"
47
+ resp
48
+ end
49
+ end
50
+
51
+ def render_request_button
52
+ exec_chain = {
53
+ :merchant_id => @@merchant_id,
54
+ :merchant_country => @@merchant_country,
55
+ :capture_mode => @@capture_mode,
56
+ :pathfile => @@pathfile_path,
57
+ :data => @order.id,
58
+ :amount => (@order.total_price * 100).to_i,
59
+ :transaction_id => @order.payment.get_new_transaction_id
60
+ }.to_a.map { |item| item[0].to_s + '=' + item[1].to_s }.join(' ')
61
+
62
+ bin_path = "#{ @@bin_path }/request"
63
+
64
+ begin
65
+ results = `#{bin_path} #{exec_chain}`.split('!')
66
+ # If OS didn't want to exec program
67
+ rescue Errno::ENOEXEC => msg
68
+ results = []
69
+ end
70
+
71
+ if results.length == 0
72
+ result = "<div style=\"color:red\">#{ bin_path } #{ exec_chain }</div>"
73
+ # If exit code is 0, render payment buttons
74
+ elsif results[1].to_i >= 0
75
+ result = results[3]
76
+ # Else render debug informations
77
+ else
78
+ result = results[2]
79
+ end
80
+
81
+ # Render HTML button
82
+ { text: result.html_safe }
83
+ end
84
+
85
+ # Launch payment processing
86
+ def process_payment! post_data
87
+ results = self.class.parse_atos_resp(Rack::Utils.parse_nested_query(post_data)['DATA'])
88
+ # Réponse acceptée
89
+ valid = results[1].to_i == 0 && results[11].to_i == 0
90
+
91
+ log "Processing remote payment : #{ valid }"
92
+
93
+ result = valid ? @order.paid! : false
94
+
95
+ @order.save
96
+ result
97
+ end
98
+
99
+ # The response returned within "render" method in the OrdersController#gateway_response method
100
+ def response
101
+ { nothing: true }
102
+ end
103
+
104
+ protected
105
+
106
+ def shell_escape(str)
107
+ String(str).gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').gsub(/\n/, "'\n'").sub(/^$/, "''")
108
+ end
109
+ end
110
+ end
111
+ end