erp_commerce 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/GPL-3-LICENSE +674 -0
- data/README.rdoc +2 -0
- data/Rakefile +32 -0
- data/app/assets/javascripts/erp_commerce/application.js +9 -0
- data/app/assets/stylesheets/erp_commerce/application.css +7 -0
- data/app/controllers/erp_commerce/application_controller.rb +4 -0
- data/app/helpers/erp_commerce/application_helper.rb +4 -0
- data/app/models/credit_card.rb +54 -0
- data/app/models/credit_card_account.rb +4 -0
- data/app/models/credit_card_account_party_role.rb +8 -0
- data/app/models/credit_card_account_purpose.rb +6 -0
- data/app/models/credit_card_token.rb +12 -0
- data/app/models/extensions/charge_line.rb +3 -0
- data/app/models/extensions/currency.rb +3 -0
- data/app/models/extensions/financial_txn.rb +3 -0
- data/app/models/extensions/order_txn.rb +3 -0
- data/app/models/extensions/party.rb +21 -0
- data/app/models/extensions/product_instance.rb +5 -0
- data/app/models/extensions/product_type.rb +3 -0
- data/app/models/fee.rb +7 -0
- data/app/models/fee_type.rb +4 -0
- data/app/models/payment.rb +38 -0
- data/app/models/payment_gateway.rb +4 -0
- data/app/models/payment_gateway_action.rb +2 -0
- data/app/models/price.rb +25 -0
- data/app/models/price_component.rb +8 -0
- data/app/models/price_component_type.rb +3 -0
- data/app/models/pricing_plan.rb +37 -0
- data/app/models/pricing_plan_assignment.rb +6 -0
- data/app/models/pricing_plan_component.rb +36 -0
- data/app/models/valid_price_plan_component.rb +8 -0
- data/app/views/layouts/erp_commerce/application.html.erb +14 -0
- data/app/widgets/orders/base.rb +40 -0
- data/app/widgets/orders/javascript/orders.js +11 -0
- data/app/widgets/orders/views/index.html.erb +63 -0
- data/app/widgets/product_catalog/base.rb +56 -0
- data/app/widgets/product_catalog/javascript/product_catalog.js +62 -0
- data/app/widgets/product_catalog/views/add_to_cart.html.erb +10 -0
- data/app/widgets/product_catalog/views/index.html.erb +69 -0
- data/app/widgets/product_catalog/views/show.html.erb +23 -0
- data/app/widgets/shopping_cart/base.rb +178 -0
- data/app/widgets/shopping_cart/javascript/shopping_cart.js +107 -0
- data/app/widgets/shopping_cart/views/cart_items.html.erb +83 -0
- data/app/widgets/shopping_cart/views/confirmation.html.erb +10 -0
- data/app/widgets/shopping_cart/views/demographics.html.erb +142 -0
- data/app/widgets/shopping_cart/views/login.html.erb +1 -0
- data/app/widgets/shopping_cart/views/payment.html.erb +81 -0
- data/app/widgets/shopping_cart/views/price_summary.html.erb +4 -0
- data/config/routes.rb +2 -0
- data/db/data_migrations/20101011152441_payment_gateway_actions.rb +27 -0
- data/db/migrate/20100823174238_erp_commerce_base.rb +174 -0
- data/db/migrate/20100913154134_setup_payments.rb +57 -0
- data/db/migrate/20101103132342_pricing_migrations.rb +169 -0
- data/db/migrate/20110921150854_create_fees.rb +50 -0
- data/lib/erp_commerce/active_merchant_wrappers/brain_tree_gateway_wrapper.rb +66 -0
- data/lib/erp_commerce/active_merchant_wrappers/credit_card_validation.rb +34 -0
- data/lib/erp_commerce/active_merchant_wrappers.rb +2 -0
- data/lib/erp_commerce/engine.rb +15 -0
- data/lib/erp_commerce/extensions/active_record/acts_as_fee.rb +64 -0
- data/lib/erp_commerce/extensions/active_record/acts_as_priceable.rb +57 -0
- data/lib/erp_commerce/extensions.rb +2 -0
- data/lib/erp_commerce/order_helper.rb +254 -0
- data/lib/erp_commerce/version.rb +3 -0
- data/lib/erp_commerce.rb +8 -0
- data/lib/tasks/erp_commerce_tasks.rake +4 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +49 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +8 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/spec.rb +27 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/models/credit_card_account_party_role_spec.rb +11 -0
- data/spec/models/credit_card_account_purpose_spec.rb +11 -0
- data/spec/models/credit_card_account_spec.rb +11 -0
- data/spec/models/credit_card_spec.rb +11 -0
- data/spec/models/fee_spec.rb +11 -0
- data/spec/models/fee_type_spec.rb +11 -0
- data/spec/models/payment_gateway_action_spec.rb +11 -0
- data/spec/models/payment_gateway_spec.rb +11 -0
- data/spec/models/payment_spec.rb +11 -0
- data/spec/models/price_component_spec.rb +11 -0
- data/spec/models/price_component_type_spec.rb +11 -0
- data/spec/models/price_spec.rb +11 -0
- data/spec/models/pricing_plan_assignment_spec.rb +11 -0
- data/spec/models/pricing_plan_component_spec.rb +11 -0
- data/spec/models/pricing_plan_spec.rb +11 -0
- data/spec/models/valid_price_plan_component_spec.rb +11 -0
- data/spec/spec_helper.rb +60 -0
- metadata +285 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
<div id="<%=widget_result_id%>">
|
2
|
+
<h2>What you're buying...</h2>
|
3
|
+
<table id="products-view">
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Product</th>
|
7
|
+
<th>Description</th>
|
8
|
+
<th>Quantity</th>
|
9
|
+
<th>Total</th>
|
10
|
+
<th>Remove</th>
|
11
|
+
</tr>
|
12
|
+
</thead>
|
13
|
+
<tbody>
|
14
|
+
<% @order.order_line_items.each do |order_line_item| %>
|
15
|
+
<tr class="product-wrap">
|
16
|
+
<td>
|
17
|
+
<div><img src="<%=order_line_item.product_type.images.empty? ? '/images/img_blank.png' : order_line_item.product_type.images.first.data.url%>" alt="Product Image" /></div>
|
18
|
+
<div>
|
19
|
+
<span><%= raw order_line_item.product_type.description %></span><br/>
|
20
|
+
</div>
|
21
|
+
</td>
|
22
|
+
<td><%= raw order_line_item.product_type.descriptions.find_by_internal_identifier('long_description').description%></td>
|
23
|
+
<td>1</td>
|
24
|
+
<td><%=link_to_remote 'Remove', build_widget_url(:remove_from_cart, order_line_item.id)%></td>
|
25
|
+
<td><span><%=order_line_item.product_type.get_current_simple_amount_with_currency.nil? ? 'no price set' : order_line_item.product_type.get_current_simple_amount_with_currency%></span></td>
|
26
|
+
</tr>
|
27
|
+
<%end%>
|
28
|
+
</tbody>
|
29
|
+
</table>
|
30
|
+
<hr/>
|
31
|
+
<div style="text-align:right;"><h2>Total <%=@price%></h2></div>
|
32
|
+
<hr/>
|
33
|
+
<%= form_remote_tag build_widget_url(:checkout_finalize), :id => 'checkout_finalize_form' do %>
|
34
|
+
<div class="form_settings">
|
35
|
+
<h2>Step 3 of 3 Pay for it...</h2>
|
36
|
+
<div id="errors" style="color:red">
|
37
|
+
<%=raw @message%>
|
38
|
+
</div>
|
39
|
+
<br/>
|
40
|
+
<p>
|
41
|
+
<span>First Name</span>
|
42
|
+
<%= text_field_tag :first_name, params[:first_name] %>
|
43
|
+
</p>
|
44
|
+
<p>
|
45
|
+
<span>Last Name</span>
|
46
|
+
<%= text_field_tag :last_name, params[:last_name] %>
|
47
|
+
</p>
|
48
|
+
<p>
|
49
|
+
<span>Credit Card Number</span>
|
50
|
+
<%= text_field_tag :card_number, params[:card_number] %>
|
51
|
+
</p>
|
52
|
+
<p>
|
53
|
+
<span>Expiration Month</span>
|
54
|
+
<%= select_tag(:exp_month,
|
55
|
+
options_for_select([["1 - January", 1],
|
56
|
+
["2 - Febuary", 2],
|
57
|
+
["3 - March",3],
|
58
|
+
["4 - April",4],
|
59
|
+
["5 - May",5],
|
60
|
+
["6 - June",6],
|
61
|
+
["7 - July",7],
|
62
|
+
["8 - August",8],
|
63
|
+
["9 - September",9],
|
64
|
+
["10 - October",10],
|
65
|
+
["11 - November",11],
|
66
|
+
["12 - December",12]], params[:exp_month])) %>
|
67
|
+
</p>
|
68
|
+
<p>
|
69
|
+
<span>Expiration Year</span>
|
70
|
+
<%= select_tag(:exp_year, options_for_select((0..30).collect{|addition| Date.today.year + addition}, params[:exp_year])) %>
|
71
|
+
</p>
|
72
|
+
<p>
|
73
|
+
<span>Card Security Code</span>
|
74
|
+
<%= text_field_tag :cvvs, params[:cvvs] %>
|
75
|
+
</p>
|
76
|
+
<p style="padding-top: 15px">
|
77
|
+
<%= submit_tag "Purchase", :disable_with => "Please wait...", :class => "submit", :style => 'margin:0px;' %> | <a href="<%=@products_url%>">Back to store</a>
|
78
|
+
</p>
|
79
|
+
</div>
|
80
|
+
<%end%>
|
81
|
+
</div>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class PaymentGatewayActions
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
PaymentGatewayAction.create(
|
5
|
+
:internal_identifier => 'capture',
|
6
|
+
:description => 'capture'
|
7
|
+
)
|
8
|
+
|
9
|
+
PaymentGatewayAction.create(
|
10
|
+
:internal_identifier => 'authorize',
|
11
|
+
:description => 'Authorize'
|
12
|
+
)
|
13
|
+
|
14
|
+
PaymentGatewayAction.create(
|
15
|
+
:internal_identifier => 'full_reverse_of_authorization',
|
16
|
+
:description => 'Full Reverse Of Authorization'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.down
|
21
|
+
['sale','void_sale','authorize'].each do |iid|
|
22
|
+
type = PaymentGatewayAction.find_by_internal_identifier(iid)
|
23
|
+
type.destroy unless type.nil?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
class ErpCommerceBase < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
#tables
|
4
|
+
unless table_exists?(:credit_cards)
|
5
|
+
create_table :credit_cards do |t|
|
6
|
+
|
7
|
+
t.column :crypted_private_card_number, :string
|
8
|
+
t.column :expiration_month, :integer
|
9
|
+
t.column :expiration_year, :integer
|
10
|
+
|
11
|
+
t.column :description, :string
|
12
|
+
t.column :first_name_on_card, :string
|
13
|
+
t.column :last_name_on_card, :string
|
14
|
+
t.column :card_type, :string
|
15
|
+
|
16
|
+
t.column :postal_address_id, :integer
|
17
|
+
t.column :credit_card_account_party_role_id, :integer
|
18
|
+
t.column :credit_card_account_purpose_id, :integer
|
19
|
+
t.column :credit_card_token, :string
|
20
|
+
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
unless table_exists?(:credit_card_accounts)
|
26
|
+
create_table :credit_card_accounts do |t|
|
27
|
+
|
28
|
+
t.timestamps
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
unless table_exists?(:credit_card_account_party_roles)
|
33
|
+
create_table :credit_card_account_party_roles do |t|
|
34
|
+
t.column :credit_card_account_id, :integer
|
35
|
+
t.column :role_type_id, :integer
|
36
|
+
t.column :party_id, :integer
|
37
|
+
|
38
|
+
t.timestamps
|
39
|
+
end
|
40
|
+
|
41
|
+
add_index :credit_card_account_party_roles, :credit_card_account_id
|
42
|
+
add_index :credit_card_account_party_roles, :role_type_id
|
43
|
+
add_index :credit_card_account_party_roles, :party_id
|
44
|
+
end
|
45
|
+
|
46
|
+
unless table_exists?(:credit_card_account_purposes)
|
47
|
+
create_table :credit_card_account_purposes do |t|
|
48
|
+
|
49
|
+
t.column :parent_id, :integer
|
50
|
+
t.column :lft, :integer
|
51
|
+
t.column :rgt, :integer
|
52
|
+
|
53
|
+
#custom columns go here
|
54
|
+
|
55
|
+
t.column :description, :string
|
56
|
+
t.column :comments, :string
|
57
|
+
|
58
|
+
t.column :internal_identifier, :string
|
59
|
+
t.column :external_identifier, :string
|
60
|
+
t.column :external_id_source, :string
|
61
|
+
|
62
|
+
t.timestamps
|
63
|
+
end
|
64
|
+
end
|
65
|
+
#end tables
|
66
|
+
|
67
|
+
#columns
|
68
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('payment_gateway_txn_id')
|
69
|
+
add_column :order_txns, :payment_gateway_txn_id, :string
|
70
|
+
end
|
71
|
+
|
72
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('credit_card_id')
|
73
|
+
add_column :order_txns, :credit_card_id, :integer
|
74
|
+
end
|
75
|
+
|
76
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('bill_to_first_name')
|
77
|
+
add_column :order_txns, :bill_to_first_name, :string
|
78
|
+
end
|
79
|
+
|
80
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('bill_to_last_name')
|
81
|
+
add_column :order_txns, :bill_to_last_name, :string
|
82
|
+
end
|
83
|
+
|
84
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('bill_to_address_line_1')
|
85
|
+
add_column :order_txns, :bill_to_address_line_1, :string
|
86
|
+
end
|
87
|
+
|
88
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('bill_to_address_line_2')
|
89
|
+
add_column :order_txns, :bill_to_address_line_2, :string
|
90
|
+
end
|
91
|
+
|
92
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('bill_to_city')
|
93
|
+
add_column :order_txns, :bill_to_city, :string
|
94
|
+
end
|
95
|
+
|
96
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('bill_to_state')
|
97
|
+
add_column :order_txns, :bill_to_state, :string
|
98
|
+
end
|
99
|
+
|
100
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('bill_to_postal_code')
|
101
|
+
add_column :order_txns, :bill_to_postal_code, :string
|
102
|
+
end
|
103
|
+
|
104
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('bill_to_country')
|
105
|
+
add_column :order_txns, :bill_to_country, :string
|
106
|
+
end
|
107
|
+
|
108
|
+
unless columns(:order_txns).collect {|c| c.name}.include?('bill_to_country_name')
|
109
|
+
rename_column :order_txns, :bill_to_country, :bill_to_country_name
|
110
|
+
rename_column :order_txns, :ship_to_country, :ship_to_country_name
|
111
|
+
add_column :order_txns, :bill_to_country, :string
|
112
|
+
add_column :order_txns, :ship_to_country, :string
|
113
|
+
end
|
114
|
+
#end
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.down
|
118
|
+
|
119
|
+
if columns(:order_txns).collect {|c| c.name}.include?('payment_gateway_txn_id')
|
120
|
+
remove_column :order_txns, :payment_gateway_txn_id
|
121
|
+
end
|
122
|
+
|
123
|
+
if columns(:order_txns).collect {|c| c.name}.include?('credit_card_id')
|
124
|
+
remove_column :order_txns, :credit_card_id, :integer
|
125
|
+
end
|
126
|
+
|
127
|
+
if columns(:order_txns).collect {|c| c.name}.include?('bill_to_first_name')
|
128
|
+
remove_column :order_txns, :bill_to_first_name, :string
|
129
|
+
end
|
130
|
+
|
131
|
+
if columns(:order_txns).collect {|c| c.name}.include?('bill_to_last_name')
|
132
|
+
remove_column :order_txns, :bill_to_last_name, :string
|
133
|
+
end
|
134
|
+
|
135
|
+
if columns(:order_txns).collect {|c| c.name}.include?('bill_to_address')
|
136
|
+
remove_column :order_txns, :bill_to_address, :string
|
137
|
+
end
|
138
|
+
|
139
|
+
if columns(:order_txns).collect {|c| c.name}.include?('bill_to_city')
|
140
|
+
remove_column :order_txns, :bill_to_city, :string
|
141
|
+
end
|
142
|
+
|
143
|
+
if columns(:order_txns).collect {|c| c.name}.include?('bill_to_state')
|
144
|
+
remove_column :order_txns, :bill_to_state, :string
|
145
|
+
end
|
146
|
+
|
147
|
+
if columns(:order_txns).collect {|c| c.name}.include?('bill_to_postal_code')
|
148
|
+
remove_column :order_txns, :bill_to_postal_code, :string
|
149
|
+
end
|
150
|
+
|
151
|
+
if columns(:order_txns).collect {|c| c.name}.include?('bill_to_country')
|
152
|
+
remove_column :order_txns, :bill_to_country, :string
|
153
|
+
end
|
154
|
+
|
155
|
+
if columns(:order_txns).collect {|c| c.name}.include?('bill_to_country_name')
|
156
|
+
remove_column :order_txns, :bill_to_country, :bill_to_country_name
|
157
|
+
remove_column :order_txns, :ship_to_country, :ship_to_country_name
|
158
|
+
end
|
159
|
+
|
160
|
+
#tables
|
161
|
+
drop_tables = [
|
162
|
+
:credit_cards,
|
163
|
+
:credit_card_accounts,
|
164
|
+
:credit_card_account_party_roles,
|
165
|
+
:credit_card_account_purposes
|
166
|
+
]
|
167
|
+
drop_tables.each do |table|
|
168
|
+
if table_exists?(table)
|
169
|
+
drop_table table
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class SetupPayments < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
|
4
|
+
unless table_exists?(:payments)
|
5
|
+
create_table :payments do |t|
|
6
|
+
|
7
|
+
t.column :success, :boolean
|
8
|
+
t.column :reference_number, :string
|
9
|
+
t.column :financial_txn_id, :integer
|
10
|
+
t.column :current_state, :string
|
11
|
+
t.column :authorization_code, :string
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :payments, :financial_txn_id
|
17
|
+
end
|
18
|
+
|
19
|
+
unless table_exists?(:payment_gateways)
|
20
|
+
create_table :payment_gateways do |t|
|
21
|
+
|
22
|
+
t.column :params, :string
|
23
|
+
t.column :payment_gateway_action_id, :integer
|
24
|
+
t.column :payment_id, :integer
|
25
|
+
t.column :response, :string
|
26
|
+
|
27
|
+
t.timestamps
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
unless table_exists?(:payment_gateway_actions)
|
32
|
+
create_table :payment_gateway_actions do |t|
|
33
|
+
|
34
|
+
t.column :internal_identifier, :string
|
35
|
+
t.column :description, :string
|
36
|
+
|
37
|
+
t.timestamps
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
add_index :payment_gateway_actions, :internal_identifier
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.down
|
45
|
+
drop_tables = [
|
46
|
+
:payments,
|
47
|
+
:payment_gateways,
|
48
|
+
:payment_gateway_actions
|
49
|
+
]
|
50
|
+
drop_tables.each do |table|
|
51
|
+
if table_exists?(table)
|
52
|
+
drop_table table
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
class PricingMigrations < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
|
4
|
+
#tables
|
5
|
+
unless table_exists?(:price_component_types)
|
6
|
+
create_table :price_component_types do |t|
|
7
|
+
|
8
|
+
t.string :description
|
9
|
+
t.string :internal_identifier
|
10
|
+
t.string :external_identifier
|
11
|
+
t.string :external_id_source
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
unless table_exists?(:pricing_plans)
|
18
|
+
create_table :pricing_plans do |t|
|
19
|
+
|
20
|
+
t.string :description
|
21
|
+
t.string :comments
|
22
|
+
|
23
|
+
t.string :internal_identifier
|
24
|
+
|
25
|
+
t.string :external_identifier
|
26
|
+
t.string :external_id_source
|
27
|
+
|
28
|
+
t.date :from_date
|
29
|
+
t.date :thru_date
|
30
|
+
|
31
|
+
#this is here as a placeholder for an 'interpreter' or 'rule' pattern
|
32
|
+
t.string :matching_rules
|
33
|
+
#this is here as a placeholder for an 'interpreter' or 'rule' pattern
|
34
|
+
t.string :pricing_calculation
|
35
|
+
|
36
|
+
#support for simple assignment of a single money amount
|
37
|
+
t.boolean :is_simple_amount
|
38
|
+
t.integer :currency_id
|
39
|
+
t.float :money_amount
|
40
|
+
|
41
|
+
t.timestamps
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
unless table_exists?(:pricing_plan_components)
|
46
|
+
create_table :pricing_plan_components do |t|
|
47
|
+
|
48
|
+
t.integer :price_component_type_id
|
49
|
+
t.string :description
|
50
|
+
t.string :comments
|
51
|
+
|
52
|
+
t.string :internal_identifier
|
53
|
+
t.string :external_identifier
|
54
|
+
t.string :external_id_source
|
55
|
+
|
56
|
+
|
57
|
+
#this is here as a placeholder for an 'interpreter' or 'rule' pattern
|
58
|
+
t.string :matching_rules
|
59
|
+
#this is here as a placeholder for an 'interpreter' or 'rule' pattern
|
60
|
+
t.string :pricing_calculation
|
61
|
+
|
62
|
+
#support for simple assignment of a single money amount
|
63
|
+
t.boolean :is_simple_amount
|
64
|
+
t.integer :currency_id
|
65
|
+
t.float :money_amount
|
66
|
+
|
67
|
+
t.timestamps
|
68
|
+
|
69
|
+
end
|
70
|
+
add_index :pricing_plan_components, :price_component_type_id
|
71
|
+
end
|
72
|
+
|
73
|
+
unless table_exists?(:valid_price_plan_components)
|
74
|
+
create_table :valid_price_plan_components do |t|
|
75
|
+
|
76
|
+
t.references :pricing_plan
|
77
|
+
t.references :pricing_plan_component
|
78
|
+
|
79
|
+
t.timestamps
|
80
|
+
|
81
|
+
end
|
82
|
+
add_index :valid_price_plan_components, :pricing_plan_id
|
83
|
+
add_index :valid_price_plan_components, :pricing_plan_component_id
|
84
|
+
end
|
85
|
+
|
86
|
+
unless table_exists?(:pricing_plan_assignments)
|
87
|
+
create_table :pricing_plan_assignments do |t|
|
88
|
+
|
89
|
+
t.references :pricing_plan
|
90
|
+
|
91
|
+
#support a polymorhic interface to the thing we want to price
|
92
|
+
t.integer :priceable_item_id
|
93
|
+
t.string :priceable_item_type
|
94
|
+
|
95
|
+
t.integer :priority
|
96
|
+
|
97
|
+
t.timestamps
|
98
|
+
|
99
|
+
end
|
100
|
+
add_index :pricing_plan_assignments, :pricing_plan_id
|
101
|
+
add_index :pricing_plan_assignments, [:priceable_item_id,:priceable_item_type], :name => 'priceable_item_idx'
|
102
|
+
end
|
103
|
+
|
104
|
+
unless table_exists?(:prices)
|
105
|
+
create_table :prices do |t|
|
106
|
+
|
107
|
+
t.string :description
|
108
|
+
|
109
|
+
#support a polymorhic interface to the thing that HAS BEEN priced
|
110
|
+
t.integer :priced_item_id
|
111
|
+
t.string :priced_item_type
|
112
|
+
|
113
|
+
#refer to the pricing plan by which this price was calculated
|
114
|
+
t.references :pricing_plan
|
115
|
+
|
116
|
+
t.references :money
|
117
|
+
|
118
|
+
t.timestamps
|
119
|
+
|
120
|
+
end
|
121
|
+
add_index :prices, :money_id
|
122
|
+
add_index :prices, :pricing_plan_id
|
123
|
+
add_index :prices, [:priced_item_id,:priced_item_type], :name => 'priced_item_idx'
|
124
|
+
end
|
125
|
+
|
126
|
+
unless table_exists?(:price_components)
|
127
|
+
create_table :price_components do |t|
|
128
|
+
|
129
|
+
t.string :description
|
130
|
+
t.references :pricing_plan_component
|
131
|
+
t.references :price
|
132
|
+
t.references :money
|
133
|
+
|
134
|
+
#polymorphic relationship
|
135
|
+
t.integer :priced_component_id
|
136
|
+
t.string :priced_component_type
|
137
|
+
|
138
|
+
t.timestamps
|
139
|
+
|
140
|
+
end
|
141
|
+
add_index :price_components, :money_id
|
142
|
+
add_index :price_components, :pricing_plan_component_id
|
143
|
+
add_index :price_components, :price_id
|
144
|
+
add_index :price_components, [:priced_component_id,:priced_component_type], :name => 'priced_component_idx'
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
def self.down
|
151
|
+
|
152
|
+
#tables
|
153
|
+
drop_tables = [
|
154
|
+
:pricing_plans,
|
155
|
+
:pricing_plan_components,
|
156
|
+
:valid_price_plan_components,
|
157
|
+
:pricing_plan_assignments,
|
158
|
+
:prices,
|
159
|
+
:price_components,
|
160
|
+
:price_component_types
|
161
|
+
]
|
162
|
+
drop_tables.each do |table|
|
163
|
+
if table_exists?(table)
|
164
|
+
drop_table table
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class CreateFees < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
unless table_exists?(:fees)
|
4
|
+
create_table :fees do |t|
|
5
|
+
t.references :fee_record, :polymorphic => true
|
6
|
+
t.references :money
|
7
|
+
t.references :fee_type
|
8
|
+
t.string :description
|
9
|
+
t.datetime :start_date
|
10
|
+
t.datetime :end_date
|
11
|
+
t.string :external_identifier
|
12
|
+
t.string :external_id_source
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
|
17
|
+
add_index :fees, [:fee_record_id, :fee_record_type], :name => 'fee_record_idx'
|
18
|
+
add_index :fees, :fee_type_id
|
19
|
+
add_index :fees, :money_id
|
20
|
+
end
|
21
|
+
|
22
|
+
unless table_exists?(:fee_types)
|
23
|
+
create_table :fee_types do |t|
|
24
|
+
t.string :internal_identifier
|
25
|
+
t.string :description
|
26
|
+
t.string :comments
|
27
|
+
t.string :external_identifier
|
28
|
+
t.string :external_id_source
|
29
|
+
|
30
|
+
#these columns are required to support the behavior of the plugin 'awesome_nested_set'
|
31
|
+
t.integer :parent_id
|
32
|
+
t.integer :lft
|
33
|
+
t.integer :rgt
|
34
|
+
|
35
|
+
t.timestamps
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def down
|
42
|
+
#tables
|
43
|
+
drop_tables = [:fees,:fee_types]
|
44
|
+
drop_tables.each do |table|
|
45
|
+
if table_exists?(table)
|
46
|
+
drop_table table
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'active_merchant'
|
2
|
+
|
3
|
+
module ErpCommerce
|
4
|
+
module ActiveMerchantWrappers
|
5
|
+
class BrainTreeGatewayWrapper
|
6
|
+
|
7
|
+
def self.purchase(credit_card_hash, gateway_options={})
|
8
|
+
result = {}
|
9
|
+
|
10
|
+
#test
|
11
|
+
ActiveMerchant::Billing::Base.mode = :test
|
12
|
+
|
13
|
+
#setup gateway
|
14
|
+
gateway = ActiveMerchant::Billing::BraintreeGateway.new(gateway_options)
|
15
|
+
|
16
|
+
#set credit card info
|
17
|
+
credit_card = ActiveMerchant::Billing::CreditCard.new({
|
18
|
+
:first_name => credit_card_hash[:first_name],
|
19
|
+
:last_name => credit_card_hash[:last_name],
|
20
|
+
:number => credit_card_hash[:number],
|
21
|
+
:month => credit_card_hash[:exp_month],
|
22
|
+
:year => credit_card_hash[:exp_year],
|
23
|
+
:verification_value => credit_card_hash[:cvvs],
|
24
|
+
:type => ErpCommerce::ActiveMerchantWrappers::CreditCardValidation.get_card_type(credit_card_hash[:number])
|
25
|
+
})
|
26
|
+
|
27
|
+
if credit_card.valid?
|
28
|
+
cents = (credit_card_hash[:charge_amount].to_f * 100)
|
29
|
+
response = gateway.purchase(cents, credit_card)
|
30
|
+
|
31
|
+
if response.success?
|
32
|
+
result[:message] = response.message
|
33
|
+
result[:payment] = Payment.new
|
34
|
+
result[:payment].authorization_code = response.authorization
|
35
|
+
result[:payment].success = true
|
36
|
+
result[:payment].purchase
|
37
|
+
else
|
38
|
+
result[:message] = response.message
|
39
|
+
result[:payment] = Payment.new
|
40
|
+
result[:payment].success = false
|
41
|
+
result[:payment].decline
|
42
|
+
end
|
43
|
+
|
44
|
+
gateway = PaymentGateway.create(
|
45
|
+
:response => response.message,
|
46
|
+
:payment_gateway_action => PaymentGatewayAction.find_by_internal_identifier('authorize')
|
47
|
+
)
|
48
|
+
|
49
|
+
result[:payment].payment_gateways << gateway
|
50
|
+
result[:payment].save
|
51
|
+
else
|
52
|
+
result[:message] = "<ul>"
|
53
|
+
credit_card.errors.full_messages.each do |current_notice_msg|
|
54
|
+
result[:message] << "<li>"
|
55
|
+
result[:message] << current_notice_msg
|
56
|
+
result[:message] << "</li>"
|
57
|
+
end
|
58
|
+
result[:message] << "<ul>"
|
59
|
+
end
|
60
|
+
|
61
|
+
result
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
module ErpCommerce
|
5
|
+
module ActiveMerchantWrappers
|
6
|
+
module CreditCardValidation
|
7
|
+
VISA_PATTERN = /^4[0-9]{12}(?:[0-9]{3})?$/
|
8
|
+
MASTER_CARD_PATTERN = /^5[1-5][0-9]{14}$/
|
9
|
+
AMEX_PATTERN = /^3[47][0-9]{13}$'/
|
10
|
+
DINERS_CLUB_PATTERN = /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/
|
11
|
+
DISCOVER_PATTERN = /^6(?:011|5[0-9]{2})[0-9]{12}$/
|
12
|
+
|
13
|
+
|
14
|
+
def self.get_card_type(number)
|
15
|
+
card_type = nil
|
16
|
+
|
17
|
+
if number =~ VISA_PATTERN
|
18
|
+
card_type = 'visa'
|
19
|
+
elsif number =~ MASTER_CARD_PATTERN
|
20
|
+
card_type = 'master'
|
21
|
+
elsif number =~ AMEX_PATTERN
|
22
|
+
card_type = 'american_express'
|
23
|
+
elsif number =~ DINERS_CLUB_PATTERN
|
24
|
+
card_type = 'diners_club'
|
25
|
+
elsif number =~ DISCOVER_PATTERN
|
26
|
+
card_type = 'discover'
|
27
|
+
end
|
28
|
+
|
29
|
+
card_type
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ErpCommerce
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
isolate_namespace ErpCommerce
|
4
|
+
|
5
|
+
initializer "erp_commerce.merge_public" do |app|
|
6
|
+
app.middleware.insert_before Rack::Lock, ::ActionDispatch::Static, "#{root}/public"
|
7
|
+
end
|
8
|
+
|
9
|
+
ActiveSupport.on_load(:active_record) do
|
10
|
+
include ErpCommerce::Extensions::ActiveRecord::ActsAsFee
|
11
|
+
include ErpCommerce::Extensions::ActiveRecord::ActsAsPriceable
|
12
|
+
end
|
13
|
+
|
14
|
+
end#Engine
|
15
|
+
end#ErpCommerce
|