opensteam 0.9.2 → 0.9.3
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.
- data/CHANGELOG +53 -0
- data/README.rdoc +19 -10
- data/generators/opensteam/opensteam_generator.rb +27 -3
- data/generators/opensteam/templates/app/controllers/admin/configurations_controller.rb +85 -0
- data/generators/opensteam/templates/app/controllers/admin/inventories_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/admin/invoices_controller.rb +35 -4
- data/generators/opensteam/templates/app/controllers/admin/orders_controller.rb +5 -4
- data/generators/opensteam/templates/app/controllers/admin/shipments_controller.rb +6 -3
- data/generators/opensteam/templates/app/controllers/admin/shipping_rate_groups_controller.rb +76 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_groups_controller.rb +124 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_rules_controller.rb +19 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_zones_controller.rb +118 -0
- data/generators/opensteam/templates/app/controllers/admin/users_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/admin_controller.rb +20 -0
- data/generators/opensteam/templates/app/controllers/carts_controller.rb +118 -0
- data/generators/opensteam/templates/app/controllers/checkout_controller.rb +119 -79
- data/generators/opensteam/templates/app/controllers/profile_controller.rb +2 -4
- data/generators/opensteam/templates/app/controllers/searches_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/user_sessions_controller.rb +2 -1
- data/generators/opensteam/templates/app/controllers/users_controller.rb +10 -3
- data/generators/opensteam/templates/app/helpers/admin_helper.rb +15 -1
- data/generators/opensteam/templates/app/helpers/checkout_helper.rb +38 -0
- data/generators/opensteam/templates/app/helpers/webshop_helper.rb +6 -1
- data/generators/opensteam/templates/app/models/zone.rb +18 -0
- data/generators/opensteam/templates/app/views/admin/_menu.html.erb +18 -0
- data/generators/opensteam/templates/app/views/admin/catalog.html.erb +2 -3
- data/generators/opensteam/templates/app/views/admin/configurations/edit.html.erb +20 -0
- data/generators/opensteam/templates/app/views/admin/configurations/index.html.erb +22 -0
- data/generators/opensteam/templates/app/views/admin/configurations/new.html.erb +19 -0
- data/generators/opensteam/templates/app/views/admin/configurations/show.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/filters/_filter.html.erb +1 -1
- data/generators/opensteam/templates/app/views/admin/index.html.erb +0 -19
- data/generators/opensteam/templates/app/views/admin/inventories/edit.html.erb +10 -6
- data/generators/opensteam/templates/app/views/admin/inventories/new.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/inventories/show.html.erb +10 -6
- data/generators/opensteam/templates/app/views/admin/invoices/_invoice.html.erb +1 -0
- data/generators/opensteam/templates/app/views/admin/invoices/_invoice_fields.html.erb +52 -0
- data/generators/opensteam/templates/app/views/admin/invoices/new.html.erb +9 -37
- data/generators/opensteam/templates/app/views/admin/invoices/show.html.erb +10 -36
- data/generators/opensteam/templates/app/views/admin/invoices/show.pdf.prawn +59 -0
- data/generators/opensteam/templates/app/views/admin/order_config.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/order_items/_item_entry.html.erb +9 -0
- data/generators/opensteam/templates/app/views/admin/order_items/_items_table.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/orders/_order.html.erb +9 -9
- data/generators/opensteam/templates/app/views/admin/orders/_orders.html.erb +1 -1
- data/generators/opensteam/templates/app/views/admin/orders/show.html.erb +25 -9
- data/generators/opensteam/templates/app/views/admin/payment_types.html.erb +27 -0
- data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment.html.erb +26 -0
- data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment_info.html.erb +15 -0
- data/generators/opensteam/templates/app/views/admin/payments/_direct_debit_payment.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/shipments/new.html.erb +45 -30
- data/generators/opensteam/templates/app/views/admin/shipments/show.html.erb +3 -3
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_payment_addition.html.erb +12 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_rate.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/edit.html.erb +63 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/index.html.erb +28 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/new.html.erb +60 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/show.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/system.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_attributes.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups.html.erb +17 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups_row.html.erb +12 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_rule.html.erb +14 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/edit.html.erb +26 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/index.html.erb +8 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/new.html.erb +27 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/show.html.erb +28 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_attributes.html.erb +18 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zone_row.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zones.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/edit.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/index.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/new.html.erb +14 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/show.html.erb +15 -0
- data/generators/opensteam/templates/app/views/admin/users.html.erb +0 -1
- data/generators/opensteam/templates/app/views/admin/users/show.html.erb +10 -0
- data/generators/opensteam/templates/app/views/administration_mailer/order_customer.erb +1 -1
- data/generators/opensteam/templates/app/views/carts/_cart.html.erb +7 -0
- data/generators/opensteam/templates/app/views/carts/_cart_content.html.erb +45 -0
- data/generators/opensteam/templates/app/views/carts/create.rjs +3 -0
- data/generators/opensteam/templates/app/views/{cart → carts}/index.html.erb +0 -0
- data/generators/opensteam/templates/app/views/carts/update.rjs +11 -0
- data/generators/opensteam/templates/app/views/checkout/_address.html.erb +42 -0
- data/generators/opensteam/templates/app/views/checkout/_customer.html.erb +31 -0
- data/generators/opensteam/templates/app/views/checkout/_edit_checkout.html.erb +42 -0
- data/generators/opensteam/templates/app/views/checkout/_new_checkout.html.erb +44 -0
- data/generators/opensteam/templates/app/views/checkout/_shipping_buttons.html.erb +8 -0
- data/generators/opensteam/templates/app/views/checkout/edit.html.erb +7 -0
- data/generators/opensteam/templates/app/views/checkout/new.html.erb +11 -0
- data/generators/opensteam/templates/app/views/checkout/outro.html.erb +1 -4
- data/generators/opensteam/templates/app/views/checkout/show.html.erb +63 -0
- data/generators/opensteam/templates/app/views/common/_header_admin.html.erb +5 -0
- data/generators/opensteam/templates/app/views/layouts/admin.html.erb +28 -12
- data/generators/opensteam/templates/app/views/layouts/profile.html.erb +2 -2
- data/generators/opensteam/templates/app/views/layouts/webshop.html.erb +5 -4
- data/generators/opensteam/templates/app/views/payment/_advance_payment_payment.html.erb +1 -0
- data/generators/opensteam/templates/app/views/payment/_credit_card_payment.html.erb +37 -0
- data/generators/opensteam/templates/app/views/payment/_credit_card_payment_confirmation.html.erb +20 -0
- data/generators/opensteam/templates/app/views/payment/_direct_debit_payment.html.erb +5 -0
- data/generators/opensteam/templates/app/views/payment/_direct_debit_payment_confirmation.html.erb +5 -0
- data/generators/opensteam/templates/app/views/profile/index.html.erb +1 -1
- data/generators/opensteam/templates/app/views/profile/infos/edit.html.erb +20 -12
- data/generators/opensteam/templates/app/views/profile/infos/edit_password.html.erb +16 -12
- data/generators/opensteam/templates/app/views/profile/orders/_order.html.erb +1 -1
- data/generators/opensteam/templates/app/views/profile/orders/show.html.erb +10 -7
- data/generators/opensteam/templates/app/views/webshop/_inventory_content.html.erb +1 -0
- data/generators/opensteam/templates/app/views/webshop/show.html.erb +3 -1
- data/generators/opensteam/templates/config/initializers/init_states.rb +13 -24
- data/generators/opensteam/templates/config/initializers/opensteam.rb +41 -0
- data/generators/opensteam/templates/config/initializers/opensteam_model_tables.rb +49 -10
- data/generators/opensteam/templates/config/initializers/opensteam_security.rb +8 -0
- data/generators/opensteam/templates/config/initializers/payment_process.rb +37 -0
- data/generators/opensteam/templates/db/migrate/20080609095723_create_addresses.rb +8 -2
- data/generators/opensteam/templates/db/migrate/20080609095726_create_inventories.rb +6 -3
- data/generators/opensteam/templates/db/migrate/20080609095728_create_order_items.rb +12 -1
- data/generators/opensteam/templates/db/migrate/20080609095729_create_orders.rb +8 -12
- data/generators/opensteam/templates/db/migrate/20080609095730_create_payment_types.rb +2 -0
- data/generators/opensteam/templates/db/migrate/20080714131513_create_invoices.rb +2 -1
- data/generators/opensteam/templates/db/migrate/20080714131650_create_shipments.rb +3 -1
- data/generators/opensteam/templates/db/migrate/20080808075247_create_containers.rb +30 -0
- data/generators/opensteam/templates/db/migrate/20080808083011_create_container_items.rb +25 -0
- data/generators/opensteam/templates/db/migrate/20080812102727_create_tax_zones.rb +16 -0
- data/generators/opensteam/templates/db/migrate/20080812102858_create_tax_rules.rb +15 -0
- data/generators/opensteam/templates/db/migrate/20080812102956_create_tax_groups.rb +14 -0
- data/generators/opensteam/templates/db/migrate/20080831181436_create_configurations.rb +15 -0
- data/generators/opensteam/templates/db/migrate/20080903131506_create_payments.rb +22 -0
- data/generators/opensteam/templates/db/migrate/20080904133625_create_payment_transactions.rb +24 -0
- data/generators/opensteam/templates/db/migrate/20080916102341_create_zones.rb +19 -0
- data/generators/opensteam/templates/db/migrate/20080916134340_create_region_shipping_rates.rb +18 -0
- data/generators/opensteam/templates/db/migrate/20080916134523_create_shipping_rate_groups.rb +18 -0
- data/generators/opensteam/templates/db/migrate/20080916135226_create_shipping_payment_additions.rb +20 -0
- data/generators/opensteam/templates/db/migrate/20080916135228_init_opensteam_config.rb +60 -0
- data/generators/opensteam/templates/public/images/opensteam_black.jpg +0 -0
- data/generators/opensteam/templates/public/images/pdf.png +0 -0
- data/generators/opensteam/templates/public/images/shader.png +0 -0
- data/generators/opensteam/templates/public/index.html +1 -0
- data/generators/opensteam/templates/public/javascripts/opensteam.js +21 -21
- data/generators/opensteam/templates/public/stylesheets/opensteam_admin.css +291 -0
- data/generators/opensteam/templates/public/stylesheets/opensteam_white.css +47 -11
- data/generators/opensteam/templates/tasks/opensteam.rake +2 -12
- data/generators/opensteam/templates/test/fixtures/addresses.yml +26 -0
- data/generators/opensteam/templates/test/fixtures/configurations.yml +29 -0
- data/generators/opensteam/templates/test/fixtures/inventories.yml +32 -15
- data/generators/opensteam/templates/test/fixtures/profiles.yml +21 -0
- data/generators/opensteam/templates/test/fixtures/region_shipping_rates.yml +33 -0
- data/generators/opensteam/templates/test/fixtures/shipping_payment_additions.yml +91 -0
- data/generators/opensteam/templates/test/fixtures/shipping_rate_groups.yml +25 -0
- data/generators/opensteam/templates/test/fixtures/tax_groups.yml +13 -0
- data/generators/opensteam/templates/test/fixtures/tax_rules.yml +29 -0
- data/generators/opensteam/templates/test/fixtures/tax_zones.yml +33 -0
- data/generators/opensteam/templates/test/fixtures/users.yml +26 -0
- data/generators/opensteam/templates/test/fixtures/zones.yml +2707 -0
- data/generators/opensteam/templates/test/functional/carts_controller_test.rb +103 -0
- data/generators/opensteam/templates/test/test_helper.rb +38 -0
- data/generators/opensteam/templates/test/unit/container_test.rb +71 -0
- data/generators/opensteam/templates/test/unit/order_test.rb +93 -0
- data/generators/opensteam/templates/test/unit/payment_test.rb +220 -0
- data/generators/opensteam/templates/test/unit/product_test.rb +158 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/.gitignore +3 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/MIT-LICENSE +20 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/README +12 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/Rakefile +22 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/init.rb +6 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto.rb +13 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/action_controller.rb +47 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/base.rb +75 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/raw.rb +54 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/tasks/prawnto_tasks.rake +4 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/action_controller_test.rb +36 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/base_template_handler_test.rb +58 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/raw_template_handler_test.rb +163 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/template_handler_test_mocks.rb +83 -0
- data/generators/opensteam_product/templates/views/admin/_attributes.html.erb +8 -3
- data/generators/opensteam_product/templates/views/admin/_inventories.html.erb +2 -0
- data/lib/opensteam.rb +0 -1
- data/lib/opensteam/base.rb +2 -1
- data/lib/opensteam/checkout.rb +3 -12
- data/lib/opensteam/config.rb +50 -2
- data/lib/opensteam/container.rb +196 -0
- data/lib/opensteam/extension_base.rb +19 -1
- data/lib/opensteam/finder.rb +1 -1
- data/lib/opensteam/helpers/config_table_helper.rb +18 -6
- data/lib/opensteam/initializer.rb +24 -4
- data/lib/opensteam/inventory_base.rb +6 -1
- data/lib/opensteam/invoice_base.rb +12 -13
- data/lib/opensteam/money.rb +230 -0
- data/lib/opensteam/order_base.rb +122 -48
- data/lib/opensteam/payment.rb +225 -0
- data/lib/opensteam/payment/advance_payment.rb +34 -0
- data/lib/opensteam/payment/credit_card_payment.rb +217 -0
- data/lib/opensteam/payment/direct_debit_payment.rb +53 -0
- data/lib/opensteam/product_base.rb +48 -12
- data/lib/opensteam/security.rb +54 -0
- data/lib/opensteam/shipment_base.rb +214 -6
- data/lib/opensteam/shopping_cart.rb +20 -300
- data/lib/opensteam/state_logic.rb +5 -3
- data/lib/opensteam/state_machine.rb +8 -3
- data/lib/opensteam/user_base.rb +48 -6
- data/lib/opensteam/version.rb +1 -1
- metadata +122 -16
- data/generators/opensteam/templates/app/controllers/cart_controller.rb +0 -94
- data/generators/opensteam/templates/app/views/admin/orders/_event.html.erb +0 -5
- data/generators/opensteam/templates/app/views/admin/orders/_order_item.html.erb +0 -10
- data/generators/opensteam/templates/app/views/cart/_cart.html.erb +0 -8
- data/generators/opensteam/templates/app/views/cart/_cart_content.html.erb +0 -20
- data/generators/opensteam/templates/app/views/cart/update.rjs +0 -1
- data/generators/opensteam/templates/app/views/checkout/payment.html.erb +0 -8
- data/generators/opensteam/templates/app/views/checkout/shipping.html.erb +0 -45
- data/generators/opensteam/templates/app/views/checkout/show_cart.html.erb +0 -13
- data/generators/opensteam/templates/app/views/checkout/update_cart_content.rjs +0 -2
- data/generators/opensteam/templates/app/views/profile/orders/_order_item.html.erb +0 -10
- data/generators/opensteam/templates/db/migrate/20080609095725_create_dummy_users.rb +0 -21
- data/lib/opensteam/cart_base.rb +0 -227
data/lib/opensteam/order_base.rb
CHANGED
|
@@ -20,105 +20,172 @@ module Opensteam
|
|
|
20
20
|
# OrderBase Module
|
|
21
21
|
#
|
|
22
22
|
# defines all Order specific Classes
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
23
|
module OrderBase
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
|
|
26
|
+
# States Namespace
|
|
27
|
+
module States #:nodoc:
|
|
29
28
|
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
|
|
33
32
|
module OrderExtension
|
|
33
|
+
# checks if all items are finished (if state == :finished)
|
|
34
34
|
def all_finished? ; empty? ? false : collect(&:finished?).all? ; end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
module OrderItemsExtension
|
|
38
|
+
# checks if all items are shipped
|
|
38
39
|
def all_shipped? ; collect { |s| s.shipment != nil }.all? ; end
|
|
40
|
+
|
|
41
|
+
# checks if all items have an invoice
|
|
39
42
|
def all_invoiced? ; collect { |s| s.invoice != nil }.all? ; end
|
|
40
43
|
end
|
|
41
44
|
|
|
42
45
|
require 'uuidtools'
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
47
|
# Order Model
|
|
47
|
-
class Order <
|
|
48
|
+
class Order < Opensteam::Container::Base
|
|
48
49
|
include Opensteam::StateMachine
|
|
49
|
-
|
|
50
|
+
# include Opensteam::UUIDHelper
|
|
51
|
+
|
|
50
52
|
|
|
53
|
+
# order collection by given column (e.g. "containers.id" )
|
|
51
54
|
named_scope :order_by, lambda { |by| { :include => Order.osteam_configtable.default_include, :order => Array(by).join(",") , :conditions => "users.id = users.id" } }
|
|
52
|
-
named_scope :by_user, lambda { |user_id| { :include => [:customer ], :conditions => { :customer_id => user_id } } }
|
|
53
55
|
|
|
54
|
-
#
|
|
56
|
+
# get orders by given user
|
|
57
|
+
named_scope :by_user, lambda { |user_id| { :include => [:customer ], :conditions => { :user_id => user_id } } }
|
|
55
58
|
|
|
56
|
-
has_many :order_items, :class_name => 'Opensteam::OrderBase::OrderItem', :extend => OrderItemsExtension
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
#== ASSOCIATIONS
|
|
61
|
+
has_many :items,
|
|
62
|
+
:class_name => "Opensteam::Container::Item",
|
|
63
|
+
:foreign_key => "container_id",
|
|
64
|
+
:extend => OrderItemsExtension
|
|
65
|
+
|
|
66
|
+
belongs_to :customer,
|
|
67
|
+
:class_name => 'Opensteam::UserBase::User',
|
|
68
|
+
:foreign_key => 'user_id'
|
|
59
69
|
|
|
60
|
-
belongs_to :payment_address,
|
|
61
|
-
|
|
70
|
+
belongs_to :payment_address,
|
|
71
|
+
:class_name => 'Opensteam::UserBase::Address',
|
|
72
|
+
:foreign_key => 'payment_address_id'
|
|
73
|
+
|
|
74
|
+
belongs_to :shipping_address,
|
|
75
|
+
:class_name => 'Opensteam::UserBase::Address',
|
|
76
|
+
:foreign_key => 'shipping_address_id'
|
|
62
77
|
|
|
63
|
-
has_many :invoices,
|
|
78
|
+
has_many :invoices,
|
|
79
|
+
:class_name => 'Opensteam::InvoiceBase::Invoice',
|
|
80
|
+
:extend => OrderExtension
|
|
64
81
|
|
|
65
|
-
has_many :shipments,
|
|
82
|
+
has_many :shipments,
|
|
83
|
+
:class_name => 'Opensteam::ShipmentBase::Shipment',
|
|
84
|
+
:extend => OrderExtension
|
|
66
85
|
|
|
67
|
-
|
|
86
|
+
has_many :payments,
|
|
87
|
+
:class_name => 'Opensteam::Payment::Base' ,
|
|
88
|
+
:extend => Opensteam::Payment::OrderExtension,
|
|
89
|
+
:dependent => :destroy
|
|
68
90
|
|
|
69
|
-
# validations
|
|
70
|
-
validates_associated :customer, :payment_address, :shipping_address
|
|
71
91
|
|
|
92
|
+
#== VALIDATIONS
|
|
93
|
+
validates_presence_of :payment_type, :shipping_type
|
|
94
|
+
validates_associated :customer, :shipping_address, :payment_address
|
|
95
|
+
validates_associated :payments
|
|
72
96
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def self.per_page ; 3 ; end
|
|
102
|
+
|
|
103
|
+
# override to_xml method
|
|
104
|
+
def to_xml( options = {} ) #:nodoc:
|
|
105
|
+
super options.merge( :root => "orders" )
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
# update the calculated tax of all items and the total_tax, total_price of the container (order)
|
|
110
|
+
def update_price_and_tax!
|
|
111
|
+
country = shipping_address ? shipping_address.country : Opensteam::Config::DEFAULT_COUNTRY
|
|
112
|
+
|
|
113
|
+
items.each do |item|
|
|
114
|
+
item.update_attribute( :tax, item.calculate_tax( :country => country ) )
|
|
115
|
+
end
|
|
76
116
|
|
|
77
|
-
|
|
117
|
+
returning( self ) do |s|
|
|
118
|
+
s.total_price = items.collect(&:total_price).sum
|
|
119
|
+
s.total_tax = items.collect(&:tax).sum
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
alias :real_customer= :customer=
|
|
127
|
+
|
|
128
|
+
def guest_customer=( cust )
|
|
129
|
+
cust[:password] = cust[:password_confirmation] = "opensteam" unless cust[:password]
|
|
130
|
+
cust[:profile] = "Guest"
|
|
78
131
|
self.real_customer = Opensteam::UserBase::User.create( cust )
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
# self.real_customer = Customer.find_or_initialize_by_email( cust[:email] )
|
|
82
|
-
#
|
|
83
|
-
# self.real_customer = Opensteam::UserBase::Customer.find_or_create_by_email( cust[:email] )
|
|
84
|
-
# self.customer.update_attributes( { :firstname => cust[:firstname], :lastname => cust[:lastname] } )
|
|
85
132
|
end
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def existing_customer=(cust)
|
|
136
|
+
self.real_customer = Opensteam::UserBase::User.find( cust )
|
|
137
|
+
end
|
|
138
|
+
|
|
86
139
|
|
|
87
140
|
|
|
88
141
|
alias :real_payment_address= :payment_address=
|
|
89
142
|
# find or create payment-address and associate it with the order
|
|
90
|
-
def payment_address=
|
|
143
|
+
def payment_address= addr
|
|
91
144
|
self.real_payment_address = get_address( addr )
|
|
92
145
|
end
|
|
93
|
-
|
|
94
|
-
|
|
146
|
+
|
|
147
|
+
|
|
95
148
|
alias :real_shipping_address= :shipping_address=
|
|
96
149
|
# find or create shipping-address and associate it with the order
|
|
97
|
-
def shipping_address=
|
|
150
|
+
def shipping_address= addr
|
|
98
151
|
self.real_shipping_address = get_address( addr )
|
|
99
152
|
end
|
|
100
153
|
|
|
101
154
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
end
|
|
111
|
-
|
|
155
|
+
# DEPRECATED!!!
|
|
156
|
+
# def self.create_from_cart( cart )
|
|
157
|
+
#
|
|
158
|
+
# returning(create) do |order|
|
|
159
|
+
# cart.items.each do |v|
|
|
160
|
+
# v.container = order
|
|
161
|
+
# v.save
|
|
162
|
+
# end
|
|
163
|
+
# end
|
|
164
|
+
#
|
|
165
|
+
# end
|
|
112
166
|
|
|
113
167
|
|
|
168
|
+
|
|
114
169
|
private
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
170
|
+
|
|
171
|
+
# finds or initialize address
|
|
172
|
+
def get_address addr
|
|
173
|
+
Opensteam::UserBase::Address.find(:first, :conditions => addr ) ||
|
|
174
|
+
Opensteam::UserBase::Address.new( addr )
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# validates payment_type
|
|
178
|
+
# if payament_type == 'bogus', return true
|
|
179
|
+
def validate
|
|
180
|
+
return if self.payment_type == "bogus"
|
|
181
|
+
unless (p = Opensteam::Payment::Types.find_by_name( self.payment_type ) ) && p.active?
|
|
182
|
+
errors.add( :payment_type, "#{self.payment_type} currently not supported!")
|
|
183
|
+
end
|
|
118
184
|
end
|
|
119
185
|
|
|
120
186
|
|
|
121
187
|
|
|
188
|
+
|
|
122
189
|
end
|
|
123
190
|
|
|
124
191
|
|
|
@@ -137,11 +204,18 @@ module Opensteam
|
|
|
137
204
|
|
|
138
205
|
def self.new_item(i)
|
|
139
206
|
returning(self.new) do |li|
|
|
140
|
-
li.itemid = i.
|
|
207
|
+
li.itemid = i.item.id
|
|
141
208
|
li.quantity = i.quantity
|
|
142
|
-
li.inventory = i.
|
|
209
|
+
li.inventory = i.item
|
|
210
|
+
li.price = i.price
|
|
143
211
|
end
|
|
212
|
+
|
|
144
213
|
end
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
145
219
|
|
|
146
220
|
end
|
|
147
221
|
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# openSteam - http://www.opensteam.net
|
|
2
|
+
# Copyright (C) 2008 DiamondDogs Webconsulting
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; version 2 of the License.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
16
|
+
|
|
17
|
+
module Opensteam
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
module Payment #:nodoc:
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Default Extension for the PaymentTransaction Association in Opensteam::Payment::Base
|
|
24
|
+
#
|
|
25
|
+
# create a new payment_transaction object, yields the given block and save the response of the block
|
|
26
|
+
# in the current-transaction.
|
|
27
|
+
# The given block must return either a string (which is save in the transaction#message attribute) or
|
|
28
|
+
# an object with the following attributes/methods:
|
|
29
|
+
# success?, authorization, message, params
|
|
30
|
+
#
|
|
31
|
+
# The PaymentTransaction Model is basically used to wrap the response of an ActiveMerchant Gateway.
|
|
32
|
+
# The first parameter for the block must be a gateway. (See ActiveMerchant#Gateways for more information.)
|
|
33
|
+
module PaymentTransactionExtension
|
|
34
|
+
def process *args
|
|
35
|
+
|
|
36
|
+
args = args.first if args.is_a? Array
|
|
37
|
+
|
|
38
|
+
create do |t|
|
|
39
|
+
|
|
40
|
+
t.action = args[:action]
|
|
41
|
+
t.amount = args[:amount]
|
|
42
|
+
|
|
43
|
+
begin
|
|
44
|
+
response = yield t.payment.gateway
|
|
45
|
+
|
|
46
|
+
if response.is_a? String
|
|
47
|
+
t.message = response
|
|
48
|
+
break
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
t.success = response.success?
|
|
52
|
+
t.reference = response.authorization
|
|
53
|
+
t.message = response.message
|
|
54
|
+
t.params = response.params
|
|
55
|
+
t.test = t.payment.gateway ? t.payment.gateway.test? : true
|
|
56
|
+
|
|
57
|
+
rescue ActiveMerchant::ActiveMerchantError => e
|
|
58
|
+
t.success = false
|
|
59
|
+
t.reference = nil
|
|
60
|
+
t.message = e.message
|
|
61
|
+
t.params = {}
|
|
62
|
+
t.test = t.payment.gateway.test?
|
|
63
|
+
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# Association Extension for Order#Payment Association
|
|
74
|
+
module OrderExtension
|
|
75
|
+
|
|
76
|
+
# create payment_object (according to proxy_owner.payment_type)
|
|
77
|
+
def create_payment( attr = {}, &block )
|
|
78
|
+
# return unless proxy_owner.payment_type_valid?
|
|
79
|
+
proxy_target << Opensteam::Payment::Base[ proxy_owner.payment_type.to_sym].create( attr, &block )
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# build payment_object (according to proxy_owner.payment_type)
|
|
83
|
+
def build_payment( attr = {}, &block )
|
|
84
|
+
# return unless proxy_owner.payment_type_valid?
|
|
85
|
+
proxy_target << Opensteam::Payment::Base[ proxy_owner.payment_type.to_sym ].new( attr, &block )
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def all_captured?
|
|
89
|
+
empty? ? false : collect(&:payment_captured?).all? ;
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class Types < ActiveRecord::Base
|
|
97
|
+
self.table_name = "payment_types"
|
|
98
|
+
|
|
99
|
+
named_scope :active, { :conditions => { :active => true } }
|
|
100
|
+
validates_uniqueness_of :name
|
|
101
|
+
|
|
102
|
+
def enable! ; self.update_attribute :active, true ; end
|
|
103
|
+
def disable! ; self.update_attribute :active, false ; end
|
|
104
|
+
def active? ; self.active ; end
|
|
105
|
+
def toggle! ; self.active? ? self.disable! : self.enable! ; end
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class << self ;
|
|
109
|
+
|
|
110
|
+
def register_payment_types!
|
|
111
|
+
|
|
112
|
+
Opensteam::Payment::Base.payment_types.each do |p|
|
|
113
|
+
unless find_by_name( p.payment_id.to_s )
|
|
114
|
+
create( :name => p.payment_id.to_s, :active => false, :klass => p.to_s )
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# Base Class for all Payment Implementations
|
|
124
|
+
#
|
|
125
|
+
#
|
|
126
|
+
class Base < ActiveRecord::Base
|
|
127
|
+
self.table_name = "payments"
|
|
128
|
+
|
|
129
|
+
belongs_to :order, :class_name => 'Opensteam::OrderBase::Order'
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
has_many :transactions,
|
|
133
|
+
:class_name => 'Opensteam::Payment::PaymentTransaction',
|
|
134
|
+
:foreign_key => 'payment_id',
|
|
135
|
+
:extend => Opensteam::Payment::PaymentTransactionExtension,
|
|
136
|
+
:dependent => :destroy
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
include Opensteam::StateMachine
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
cattr_accessor :payment_types
|
|
144
|
+
@@payment_types = []
|
|
145
|
+
|
|
146
|
+
# the gateway class to use
|
|
147
|
+
class_inheritable_accessor :gateway_class
|
|
148
|
+
|
|
149
|
+
# the gateway login
|
|
150
|
+
class_inheritable_accessor :gateway_user
|
|
151
|
+
|
|
152
|
+
# the gateway password
|
|
153
|
+
class_inheritable_accessor :gateway_password
|
|
154
|
+
|
|
155
|
+
class_inheritable_accessor :display_name
|
|
156
|
+
self.display_name = 'Payment Base Class'
|
|
157
|
+
|
|
158
|
+
class_inheritable_accessor :display_description
|
|
159
|
+
self.display_description = 'Base Class for all Payment Implementations'
|
|
160
|
+
|
|
161
|
+
class_inheritable_accessor :payment_id
|
|
162
|
+
self.payment_id = :base
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
class << self
|
|
166
|
+
|
|
167
|
+
def inherited(sub) #:nodoc:
|
|
168
|
+
@@payment_types << sub
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# retrieve a payment-implementation class using the :payment_id
|
|
172
|
+
# Ex:
|
|
173
|
+
# class CreditCardPayment < Opensteam::Payment::Base
|
|
174
|
+
# self.payment_id = :credit_card
|
|
175
|
+
# end
|
|
176
|
+
#
|
|
177
|
+
# Opensteam::Payment::Base[ :credit_card ] # => CreditCardPayment
|
|
178
|
+
#
|
|
179
|
+
def [](payment_id)
|
|
180
|
+
@@payment_types.find { |t| t.payment_id.to_sym == payment_id.to_sym }
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def new_with_type( *attr, &block )
|
|
186
|
+
if( h = attr.first).is_a? Hash and (type = h["type"] || h[:type] ) and ( klass = type.constantize ) != self
|
|
187
|
+
raise "#{klass} is not a subclass of #{self}" unless klass < self
|
|
188
|
+
return klass.new( *attr, &block )
|
|
189
|
+
end
|
|
190
|
+
new_without_type( *attr, &block )
|
|
191
|
+
end
|
|
192
|
+
alias_method_chain :new, :type
|
|
193
|
+
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
private
|
|
197
|
+
|
|
198
|
+
# returns the current amount in cents
|
|
199
|
+
def amount_in_cents
|
|
200
|
+
( amount * 100 ).to_i
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
class PaymentTransaction < ActiveRecord::Base
|
|
212
|
+
belongs_to :payment, :class_name => 'Opensteam::Payment::Base'
|
|
213
|
+
serialize :params
|
|
214
|
+
|
|
215
|
+
def action= a
|
|
216
|
+
self[:action] = a.to_s
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
end
|