opensteam 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,34 @@
|
|
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
|
+
module Payment
|
19
|
+
|
20
|
+
|
21
|
+
class AdvancePayment < Base
|
22
|
+
self.display_name = "Advance Payment"
|
23
|
+
self.payment_id = :advance_payment
|
24
|
+
|
25
|
+
self.observers = []
|
26
|
+
|
27
|
+
def gateway
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,217 @@
|
|
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
|
+
module Payment
|
19
|
+
|
20
|
+
|
21
|
+
require 'active_merchant'
|
22
|
+
|
23
|
+
class CreditCardPayment < Base
|
24
|
+
self.display_name = "CreditCard Payment"
|
25
|
+
self.payment_id = :credit_card
|
26
|
+
|
27
|
+
#self.gateway_class = ActiveMerchant::Billing::BrainTreeGateway
|
28
|
+
self.gateway_class = nil #ActiveMerchant::Billing::BogusGateway
|
29
|
+
self.gateway_user = 'demo'
|
30
|
+
self.gateway_password = 'password'
|
31
|
+
self.observers = []
|
32
|
+
|
33
|
+
serialize :data
|
34
|
+
|
35
|
+
attr_accessor :credit_card
|
36
|
+
|
37
|
+
# validates_presence_of :credit_card
|
38
|
+
|
39
|
+
|
40
|
+
def initialize(*args, &block )
|
41
|
+
self.credit_card = ActiveMerchant::Billing::CreditCard.new
|
42
|
+
super( *args, &block )
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def gateway
|
47
|
+
self.class.gateway_class.new( :login => self.class.gateway_user, :password => self.class.gateway_password )
|
48
|
+
end
|
49
|
+
|
50
|
+
# inits a new credit card and assigns it to current payment object
|
51
|
+
def set_credit_card=(fields)
|
52
|
+
#self.credit_card = CreditCard.new( fields )
|
53
|
+
fields.update( :type => fields.delete(:brand) ) if fields[:brand]
|
54
|
+
self.credit_card = ActiveMerchant::Billing::CreditCard.new( fields )
|
55
|
+
self.data = { :number => self.credit_card.display_number,
|
56
|
+
:first_name => self.credit_card.first_name,
|
57
|
+
:last_name => self.credit_card.last_name }
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# authorize amount and credit_card at payment gateway
|
62
|
+
def authorize( amount = nil, options = {} )
|
63
|
+
self.amount = amount || self.order.total_price
|
64
|
+
#self.credit_card.decrypt_number
|
65
|
+
|
66
|
+
transactions.process( :action => :authorize, :amount => amount_in_cents ) do |gw|
|
67
|
+
gw.authorize( amount_in_cents, self.credit_card, options )
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
# capture amount from authorization
|
74
|
+
def capture( amount, authorization, options = {} )
|
75
|
+
self.amount = amount || self.order.total_price
|
76
|
+
|
77
|
+
transactions.process( :action => :capture, :amount => amount ) do |gw|
|
78
|
+
gw.capture( amount_in_cents, authorization, options )
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
# purchase amount from credit_card
|
85
|
+
def purchase( amount = nil, options = {} )
|
86
|
+
self.amount = amount || self.order.total_price
|
87
|
+
# self.credit_card.decrypt_number
|
88
|
+
|
89
|
+
process :purchase, amount_in_cents, self.credit_card, options
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def process action, amount, credit_card,options
|
99
|
+
transactions.process( :action => action, :amount => amount ) do |gw|
|
100
|
+
gw.__send__( action, amount, credit_card, options )
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
def validate
|
107
|
+
if credit_card
|
108
|
+
errors.add( :credit_card, "not valid" ) unless credit_card.valid?
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# charge credit card transaction
|
113
|
+
|
114
|
+
#
|
115
|
+
# response = gateway.purchase( amount_in_cents, credit_card )
|
116
|
+
#
|
117
|
+
# self.test = response.test?
|
118
|
+
# self.reference = response.authorization
|
119
|
+
# self.message = response.message
|
120
|
+
# self.receipt = response.receipt
|
121
|
+
#
|
122
|
+
# if !response.success?
|
123
|
+
# errors.add_to_base( self.message )
|
124
|
+
# return false
|
125
|
+
# end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
module States
|
131
|
+
|
132
|
+
module PaymentAuthorized
|
133
|
+
include Opensteam::StateLogic::Mod
|
134
|
+
end
|
135
|
+
|
136
|
+
module PaymentCaptured
|
137
|
+
include Opensteam::StateLogic::Mod
|
138
|
+
end
|
139
|
+
|
140
|
+
module PaymentDeclined
|
141
|
+
include Opensteam::StateLogic::Mod
|
142
|
+
end
|
143
|
+
|
144
|
+
module PaymentFailed
|
145
|
+
include Opensteam::StateLogic::Mod
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
# # CreditClass Model
|
152
|
+
# # persist CreditCards
|
153
|
+
# class CreditCard < ActiveRecord::Base
|
154
|
+
#
|
155
|
+
# include ActiveMerchant::Billing::CreditCardMethods
|
156
|
+
# include Opensteam::Security::Encryption
|
157
|
+
#
|
158
|
+
# cattr_accessor :password
|
159
|
+
# attr_accessor :number
|
160
|
+
#
|
161
|
+
# def verification_value? ; false ; end
|
162
|
+
#
|
163
|
+
#
|
164
|
+
# def to_xml options = {}
|
165
|
+
# super options.merge( :except => [ :data, :salt ] )
|
166
|
+
# end
|
167
|
+
#
|
168
|
+
#
|
169
|
+
# def encrypt_number
|
170
|
+
# self.data = encrypt( number, password, salt )
|
171
|
+
# end
|
172
|
+
#
|
173
|
+
#
|
174
|
+
# def decrypt_number
|
175
|
+
# self.number = decrypt( data, password, salt )
|
176
|
+
# end
|
177
|
+
#
|
178
|
+
#
|
179
|
+
# private
|
180
|
+
#
|
181
|
+
# before_create :store_last_digits, :generate_salt, :encrypt_number
|
182
|
+
# validates_presence_of :first_name, :last_name, :brand
|
183
|
+
#
|
184
|
+
# def store_last_digits
|
185
|
+
# self.last_digits = self.class.last_digits( number )
|
186
|
+
# end
|
187
|
+
#
|
188
|
+
# def generate_salt
|
189
|
+
# self.salt = [ rand(2**64 - 1)].pack("Q")
|
190
|
+
# end
|
191
|
+
#
|
192
|
+
# def validate
|
193
|
+
# errors.add( :year, "is invalid") unless valid_expiry_year?( year )
|
194
|
+
# errors.add( :month, "is invalid") unless valid_month?( month )
|
195
|
+
# # errors.add( :number, "is invalid") unless self.class.valid_number?( number )
|
196
|
+
# if password.blank?
|
197
|
+
# errors.add_to_base( "Unable to encrypt or decrypt data without password")
|
198
|
+
# end
|
199
|
+
# end
|
200
|
+
#
|
201
|
+
# end
|
202
|
+
#
|
203
|
+
#
|
204
|
+
#
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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
|
+
module Payment
|
19
|
+
|
20
|
+
|
21
|
+
class DirectDebitPayment < Base
|
22
|
+
self.display_name = "DirectDebit Payment"
|
23
|
+
self.payment_id = :direct_debit
|
24
|
+
|
25
|
+
self.observers = []
|
26
|
+
|
27
|
+
def gateway
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# authorize amount and credit_card at payment gateway
|
33
|
+
def authorize( amount = nil, options = {} )
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
# capture amount from authorization
|
38
|
+
def capture( amount, authorization, options = {} )
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# purchase amount from credit_card
|
43
|
+
def purchase( amount = nil, options = {} )
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
end
|
@@ -105,12 +105,6 @@ Used to either be included into a model or injected with the
|
|
105
105
|
|
106
106
|
|
107
107
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
108
|
|
115
109
|
# holds the properties the product is allowed to have
|
116
110
|
# used for view
|
@@ -144,7 +138,7 @@ Used to either be included into a model or injected with the
|
|
144
138
|
def property_errors=(a) @property_errors = a end
|
145
139
|
|
146
140
|
def is_available?
|
147
|
-
selected_inventories.
|
141
|
+
selected_inventories.active && selected_inventories.storage > 0
|
148
142
|
end
|
149
143
|
|
150
144
|
def products ; [] ; end
|
@@ -166,22 +160,29 @@ Used to either be included into a model or injected with the
|
|
166
160
|
#
|
167
161
|
# used in the admin-views, to update the product-property associations.
|
168
162
|
#
|
169
|
-
def
|
163
|
+
def set_properties2=(p)
|
170
164
|
save
|
171
165
|
|
166
|
+
|
172
167
|
if p.empty? && properties.empty?
|
173
168
|
inventories << Opensteam::InventoryBase::Inventory.create( :price => 0, :storage => 0, :active => 0 )
|
174
|
-
return
|
169
|
+
return
|
175
170
|
end
|
176
|
-
|
171
|
+
|
177
172
|
if p.kind_of? Hash
|
178
173
|
prop = {}
|
179
|
-
p.each_pair { |k,v|
|
174
|
+
p.each_pair { |k,v|
|
175
|
+
if ( pr = k.classify.constantize ).ancestors.include?( Opensteam::PropertyBase )
|
176
|
+
prop[ k.to_sym ] = v.collect { |x| pr.find( x ) }
|
177
|
+
else
|
178
|
+
raise Opensteam::Config::Errors::NotAProperty, "'#{k.classify}' is not a property"
|
179
|
+
end }
|
180
180
|
prop = prop.values.perm.collect(&:sort)
|
181
181
|
else
|
182
182
|
prop = p
|
183
183
|
end
|
184
184
|
|
185
|
+
|
185
186
|
inventories.each do |i|
|
186
187
|
i.destroy unless prop.include? i.properties.sort
|
187
188
|
end
|
@@ -191,6 +192,40 @@ Used to either be included into a model or injected with the
|
|
191
192
|
save
|
192
193
|
end
|
193
194
|
|
195
|
+
|
196
|
+
|
197
|
+
def set_properties= p
|
198
|
+
if p.empty? && properties.empty?
|
199
|
+
self.inventories.build( :price => 0, :storage => 0, :active => 0 )
|
200
|
+
return
|
201
|
+
end
|
202
|
+
|
203
|
+
if p.is_a? Hash
|
204
|
+
prop = {}
|
205
|
+
|
206
|
+
p.each_pair { |k,v|
|
207
|
+
if ( pr = k.classify.constantize ) < Opensteam::PropertyBase
|
208
|
+
prop[ k.to_sym ] = v.collect { |x| pr.find( x ) }
|
209
|
+
else
|
210
|
+
raise Opensteam::Config::Errors::NotAProperty, "'#{k.classify}' is not a property"
|
211
|
+
end }
|
212
|
+
prop = prop.values.perm.collect(&:sort)
|
213
|
+
else
|
214
|
+
prop = p
|
215
|
+
end
|
216
|
+
|
217
|
+
inventories.each do |i|
|
218
|
+
i.destroy unless prop.include? i.properties.sort
|
219
|
+
end
|
220
|
+
|
221
|
+
prop.each do |pp|
|
222
|
+
if self.inventories.by_properties( pp.is_a?( Array ) ? pp : [pp] ).empty?
|
223
|
+
# unless self.inventories.by_properties?( pp.is_a?( Array ) ? pp : [pp] )
|
224
|
+
self.inventories.build( :price => 0, :storage => 0, :active => 0, :properties => pp )
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
194
229
|
alias :properties= :set_properties=
|
195
230
|
|
196
231
|
|
@@ -198,7 +233,7 @@ Used to either be included into a model or injected with the
|
|
198
233
|
# For every property (or set of properties) an inventory-object is created (unless an inventory-object for the property (or set of properties) already exists).
|
199
234
|
def add_properties(prop)
|
200
235
|
prop.each do |pp|
|
201
|
-
unless inventories.exist_by_properties?( pp )
|
236
|
+
unless self.inventories.exist_by_properties?( pp.is_a?( Array ) ? pp : [pp] )
|
202
237
|
i = Opensteam::InventoryBase::Inventory.create( :price => 0, :storage => 0, :active => 0 )
|
203
238
|
i.properties << pp
|
204
239
|
inventories << i
|
@@ -210,6 +245,7 @@ Used to either be included into a model or injected with the
|
|
210
245
|
|
211
246
|
# delete properties from the current product
|
212
247
|
def del_properties(p)
|
248
|
+
p = Array(p)
|
213
249
|
return nil if p.empty?
|
214
250
|
return ( i = inventories( p ) ) ? i.collect(&:destroy) : nil ;
|
215
251
|
end
|
@@ -0,0 +1,54 @@
|
|
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
|
+
|
18
|
+
module Opensteam
|
19
|
+
|
20
|
+
|
21
|
+
# Security Module (Encryption, etc)
|
22
|
+
# (not in use right now)
|
23
|
+
module Security #:nodoc:
|
24
|
+
|
25
|
+
|
26
|
+
module Encryption
|
27
|
+
|
28
|
+
mattr_accessor :algorithm
|
29
|
+
|
30
|
+
self.algorithm = 'aes-256-cbc'
|
31
|
+
|
32
|
+
def encrypt( data, password, salt )
|
33
|
+
cipher = OpenSSL::Cipher::Cipher.new algorithm
|
34
|
+
cipher.encrypt
|
35
|
+
cipher.pkcs5_keyivgen( password, salt )
|
36
|
+
encrypted_data = cipher.update( data )
|
37
|
+
encrypted_data << cipher.final
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def decrypt( encrypted_data, password, salt )
|
42
|
+
cipher = OpenSSL::Cipher::Cipher.new( algorithm )
|
43
|
+
cipher.decrypt
|
44
|
+
cipher.pkcs5_keyivgen( password, salt )
|
45
|
+
data = cipher.update( encrypted_data )
|
46
|
+
data << cipher.final
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|