webtopay 1.2.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/README.md +145 -0
  4. data/lib/webtopay.rb +5 -3
  5. data/lib/webtopay/exception.rb +11 -1
  6. data/lib/webtopay/payment.rb +45 -0
  7. data/lib/webtopay/response.rb +198 -0
  8. data/lib/webtopay/version.rb +1 -1
  9. data/lib/webtopay_controller.rb +14 -19
  10. data/lib/webtopay_helper.rb +19 -15
  11. data/spec/dummy/README.rdoc +28 -0
  12. data/spec/dummy/Rakefile +6 -0
  13. data/spec/dummy/app/assets/images/.keep +0 -0
  14. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  15. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  16. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  17. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  18. data/spec/dummy/app/controllers/payments_controller.rb +11 -0
  19. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  20. data/spec/dummy/app/mailers/.keep +0 -0
  21. data/spec/dummy/app/models/.keep +0 -0
  22. data/spec/dummy/app/models/concerns/.keep +0 -0
  23. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  24. data/spec/dummy/bin/bundle +3 -0
  25. data/spec/dummy/bin/rails +4 -0
  26. data/spec/dummy/bin/rake +4 -0
  27. data/spec/dummy/config.ru +4 -0
  28. data/spec/dummy/config/application.rb +23 -0
  29. data/spec/dummy/config/boot.rb +5 -0
  30. data/spec/dummy/config/database.yml +25 -0
  31. data/spec/dummy/config/environment.rb +5 -0
  32. data/spec/dummy/config/environments/development.rb +29 -0
  33. data/spec/dummy/config/environments/production.rb +80 -0
  34. data/spec/dummy/config/environments/test.rb +36 -0
  35. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  37. data/spec/dummy/config/initializers/inflections.rb +16 -0
  38. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  39. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  40. data/spec/dummy/config/initializers/session_store.rb +3 -0
  41. data/spec/dummy/config/initializers/webtopay.rb +4 -0
  42. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  43. data/spec/dummy/config/locales/en.yml +23 -0
  44. data/spec/dummy/config/routes.rb +61 -0
  45. data/spec/dummy/db/test.sqlite3 +0 -0
  46. data/spec/dummy/lib/assets/.keep +0 -0
  47. data/spec/dummy/log/.keep +0 -0
  48. data/spec/dummy/public/404.html +58 -0
  49. data/spec/dummy/public/422.html +58 -0
  50. data/spec/dummy/public/500.html +57 -0
  51. data/spec/dummy/public/favicon.ico +0 -0
  52. data/spec/lib/webtopay/payment_spec.rb +31 -0
  53. data/spec/lib/webtopay/response_spec.rb +57 -0
  54. data/spec/lib/webtopay_controller_spec.rb +19 -0
  55. data/spec/spec_helper.rb +59 -0
  56. data/webtopay.gemspec +10 -3
  57. metadata +195 -47
  58. data/README +0 -71
  59. data/lib/webtopay/api.rb +0 -407
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,4 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure sensitive parameters which will be filtered from the log file.
4
+ Rails.application.config.filter_parameters += [:password]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, '\1en'
8
+ # inflect.singular /^(ox)en/i, '\1'
9
+ # inflect.irregular 'person', 'people'
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym 'RESTful'
16
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,12 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rake secret` to generate a secure secret key.
9
+
10
+ # Make sure your secret_key_base is kept private
11
+ # if you're sharing your code publicly.
12
+ Dummy::Application.config.secret_key_base = '05a50aaa1a17b07e88edaf3ade46ca0e525078bae1a2a7f9b79cdc4e37e97ad2c7eb1a102fa518e378e7b00da1b0c406fcb8233d2dfd219b78b496c88005874f'
@@ -0,0 +1,3 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
@@ -0,0 +1,4 @@
1
+ WebToPay.configure do |config|
2
+ config.project_id = 12345
3
+ config.sign_password = 'abcdabcd'
4
+ end
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
+ end
10
+
11
+ # To enable root element in JSON for ActiveRecord objects.
12
+ # ActiveSupport.on_load(:active_record) do
13
+ # self.include_root_in_json = true
14
+ # end
@@ -0,0 +1,23 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ hello: "Hello world"
@@ -0,0 +1,61 @@
1
+ Dummy::Application.routes.draw do
2
+ resources :payments do
3
+ collection do
4
+ get :order
5
+ end
6
+ end
7
+ # The priority is based upon order of creation: first created -> highest priority.
8
+ # See how all your routes lay out with "rake routes".
9
+
10
+ # You can have the root of your site routed with "root"
11
+ # root 'welcome#index'
12
+
13
+ # Example of regular route:
14
+ # get 'products/:id' => 'catalog#view'
15
+
16
+ # Example of named route that can be invoked with purchase_url(id: product.id)
17
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
18
+
19
+ # Example resource route (maps HTTP verbs to controller actions automatically):
20
+ # resources :products
21
+
22
+ # Example resource route with options:
23
+ # resources :products do
24
+ # member do
25
+ # get 'short'
26
+ # post 'toggle'
27
+ # end
28
+ #
29
+ # collection do
30
+ # get 'sold'
31
+ # end
32
+ # end
33
+
34
+ # Example resource route with sub-resources:
35
+ # resources :products do
36
+ # resources :comments, :sales
37
+ # resource :seller
38
+ # end
39
+
40
+ # Example resource route with more complex sub-resources:
41
+ # resources :products do
42
+ # resources :comments
43
+ # resources :sales do
44
+ # get 'recent', on: :collection
45
+ # end
46
+ # end
47
+
48
+ # Example resource route with concerns:
49
+ # concern :toggleable do
50
+ # post 'toggle'
51
+ # end
52
+ # resources :posts, concerns: :toggleable
53
+ # resources :photos, concerns: :toggleable
54
+
55
+ # Example resource route within a namespace:
56
+ # namespace :admin do
57
+ # # Directs /admin/products/* to Admin::ProductsController
58
+ # # (app/controllers/admin/products_controller.rb)
59
+ # resources :products
60
+ # end
61
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe WebToPay::Payment do
4
+ subject{ WebToPay::Payment.new(payment_data, sign_password: sign_password) }
5
+ let(:sign_password){ 'a1b2c3d4e5a1b2c3d4e5a1b2c3d4e5'}
6
+ let(:payment_data) {
7
+ {
8
+ 'projectid' => 123456,
9
+ 'orderid' => 654321,
10
+ 'lang' => 'LIT',
11
+ 'amount' => 2000,
12
+ 'currency' => 'LTL',
13
+ 'accepturl' => 'http://example.com/accept',
14
+ 'cancelurl' => 'http://example.com/cancel',
15
+ 'callbackurl' => 'http://example.com/callback',
16
+ 'country' => 'lt',
17
+ 'paytext' => 'Billing for XX at the website XXX',
18
+ 'p_email' => 'petras@example.com',
19
+ 'p_name' => 'Jonas',
20
+ 'p_surname' => 'Jonaitis',
21
+ 'payment' => 'vb2',
22
+ 'test' => 1,
23
+ 'version' => 1.6
24
+ }
25
+ }
26
+
27
+ its(:query){ should == 'projectid=123456&orderid=654321&lang=LIT&amount=2000&currency=LTL&accepturl=http%3A%2F%2Fexample.com%2Faccept&cancelurl=http%3A%2F%2Fexample.com%2Fcancel&callbackurl=http%3A%2F%2Fexample.com%2Fcallback&country=lt&paytext=Billing+for+XX+at+the+website+XXX&p_email=petras%40example.com&p_name=Jonas&p_surname=Jonaitis&payment=vb2&test=1&version=1.6' }
28
+ its(:data) { should == 'cHJvamVjdGlkPTEyMzQ1NiZvcmRlcmlkPTY1NDMyMSZsYW5nPUxJVCZhbW91bnQ9MjAwMCZjdXJyZW5jeT1MVEwmYWNjZXB0dXJsPWh0dHAlM0ElMkYlMkZleGFtcGxlLmNvbSUyRmFjY2VwdCZjYW5jZWx1cmw9aHR0cCUzQSUyRiUyRmV4YW1wbGUuY29tJTJGY2FuY2VsJmNhbGxiYWNrdXJsPWh0dHAlM0ElMkYlMkZleGFtcGxlLmNvbSUyRmNhbGxiYWNrJmNvdW50cnk9bHQmcGF5dGV4dD1CaWxsaW5nK2ZvcitYWCthdCt0aGUrd2Vic2l0ZStYWFgmcF9lbWFpbD1wZXRyYXMlNDBleGFtcGxlLmNvbSZwX25hbWU9Sm9uYXMmcF9zdXJuYW1lPUpvbmFpdGlzJnBheW1lbnQ9dmIyJnRlc3Q9MSZ2ZXJzaW9uPTEuNg==' }
29
+ its(:sign) { should == '51f7a63b3e43fde47daa0afdb02cdb8f' }
30
+
31
+ end
@@ -0,0 +1,57 @@
1
+ # coding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe WebToPay::Response do
5
+ let(:response_data) {
6
+ {
7
+ "data" => "cHJvamVjdGlkPTQzMjcyJm9yZGVyaWQ9MSZhbW91bnQ9MTQwMCZwX2VtYWlsPWJsb29tcmFpbiU0MGdtYWlsLmNvbSZwX25hbWU9VG9tYXMmcF9zdXJuYW1lPUJ1dGtldmljaXVzJnBheW1lbnQ9dmIyJnRlc3Q9MSZ2ZXJzaW9uPTEuNiZ0eXBlPUVNQSZsYW5nPSZjdXJyZW5jeT1MVEwmcGF5dGV4dD1VJUM1JUJFc2FreW1hcytuciUzQSsxK2h0dHAlM0ElMkYlMkZsb2NhbGhvc3QrcHJvamVrdGUuKyUyOFBhcmRhdiVDNCU5N2phcyUzQStQb3ZpbGFzK0p1ciVDNCU4RHlzJTI5JmNvdW50cnk9TFQmX2NsaWVudF9sYW5ndWFnZT1saXQmc3RhdHVzPTEmcmVxdWVzdGlkPTUzODgwMzk0Jm5hbWU9VUFCJnN1cmVuYW1lPU1vayVDNCU5N2ppbWFpLmx0JnBheWFtb3VudD0xNDAwJnBheWN1cnJlbmN5PUxUTA==",
8
+ "ss1" => "d7fbde5cb3fcfc8f55a8737621f70b02",
9
+ "ss2" => "fBplGfKCAGOxqEd9GjheT3psaivT34sO0CcupPSQgQNqZkcbgUxtCk06j7oUiAMG_jLBuqsUs55TsD1z2eAXMY4N8Pcbqf6dQ7xOHvpshcvkAzXu3n9JHspxvEGR7Mgbv6etb0DvpEtBR9WClQTnhQbSmnCkDaCSOtn3l0ACSYI="
10
+ }
11
+ }
12
+
13
+ subject{ WebToPay::Response.new(response_data, { projectid: 43272, sign_password: 'bd842a6ef17060c1bd6d096085dc8e40'}) }
14
+
15
+ describe '#valid?' do
16
+ context 'when fields does not match' do
17
+ let(:validation_params) { { amount: 999, p_email: "foo@bar.baz" } }
18
+ it 'returns false' do
19
+ subject.valid?(validation_params).should be_false
20
+ end
21
+ it 'adds errors' do
22
+ expect {
23
+ subject.valid?(validation_params)
24
+ }.to change{ subject.errors.size }.from(0).to(2)
25
+ end
26
+ end
27
+ end
28
+
29
+ its(:query){ should == "projectid=43272&orderid=1&amount=1400&p_email=bloomrain%40gmail.com&p_name=Tomas&p_surname=Butkevicius&payment=vb2&test=1&version=1.6&type=EMA&lang=&currency=LTL&paytext=U%C5%BEsakymas+nr%3A+1+http%3A%2F%2Flocalhost+projekte.+%28Pardav%C4%97jas%3A+Povilas+Jur%C4%8Dys%29&country=LT&_client_language=lit&status=1&requestid=53880394&name=UAB&surename=Mok%C4%97jimai.lt&payamount=1400&paycurrency=LTL" }
30
+ its(:query_params){ should == {
31
+ "_client_language" => "lit",
32
+ "amount" => "1400",
33
+ "country" => "LT",
34
+ "currency" => "LTL",
35
+ "lang" => "",
36
+ "name" => "UAB",
37
+ "orderid" => "1",
38
+ "p_email" => "bloomrain@gmail.com",
39
+ "p_name" => "Tomas",
40
+ "p_surname" => "Butkevicius",
41
+ "payamount" => "1400",
42
+ "paycurrency" => "LTL",
43
+ "payment" => "vb2",
44
+ "paytext" => "Užsakymas nr: 1 http://localhost projekte. (Pardavėjas: Povilas Jurčys)",
45
+ "projectid" => "43272",
46
+ "requestid" => "53880394",
47
+ "ss1" => "d7fbde5cb3fcfc8f55a8737621f70b02",
48
+ "ss2" => "fBplGfKCAGOxqEd9GjheT3psaivT34sO0CcupPSQgQNqZkcbgUxtCk06j7oUiAMG_jLBuqsUs55TsD1z2eAXMY4N8Pcbqf6dQ7xOHvpshcvkAzXu3n9JHspxvEGR7Mgbv6etb0DvpEtBR9WClQTnhQbSmnCkDaCSOtn3l0ACSYI=",
49
+ "status" => "1",
50
+ "surename" => "Mokėjimai.lt",
51
+ "test" => "1",
52
+ "type" => "EMA",
53
+ "version" => "1.6"
54
+ } }
55
+
56
+ its(:valid?){ should be_true }
57
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe PaymentsController, type: :controller do
4
+
5
+ describe '.webtopay' do
6
+ it 'ignores methods that are not mentioned on webtopay actions list' do
7
+ get :index
8
+ # if webtopay is not ignored then then we should get message "'projectid' is required but missing." with 500 status code
9
+ response.should be_success
10
+ end
11
+
12
+ context "when webtopay params are missing" do
13
+ it 'raises error message' do
14
+ expect { get :order }.to raise_error('"projectid" is invalid. Expected "12345", but was ""')
15
+ end
16
+ end
17
+
18
+ end
19
+ end