platon.ua 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +6 -0
  3. data/.github/dependabot.yml +12 -0
  4. data/.github/workflows/gem-push.yml +38 -0
  5. data/.gitignore +9 -0
  6. data/.rspec +2 -0
  7. data/.travis.yml +5 -0
  8. data/Gemfile +6 -0
  9. data/Gemfile.lock +162 -0
  10. data/README.md +103 -0
  11. data/Rakefile +6 -0
  12. data/app/controllers/platon/application_controller.rb +4 -0
  13. data/app/controllers/platon/callbacks_controller.rb +14 -0
  14. data/app/controllers/platon/errors_controller.rb +9 -0
  15. data/app/controllers/platon/forms_controller.rb +14 -0
  16. data/app/models/platon/callbacks.rb +11 -0
  17. data/app/models/platon/configure.rb +11 -0
  18. data/app/models/platon/encrypt.rb +13 -0
  19. data/app/models/platon/status.rb +17 -0
  20. data/app/services/platon/callback_service.rb +30 -0
  21. data/app/services/platon/form_service.rb +42 -0
  22. data/app/services/platon/request_checksum_hash_service.rb +21 -0
  23. data/app/views/layouts/platon/application.html.erb +1 -0
  24. data/app/views/platon/forms/show.html.erb +6 -0
  25. data/app/views/platon/forms/show.json.jbuilder +12 -0
  26. data/bin/rails +13 -0
  27. data/bitbucket-pipelines.yml +19 -0
  28. data/config/routes.rb +5 -0
  29. data/lib/platon/engine.rb +12 -0
  30. data/lib/platon/version.rb +3 -0
  31. data/lib/platon.rb +5 -0
  32. data/lib/tasks/platon_tasks.rake +4 -0
  33. data/platon.gemspec +35 -0
  34. data/spec/controllers/platon/callbacks_controller_spec.rb +30 -0
  35. data/spec/controllers/platon/errors_controller_spec.rb +16 -0
  36. data/spec/controllers/platon/forms_controller_spec.rb +30 -0
  37. data/spec/dummy/Rakefile +6 -0
  38. data/spec/dummy/app/assets/config/manifest.js +4 -0
  39. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  40. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  41. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  42. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  43. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  44. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  45. data/spec/dummy/app/jobs/application_job.rb +2 -0
  46. data/spec/dummy/app/views/layouts/application.html.erb +13 -0
  47. data/spec/dummy/bin/bundle +3 -0
  48. data/spec/dummy/bin/rails +4 -0
  49. data/spec/dummy/bin/rake +4 -0
  50. data/spec/dummy/bin/setup +34 -0
  51. data/spec/dummy/bin/update +29 -0
  52. data/spec/dummy/config/application.rb +26 -0
  53. data/spec/dummy/config/boot.rb +5 -0
  54. data/spec/dummy/config/cable.yml +9 -0
  55. data/spec/dummy/config/environment.rb +5 -0
  56. data/spec/dummy/config/environments/development.rb +46 -0
  57. data/spec/dummy/config/environments/production.rb +78 -0
  58. data/spec/dummy/config/environments/test.rb +36 -0
  59. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  60. data/spec/dummy/config/initializers/assets.rb +11 -0
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  63. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/spec/dummy/config/initializers/inflections.rb +16 -0
  65. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  66. data/spec/dummy/config/initializers/new_framework_defaults.rb +21 -0
  67. data/spec/dummy/config/initializers/session_store.rb +3 -0
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
  69. data/spec/dummy/config/locales/en.yml +23 -0
  70. data/spec/dummy/config/puma.rb +47 -0
  71. data/spec/dummy/config/routes.rb +3 -0
  72. data/spec/dummy/config/secrets.yml +25 -0
  73. data/spec/dummy/config/spring.rb +6 -0
  74. data/spec/dummy/config.ru +5 -0
  75. data/spec/dummy/log/test.log +34 -0
  76. data/spec/dummy/public/404.html +67 -0
  77. data/spec/dummy/public/422.html +67 -0
  78. data/spec/dummy/public/500.html +66 -0
  79. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  80. data/spec/dummy/public/apple-touch-icon.png +0 -0
  81. data/spec/dummy/public/favicon.ico +0 -0
  82. data/spec/models/platon/platon_configures_spec.rb +36 -0
  83. data/spec/platon_spec.rb +7 -0
  84. data/spec/services/platon/platon_callback_services_spec.rb +43 -0
  85. data/spec/services/platon/platon_encrypt_spec.rb +19 -0
  86. data/spec/services/platon/platon_form_services_spec.rb +56 -0
  87. data/spec/services/platon/platon_request_checksum_hash_services_spec.rb +23 -0
  88. data/spec/services/platon/platon_statuses_spec.rb +15 -0
  89. data/spec/spec_helper.rb +30 -0
  90. data/spec/support/assigns.rb +9 -0
  91. metadata +329 -0
@@ -0,0 +1,47 @@
1
+ # Puma can serve each request in a thread from an internal thread pool.
2
+ # The `threads` method setting takes two numbers a minimum and maximum.
3
+ # Any libraries that use thread pools should be configured to match
4
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
+ # and maximum, this matches the default thread size of Active Record.
6
+ #
7
+ threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
8
+ threads threads_count, threads_count
9
+
10
+ # Specifies the `port` that Puma will listen on to receive requests, default is 3000.
11
+ #
12
+ port ENV.fetch("PORT") { 3000 }
13
+
14
+ # Specifies the `environment` that Puma will run in.
15
+ #
16
+ environment ENV.fetch("RAILS_ENV") { "development" }
17
+
18
+ # Specifies the number of `workers` to boot in clustered mode.
19
+ # Workers are forked webserver processes. If using threads and workers together
20
+ # the concurrency of the application would be max `threads` * `workers`.
21
+ # Workers do not work on JRuby or Windows (both of which do not support
22
+ # processes).
23
+ #
24
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
25
+
26
+ # Use the `preload_app!` method when specifying a `workers` number.
27
+ # This directive tells Puma to first boot the application and load code
28
+ # before forking the application. This takes advantage of Copy On Write
29
+ # process behavior so workers use less memory. If you use this option
30
+ # you need to make sure to reconnect any threads in the `on_worker_boot`
31
+ # block.
32
+ #
33
+ # preload_app!
34
+
35
+ # The code in the `on_worker_boot` will be called if you are using
36
+ # clustered mode by specifying a number of `workers`. After each worker
37
+ # process is booted this block will be run, if you are using `preload_app!`
38
+ # option you will want to use this block to reconnect to any threads
39
+ # or connections that may have been created at application boot, Ruby
40
+ # cannot share connections between processes.
41
+ #
42
+ # on_worker_boot do
43
+ # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
44
+ # end
45
+
46
+ # Allow puma to be restarted by `rails restart` command.
47
+ plugin :tmp_restart
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ mount Platon::Engine => "/platon"
3
+ end
@@ -0,0 +1,25 @@
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 `rails secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: 0d52cd61108d2aa08d5c3b8de92f22a0573b1d87f2815bda630062d30c66a4f9db1e525d6a781ebd5e9104c0e3210463bea13c0e077405d7535afb7b00a6ee7a
15
+
16
+ test:
17
+ secret_key_base: 7623cea67dc87f9df100ffa73635f9ac950077728c65e46e4d09d5b62e15999faee66797bb56983a6854d0264defc79f865147e104644a6f526e96beb7d71c37
18
+
19
+ ci:
20
+ secret_key_base: 42cbdea5764388782df88ef9590cf20dd9bec5127eb74de092c841585ce0ed5bc9178cc770f72462cb85175387edeb14d4da526e63a9d6a191f4bae8ba5663eb
21
+
22
+ # Do not keep production secrets in the repository,
23
+ # instead read values from the environment.
24
+ production:
25
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,6 @@
1
+ %w(
2
+ .ruby-version
3
+ .rbenv-vars
4
+ tmp/restart.txt
5
+ tmp/caching-dev.txt
6
+ ).each { |path| Spring.watch(path) }
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -0,0 +1,34 @@
1
+ Processing by Platon::CallbacksController#create as HTML
2
+ Parameters: {"card"=>"0000 0000 0000 0001", "email"=>"example@email.org", "sign"=>"60be9c95f46e5707a580a50ac141fc0d", "status"=>"accepted"}
3
+ Completed 200 OK in 1ms
4
+ Processing by Platon::CallbacksController#create as HTML
5
+ Parameters: {"card"=>"0000 0000 0000 0001", "email"=>"example@email.org", "sign"=>"60be9c95f46e5707a580a50ac141fc0d", "status"=>"refund"}
6
+ Completed 200 OK in 1ms
7
+ Processing by Platon::ErrorsController#show as HTML
8
+ Parameters: {"any"=>"any"}
9
+ Completed 200 OK in 0ms
10
+ Processing by Platon::FormsController#show as
11
+ Parameters: {"data"=>{"amount"=>"100.25", "currency"=>"UAH", "description"=>"Desc", "name"=>"rails way"}, "ext"=>[{"reserve"=>"UUID"}], "id"=>"1"}
12
+ Unpermitted parameter: :name
13
+ Unpermitted parameter: :reserve
14
+ Unpermitted parameter: :format
15
+ Unpermitted parameter: :name
16
+ Unpermitted parameter: :reserve
17
+ Unpermitted parameter: :format
18
+ Rendering /home/runner/work/platon/platon/app/views/platon/forms/show.html.erb within layouts/platon/application
19
+ Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.
20
+ Rendered /home/runner/work/platon/platon/app/views/platon/forms/show.html.erb within layouts/platon/application (0.2ms)
21
+ Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.
22
+ Completed 200 OK in 9ms (Views: 3.5ms)
23
+ Started GET "/platon/forms?data[amount]=100.25&data[currency]=UAH&data[description]=Desc&data[name]=rails+way&id=1&ext[][reserve]=UUID&format=html" for 127.0.0.1 at 2022-10-18 03:59:06 +0000
24
+ Processing by Platon::FormsController#show as HTML
25
+ Parameters: {"data"=>{"amount"=>"100.25", "currency"=>"UAH", "description"=>"Desc", "name"=>"rails way"}, "id"=>"1", "ext"=>[{"reserve"=>"UUID"}]}
26
+ Unpermitted parameter: :name
27
+ Unpermitted parameter: :reserve
28
+ Unpermitted parameter: :format
29
+ Unpermitted parameter: :name
30
+ Unpermitted parameter: :reserve
31
+ Unpermitted parameter: :format
32
+ Rendering /home/runner/work/platon/platon/app/views/platon/forms/show.html.erb within layouts/platon/application
33
+ Rendered /home/runner/work/platon/platon/app/views/platon/forms/show.html.erb within layouts/platon/application (0.8ms)
34
+ Completed 200 OK in 3ms (Views: 1.9ms)
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
File without changes
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module Platon
4
+ RSpec.describe Configure, type: :model do
5
+
6
+ describe 'Set configuration' do
7
+ context 'when user set configuration' do
8
+ subject(:config) { described_class.cfg }
9
+
10
+ it 'key account_key exists' do
11
+ expect(config.account_key).not_to be_nil
12
+ end
13
+
14
+ it 'key account_password exists' do
15
+ expect(config.account_password).not_to be_nil
16
+ end
17
+
18
+ it 'key pay_url exists' do
19
+ expect(config.pay_url).not_to be_nil
20
+ end
21
+
22
+ it 'key callback_url exists' do
23
+ expect(config.callback_url).not_to be_nil
24
+ end
25
+
26
+ it 'key error_url exists' do
27
+ expect(config.error_url).not_to be_nil
28
+ end
29
+
30
+ it 'key payment_method exists' do
31
+ expect(config.payment_method).not_to be_nil
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe Platon do
4
+ it "has a version number" do
5
+ expect(Platon::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ module Platon
4
+ RSpec.describe CallbackService do
5
+ let(:params) {
6
+ {
7
+ email: 'example@email.org',
8
+ card: '0000 0000 0000 0001',
9
+ sign: 'd29a496b14206feb20d5c8382b23b356'
10
+ }
11
+ }
12
+ before do
13
+ Platon::Configure.cfg.account_password = 'R5JGxRTu2Q4nTDJeVnn9DJ7M'
14
+ end
15
+
16
+ describe '.success?' do
17
+ subject { described_class.call(params.merge(status: 'accepted').as_json) }
18
+ it { expect(subject.success?).to be_truthy }
19
+ end
20
+
21
+ describe '.failed?' do
22
+ subject { described_class.call(params.merge(status: 'refund').as_json) }
23
+ it { expect(subject.success?).to be_falsey }
24
+ end
25
+
26
+ describe 'signature' do
27
+ context 'when valid' do
28
+ subject { described_class.call(params.merge(status: 'accepted').as_json) }
29
+ it {
30
+ expect(subject).to be_a(Status)
31
+ }
32
+ end
33
+
34
+ context 'when invalid' do
35
+ subject { described_class.call(params.merge(status: 'accepted', sign: '-').as_json) }
36
+ it {
37
+ expect(subject).to be_a(CallbackService::Error)
38
+ expect(subject.message).to eq('Error: Invalid signature')
39
+ }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module Platon
4
+ RSpec.describe Encrypt do
5
+ let(:data) do
6
+ {
7
+ amount: '99.99',
8
+ currency: 'USD',
9
+ description: 'Desc',
10
+ }
11
+ end
12
+
13
+ let(:result) { 'eyJhbW91bnQiOiI5OS45OSIsImN1cnJlbmN5IjoiVVNEIiwiZGVzY3JpcHRpb24iOiJEZXNjIn0=' }
14
+
15
+ it do
16
+ expect(described_class.code(data)).to eq result
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'faraday'
3
+
4
+ module Platon
5
+ RSpec.describe FormService do
6
+ describe '#call' do
7
+ let(:params) {
8
+ {
9
+ data: { amount: '99.99', currency: 'UAH', description: 'description' },
10
+ extra: [{ name: 'name1', value: 'value1' }]
11
+ }
12
+ }
13
+
14
+ subject { described_class.call(params[:data], order: 1) }
15
+
16
+ it 'send request' do
17
+ response = Faraday.post do |req|
18
+ req.url subject.form_prop[:url]
19
+ req.body = {}.tap do |body|
20
+ subject.fields.each { |f| body[f[:name]] = f[:value] }
21
+ end
22
+ end
23
+
24
+ expect(Nokogiri.parse(response.body).xpath('//div[@class="main"]').text.strip).not_to eq("Not enough input data")
25
+ end
26
+ end
27
+
28
+ describe 'Compare with the reference value' do
29
+ subject do
30
+ Platon::Configure.cfg.account_key = '7LNR6TEHWF'
31
+ Platon::Configure.cfg.callback_url ='http://localhost:3000/platon/callback'
32
+ Platon::Configure.cfg.account_password = 'ExcNdmUj0zwxpHAnGbWUnhv0G04RRahV'
33
+ described_class.call(params[:data], order: params[:order])
34
+ end
35
+
36
+ let(:params) do
37
+ {
38
+ data: { amount: '99.99', currency: 'USD', description: 'Desc' },
39
+ order: 1
40
+ }
41
+ end
42
+
43
+ # Next values were generated by platon example php script (buy_platon.php) at the same data
44
+ let(:ref_sign) { 'c006d7beb0a732a3bb637587ce7c8aef' }
45
+ let(:ref_data_key) { 'eyJhbW91bnQiOiI5OS45OSIsImN1cnJlbmN5IjoiVVNEIiwiZGVzY3JpcHRpb24iOiJEZXNjIn0=' }
46
+
47
+ it 'encrypted data is valid' do
48
+ expect(subject.fields.find{ |_| _[:name] == 'data' }[:value]).to eq ref_data_key
49
+ end
50
+
51
+ it 'encrypted sing is valid' do
52
+ expect(subject.fields.find{ |_| _[:name] == 'sign' }[:value]).to eq ref_sign
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ module Platon
4
+ RSpec.describe RequestChecksumHashService do
5
+ let(:product_prop) do
6
+ {
7
+ amount: '99.99',
8
+ currency: 'USD',
9
+ description: 'Desc',
10
+ }
11
+ end
12
+
13
+ before do
14
+ Platon::Configure.cfg.account_key = 'OSNK298HD'
15
+ Platon::Configure.cfg.callback_url ='http://localhost:3000/platon/callback'
16
+ Platon::Configure.cfg.account_password = '3pVzbpKpRHxbgAQfKqSEznNj'
17
+ end
18
+
19
+ it do
20
+ expect(described_class.call(product_prop)).to eq 'bfff5e71fce192d77304980f8eadcc9c'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ module Platon
4
+ RSpec.describe Status do
5
+ describe '#failed?' do
6
+ subject { described_class.new('sale') }
7
+ it { is_expected.to be_success }
8
+ end
9
+
10
+ describe '#success?' do
11
+ subject { described_class.new('chargeback') }
12
+ it { is_expected.to be_failed }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+
3
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
4
+
5
+ require 'pry'
6
+
7
+ require 'rspec/rails'
8
+
9
+ require 'dotenv'
10
+ Dotenv.load(".env.#{ENV['RAILS_ENV']}")
11
+
12
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
13
+ require 'platon'
14
+
15
+ ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
16
+
17
+ Dir[File.join(ENGINE_RAILS_ROOT, 'spec/support/**/*.rb')].each {|f| require f }
18
+
19
+ Platon::Configure.cfg do |cfg|
20
+ cfg.account_key = SecureRandom.hex
21
+ cfg.account_password = SecureRandom.hex
22
+ cfg.pay_url = 'https://secure.platononline.com/payment/auth'
23
+ cfg.callback_url = '/success_url'
24
+ cfg.error_url = '/error.url'
25
+ cfg.payment_method = 'CC'
26
+ end
27
+
28
+ RSpec.configure do |config|
29
+ config.use_transactional_fixtures = true
30
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails-controller-testing'
2
+
3
+ RSpec.configure do |config|
4
+ [:controller, :view, :request].each do |type|
5
+ config.include ::Rails::Controller::Testing::TestProcess, :type => type
6
+ config.include ::Rails::Controller::Testing::TemplateAssertions, :type => type
7
+ config.include ::Rails::Controller::Testing::Integration, :type => type
8
+ end
9
+ end