mandarin_pay 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +29 -0
  3. data/.rubocop.yml +63 -0
  4. data/.travis.yml +6 -0
  5. data/CHANGELOG.md +3 -0
  6. data/Gemfile +9 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +88 -0
  9. data/Rakefile +7 -0
  10. data/app/controllers/.gitkeep +0 -0
  11. data/app/controllers/mandarin_pay_controller.rb +33 -0
  12. data/bin/bundler +16 -0
  13. data/bin/cdiff +16 -0
  14. data/bin/colortab +16 -0
  15. data/bin/coveralls +16 -0
  16. data/bin/decolor +16 -0
  17. data/bin/erubis +16 -0
  18. data/bin/htmldiff +16 -0
  19. data/bin/ldiff +16 -0
  20. data/bin/nokogiri +16 -0
  21. data/bin/rackup +16 -0
  22. data/bin/rails +16 -0
  23. data/bin/rake +16 -0
  24. data/bin/rspec +16 -0
  25. data/bin/sprockets +16 -0
  26. data/bin/term_display +16 -0
  27. data/bin/term_mandel +16 -0
  28. data/bin/thor +16 -0
  29. data/config/routes.rb +11 -0
  30. data/lib/generators/mandarin_pay/install_generator.rb +10 -0
  31. data/lib/generators/mandarin_pay/templates/mandarin_pay.rb +15 -0
  32. data/lib/mandarin_pay/action_view_extension.rb +17 -0
  33. data/lib/mandarin_pay/client.rb +16 -0
  34. data/lib/mandarin_pay/configuration.rb +17 -0
  35. data/lib/mandarin_pay/conformity_params.rb +47 -0
  36. data/lib/mandarin_pay/engine.rb +9 -0
  37. data/lib/mandarin_pay/notification.rb +29 -0
  38. data/lib/mandarin_pay/payment_interface.rb +25 -0
  39. data/lib/mandarin_pay/signature_generator.rb +28 -0
  40. data/lib/mandarin_pay/version.rb +3 -0
  41. data/lib/mandarin_pay.rb +26 -0
  42. data/mandarin_pay.gemspec +24 -0
  43. data/spec/dummy/README.rdoc +261 -0
  44. data/spec/dummy/Rakefile +7 -0
  45. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  46. data/spec/dummy/app/controllers/welcome_controller.rb +5 -0
  47. data/spec/dummy/app/views/layouts/application.html.erb +12 -0
  48. data/spec/dummy/app/views/welcome/index.html.erb +17 -0
  49. data/spec/dummy/config/application.rb +56 -0
  50. data/spec/dummy/config/boot.rb +11 -0
  51. data/spec/dummy/config/database.yml +25 -0
  52. data/spec/dummy/config/environment.rb +6 -0
  53. data/spec/dummy/config/environments/development.rb +40 -0
  54. data/spec/dummy/config/environments/production.rb +70 -0
  55. data/spec/dummy/config/environments/test.rb +40 -0
  56. data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
  57. data/spec/dummy/config/initializers/inflections.rb +16 -0
  58. data/spec/dummy/config/initializers/mandarin_pay.rb +4 -0
  59. data/spec/dummy/config/initializers/mime_types.rb +6 -0
  60. data/spec/dummy/config/initializers/secret_token.rb +8 -0
  61. data/spec/dummy/config/initializers/session_store.rb +9 -0
  62. data/spec/dummy/config/initializers/wrap_parameters.rb +15 -0
  63. data/spec/dummy/config/locales/en.yml +5 -0
  64. data/spec/dummy/config/routes.rb +6 -0
  65. data/spec/dummy/config.ru +4 -0
  66. data/spec/dummy/lib/assets/.gitkeep +0 -0
  67. data/spec/dummy/public/404.html +26 -0
  68. data/spec/dummy/public/422.html +26 -0
  69. data/spec/dummy/public/500.html +25 -0
  70. data/spec/dummy/public/favicon.ico +0 -0
  71. data/spec/dummy/script/rails +6 -0
  72. data/spec/mandarin_pay/client_configuration_spec.rb +35 -0
  73. data/spec/mandarin_pay/notification_spec.rb +51 -0
  74. data/spec/mandarin_pay/payment_interface_spec.rb +39 -0
  75. data/spec/spec_helper.rb +11 -0
  76. metadata +177 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c6aa66899bf036fe36b6d408f2a7f123ed8036d6
4
+ data.tar.gz: 13e097421df68143d2c77129e9d697835104dd8e
5
+ SHA512:
6
+ metadata.gz: 782885f15b6a4286a390003e57910a855d00d6250f9d168abd44199395fb29d4269d0f6bb5d788eb57d68f49bf0611b3d36a7c5400f0a505fdabbea6fdf0aa6b
7
+ data.tar.gz: db5859cb85061582a8dfeba7855ce168dd20c34bbde686c5a45286db883f3ea60668f984d325064f46500bf31c86e3b9bb8e065946a3bf693db5a2549fadb638
data/.gitignore ADDED
@@ -0,0 +1,29 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/log
5
+ spec/dummy/db/*.sqlite3
6
+ spec/dummy/tmp/
7
+ spec/dummy/.sass-cache
8
+ *.gem
9
+ *.rbc
10
+ .config
11
+ coverage
12
+ InstalledFiles
13
+ lib/bundler/man
14
+ rdoc
15
+ spec/reports
16
+ spec/tmp
17
+ spec/version_tmp
18
+ tmp
19
+ .DS_Store
20
+ passenger.3000.log
21
+ passenger.3000.pid.lock
22
+
23
+ # YARD artifacts
24
+ .yardoc
25
+ _yardoc
26
+ doc/
27
+ Gemfile.lock
28
+ *.swp
29
+ *.swo
data/.rubocop.yml ADDED
@@ -0,0 +1,63 @@
1
+ AllCops:
2
+ Include:
3
+ - "**/Rakefile"
4
+ - "**/config.ru"
5
+ Exclude:
6
+ - "db/**/*"
7
+ - "config/**/*"
8
+ - "script/**/*"
9
+ - "frontend/**/*"
10
+ - "vendor/**/*"
11
+ - "lib/generators/**/*"
12
+ - "lib/templates/**/*"
13
+ TargetRubyVersion: 2.3
14
+
15
+ Rails:
16
+ Enabled: true
17
+
18
+ Style/Documentation:
19
+ Enabled: false
20
+
21
+ Style/Encoding:
22
+ Enabled: false
23
+
24
+ Style/StringLiterals:
25
+ EnforcedStyle: double_quotes
26
+
27
+ Style/MultilineOperationIndentation:
28
+ EnforcedStyle: indented
29
+
30
+ Style/MultilineMethodCallIndentation:
31
+ EnforcedStyle: indented
32
+
33
+ Style/IfUnlessModifier:
34
+ MaxLineLength: 120
35
+
36
+ Style/WhileUntilModifier:
37
+ MaxLineLength: 120
38
+
39
+ Style/LambdaCall:
40
+ Enabled: false
41
+
42
+ Metrics/LineLength:
43
+ Max: 120
44
+
45
+ Metrics/ClassLength:
46
+ CountComments: false
47
+ Max: 300
48
+
49
+ Metrics/ModuleLength:
50
+ CountComments: false
51
+ Max: 300
52
+
53
+ Metrics/MethodLength:
54
+ CountComments: false
55
+ Max: 15
56
+
57
+ Metrics/AbcSize:
58
+ Max: 25
59
+
60
+ Style/AsciiComments:
61
+ Description: "Use only ascii symbols in comments."
62
+ StyleGuide: "https://github.com/bbatsov/ruby-style-guide#english-comments"
63
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.2.0
6
+ - 2.3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 1.0.0
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "~> 4.2.0"
4
+
5
+ group :test do
6
+ gem "coveralls", require: false
7
+ end
8
+
9
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Alexander Maslov <drakmail@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ ## The MandarinPay gem
2
+
3
+ by [Drakmail][]
4
+
5
+ [Drakmail]: http://drakmail.ru
6
+
7
+ Ruby wrapper for [Mandarin Pay API][]. Make Mandarin Pay to work with your Rails project without pain. MandarinPay took the best from [rubykassa gem][] and [Active Merchant Robokassa integration] but easier to use and setup.
8
+
9
+ [MandarinPay API]: http://mandarin_pay.com/sites/default/files/protokol_integracii_v0.5.5_0.pdf
10
+ [rubykassa gem]: https://github.com/ZeroOneStudio/rubykassa
11
+ [Active Merchant Robokassa integration]: https://github.com/Shopify/active_merchant/tree/master/lib/active_merchant/billing/integrations/robokassa
12
+
13
+ ## Installation
14
+
15
+ Add to your `Gemfile`:
16
+
17
+ gem "mandarin_pay"
18
+
19
+ ## Usage
20
+
21
+ Run `rails g mandarin_pay:install`, get an initializer with the following code:
22
+
23
+ ```ruby
24
+ MandarinPay.configure do |config|
25
+ config.merchant_id = ENV["MANDARINPAY_MERCHANT_ID"]
26
+ config.sharedsec = ENV["MANDARINPAY_SHAREDSEC"]
27
+
28
+ # Result callback is called in MandarinPayController#paid action if valid signature
29
+ # was generated. It should always return "OK#{ invoice_id }" string, so implement
30
+ # your custom logic above `render text: notification.success` line
31
+
32
+ config.result_callback = ->(notification) { render text: notification.success }
33
+
34
+ # Define success or failure callbacks here like:
35
+
36
+ # config.success_callback = ->(notification) { render text: 'success' }
37
+ # config.fail_callback = ->(notification) { redirect_to root_path }
38
+ end
39
+ ```
40
+
41
+ and configure it with your credentials.
42
+
43
+ Also, you need to specify Result URL, Success URL and Fail URL at the "Technical Settings" (Технические настройки) in your MandarinPay dashboard:
44
+
45
+ * Result URL: `http://<your_domain>/mandarin_pay/paid`
46
+ * Success URL: `http://<your_domain>/mandarin_pay/success`
47
+ * Fail URL: `http://<your_domain>/mandarin_pay/fail`
48
+
49
+ To define custom success/fail callbacks you can also use the initializer:
50
+
51
+ MandarinPay.configure do |config|
52
+ ...
53
+ config.success_callback = ->(notification) { render text: 'success' }
54
+ config.fail_callback = ->(notification) { redirect_to root_path }
55
+ config.result_callback = ->(notification) { render text: notification.success }
56
+ end
57
+
58
+ Lambdas are called in MandarinPayController so you can respond with [any kind that is supported by Rails](http://guides.rubyonrails.org/layouts_and_rendering.html#creating-responses).
59
+
60
+ NOTE: `result_callback` should always return `"OK"` string. So, implement your custom logic above `render text: notification.success` line.
61
+
62
+ Once you are done, simply use `pay_form` helper in your view:
63
+
64
+ <%= pay_form "Pay with Mandarin Pay", "invoice_number", 20.00 %>
65
+
66
+ Additionally you may want to pass extra options. There is no problem:
67
+
68
+ <%= pay_form "Pay with Mandarin Pay", "invoice_number", 20.00, customer_email: "user@example.com", class: "btn btn-succses", form_class: "mp-form" %>
69
+
70
+ ## Supported Rubies and Rails versions
71
+
72
+ Rubies:
73
+ * 2.0.0
74
+ * 2.1.0
75
+ * 2.2.0
76
+ * 2.3.0
77
+
78
+ Rails:
79
+ * ~> 4.0.0
80
+ * ~> 4.1.0
81
+ * ~> 4.2.0
82
+
83
+ ## License
84
+
85
+ This project rocks and uses MIT-LICENSE
86
+ Copyright (c) 2016 [Drakmail][]
87
+
88
+ [Drakmail]: http://drakmail.ru
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
File without changes
@@ -0,0 +1,33 @@
1
+ class MandarinPayController < ApplicationController
2
+ before_action :create_notification
3
+
4
+ def paid
5
+ if @notification.valid_result_signature?
6
+ instance_exec @notification, &MandarinPay.result_callback
7
+ else
8
+ instance_exec @notification, &MandarinPay.fail_callback
9
+ end
10
+ end
11
+
12
+ def success
13
+ if @notification.valid_success_signature?
14
+ instance_exec @notification, &MandarinPay.success_callback
15
+ else
16
+ instance_exec @notification, &MandarinPay.fail_callback
17
+ end
18
+ end
19
+
20
+ def fail
21
+ instance_exec @notification, &MandarinPay.fail_callback
22
+ end
23
+
24
+ private
25
+
26
+ def create_notification
27
+ if request.get?
28
+ @notification = MandarinPay::Notification.new request.query_parameters
29
+ elsif request.post?
30
+ @notification = MandarinPay::Notification.new request.request_parameters
31
+ end
32
+ end
33
+ end
data/bin/bundler ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'bundler' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("bundler", "bundler")
data/bin/cdiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'cdiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("term-ansicolor", "cdiff")
data/bin/colortab ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'colortab' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("term-ansicolor", "colortab")
data/bin/coveralls ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'coveralls' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("coveralls", "coveralls")
data/bin/decolor ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'decolor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("term-ansicolor", "decolor")
data/bin/erubis ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'erubis' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("erubis", "erubis")
data/bin/htmldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'htmldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("diff-lcs", "htmldiff")
data/bin/ldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("diff-lcs", "ldiff")
data/bin/nokogiri ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'nokogiri' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("nokogiri", "nokogiri")
data/bin/rackup ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rackup' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rack", "rackup")
data/bin/rails ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rails' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("railties", "rails")
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rake", "rake")
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/sprockets ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'sprockets' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("sprockets", "sprockets")
data/bin/term_display ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'term_display' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("term-ansicolor", "term_display")
data/bin/term_mandel ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'term_mandel' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("term-ansicolor", "term_mandel")
data/bin/thor ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("thor", "thor")
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.routes.draw do
4
+ if MandarinPay::Client.configuration
5
+ scope "/mandarin_pay" do
6
+ %w(paid success fail).map do |route|
7
+ post "/#{route}" => "mandarin_pay##{route}", as: "mandarin_pay_#{route}"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require "rails/generators"
2
+
3
+ module MandarinPay
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+ def create_initializer_file
7
+ template "mandarin_pay.rb", File.join("config", "initializers", "mandarin_pay.rb")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ MandarinPay.configure do |config|
2
+ config.merchant_id = ENV["MANDARINPAY_MERCHANT_ID"]
3
+ config.sharedsec = ENV["MANDARINPAY_SHAREDSEC"]
4
+
5
+ # Result callback is called in MandarinPayController#paid action if valid signature
6
+ # was generated. It should always return "OK#{ invoice_id }" string, so implement
7
+ # your custom logic above `render text: notification.success` line
8
+
9
+ config.result_callback = ->(notification) { render text: notification.success }
10
+
11
+ # Define success or failure callbacks here like:
12
+
13
+ # config.success_callback = ->(notification) { render text: 'success' }
14
+ # config.fail_callback = ->(notification) { redirect_to root_path }
15
+ end
@@ -0,0 +1,17 @@
1
+ module MandarinPay
2
+ module ActionViewExtension
3
+ def pay_form(phrase, order_id, price, options = {})
4
+ pi = MandarinPay::PaymentInterface.new
5
+ class_names = options.delete(:class)
6
+ form_class = options.delete(:form_class)
7
+ params = pi.pay_params({ order_id: order_id, price: price }.merge(options))
8
+ form_tag pi.base_url, method: :post, class: form_class do
9
+ fields = params.map do |param, value|
10
+ hidden_field_tag param, value
11
+ end
12
+ fields.push submit_tag(phrase, class: class_names)
13
+ fields.join.html_safe
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mandarin_pay/configuration"
4
+
5
+ module MandarinPay
6
+ class Client
7
+ class << self
8
+ attr_accessor :configuration
9
+
10
+ def configure
11
+ self.configuration = MandarinPay::Configuration.new
12
+ yield configuration
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MandarinPay
4
+ class Configuration
5
+ ATTRIBUTES = [:merchant_id, :sharedsec, :success_callback, :fail_callback, :result_callback].freeze
6
+
7
+ attr_accessor(*ATTRIBUTES)
8
+
9
+ def initialize
10
+ self.merchant_id = "your_merchant_id"
11
+ self.sharedsec = "sharedsec"
12
+ self.success_callback = ->(_notification) { render text: "success" }
13
+ self.fail_callback = ->(_notification) { render text: "fail" }
14
+ self.result_callback = ->(_notification) { render text: notification.success }
15
+ end
16
+ end
17
+ end