saasaparilla 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/Gemfile +36 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +39 -0
- data/app/controllers/saasaparilla/admin/plans_controller.rb +87 -0
- data/app/controllers/saasaparilla/admin/subscriptions_controller.rb +34 -0
- data/app/controllers/saasaparilla/admin/transactions_controller.rb +14 -0
- data/app/controllers/saasaparilla/application_controller.rb +4 -0
- data/app/controllers/saasaparilla/billing_history_controller.rb +9 -0
- data/app/controllers/saasaparilla/contact_info_controller.rb +31 -0
- data/app/controllers/saasaparilla/credit_card_controller.rb +41 -0
- data/app/controllers/saasaparilla/invoices_controller.rb +19 -0
- data/app/controllers/saasaparilla/payments_controller.rb +71 -0
- data/app/controllers/saasaparilla/plans_controller.rb +34 -0
- data/app/controllers/saasaparilla/subscription_controller.rb +71 -0
- data/app/helpers/application_helper.rb +3 -0
- data/app/helpers/plans_helper.rb +2 -0
- data/app/helpers/saasaparilla/billing_history_helper.rb +4 -0
- data/app/mailers/saasaparilla/notifier.rb +38 -0
- data/app/models/billing_activity.rb +12 -0
- data/app/models/contact_info.rb +107 -0
- data/app/models/credit_card.rb +109 -0
- data/app/models/invoice.rb +31 -0
- data/app/models/invoice_line_item.rb +3 -0
- data/app/models/payment.rb +39 -0
- data/app/models/plan.rb +36 -0
- data/app/models/subscription.rb +363 -0
- data/app/models/transaction.rb +32 -0
- data/app/views/layouts/saasaparilla.html.haml +9 -0
- data/app/views/saasaparilla/admin/plans/_form.html.haml +45 -0
- data/app/views/saasaparilla/admin/plans/edit.html.erb +4 -0
- data/app/views/saasaparilla/admin/plans/index.html.erb +31 -0
- data/app/views/saasaparilla/admin/plans/new.html.haml +4 -0
- data/app/views/saasaparilla/admin/plans/show.html.haml +20 -0
- data/app/views/saasaparilla/admin/subscriptions/_subscription.html.haml +7 -0
- data/app/views/saasaparilla/admin/subscriptions/index.html.haml +14 -0
- data/app/views/saasaparilla/admin/subscriptions/show.html.haml +52 -0
- data/app/views/saasaparilla/admin/transactions/_transaction.html.haml +6 -0
- data/app/views/saasaparilla/admin/transactions/index.html.haml +16 -0
- data/app/views/saasaparilla/billing_history/_billing_activity.html.haml +10 -0
- data/app/views/saasaparilla/billing_history/show.html.haml +11 -0
- data/app/views/saasaparilla/contact_info/edit.html.haml +8 -0
- data/app/views/saasaparilla/credit_card/edit.html.haml +18 -0
- data/app/views/saasaparilla/invoices/show.html.haml +17 -0
- data/app/views/saasaparilla/notifier/billing_failed.html.haml +5 -0
- data/app/views/saasaparilla/notifier/billing_successful.html.haml +5 -0
- data/app/views/saasaparilla/notifier/invoice_created.html.haml +24 -0
- data/app/views/saasaparilla/notifier/pending_cancellation_notice.html.haml +6 -0
- data/app/views/saasaparilla/notifier/subscription_canceled.html.haml +4 -0
- data/app/views/saasaparilla/notifier/subscription_created.html.haml +5 -0
- data/app/views/saasaparilla/payments/edit.html.haml +10 -0
- data/app/views/saasaparilla/payments/new.html.haml +10 -0
- data/app/views/saasaparilla/payments/show.html.haml +8 -0
- data/app/views/saasaparilla/plans/edit.html.haml +34 -0
- data/app/views/saasaparilla/subscription/_contact_info_form.html.haml +19 -0
- data/app/views/saasaparilla/subscription/_credit_card_form.html.haml +10 -0
- data/app/views/saasaparilla/subscription/new.html.haml +24 -0
- data/app/views/saasaparilla/subscription/show.html.haml +73 -0
- data/autotest/discover.rb +2 -0
- data/config/routes.rb +27 -0
- data/lib/country_select/MIT-LICENSE +20 -0
- data/lib/country_select/README +15 -0
- data/lib/country_select/init.rb +1 -0
- data/lib/country_select/install.rb +2 -0
- data/lib/country_select/lib/country_select.rb +88 -0
- data/lib/country_select/uninstall.rb +1 -0
- data/lib/extensions/action_controller/base.rb +7 -0
- data/lib/extensions/active_record/nested_attributes.rb +36 -0
- data/lib/extensions/active_record/statuses.rb +16 -0
- data/lib/extensions/billable.rb +12 -0
- data/lib/generators/saasaparilla/install/install_generator.rb +29 -0
- data/lib/generators/saasaparilla/install/templates/create_saasaparilla_tables.rb +106 -0
- data/lib/generators/saasaparilla/install/templates/saasaparilla.yml +32 -0
- data/lib/initializers/auth_dot_net.rb +25 -0
- data/lib/initializers/simple_form.rb +77 -0
- data/lib/initializers/time_format.rb +3 -0
- data/lib/saasaparilla.rb +16 -0
- data/lib/saasaparilla/authentication.rb +18 -0
- data/lib/saasaparilla/authorization.rb +26 -0
- data/lib/saasaparilla/engine.rb +30 -0
- data/lib/saasaparilla/version.rb +3 -0
- data/saasaparilla.gemspec +48 -0
- data/spec/.livereload +21 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +11 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/model/user.rb +4 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +46 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +30 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +39 -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/simple_form.rb +77 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/locales/simple_form.en.yml +24 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config/saasaparilla.yml +32 -0
- data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -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/public/index.html +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/jquery.js +8374 -0
- data/spec/dummy/public/javascripts/jquery.min.js +16 -0
- data/spec/dummy/public/javascripts/rails.js +159 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/MIT-LICENSE +20 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/README +32 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/Rakefile +23 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/init.rb +1 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/install.rb +1 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/lib/authorize_net_cim_gateway_test.rb +492 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/lib/authorize_net_gateway_test.rb +133 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/lib/paypal_express_gateway_test.rb +138 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/tasks/activemerchant_testing_tasks.rake +4 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/test/activemerchant_testing_test.rb +8 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/test/test_helper.rb +3 -0
- data/spec/dummy/vendor/plugins/active_merchant_testing/uninstall.rb +1 -0
- data/spec/factories/factories.rb +75 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/mailers/notifier_spec.rb +167 -0
- data/spec/models/billing_activity_spec.rb +27 -0
- data/spec/models/contact_info_spec.rb +32 -0
- data/spec/models/credit_card_spec.rb +57 -0
- data/spec/models/invoice_line_item_spec.rb +7 -0
- data/spec/models/invoice_spec.rb +25 -0
- data/spec/models/payment_spec.rb +29 -0
- data/spec/models/plan_spec.rb +16 -0
- data/spec/models/subscription_spec.rb +414 -0
- data/spec/requests/admin_plans_spec.rb +32 -0
- data/spec/requests/admin_subscriptions_spec.rb +31 -0
- data/spec/requests/billing_history_spec.rb +26 -0
- data/spec/requests/contact_info_controller_spec.rb +42 -0
- data/spec/requests/credit_cards_spec.rb +79 -0
- data/spec/requests/invoices_spec.rb +23 -0
- data/spec/requests/payments_spec.rb +89 -0
- data/spec/requests/subscription_plans_spec.rb +34 -0
- data/spec/requests/subscriptions_spec.rb +80 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/spec_helpers/spec_helpers.rb +8 -0
- metadata +611 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
class AuthorizeNetGatewayTest < ActiveMerchant::Billing::AuthorizeNetGateway
|
2
|
+
|
3
|
+
def initialize(options = {})
|
4
|
+
options[:login] = "X"
|
5
|
+
options[:password] = "Y"
|
6
|
+
@options = options
|
7
|
+
@subscription_id = '100748'
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def commit(action, money, parameters)
|
13
|
+
parameters[:amount] = amount(money) unless action == 'VOID'
|
14
|
+
|
15
|
+
# Only activate the test_request when the :test option is passed in
|
16
|
+
parameters[:test_request] = @options[:test] ? 'TRUE' : 'FALSE'
|
17
|
+
|
18
|
+
url = test? ? self.test_url : self.live_url
|
19
|
+
#data = ssl_post url, post_data(action, parameters)
|
20
|
+
data = eval("successful_#{action.downcase}_response")
|
21
|
+
|
22
|
+
response = parse(data)
|
23
|
+
|
24
|
+
message = message_from(response)
|
25
|
+
|
26
|
+
# Return the response. The authorization can be taken out of the transaction_id
|
27
|
+
# Test Mode on/off is something we have to parse from the response text.
|
28
|
+
# It usually looks something like this
|
29
|
+
#
|
30
|
+
# (TESTMODE) Successful Sale
|
31
|
+
test_mode = test? || message =~ /TESTMODE/
|
32
|
+
|
33
|
+
ActiveMerchant::Billing::Response.new(success?(response), message, response,
|
34
|
+
:test => test_mode,
|
35
|
+
:authorization => response[:transaction_id],
|
36
|
+
:fraud_review => fraud_review?(response),
|
37
|
+
:avs_result => { :code => response[:avs_result_code] },
|
38
|
+
:cvv_result => response[:card_code]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def post_data_fixture
|
43
|
+
'x_encap_char=%24&x_card_num=4242424242424242&x_exp_date=0806&x_card_code=123&x_type=AUTH_ONLY&x_first_name=Longbob&x_version=3.1&x_login=X&x_last_name=Longsen&x_tran_key=Y&x_relay_response=FALSE&x_delim_data=TRUE&x_delim_char=%2C&x_amount=1.01'
|
44
|
+
end
|
45
|
+
|
46
|
+
def minimum_requirements
|
47
|
+
%w(version delim_data relay_response login tran_key amount card_num exp_date type)
|
48
|
+
end
|
49
|
+
|
50
|
+
def failed_credit_response
|
51
|
+
'$3$,$2$,$54$,$The referenced transaction does not meet the criteria for issuing a credit.$,$$,$P$,$0$,$$,$$,$1.00$,$CC$,$credit$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$39265D8BA0CDD4F045B5F4129B2AAA01$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$'
|
52
|
+
end
|
53
|
+
|
54
|
+
def successful_authorization_response
|
55
|
+
'$1$,$1$,$1$,$This transaction has been approved.$,$advE7f$,$Y$,$508141794$,$5b3fe66005f3da0ebe51$,$$,$1.00$,$CC$,$auth_only$,$$,$Longbob$,$Longsen$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$2860A297E0FE804BCB9EF8738599645C$,$P$,$2$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$'
|
56
|
+
end
|
57
|
+
|
58
|
+
# copied from successful_authorization_response - not sure if this is the correct format
|
59
|
+
def successful_auth_only_response
|
60
|
+
'$1$,$1$,$1$,$This transaction has been approved.$,$advE7f$,$Y$,$508141794$,$5b3fe66005f3da0ebe51$,$$,$1.00$,$CC$,$auth_only$,$$,$Longbob$,$Longsen$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$2860A297E0FE804BCB9EF8738599645C$,$P$,$2$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$'
|
61
|
+
end
|
62
|
+
|
63
|
+
# copied from successful_authorization_response - not sure if this is the correct format
|
64
|
+
def successful_prior_auth_capture_response
|
65
|
+
'$1$,$1$,$1$,$This transaction has been approved.$,$advE7f$,$Y$,$508141794$,$5b3fe66005f3da0ebe51$,$$,$1.00$,$CC$,$auth_only$,$$,$Longbob$,$Longsen$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$2860A297E0FE804BCB9EF8738599645C$,$P$,$2$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$'
|
66
|
+
end
|
67
|
+
|
68
|
+
def successful_purchase_response
|
69
|
+
'$1$,$1$,$1$,$This transaction has been approved.$,$d1GENk$,$Y$,$508141795$,$32968c18334f16525227$,$Store purchase$,$1.00$,$CC$,$auth_capture$,$$,$Longbob$,$Longsen$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$269862C030129C1173727CC10B1935ED$,$P$,$2$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$'
|
70
|
+
end
|
71
|
+
|
72
|
+
#copied from purchase... not sure if this is the correct format
|
73
|
+
def successful_void_response
|
74
|
+
'$1$,$1$,$1$,$This transaction has been approved.$,$d1GENk$,$Y$,$508141795$,$32968c18334f16525227$,$Store purchase$,$1.00$,$CC$,$auth_capture$,$$,$Longbob$,$Longsen$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$269862C030129C1173727CC10B1935ED$,$P$,$2$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$'
|
75
|
+
end
|
76
|
+
|
77
|
+
def failed_authorization_response
|
78
|
+
'$2$,$1$,$1$,$This transaction was declined.$,$advE7f$,$Y$,$508141794$,$5b3fe66005f3da0ebe51$,$$,$1.00$,$CC$,$auth_only$,$$,$Longbob$,$Longsen$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$2860A297E0FE804BCB9EF8738599645C$,$P$,$2$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$'
|
79
|
+
end
|
80
|
+
|
81
|
+
def fraud_review_response
|
82
|
+
"$4$,$$,$253$,$Thank you! For security reasons your order is currently being reviewed.$,$$,$X$,$0$,$$,$$,$1.00$,$$,$auth_capture$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$207BCBBF78E85CF174C87AE286B472D2$,$M$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$,$$"
|
83
|
+
end
|
84
|
+
|
85
|
+
def successful_recurring_response
|
86
|
+
<<-XML
|
87
|
+
<ARBCreateSubscriptionResponse xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
|
88
|
+
<refId>Sample</refId>
|
89
|
+
<messages>
|
90
|
+
<resultCode>Ok</resultCode>
|
91
|
+
<message>
|
92
|
+
<code>I00001</code>
|
93
|
+
<text>Successful.</text>
|
94
|
+
</message>
|
95
|
+
</messages>
|
96
|
+
<subscriptionId>#{@subscription_id}</subscriptionId>
|
97
|
+
</ARBCreateSubscriptionResponse>
|
98
|
+
XML
|
99
|
+
end
|
100
|
+
|
101
|
+
def successful_update_recurring_response
|
102
|
+
<<-XML
|
103
|
+
<ARBUpdateSubscriptionResponse xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
|
104
|
+
<refId>Sample</refId>
|
105
|
+
<messages>
|
106
|
+
<resultCode>Ok</resultCode>
|
107
|
+
<message>
|
108
|
+
<code>I00001</code>
|
109
|
+
<text>Successful.</text>
|
110
|
+
</message>
|
111
|
+
</messages>
|
112
|
+
<subscriptionId>#{@subscription_id}</subscriptionId>
|
113
|
+
</ARBUpdateSubscriptionResponse>
|
114
|
+
XML
|
115
|
+
end
|
116
|
+
|
117
|
+
def successful_cancel_recurring_response
|
118
|
+
<<-XML
|
119
|
+
<ARBCancelSubscriptionResponse xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
|
120
|
+
<refId>Sample</refId>
|
121
|
+
<messages>
|
122
|
+
<resultCode>Ok</resultCode>
|
123
|
+
<message>
|
124
|
+
<code>I00001</code>
|
125
|
+
<text>Successful.</text>
|
126
|
+
</message>
|
127
|
+
</messages>
|
128
|
+
<subscriptionId>#{@subscription_id}</subscriptionId>
|
129
|
+
</ARBCancelSubscriptionResponse>
|
130
|
+
XML
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# TODO THIS IS QUITE A HACK - when I have time I need to really clean this up with some mocks or something
|
2
|
+
|
3
|
+
class PaypalExpressGatewayTest < ActiveMerchant::Billing::PaypalExpressGateway
|
4
|
+
|
5
|
+
attr_accessor :purchase_options
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup_purchase(amount, options = {})
|
12
|
+
requires!(options, :return_url, :cancel_return_url)
|
13
|
+
self.purchase_options = options
|
14
|
+
|
15
|
+
response = response_data(amount)
|
16
|
+
|
17
|
+
build_response(true, "Success", response,
|
18
|
+
:test => true,
|
19
|
+
:authorization => get_hex_code,
|
20
|
+
:fraud_review => false,
|
21
|
+
:avs_result => { :code => "" },
|
22
|
+
:cvv_result => ""
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def redirect_url_for(token)
|
27
|
+
"#{self.purchase_options[:return_url]}?token=#{token}&payer_id=#{self.purchase_options[:payer_id]}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def details_for(token)
|
31
|
+
response = parse("GetExpressCheckoutDetails", successful_get_express_details_response(:token => token))
|
32
|
+
|
33
|
+
res = build_response(successful?(response), message_from(response), response,
|
34
|
+
:test => test?,
|
35
|
+
:authorization => authorization_from(response),
|
36
|
+
:fraud_review => fraud_review?(response),
|
37
|
+
:avs_result => { :code => response[:avs_code] },
|
38
|
+
:cvv_result => response[:cvv2_code]
|
39
|
+
)
|
40
|
+
res.params[:payer] = User.last.email
|
41
|
+
return res
|
42
|
+
end
|
43
|
+
|
44
|
+
def purchase(amount, options = {})
|
45
|
+
# request = build_setup_express_sale_or_authorization_request('Sale', money, options)
|
46
|
+
# commit(request)
|
47
|
+
res = build_response(true, "Success", {},
|
48
|
+
:test => true,
|
49
|
+
:authorization => get_hex_code,
|
50
|
+
:fraud_review => false,
|
51
|
+
:avs_result => { :code => "" },
|
52
|
+
:cvv_result => ""
|
53
|
+
)
|
54
|
+
res.params[:transaction_id] = get_hex_code
|
55
|
+
return res
|
56
|
+
end
|
57
|
+
|
58
|
+
def test?
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
def successful?(response)
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
def get_hex_code
|
68
|
+
arr = Time.now.to_f.to_s.split(".")
|
69
|
+
x = arr[0].to_i + arr[1].to_i
|
70
|
+
x.to_s(16).upcase
|
71
|
+
end
|
72
|
+
|
73
|
+
def response_data(amount, options = {})
|
74
|
+
{
|
75
|
+
:payment_status => "Completed",
|
76
|
+
:tax_amount_currency_id => "USD",
|
77
|
+
:correlation_id => get_hex_code, #???
|
78
|
+
:timestamp => DateTime.now.to_s,
|
79
|
+
:token => "EC-#{get_hex_code}",
|
80
|
+
:pending_reason => "none",
|
81
|
+
:transaction_id => get_hex_code,
|
82
|
+
:fee_amount_currency_id => "USD",
|
83
|
+
:transaction_type => "express-checkout",
|
84
|
+
:build => "767689",
|
85
|
+
:tax_amount => "0.00",
|
86
|
+
:version => "2.0",
|
87
|
+
:receipt_id => "",
|
88
|
+
:gross_amount_currency_id => "USD",
|
89
|
+
:fee_amount => "0.00",
|
90
|
+
:exchange_rate => "",
|
91
|
+
:gross_amount => amount,
|
92
|
+
:parent_transaction_id => "",
|
93
|
+
:ack => "Success",
|
94
|
+
:payment_date => DateTime.now.to_s,
|
95
|
+
:reason_code => "none",
|
96
|
+
:payment_type => "instant"
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
def successful_get_express_details_response(options = {})
|
101
|
+
options[:token] ||= "EC-2OPN7UJGFWK9OYFV"
|
102
|
+
options[:payer_id] ||= "12345678901234567"
|
103
|
+
<<-RESPONSE
|
104
|
+
<XMLPayResponse xmlns='http://www.verisign.com/XMLPay'>
|
105
|
+
<ResponseData>
|
106
|
+
<Vendor>TEST</Vendor>
|
107
|
+
<Partner>verisign</Partner>
|
108
|
+
<TransactionResults>
|
109
|
+
<TransactionResult>
|
110
|
+
<Result>0</Result>
|
111
|
+
<Message>Approved</Message>
|
112
|
+
<PayPalResult>
|
113
|
+
<EMail>Buyer1@paypal.com</EMail>
|
114
|
+
<PayerID>#{options[:payer_id]}</PayerID>
|
115
|
+
<Token>#{options[:token]}</Token>
|
116
|
+
<FeeAmount>0</FeeAmount>
|
117
|
+
<PayerStatus>verified</PayerStatus>
|
118
|
+
<Name>Joe</Name>
|
119
|
+
<ShipTo>
|
120
|
+
<Address>
|
121
|
+
<Street>111 Main St.</Street>
|
122
|
+
<City>San Jose</City>
|
123
|
+
<State>CA</State>
|
124
|
+
<Zip>95100</Zip>
|
125
|
+
<Country>US</Country>
|
126
|
+
</Address>
|
127
|
+
</ShipTo>
|
128
|
+
<CorrelationID>9c3706997455e</CorrelationID>
|
129
|
+
</PayPalResult>
|
130
|
+
<ExtData Name='LASTNAME' Value='Smith'/>
|
131
|
+
</TransactionResult>
|
132
|
+
</TransactionResults>
|
133
|
+
</ResponseData>
|
134
|
+
</XMLPayResponse>
|
135
|
+
RESPONSE
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
@@ -0,0 +1,75 @@
|
|
1
|
+
Factory.define :subscription, :class => Subscription do |f|
|
2
|
+
f.customer_cim_id
|
3
|
+
f.customer_payment_profile_id
|
4
|
+
f.balance 10
|
5
|
+
f.status
|
6
|
+
f.association :credit_card
|
7
|
+
f.association :contact_info
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
Factory.define :contact_info, :class => ContactInfo do |f|
|
14
|
+
f.first_name "Bob"
|
15
|
+
f.last_name "Jones"
|
16
|
+
f.email "bobjones@123.com"
|
17
|
+
f.company "my company"
|
18
|
+
f.address "123 fake st"
|
19
|
+
f.city "seattle"
|
20
|
+
f.state "wa"
|
21
|
+
f.zip "98123"
|
22
|
+
f.country "US"
|
23
|
+
f.phone_number "206-123-2322"
|
24
|
+
end
|
25
|
+
|
26
|
+
Factory.define :credit_card, :class => CreditCard do |f|
|
27
|
+
f.first_name "bob"
|
28
|
+
f.last_name "Herman"
|
29
|
+
f.card_type "Visa"
|
30
|
+
f.card_number "4111111111111111"
|
31
|
+
f.card_verification "545"
|
32
|
+
f.expiry_month "10"
|
33
|
+
f.expiry_year "2011"
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
Factory.define :plan, :class => Plan do |f|
|
38
|
+
f.name "Gold"
|
39
|
+
f.billing_period "monthly"
|
40
|
+
f.price 12.99
|
41
|
+
|
42
|
+
#f.plan_extras {|plan_extras| [plan_extras.association(:plan_extra)]}
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
Factory.define :payment, :class => Payment do |f|
|
49
|
+
f.status
|
50
|
+
f.amount 20.00
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
Factory.define :billing_activity, :class => BillingActivity do |f|
|
56
|
+
f.created_at Time.now
|
57
|
+
f.amount 12.00
|
58
|
+
f.message "Thanks for your payment"
|
59
|
+
end
|
60
|
+
Factory.define :user, :class => User do |f|
|
61
|
+
f.name "Ted"
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
Factory.define :subscription_with_all, :parent => :subscription do |subscription|
|
66
|
+
|
67
|
+
subscription.before_create do |a|
|
68
|
+
Factory(:contact_info, :subscription => a)
|
69
|
+
Factory(:credit_card, :subscription => a)
|
70
|
+
Factory(:subscription, :subscription => a, :plan => Factory(:plan, :name => "Gold"))
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Notifier' do
|
4
|
+
|
5
|
+
describe 'subscription created email' do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
ActionMailer::Base.deliveries = []
|
9
|
+
plan = Factory.build(:plan, :name => "Gold", :price => 20.0)
|
10
|
+
contact_info = Factory.build(:contact_info)
|
11
|
+
credit_card = Factory.build(:credit_card)
|
12
|
+
@subscription = Factory.build(:subscription, :contact_info => contact_info, :plan => plan, :credit_card => credit_card)
|
13
|
+
@email = Saasaparilla::Notifier.subscription_created(@subscription)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should deliver to the subscription passed in" do
|
17
|
+
@email.should deliver_to(@subscription.contact_info.email)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should contain the plan in the mail body" do
|
21
|
+
@email.should have_body_text(/Gold/)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should contain the billing period in the mail body" do
|
25
|
+
@email.should have_body_text(/monthly/)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'invoice created email' do
|
31
|
+
|
32
|
+
before(:all) do
|
33
|
+
plan = Factory.build(:plan, :name => "Gold", :price => 20.0)
|
34
|
+
contact_info = Factory.build(:contact_info)
|
35
|
+
credit_card = Factory.build(:credit_card)
|
36
|
+
@subscription = Factory.build(:subscription, :contact_info => contact_info, :plan => plan, :credit_card => credit_card)
|
37
|
+
@subscription.invoice!
|
38
|
+
@invoice = BillingActivity.recent.first.invoice
|
39
|
+
@email = Saasaparilla::Notifier.invoice_created(@subscription, @invoice)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should deliver to the subscription passed in" do
|
43
|
+
@email.should deliver_to(@subscription.contact_info.email)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should contain the plan in the mail body" do
|
47
|
+
@email.should have_body_text(/Gold/)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should contain the line item amount the mail body" do
|
51
|
+
@email.should have_body_text(/20/)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'subscription billed successfully email' do
|
57
|
+
|
58
|
+
before(:all) do
|
59
|
+
plan = Factory.build(:plan, :name => "Gold", :price => 20.0)
|
60
|
+
contact_info = Factory.build(:contact_info)
|
61
|
+
|
62
|
+
credit_card = Factory.build(:credit_card)
|
63
|
+
@subscription = Factory.build(:subscription, :contact_info => contact_info, :plan => plan, :credit_card => credit_card)
|
64
|
+
@email = Saasaparilla::Notifier.billing_successful(@subscription, 20)
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should deliver to the subscription passed in" do
|
69
|
+
@email.should deliver_to(@subscription.contact_info.email)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should contain the plan in the mail body" do
|
73
|
+
@email.should have_body_text(/Gold/)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should contain the billing period in the mail body" do
|
77
|
+
@email.should have_body_text(/monthly/)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should contain the amount billed in the mail body" do
|
81
|
+
@email.should have_body_text(/20/)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'subscription billing failed email' do
|
87
|
+
|
88
|
+
before(:all) do
|
89
|
+
plan = Factory.build(:plan, :name => "Gold", :price => 20.0)
|
90
|
+
contact_info = Factory.build(:contact_info)
|
91
|
+
|
92
|
+
credit_card = Factory.build(:credit_card)
|
93
|
+
@subscription = Factory.build(:subscription, :contact_info => contact_info, :plan => plan, :credit_card => credit_card)
|
94
|
+
@email = Saasaparilla::Notifier.billing_failed(@subscription)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should deliver to the subscription passed in" do
|
98
|
+
@email.should deliver_to(@subscription.contact_info.email)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should contain the plan in the mail body" do
|
102
|
+
@email.should have_body_text(/Gold/)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should contain the billing period in the mail body" do
|
106
|
+
@email.should have_body_text(/monthly/)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should contain the #edit_subscription_credit_card_url in the mail body" do
|
110
|
+
@email.should have_body_text(/#{edit_subscription_credit_card_url(:host => "test.com")}/)
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
describe 'pending cancellation notice email' do
|
117
|
+
|
118
|
+
before(:all) do
|
119
|
+
plan = Factory.build(:plan, :name => "Gold", :price => 20.0)
|
120
|
+
contact_info = Factory.build(:contact_info)
|
121
|
+
|
122
|
+
credit_card = Factory.build(:credit_card)
|
123
|
+
@subscription = Factory.build(:subscription, :contact_info => contact_info, :plan => plan, :credit_card => credit_card)
|
124
|
+
@email = Saasaparilla::Notifier.pending_cancellation_notice(@subscription)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should deliver to the subscription passed in" do
|
128
|
+
@email.should deliver_to(@subscription.contact_info.email)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should contain the plan in the mail body" do
|
132
|
+
@email.should have_body_text(/Gold/)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should contain the billing period in the mail body" do
|
136
|
+
@email.should have_body_text(/monthly/)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should contain the #edit_subscription_credit_card_url in the mail body" do
|
140
|
+
@email.should have_body_text(/#{edit_subscription_credit_card_url(:host => "test.com")}/)
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
describe 'subscription canceled email' do
|
147
|
+
|
148
|
+
before(:all) do
|
149
|
+
plan = Factory.build(:plan, :name => "Gold", :price => 20.0)
|
150
|
+
contact_info = Factory.build(:contact_info)
|
151
|
+
|
152
|
+
credit_card = Factory.build(:credit_card)
|
153
|
+
@subscription = Factory.build(:subscription, :contact_info => contact_info, :plan => plan, :credit_card => credit_card)
|
154
|
+
@email = Saasaparilla::Notifier.subscription_canceled(@subscription)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should deliver to the subscription passed in" do
|
158
|
+
@email.should deliver_to(@subscription.contact_info.email)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should contain the plan in the mail body" do
|
162
|
+
@email.should have_body_text(/Your subscription has been canceled/)
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|