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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 311e575bab7c341ed7595269d2422af27b06921fbd6742966763436e167ddcca
4
+ data.tar.gz: a568585fefe948ae0ad65a1673be4011241bb3a33b5651e893411bedbb5c2b66
5
+ SHA512:
6
+ metadata.gz: 90967ab09017870cfe376b1af09d6942ca49a37f3a5509bb8e1523996591c7ed409575e893a1b6d2226a0ca4977eb0acabafd43c42e701b81fdeee328b21bd68
7
+ data.tar.gz: 8ea4cc0fc2d49c5ab21aa6df97ef0cc83b8b91dc4b26eaf20ad4cd1f5bfde4d13bb44938db8c5e40cdd20dd6b74c680c67087821aa13afd41efdd39f163297b6
data/.env.example ADDED
@@ -0,0 +1,6 @@
1
+ PLATON_KEY=
2
+ PLATON_PASSWORD=
3
+ PLATON_PAY=https://secure.platononline.com/payment/auth
4
+ PLATON_CALLBACK=
5
+ PLATON_ERROR=
6
+ PLATON_PAYMENT_METHOD=CC
@@ -0,0 +1,12 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+ #
6
+
7
+ version: 2
8
+ updates:
9
+ - package-ecosystem: "" # See documentation for possible values
10
+ directory: "/" # Location of package manifests
11
+ schedule:
12
+ interval: "weekly"
@@ -0,0 +1,38 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ "master" ]
6
+ pull_request:
7
+ branches: [ "master" ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ packages: write
16
+
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - name: Set up Ruby 2.6
20
+ uses: actions/setup-ruby@v1
21
+ with:
22
+ ruby-version: 2.6.x
23
+
24
+ - name: Run tests
25
+ run: |
26
+ bundle install
27
+ bundle exec rspec
28
+
29
+ - name: Publish to RubyGems
30
+ run: |
31
+ mkdir -p $HOME/.gem
32
+ touch $HOME/.gem/credentials
33
+ chmod 0600 $HOME/.gem/credentials
34
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
35
+ gem build *.gemspec
36
+ gem push *.gem
37
+ env:
38
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .idea
2
+ .bundle/
3
+ log/*.log
4
+ pkg/
5
+ spec/dummy/db/*.sqlite3
6
+ spec/dummy/db/*.sqlite3-journal
7
+ spec/dummy/log/*.log
8
+ spec/dummy/tmp/
9
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.13.7
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in platon.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,162 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ platon.ua (1.0.1)
5
+ jbuilder (~> 2.6)
6
+ rails (~> 5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (5.1.7)
12
+ actionpack (= 5.1.7)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.1.7)
16
+ actionpack (= 5.1.7)
17
+ actionview (= 5.1.7)
18
+ activejob (= 5.1.7)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.1.7)
22
+ actionview (= 5.1.7)
23
+ activesupport (= 5.1.7)
24
+ rack (~> 2.0)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.1.7)
29
+ activesupport (= 5.1.7)
30
+ builder (~> 3.1)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
+ activejob (5.1.7)
35
+ activesupport (= 5.1.7)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.1.7)
38
+ activesupport (= 5.1.7)
39
+ activerecord (5.1.7)
40
+ activemodel (= 5.1.7)
41
+ activesupport (= 5.1.7)
42
+ arel (~> 8.0)
43
+ activesupport (5.1.7)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ i18n (>= 0.7, < 2)
46
+ minitest (~> 5.1)
47
+ tzinfo (~> 1.1)
48
+ arel (8.0.0)
49
+ builder (3.2.4)
50
+ coderay (1.1.2)
51
+ concurrent-ruby (1.1.10)
52
+ crass (1.0.6)
53
+ diff-lcs (1.3)
54
+ dotenv (2.2.0)
55
+ erubi (1.11.0)
56
+ faraday (0.11.0)
57
+ multipart-post (>= 1.2, < 3)
58
+ globalid (1.0.0)
59
+ activesupport (>= 5.0)
60
+ i18n (1.12.0)
61
+ concurrent-ruby (~> 1.0)
62
+ jbuilder (2.6.3)
63
+ activesupport (>= 3.0.0, < 5.2)
64
+ multi_json (~> 1.2)
65
+ loofah (2.19.0)
66
+ crass (~> 1.0.2)
67
+ nokogiri (>= 1.5.9)
68
+ mail (2.7.1)
69
+ mini_mime (>= 0.1.1)
70
+ method_source (0.9.2)
71
+ mini_mime (1.1.2)
72
+ mini_portile2 (2.8.0)
73
+ minitest (5.16.3)
74
+ multi_json (1.12.2)
75
+ multipart-post (2.0.0)
76
+ nio4r (2.5.8)
77
+ nokogiri (1.13.8)
78
+ mini_portile2 (~> 2.8.0)
79
+ racc (~> 1.4)
80
+ pry (0.11.3)
81
+ coderay (~> 1.1.0)
82
+ method_source (~> 0.9.0)
83
+ racc (1.6.0)
84
+ rack (2.2.4)
85
+ rack-test (2.0.2)
86
+ rack (>= 1.3)
87
+ rails (5.1.7)
88
+ actioncable (= 5.1.7)
89
+ actionmailer (= 5.1.7)
90
+ actionpack (= 5.1.7)
91
+ actionview (= 5.1.7)
92
+ activejob (= 5.1.7)
93
+ activemodel (= 5.1.7)
94
+ activerecord (= 5.1.7)
95
+ activesupport (= 5.1.7)
96
+ bundler (>= 1.3.0)
97
+ railties (= 5.1.7)
98
+ sprockets-rails (>= 2.0.0)
99
+ rails-controller-testing (1.0.2)
100
+ actionpack (~> 5.x, >= 5.0.1)
101
+ actionview (~> 5.x, >= 5.0.1)
102
+ activesupport (~> 5.x)
103
+ rails-dom-testing (2.0.3)
104
+ activesupport (>= 4.2.0)
105
+ nokogiri (>= 1.6)
106
+ rails-html-sanitizer (1.4.3)
107
+ loofah (~> 2.3)
108
+ railties (5.1.7)
109
+ actionpack (= 5.1.7)
110
+ activesupport (= 5.1.7)
111
+ method_source
112
+ rake (>= 0.8.7)
113
+ thor (>= 0.18.1, < 2.0)
114
+ rake (13.0.6)
115
+ rspec-core (3.7.0)
116
+ rspec-support (~> 3.7.0)
117
+ rspec-expectations (3.7.0)
118
+ diff-lcs (>= 1.2.0, < 2.0)
119
+ rspec-support (~> 3.7.0)
120
+ rspec-mocks (3.7.0)
121
+ diff-lcs (>= 1.2.0, < 2.0)
122
+ rspec-support (~> 3.7.0)
123
+ rspec-rails (3.7.1)
124
+ actionpack (>= 3.0)
125
+ activesupport (>= 3.0)
126
+ railties (>= 3.0)
127
+ rspec-core (~> 3.7.0)
128
+ rspec-expectations (~> 3.7.0)
129
+ rspec-mocks (~> 3.7.0)
130
+ rspec-support (~> 3.7.0)
131
+ rspec-support (3.7.0)
132
+ sprockets (4.1.1)
133
+ concurrent-ruby (~> 1.0)
134
+ rack (> 1, < 3)
135
+ sprockets-rails (3.2.2)
136
+ actionpack (>= 4.0)
137
+ activesupport (>= 4.0)
138
+ sprockets (>= 3.0.0)
139
+ thor (1.2.1)
140
+ thread_safe (0.3.6)
141
+ tzinfo (1.2.10)
142
+ thread_safe (~> 0.1)
143
+ websocket-driver (0.6.5)
144
+ websocket-extensions (>= 0.1.0)
145
+ websocket-extensions (0.1.5)
146
+
147
+ PLATFORMS
148
+ ruby
149
+
150
+ DEPENDENCIES
151
+ bundler (~> 1.13)
152
+ dotenv
153
+ faraday
154
+ jbuilder
155
+ platon.ua!
156
+ pry
157
+ rails-controller-testing
158
+ rake (~> 13.0)
159
+ rspec-rails
160
+
161
+ BUNDLED WITH
162
+ 1.17.2
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Platon [![Ruby Gem](https://github.com/mikhail-krainik/platon/actions/workflows/gem-push.yml/badge.svg)](https://github.com/mikhail-krainik/platon/actions/workflows/gem-push.yml)
2
+ Gateway for Platon processing center
3
+ (https://platon.ua/)
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'platon'
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ $ bundle
14
+ ```
15
+
16
+ Or install it yourself as:
17
+ ```bash
18
+ $ gem install platon
19
+ ```
20
+
21
+ ## Usage as engine
22
+
23
+ ##### /config/routes.rb
24
+
25
+ ```ruby
26
+ Rails.application.routes.draw do
27
+ mount Platon::Engine => "/platon"
28
+ end
29
+ ```
30
+ ##### /config/initializer/platon.rb
31
+
32
+ Methods which called when something happen.
33
+ ```ruby
34
+ Platon::Callbacks.setup.success =->(_result) { puts 'success' }
35
+
36
+ Platon::Callbacks.setup.failed =->(_result) { puts 'failed' }
37
+
38
+ Platon::Callbacks.setup.error =->(_result) { puts 'error' }
39
+ ```
40
+
41
+ ## Usage as service
42
+
43
+ #### create form
44
+ ```
45
+ # product description (important keys)
46
+ data = {amount: '99.99', currency: 'USD', description: 'Show desciption less that 255 byte'}
47
+
48
+ # product order id (important key)
49
+ order = 1892
50
+
51
+ # addition field in form :name, :value
52
+ ext = [{name: 'discont', value: 10}]
53
+
54
+ @service = Platon::FormService.call(data, order: order, extra_fields: ext)
55
+
56
+ # views/pay/index.html.erb
57
+ <form action="<%= @service.form_prop[:url] %>" method="<%= @service.form_prop[:method] %>">
58
+ <% @service.fields.map do |field| %>
59
+ <input type="<%= field[:type] %>" name="<%= field[:name] %>" value="<%= field[:value] %>">
60
+ <% end %>
61
+ <input type="submit" value="Pay">
62
+ </form>
63
+ ```
64
+
65
+ #### parse response
66
+
67
+ ```
68
+ # /app/controllers/callback_controller.rb
69
+
70
+ def create
71
+ service = Platon::CallbackService.call(params)
72
+
73
+ if service.success?
74
+ head :ok
75
+ else
76
+ head :bad_request
77
+ end
78
+ end
79
+ ```
80
+
81
+ ## General options
82
+
83
+ ```
84
+ gem 'dotenv-rails'
85
+
86
+ # config/application.rb
87
+ Bundler.require(*Rails.groups)
88
+
89
+ Dotenv::Railtie.load
90
+ ```
91
+
92
+ ##### /.env
93
+
94
+ ```ruby
95
+ PLATON_KEY=XXXXXXXXXX
96
+ PLATON_PASSWORD=XXXXXXXXXX
97
+ PLATON_URL=https://secure.platononline.com/payment/auth
98
+ PLATON_CALLBACK_URL=http://localhost/platon
99
+ PLATON_PAYMENT_METHOD=CC
100
+ ```
101
+
102
+ ## License
103
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ module Platon
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ module Platon
2
+ class CallbacksController < ApplicationController
3
+
4
+ def create
5
+ service = CallbackService.call(params)
6
+ if service.success?
7
+ Platon::Callbacks.setup.success.call(params)
8
+ else
9
+ Platon::Callbacks.setup.failed.call(params)
10
+ end
11
+ head :ok
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Platon
2
+ class ErrorsController < ApplicationController
3
+
4
+ def show
5
+ Platon::Callbacks.setup.error.call(params)
6
+ head :ok
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Platon
2
+ class FormsController < ApplicationController
3
+ def show
4
+ @service = FormService.call(form_params[:data], order: form_params[:id])
5
+ end
6
+
7
+ private def form_params
8
+ params.permit(:id,
9
+ data: [:amount, :currency, :description, :selected, :recurring],
10
+ ext: [:name, :value]
11
+ )
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Platon
2
+ class Callbacks < Struct.new(:success, :failed, :error)
3
+ def self.setup
4
+ @setup ||= Callbacks.new
5
+ end
6
+ end
7
+
8
+ Callbacks.setup.success = ->(_) {}
9
+ Callbacks.setup.failed = ->(_) {}
10
+ Callbacks.setup.error = ->(_) {}
11
+ end
@@ -0,0 +1,11 @@
1
+ module Platon
2
+ class Configure < Struct.new(:account_key, :account_password, :pay_url, :callback_url, :error_url, :payment_method)
3
+ def self.cfg
4
+ @@cfg ||= Configure.new
5
+ if block_given?
6
+ yield @@cfg
7
+ end
8
+ @@cfg
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Platon
2
+ class Encrypt
3
+ class << self
4
+ def code(data)
5
+ Base64.strict_encode64(
6
+ ActiveSupport::JSON.encode(
7
+ Hash(data)
8
+ )
9
+ )
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Platon
2
+ class Status
3
+ attr_accessor :order_status
4
+
5
+ def initialize(order_status)
6
+ @order_status = order_status.upcase
7
+ end
8
+
9
+ def failed?
10
+ %w{CHARGEBACK REFUND}.include?(@order_status)
11
+ end
12
+
13
+ def success?
14
+ %w{SALE ACCEPTED}.include?(@order_status)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module Platon
2
+ class CallbackService
3
+ class Error < Struct.new(:message)
4
+ def success?
5
+ false
6
+ end
7
+ end
8
+
9
+ class << self
10
+ def call(params)
11
+ if params['sign'] == callback_signature(params).to_str
12
+ Platon::Status.new(params['status'])
13
+ else
14
+ Error.new('Error: Invalid signature')
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def callback_signature(params)
21
+ Digest::MD5.hexdigest([
22
+ params['email'].to_s.reverse,
23
+ Platon::Configure.cfg.account_password,
24
+ params['order'],
25
+ (params['card'][0, 6] + params['card'][-4, 4]).reverse
26
+ ].map { |_| _.to_s.upcase }.join)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ require 'base64'
2
+
3
+ module Platon
4
+ class FormService < Struct.new(:form_prop, :fields)
5
+ class << self
6
+ def call(data, order:, extra_fields: nil)
7
+ form_prop = { method: :POST, url: cfg.pay_url }
8
+
9
+ encrypted_data = Platon::Encrypt.code(data)
10
+ sign = Platon::RequestChecksumHashService.call(encrypted_data)
11
+
12
+ fields = [{ type: 'hidden', name: 'key', value: cfg.account_key },
13
+ { type: 'hidden', name: 'payment', value: cfg.payment_method },
14
+ { type: 'hidden', name: 'url', value: cfg.callback_url },
15
+ { type: 'hidden', name: 'order', value: order },
16
+ { type: 'hidden', name: 'data', value: encrypted_data },
17
+ { type: 'hidden', name: 'sign', value: sign }]
18
+
19
+ if extra_fields.is_a? Hash
20
+ fields.push extract_extra_fields(extra_fields, keys_skip: fields.map { |i| i[:name] })
21
+ end
22
+
23
+ new(form_prop, fields)
24
+ end
25
+
26
+ private
27
+
28
+ def extract_extra_fields(extra_fields, keys_skip: [])
29
+ extra_fields[:ext].map do |ext|
30
+ skip if keys_skip.include? ext[:name]
31
+ {type: 'hidden', name: ext[:name], value: ext[:value]}
32
+ end
33
+ end
34
+
35
+ def cfg
36
+ cfg = Platon::Configure.cfg
37
+ raise ArgumentError, "Can't find Platon credentials" if cfg.account_key.nil?
38
+ cfg
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ require 'digest'
2
+
3
+ module Platon
4
+ class RequestChecksumHashService
5
+ class << self
6
+ def call(product_prop)
7
+ cfg = Platon::Configure.cfg
8
+ params = [
9
+ cfg.account_key,
10
+ cfg.payment_method,
11
+ product_prop,
12
+ cfg.callback_url,
13
+ cfg.account_password
14
+ ].map { |k| k.to_s.reverse.upcase }.join
15
+
16
+ d = Digest::MD5.new
17
+ d.hexdigest(params)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,6 @@
1
+ <form action="<%= @service.form_prop[:url] %>" method="<%= @service.form_prop[:method] %>">
2
+ <% @service.fields.map do |field| %>
3
+ <input type="<%= field[:type] %>" name="<%= field[:name] %>" value="<%= field[:value] %>">
4
+ <% end %>
5
+ <input type="submit" value="Pay">
6
+ </form>
@@ -0,0 +1,12 @@
1
+ json.form do
2
+ json.url @service.form_prop[:url]
3
+ json.method @service.form_prop[:method]
4
+
5
+ json.fields @service.fields do |field|
6
+ unless field[:value].nil?
7
+ json.type field[:type]
8
+ json.name field[:name]
9
+ json.value field[:value]
10
+ end
11
+ end
12
+ end
data/bin/rails ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/platon/engine', __FILE__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
@@ -0,0 +1,19 @@
1
+ options:
2
+ docker: true
3
+
4
+ pipelines:
5
+ default:
6
+ - step:
7
+ name: install gems and run tests
8
+ image: eticket/eticket-ruby-base:2.3.1
9
+ caches:
10
+ - bundler
11
+ script:
12
+ - export RAILS_ENV=ci
13
+ - gem install bundler
14
+ - gem install bundler --no-ri --no-rdoc
15
+ - bundle install --path vendor/bundle
16
+ - bundle exec rspec spec
17
+ definitions:
18
+ caches:
19
+ bundler: vendor/bundle
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Platon::Engine.routes.draw do
2
+ resource :callbacks, only: :create
3
+ resource :errors, only: :show
4
+ resource :forms, only: :show
5
+ end
@@ -0,0 +1,12 @@
1
+ module Platon
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Platon
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec, :fixture => false
7
+ g.fixture_replacement :factory_girl, :dir => 'spec/support/factories'
8
+ g.assets false
9
+ g.helper false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Platon
2
+ VERSION = '1.0.1'
3
+ end
data/lib/platon.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "platon/engine"
2
+
3
+ module Platon
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :platon do
3
+ # # Task goes here
4
+ # end