opay 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +3 -0
  3. data/Rakefile +22 -0
  4. data/app/assets/javascripts/opay/application.js +15 -0
  5. data/app/assets/stylesheets/opay/application.css +13 -0
  6. data/app/controllers/opay/application_controller.rb +4 -0
  7. data/app/controllers/opay/payu_controller.rb +9 -0
  8. data/app/helpers/opay/application_helper.rb +4 -0
  9. data/app/helpers/opay/payu_helper.rb +4 -0
  10. data/app/models/opay/payment.rb +6 -0
  11. data/app/views/layouts/opay/application.html.erb +14 -0
  12. data/config/routes.rb +8 -0
  13. data/db/migrate/20130321114023_create_opay_payments.rb +14 -0
  14. data/lib/generators/opay/config_generator.rb +12 -0
  15. data/lib/generators/opay/templates/opay_config.rb +9 -0
  16. data/lib/opay/configuration.rb +42 -0
  17. data/lib/opay/engine.rb +23 -0
  18. data/lib/opay/form_builder.rb +5 -0
  19. data/lib/opay/helpers/form_helper.rb +14 -0
  20. data/lib/opay/helpers/payu_helper.rb +41 -0
  21. data/lib/opay/helpers.rb +6 -0
  22. data/lib/opay/payable.rb +30 -0
  23. data/lib/opay/providers/payu.rb +76 -0
  24. data/lib/opay/providers.rb +5 -0
  25. data/lib/opay/version.rb +3 -0
  26. data/lib/opay.rb +14 -0
  27. data/lib/tasks/opay_tasks.rake +4 -0
  28. data/spec/dummy/README.rdoc +261 -0
  29. data/spec/dummy/Rakefile +7 -0
  30. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  31. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  32. data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
  33. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  34. data/spec/dummy/app/controllers/orders_controller.rb +83 -0
  35. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  36. data/spec/dummy/app/helpers/orders_helper.rb +2 -0
  37. data/spec/dummy/app/models/order.rb +7 -0
  38. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  39. data/spec/dummy/app/views/orders/_form.html.erb +25 -0
  40. data/spec/dummy/app/views/orders/edit.html.erb +6 -0
  41. data/spec/dummy/app/views/orders/index.html.erb +25 -0
  42. data/spec/dummy/app/views/orders/new.html.erb +5 -0
  43. data/spec/dummy/app/views/orders/show.html.erb +15 -0
  44. data/spec/dummy/config/application.rb +76 -0
  45. data/spec/dummy/config/boot.rb +10 -0
  46. data/spec/dummy/config/database.yml +30 -0
  47. data/spec/dummy/config/environment.rb +5 -0
  48. data/spec/dummy/config/environments/development.rb +37 -0
  49. data/spec/dummy/config/environments/production.rb +67 -0
  50. data/spec/dummy/config/environments/test.rb +37 -0
  51. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/spec/dummy/config/initializers/inflections.rb +15 -0
  53. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  54. data/spec/dummy/config/initializers/opay_config.rb +9 -0
  55. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  56. data/spec/dummy/config/initializers/session_store.rb +8 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/en.yml +5 -0
  59. data/spec/dummy/config/routes.rb +4 -0
  60. data/spec/dummy/config.ru +4 -0
  61. data/spec/dummy/db/development.sqlite3 +0 -0
  62. data/spec/dummy/db/migrate/20130326152550_create_orders.rb +10 -0
  63. data/spec/dummy/db/schema.rb +36 -0
  64. data/spec/dummy/db/test.sqlite3 +0 -0
  65. data/spec/dummy/log/development.log +1511 -0
  66. data/spec/dummy/log/test.log +1629 -0
  67. data/spec/dummy/opay_config.rb +1 -0
  68. data/spec/dummy/public/404.html +26 -0
  69. data/spec/dummy/public/422.html +26 -0
  70. data/spec/dummy/public/500.html +25 -0
  71. data/spec/dummy/public/favicon.ico +0 -0
  72. data/spec/dummy/script/rails +6 -0
  73. data/spec/dummy/spec/factories/orders.rb +8 -0
  74. data/spec/dummy/spec/models/order_spec.rb +5 -0
  75. data/spec/dummy/tmp/cache/assets/C23/400/sprockets%2F31710301f0d68b89727f5de964446610 +0 -0
  76. data/spec/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
  77. data/spec/dummy/tmp/cache/assets/CA6/480/sprockets%2F46f1812fd06c1e0802a414931ff82f71 +0 -0
  78. data/spec/dummy/tmp/cache/assets/CB2/7F0/sprockets%2F9d79a842f086f17d3420e5cb88710c10 +0 -0
  79. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  80. data/spec/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
  81. data/spec/dummy/tmp/cache/assets/D25/7A0/sprockets%2F0c58b40b01f62ed06f75ee2d444a111a +0 -0
  82. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  83. data/spec/dummy/tmp/cache/assets/D39/8F0/sprockets%2F931d437216848cdf2a7bbac6c0f4c426 +0 -0
  84. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  85. data/spec/dummy/tmp/cache/assets/D54/F30/sprockets%2F8ea40d0224e2d772232dcbfbf0fc3005 +0 -0
  86. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  87. data/spec/dummy/tmp/cache/assets/D99/A20/sprockets%2F552b4516be6f766a2da35c26be2f1ecf +0 -0
  88. data/spec/dummy/tmp/cache/assets/DC9/EF0/sprockets%2F508b2ee0aa9ed068a10af6d8cf9d0e19 +0 -0
  89. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  90. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  91. data/spec/factories/opay_payments.rb +10 -0
  92. data/spec/lib/opay/helpers/payu_helper_spec.rb +41 -0
  93. data/spec/lib/opay/payable_spec.rb +18 -0
  94. data/spec/lib/opay/providers/payu_spec.rb +106 -0
  95. data/spec/models/opay/payment_spec.rb +7 -0
  96. data/spec/spec_helper.rb +83 -0
  97. data/spec/support/xml/error.xml.erb +8 -0
  98. data/spec/support/xml/success.xml.erb +24 -0
  99. metadata +379 -0
@@ -0,0 +1 @@
1
+ contant
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,8 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :order do
5
+ name "MyString"
6
+ amount "MyString"
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Order do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end
@@ -0,0 +1,10 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :opay_payment, :class => 'Payment' do
5
+ item nil
6
+ session "MyString"
7
+ amount 1.5
8
+ finished false
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Opay
4
+ describe Helpers::PayuHelper, type: :helper do
5
+
6
+ before do
7
+ # stub(request).env { {"HTTP_USER_AGENT" => "Some String"} }
8
+ end
9
+
10
+ context 'form tag' do
11
+ it 'creates form tag' do
12
+ order = Order.create! name: 'first order', amount: 1000 # 10 zł
13
+
14
+ # helper.payu_form_for(order) do |f|
15
+ # f.payment_info first_name: 'Jan', last_name: 'Kowalski', email: 'kowalski@gmail.com', desc: 'Test payment', client_ip: '127.0.0.1'
16
+ # end.should be true
17
+
18
+ html = helper.payu_form_for(order) do |f|
19
+ f.payment_info first_name: 'Jan', last_name: 'Kowalski', email: 'kowalski@gmail.com', desc: 'Test payment', client_ip: '127.0.0.1'
20
+ end
21
+
22
+ html.should have_css('form[action="https://www.platnosci.pl/paygw/UTF/NewPayment"]')
23
+ html.should have_css('form[method="post"]')
24
+
25
+ html.should have_css('input[name="first_name"]')
26
+ html.should have_css('input[name="last_name"]')
27
+ html.should have_css('input[name="email"]')
28
+
29
+ html.should have_css('input[name="pos_id"]')
30
+ html.should have_css('input[name="pos_auth_key"]')
31
+ html.should have_css('input[name="session_id"]')
32
+
33
+ html.should have_css('input[name="amount"]')
34
+ html.should have_css('input[name="desc"]')
35
+ html.should have_css('input[name="client_ip"]')
36
+ html.should have_css('input[name="js"]')
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ module Opay
4
+ describe Payable do
5
+ subject { Order.new }
6
+
7
+ it { should have_one(:payment) }
8
+ it { should respond_to(:finished?) }
9
+
10
+ it 'has unique session_id' do
11
+ # unsaved record raises exception
12
+ expect { subject.payment_session_id }.to raise_error RuntimeError
13
+
14
+ subject.save!
15
+ subject.payment_session_id.should eq Digest::MD5.hexdigest('Order' + subject.id.to_s)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ module Opay
4
+ describe Providers::Payu do
5
+ context 'md5 signs' do
6
+
7
+ before do
8
+ @key1 = Opay.config.key1
9
+ @key2 = Opay.config.key2
10
+ end
11
+
12
+ it 'creates md5 sig' do
13
+ pos_id = '123456'
14
+ session_id = '0cde9e950d99630410661b2dedbbd822'
15
+ ts = '1234567890'
16
+ sig = Digest::MD5.hexdigest(pos_id + session_id + ts + @key1)
17
+
18
+ # valid sig
19
+ subject.class_eval { create_sig(pos_id, session_id, ts) }.should eq sig
20
+
21
+ # invalid sig
22
+ subject.class_eval { create_sig('23456', session_id, ts) }.should_not eq sig
23
+ end
24
+
25
+ it 'checks md5 sig' do
26
+ pos_id = '123456'
27
+ session_id = '0cdeyutyuuytt410661b2dedbbd822'
28
+ ts = '1234567890'
29
+ sig = Digest::MD5.hexdigest(pos_id + session_id + ts + @key2)
30
+
31
+ # valid received params
32
+ subject.class_eval { verify_sig(sig, pos_id, session_id, ts) }.should be true
33
+
34
+ # invalid received params
35
+ subject.class_eval { verify_sig(sig, '23456', session_id, ts) }.should be false
36
+ end
37
+
38
+ end
39
+
40
+ context 'online' do
41
+ subject { Providers::Payu }
42
+
43
+ before do
44
+ @order = Order.create! name: 'first order', amount: 1000 # 10 zł
45
+ @order.create_payment!(session_id: @order.payment_session_id, provider: 'payu', amount: @order.amount)
46
+ end
47
+
48
+ it 'valid payment' do
49
+ payment_info = {
50
+ pos_id: Opay.config.pos_id,
51
+ session_id: @order.payment_session_id,
52
+ order_id: nil,
53
+ status: 99,
54
+ amount: @order.amount,
55
+ desc: 'description',
56
+ ts: Time.now.to_i.to_s
57
+ }
58
+
59
+ payment_info[:sig] = Digest::MD5.hexdigest(payment_info.values.join + Opay.config.key2)
60
+
61
+ stub_request(:post, 'https://www.platnosci.pl/paygw/UTF/Payment/get/xml')
62
+ .to_return(status: 200, body: response_from_template('success.xml', payment_info))
63
+
64
+ ts = Time.now.to_i.to_s
65
+ sig = Digest::MD5.hexdigest(Opay.config.pos_id.to_s + @order.payment_session_id + ts + Opay.config.key2)
66
+
67
+ @order.payment.finished.should be false
68
+ subject.process(Opay.config.pos_id, @order.payment_session_id, ts, sig).should be true
69
+ @order.payment.reload.finished.should be true
70
+ end
71
+
72
+ it 'invalid payment' do
73
+ payment_info = {
74
+ pos_id: Opay.config.pos_id,
75
+ session_id: @order.payment_session_id,
76
+ order_id: nil,
77
+ status: 99,
78
+ amount: @order.amount,
79
+ desc: 'description',
80
+ ts: Time.now.to_i.to_s
81
+ }
82
+
83
+ payment_info[:sig] = 'invalid sig'
84
+
85
+ stub_request(:post, 'https://www.platnosci.pl/paygw/UTF/Payment/get/xml')
86
+ .to_return(status: 200, body: response_from_template('success.xml', payment_info))
87
+
88
+ ts = Time.now.to_i.to_s
89
+ sig = Digest::MD5.hexdigest(Opay.config.pos_id.to_s + @order.payment_session_id + ts + Opay.config.key2)
90
+
91
+ subject.process(Opay.config.pos_id, @order.payment_session_id, ts, sig).should be false
92
+ end
93
+
94
+ it 'error' do
95
+ stub_request(:post, 'https://www.platnosci.pl/paygw/UTF/Payment/get/xml')
96
+ .to_return(status: 200, body: response_from_template('error.xml'))
97
+
98
+ ts = Time.now.to_i.to_s
99
+ sig = Digest::MD5.hexdigest(Opay.config.pos_id.to_s + @order.payment_session_id + ts + Opay.config.key2)
100
+
101
+ subject.process(Opay.config.pos_id, @order.payment_session_id, ts, sig).should be false
102
+ end
103
+
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ module Opay
4
+ describe Payment do
5
+ pending "add some examples to (or delete) #{__FILE__}"
6
+ end
7
+ end
@@ -0,0 +1,83 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+
4
+ require 'erb'
5
+ require 'ostruct'
6
+
7
+ #uncomment the following line to use spork with the debugger
8
+ #require 'spork/ext/ruby-debug'
9
+
10
+ Spork.prefork do
11
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
12
+ ENV['RAILS_ENV'] ||= 'test'
13
+
14
+ require File.expand_path('../dummy/config/environment', __FILE__)
15
+
16
+ require 'rspec/rails'
17
+ require 'rspec/autorun'
18
+ require 'factory_girl_rails'
19
+ require 'database_cleaner'
20
+ require 'shoulda'
21
+ require 'capybara/rspec'
22
+ require 'webmock/rspec'
23
+
24
+ # Requires supporting ruby files with custom matchers and macros, etc,
25
+ # in spec/support/ and its subdirectories.
26
+ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
27
+
28
+ FactoryGirl.definition_file_paths = [ File.join(Rails.root, '../factories') ]
29
+
30
+ RSpec.configure do |config|
31
+ # ## Mock Framework
32
+ #
33
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
34
+ #
35
+ # config.mock_with :mocha
36
+ # config.mock_with :flexmock
37
+ # config.mock_with :rr
38
+
39
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
40
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
41
+
42
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
43
+ # examples within a transaction, remove the following line or assign false
44
+ # instead of true.
45
+ # config.use_transactional_fixtures = true
46
+
47
+ # If true, the base class of anonymous controllers will be inferred
48
+ # automatically. This will be the default behavior in future versions of
49
+ # rspec-rails.
50
+ config.infer_base_class_for_anonymous_controllers = false
51
+
52
+ # Run specs in random order to surface order dependencies. If you find an
53
+ # order dependency and want to debug it, you can fix the order by providing
54
+ # the seed, which is printed after each run.
55
+ # --seed 1234
56
+ config.order = 'random'
57
+
58
+ config.before(:suite) do
59
+ DatabaseCleaner.strategy = :truncation
60
+ end
61
+ config.before(:each) do
62
+ DatabaseCleaner.start
63
+ end
64
+ config.after(:each) do
65
+ DatabaseCleaner.clean
66
+ end
67
+
68
+ # FactoryGirl
69
+ config.include FactoryGirl::Syntax::Methods
70
+ config.include Capybara::RSpecMatchers
71
+ end
72
+ end
73
+
74
+ Spork.each_run do
75
+ FactoryGirl.reload
76
+ end
77
+
78
+ def response_from_template(tpl, vars = {})
79
+ bind = OpenStruct.new(vars)
80
+
81
+ tpl = File.read(Rails.root.join('../support/xml', "#{tpl}.erb"))
82
+ ERB.new(tpl).result(bind.instance_eval { binding })
83
+ end
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <response>
3
+ <status>ERROR</status>
4
+ <error>
5
+ <nr>100</nr>
6
+ <message>Kod błędu: 100</message>
7
+ </error>
8
+ </response>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <response>
3
+ <status>OK</status>
4
+ <trans>
5
+ <id>7</id>
6
+ <pos_id><%= pos_id %></pos_id>
7
+ <session_id><%= session_id %></session_id>
8
+ <order_id><%= order_id %></order_id>
9
+ <amount><%= amount %></amount>
10
+ <status><%= status %></status>
11
+ <pay_type>t</pay_type>
12
+ <pay_gw_name>pt</pay_gw_name>
13
+ <desc><%= desc %></desc>
14
+ <desc2></desc2>
15
+ <create>2004-08-2310:39:52</create>
16
+ <init>2013-08-3113:42:43</init>
17
+ <sent>2013-08-3113:48:13</sent>
18
+ <recv></recv>
19
+ <cancel></cancel>
20
+ <auth_fraud>0</auth_fraud>
21
+ <ts><%= ts %></ts>
22
+ <sig><%= sig %></sig>
23
+ </trans>
24
+ </response>