veritrans 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.idea/.gitignore +8 -0
  4. data/.rubocop.yml +1 -1
  5. data/.travis.yml +2 -1
  6. data/CHANGELOG.md +13 -0
  7. data/Gemfile +2 -11
  8. data/Gemfile.lock +116 -145
  9. data/Maintaining.MD +8 -0
  10. data/README.md +247 -278
  11. data/api_reference.md +482 -173
  12. data/example/coreapi/core_api_credit_card_example.rb +66 -0
  13. data/example/coreapi/readme.md +4 -0
  14. data/example/sinatra/Gemfile +7 -0
  15. data/example/sinatra/README.md +4 -6
  16. data/example/sinatra/index.erb +180 -192
  17. data/example/sinatra/response.erb +1 -40
  18. data/example/sinatra/snap.erb +33 -0
  19. data/example/sinatra/snap_redirect.erb +10 -0
  20. data/example/sinatra/webapp.rb +113 -0
  21. data/example/snap/readme.md +4 -0
  22. data/example/snap/snap_example.rb +39 -0
  23. data/lib/test/all.rb +1 -0
  24. data/lib/test/api_test.rb +319 -0
  25. data/lib/test/config_test.rb +26 -0
  26. data/lib/test/gopay_tokenization_test.rb +80 -0
  27. data/lib/test/snap_test.rb +79 -0
  28. data/lib/test/subscription_test.rb +116 -0
  29. data/lib/test/transaction_test.rb +160 -0
  30. data/lib/veritrans/api.rb +105 -8
  31. data/lib/veritrans/client.rb +40 -7
  32. data/lib/veritrans/config.rb +26 -3
  33. data/lib/veritrans/midtrans_error.rb +15 -0
  34. data/lib/veritrans/version.rb +1 -1
  35. data/lib/veritrans.rb +5 -6
  36. data/veritrans.gemspec +1 -2
  37. metadata +25 -248
  38. data/.rspec +0 -2
  39. data/Procfile +0 -1
  40. data/Rakefile +0 -16
  41. data/bin/midtrans +0 -3
  42. data/bin/veritrans +0 -68
  43. data/example/rails/cable/Gemfile +0 -48
  44. data/example/rails/cable/Gemfile.lock +0 -184
  45. data/example/rails/cable/README.md +0 -29
  46. data/example/rails/cable/Rakefile +0 -6
  47. data/example/rails/cable/app/assets/config/manifest.js +0 -3
  48. data/example/rails/cable/app/assets/images/.keep +0 -0
  49. data/example/rails/cable/app/assets/javascripts/application.js +0 -15
  50. data/example/rails/cable/app/assets/javascripts/cable.js +0 -13
  51. data/example/rails/cable/app/assets/javascripts/channels/.keep +0 -0
  52. data/example/rails/cable/app/assets/javascripts/chats.js +0 -39
  53. data/example/rails/cable/app/assets/javascripts/rooms.js +0 -55
  54. data/example/rails/cable/app/assets/stylesheets/application.css +0 -16
  55. data/example/rails/cable/app/assets/stylesheets/chatbox.scss +0 -31
  56. data/example/rails/cable/app/assets/stylesheets/peoplebox.scss +0 -6
  57. data/example/rails/cable/app/channels/application_cable/channel.rb +0 -4
  58. data/example/rails/cable/app/channels/application_cable/connection.rb +0 -4
  59. data/example/rails/cable/app/channels/rooms_texting_channel.rb +0 -13
  60. data/example/rails/cable/app/controllers/application_controller.rb +0 -3
  61. data/example/rails/cable/app/controllers/chats_controller.rb +0 -18
  62. data/example/rails/cable/app/controllers/concerns/.keep +0 -0
  63. data/example/rails/cable/app/controllers/pays_controller.rb +0 -28
  64. data/example/rails/cable/app/controllers/rooms_controller.rb +0 -4
  65. data/example/rails/cable/app/helpers/application_helper.rb +0 -2
  66. data/example/rails/cable/app/helpers/chats_helper.rb +0 -2
  67. data/example/rails/cable/app/helpers/rooms_helper.rb +0 -5
  68. data/example/rails/cable/app/jobs/application_job.rb +0 -2
  69. data/example/rails/cable/app/jobs/chat_broadcaster_job.rb +0 -15
  70. data/example/rails/cable/app/mailers/application_mailer.rb +0 -4
  71. data/example/rails/cable/app/models/application_record.rb +0 -3
  72. data/example/rails/cable/app/models/chat.rb +0 -41
  73. data/example/rails/cable/app/models/concerns/.keep +0 -0
  74. data/example/rails/cable/app/models/order.rb +0 -2
  75. data/example/rails/cable/app/models/user.rb +0 -2
  76. data/example/rails/cable/app/views/chats/_chat.html.erb +0 -18
  77. data/example/rails/cable/app/views/layouts/application.html.erb +0 -19
  78. data/example/rails/cable/app/views/layouts/mailer.html.erb +0 -13
  79. data/example/rails/cable/app/views/layouts/mailer.text.erb +0 -1
  80. data/example/rails/cable/app/views/rooms/_chatbox.html.erb +0 -13
  81. data/example/rails/cable/app/views/rooms/_online_people.html.erb +0 -53
  82. data/example/rails/cable/app/views/rooms/index.html.erb +0 -9
  83. data/example/rails/cable/bin/bundle +0 -3
  84. data/example/rails/cable/bin/rails +0 -9
  85. data/example/rails/cable/bin/rake +0 -9
  86. data/example/rails/cable/bin/setup +0 -34
  87. data/example/rails/cable/bin/spring +0 -16
  88. data/example/rails/cable/bin/update +0 -29
  89. data/example/rails/cable/config/application.rb +0 -16
  90. data/example/rails/cable/config/boot.rb +0 -3
  91. data/example/rails/cable/config/cable.yml +0 -9
  92. data/example/rails/cable/config/database.yml +0 -20
  93. data/example/rails/cable/config/environment.rb +0 -5
  94. data/example/rails/cable/config/environments/development.rb +0 -57
  95. data/example/rails/cable/config/environments/production.rb +0 -86
  96. data/example/rails/cable/config/environments/test.rb +0 -42
  97. data/example/rails/cable/config/initializers/application_controller_renderer.rb +0 -6
  98. data/example/rails/cable/config/initializers/assets.rb +0 -11
  99. data/example/rails/cable/config/initializers/backtrace_silencers.rb +0 -7
  100. data/example/rails/cable/config/initializers/cookies_serializer.rb +0 -5
  101. data/example/rails/cable/config/initializers/filter_parameter_logging.rb +0 -4
  102. data/example/rails/cable/config/initializers/inflections.rb +0 -16
  103. data/example/rails/cable/config/initializers/mime_types.rb +0 -4
  104. data/example/rails/cable/config/initializers/new_framework_defaults.rb +0 -24
  105. data/example/rails/cable/config/initializers/session_store.rb +0 -3
  106. data/example/rails/cable/config/initializers/sidekiq.rb +0 -2
  107. data/example/rails/cable/config/initializers/veritrans.rb +0 -46
  108. data/example/rails/cable/config/initializers/wrap_parameters.rb +0 -14
  109. data/example/rails/cable/config/locales/en.yml +0 -23
  110. data/example/rails/cable/config/puma.rb +0 -47
  111. data/example/rails/cable/config/routes.rb +0 -18
  112. data/example/rails/cable/config/secrets.yml +0 -22
  113. data/example/rails/cable/config/spring.rb +0 -6
  114. data/example/rails/cable/config/veritrans.yml +0 -13
  115. data/example/rails/cable/config.ru +0 -5
  116. data/example/rails/cable/db/development.sqlite3 +0 -0
  117. data/example/rails/cable/db/migrate/20161215070044_create_chats.rb +0 -10
  118. data/example/rails/cable/db/migrate/20161215072021_create_users.rb +0 -10
  119. data/example/rails/cable/db/migrate/20161219110219_create_orders.rb +0 -11
  120. data/example/rails/cable/db/schema.rb +0 -37
  121. data/example/rails/cable/db/seeds.rb +0 -41
  122. data/example/rails/cable/db/test.sqlite3 +0 -0
  123. data/example/rails/cable/lib/assets/.keep +0 -0
  124. data/example/rails/cable/lib/tasks/.keep +0 -0
  125. data/example/rails/cable/log/.keep +0 -0
  126. data/example/rails/cable/public/404.html +0 -67
  127. data/example/rails/cable/public/422.html +0 -67
  128. data/example/rails/cable/public/500.html +0 -66
  129. data/example/rails/cable/public/apple-touch-icon-precomposed.png +0 -0
  130. data/example/rails/cable/public/apple-touch-icon.png +0 -0
  131. data/example/rails/cable/public/favicon.ico +0 -0
  132. data/example/rails/cable/public/images/avatar1.jpg +0 -0
  133. data/example/rails/cable/public/images/avatar2.jpg +0 -0
  134. data/example/rails/cable/public/images/avatar3.jpg +0 -0
  135. data/example/rails/cable/public/images/avatar4.jpg +0 -0
  136. data/example/rails/cable/public/images/avatar5.jpg +0 -0
  137. data/example/rails/cable/public/images/avatar6.jpg +0 -0
  138. data/example/rails/cable/public/robots.txt +0 -5
  139. data/example/rails/cable/vendor/assets/javascripts/.keep +0 -0
  140. data/example/rails/cable/vendor/assets/stylesheets/.keep +0 -0
  141. data/example/rails/cable/vendor/assets/stylesheets/photon.css +0 -2333
  142. data/example/rails/simplepay/Gemfile +0 -54
  143. data/example/rails/simplepay/Gemfile.lock +0 -178
  144. data/example/rails/simplepay/README.md +0 -30
  145. data/example/rails/simplepay/Rakefile +0 -6
  146. data/example/rails/simplepay/app/assets/config/manifest.js +0 -3
  147. data/example/rails/simplepay/app/assets/images/.keep +0 -0
  148. data/example/rails/simplepay/app/assets/javascripts/application.js +0 -16
  149. data/example/rails/simplepay/app/assets/javascripts/cable.js +0 -13
  150. data/example/rails/simplepay/app/assets/javascripts/channels/.keep +0 -0
  151. data/example/rails/simplepay/app/assets/javascripts/pay.js +0 -18
  152. data/example/rails/simplepay/app/assets/stylesheets/application.css +0 -15
  153. data/example/rails/simplepay/app/assets/stylesheets/style.css +0 -254
  154. data/example/rails/simplepay/app/channels/application_cable/channel.rb +0 -4
  155. data/example/rails/simplepay/app/channels/application_cable/connection.rb +0 -4
  156. data/example/rails/simplepay/app/controllers/application_controller.rb +0 -3
  157. data/example/rails/simplepay/app/controllers/concerns/.keep +0 -0
  158. data/example/rails/simplepay/app/controllers/home_controller.rb +0 -16
  159. data/example/rails/simplepay/app/controllers/pay_controller.rb +0 -10
  160. data/example/rails/simplepay/app/helpers/application_helper.rb +0 -2
  161. data/example/rails/simplepay/app/helpers/pay_helper.rb +0 -2
  162. data/example/rails/simplepay/app/jobs/application_job.rb +0 -2
  163. data/example/rails/simplepay/app/mailers/application_mailer.rb +0 -4
  164. data/example/rails/simplepay/app/models/application_record.rb +0 -3
  165. data/example/rails/simplepay/app/models/concerns/.keep +0 -0
  166. data/example/rails/simplepay/app/models/order.rb +0 -2
  167. data/example/rails/simplepay/app/views/home/index.html.erb +0 -19
  168. data/example/rails/simplepay/app/views/layouts/application.html.erb +0 -15
  169. data/example/rails/simplepay/app/views/layouts/mailer.html.erb +0 -13
  170. data/example/rails/simplepay/app/views/layouts/mailer.text.erb +0 -1
  171. data/example/rails/simplepay/app/views/pay/notify.html.erb +0 -2
  172. data/example/rails/simplepay/bin/bundle +0 -3
  173. data/example/rails/simplepay/bin/rails +0 -9
  174. data/example/rails/simplepay/bin/rake +0 -9
  175. data/example/rails/simplepay/bin/setup +0 -34
  176. data/example/rails/simplepay/bin/spring +0 -16
  177. data/example/rails/simplepay/bin/update +0 -29
  178. data/example/rails/simplepay/config/application.rb +0 -15
  179. data/example/rails/simplepay/config/boot.rb +0 -3
  180. data/example/rails/simplepay/config/cable.yml +0 -9
  181. data/example/rails/simplepay/config/database.yml +0 -25
  182. data/example/rails/simplepay/config/environment.rb +0 -5
  183. data/example/rails/simplepay/config/environments/development.rb +0 -57
  184. data/example/rails/simplepay/config/environments/production.rb +0 -86
  185. data/example/rails/simplepay/config/environments/test.rb +0 -42
  186. data/example/rails/simplepay/config/initializers/application_controller_renderer.rb +0 -6
  187. data/example/rails/simplepay/config/initializers/assets.rb +0 -11
  188. data/example/rails/simplepay/config/initializers/backtrace_silencers.rb +0 -7
  189. data/example/rails/simplepay/config/initializers/cookies_serializer.rb +0 -5
  190. data/example/rails/simplepay/config/initializers/filter_parameter_logging.rb +0 -4
  191. data/example/rails/simplepay/config/initializers/inflections.rb +0 -16
  192. data/example/rails/simplepay/config/initializers/mime_types.rb +0 -4
  193. data/example/rails/simplepay/config/initializers/new_framework_defaults.rb +0 -24
  194. data/example/rails/simplepay/config/initializers/session_store.rb +0 -3
  195. data/example/rails/simplepay/config/initializers/veritrans.rb +0 -46
  196. data/example/rails/simplepay/config/initializers/wrap_parameters.rb +0 -14
  197. data/example/rails/simplepay/config/locales/en.yml +0 -23
  198. data/example/rails/simplepay/config/puma.rb +0 -47
  199. data/example/rails/simplepay/config/routes.rb +0 -5
  200. data/example/rails/simplepay/config/secrets.yml +0 -22
  201. data/example/rails/simplepay/config/spring.rb +0 -6
  202. data/example/rails/simplepay/config/veritrans.yml +0 -18
  203. data/example/rails/simplepay/config.ru +0 -5
  204. data/example/rails/simplepay/db/development.sqlite3 +0 -0
  205. data/example/rails/simplepay/db/migrate/20161221090855_create_orders.rb +0 -10
  206. data/example/rails/simplepay/db/schema.rb +0 -22
  207. data/example/rails/simplepay/db/seeds.rb +0 -7
  208. data/example/rails/simplepay/db/test.sqlite3 +0 -0
  209. data/example/rails/simplepay/lib/assets/.keep +0 -0
  210. data/example/rails/simplepay/lib/tasks/.keep +0 -0
  211. data/example/rails/simplepay/log/.keep +0 -0
  212. data/example/rails/simplepay/public/404.html +0 -67
  213. data/example/rails/simplepay/public/422.html +0 -67
  214. data/example/rails/simplepay/public/500.html +0 -66
  215. data/example/rails/simplepay/public/apple-touch-icon-precomposed.png +0 -0
  216. data/example/rails/simplepay/public/apple-touch-icon.png +0 -0
  217. data/example/rails/simplepay/public/favicon.ico +0 -0
  218. data/example/rails/simplepay/public/robots.txt +0 -5
  219. data/example/rails/simplepay/vendor/assets/javascripts/.keep +0 -0
  220. data/example/rails/simplepay/vendor/assets/stylesheets/.keep +0 -0
  221. data/example/sinatra/config.ru +0 -9
  222. data/example/sinatra/localization.erb +0 -249
  223. data/example/sinatra/points.erb +0 -188
  224. data/example/sinatra/recurring.erb +0 -201
  225. data/example/sinatra/sinatra.rb +0 -194
  226. data/example/sinatra/style.css +0 -137
  227. data/example/sinatra/veritrans.yml +0 -11
  228. data/example/sinatra/widget.erb +0 -63
  229. data/lib/generators/templates/assets/credit_card_form.js +0 -57
  230. data/lib/generators/templates/payments_controller.rb +0 -85
  231. data/lib/generators/templates/veritrans.rb +0 -46
  232. data/lib/generators/templates/veritrans.yml +0 -18
  233. data/lib/generators/templates/views/_credit_card_form.erb +0 -42
  234. data/lib/generators/templates/views/_veritrans_include.erb +0 -10
  235. data/lib/generators/templates/views/payments/create.erb +0 -15
  236. data/lib/generators/templates/views/payments/new.erb +0 -6
  237. data/lib/generators/veritrans/install_generator.rb +0 -32
  238. data/lib/generators/veritrans/payment_form_generator.rb +0 -45
  239. data/lib/veritrans/cli.rb +0 -161
  240. data/lib/veritrans/testing.rb +0 -156
  241. data/spec/cli_spec.rb +0 -83
  242. data/spec/configs/real_key.yml +0 -4
  243. data/spec/configs/veritrans.yml +0 -7
  244. data/spec/configs/veritrans_flat.yml +0 -2
  245. data/spec/configs/veritrans_with_erb.yml +0 -2
  246. data/spec/fixtures/approve_failed.yml +0 -48
  247. data/spec/fixtures/cancel_failed.yml +0 -48
  248. data/spec/fixtures/cancel_success.yml +0 -126
  249. data/spec/fixtures/capture_failed.yml +0 -48
  250. data/spec/fixtures/charge.yml +0 -50
  251. data/spec/fixtures/charge_direct.yml +0 -56
  252. data/spec/fixtures/charge_vtweb.yml +0 -50
  253. data/spec/fixtures/cli_test_1111-not-exists.yml +0 -45
  254. data/spec/fixtures/cli_test_not_exists.yml +0 -45
  255. data/spec/fixtures/cli_test_real_txn.yml +0 -55
  256. data/spec/fixtures/cli_test_unauthorized.yml +0 -47
  257. data/spec/fixtures/deny_failed.yml +0 -144
  258. data/spec/fixtures/events_test_real_txn.yml +0 -55
  259. data/spec/fixtures/expire_failed.yml +0 -50
  260. data/spec/fixtures/expire_success.yml +0 -56
  261. data/spec/fixtures/midtrans_status.yml +0 -117
  262. data/spec/fixtures/refund_failed.yml +0 -54
  263. data/spec/fixtures/status_fail.yml +0 -48
  264. data/spec/fixtures/status_success.yml +0 -128
  265. data/spec/fixtures/test_token.yml +0 -49
  266. data/spec/midtrans_rename_spec.rb +0 -27
  267. data/spec/rails_plugin_spec.rb +0 -317
  268. data/spec/spec_helper.rb +0 -71
  269. data/spec/veritrans_client_spec.rb +0 -235
  270. data/spec/veritrans_config_spec.rb +0 -70
  271. data/spec/veritrans_events_spec.rb +0 -72
  272. data/spec/veritrans_logger_spec.rb +0 -46
  273. data/spec/veritrans_snap_spec.rb +0 -54
  274. data/spec/veritrans_testing_spec.rb +0 -184
  275. data/testing_webhooks.md +0 -78
@@ -1,317 +0,0 @@
1
- require 'fileutils'
2
- require 'open3'
3
- require 'shellwords'
4
- require 'socket'
5
-
6
- describe 'Rails plugin', vcr: false do
7
- include Capybara::DSL
8
-
9
- MAIN_RAILS_VER = '5.2.3'.freeze
10
- APP_DIR = 'plugin_test'.freeze
11
- PLUGIN_DIR = File.expand_path('..', File.dirname(__FILE__))
12
-
13
- RAILS_VERSIONS = %w[4.2.11.1 5.0.7.2 5.1.7 5.2.3].freeze
14
-
15
- before :all do
16
- FileUtils.mkdir_p("#{PLUGIN_DIR}/tmp")
17
- # Capybara::Screenshot.instance_variable_set(:@capybara_root, "#{PLUGIN_DIR}/tmp")
18
- end
19
-
20
- def capture_stdout(&block)
21
- original_stdout = $stdout
22
- $stdout = fake = StringIO.new
23
- begin
24
- yield
25
- ensure
26
- $stdout = original_stdout
27
- end
28
- fake.string
29
- end
30
-
31
- def run_cmd(cmd, cli_args = [])
32
- full_cmd = ([cmd] + cli_args).join.strip
33
-
34
- puts "RUN: #{full_cmd}" if ENV['DEBUG']
35
-
36
- output, status = Open3.capture2e(full_cmd)
37
-
38
- if status != 0
39
- puts "CMD: #{full_cmd}"
40
- puts 'FAILED'
41
- puts output
42
-
43
- exit 1
44
- end
45
- output
46
- end
47
-
48
- def install_rails_in_tmp(rails_version = MAIN_RAILS_VER)
49
- @rails_dir = Dir.mktmpdir
50
- @app_abs_path = "#{@rails_dir}/#{APP_DIR}"
51
-
52
- Dir.chdir(@rails_dir) do
53
- Bundler.with_clean_env do
54
- ENV['RAILS_ENV'] = 'development'
55
- find_or_install_rails(rails_version)
56
- generate_rails_app(rails_version)
57
- generate_plugin_things
58
- end
59
- end
60
- end
61
-
62
- def find_or_install_rails(rails_version)
63
- response = run_cmd('gem list \^rails\$ -q')
64
-
65
- return true if response =~ /[^\d]#{rails_version}[^\d]/
66
-
67
- run_cmd("gem install rails -v #{rails_version}")
68
- end
69
-
70
- def generate_rails_app(rails_version)
71
- gemfile_content = "
72
- source 'https://rubygems.org'
73
-
74
- gem 'rails', '#{rails_version}'
75
- gem 'sqlite3', '~> 1.3.13'
76
- gem 'turbolinks'
77
- gem 'jquery-rails'
78
- gem 'veritrans', path: '#{PLUGIN_DIR}'
79
- ".gsub(/^\s+/, '')
80
-
81
- File.open('./Gemfile', 'w') { |f| f.write(gemfile_content) }
82
- run_cmd('bundle _1.17.3_')
83
-
84
- extra_rails_args = []
85
- if rails_version >= '5.2.0'
86
- extra_rails_args << '--skip-bootsnap'
87
- end
88
-
89
- gen = "bundle exec rails _#{rails_version}_ new #{APP_DIR} -B -G --skip-spring -d sqlite3 --skip-turbolinks --skip-test-unit --skip-action-cable --no-rc --skip-puma --skip-listen #{extra_rails_args.join(' ')}"
90
-
91
- run_cmd(gen)
92
-
93
- File.open("#{@app_abs_path}/Gemfile", 'w') { |f| f.write(gemfile_content) }
94
-
95
- Dir.chdir(@app_abs_path) do
96
- run_cmd('bundle _1.17.3_')
97
- end
98
- end
99
-
100
- def generate_plugin_things
101
- Dir.chdir(@app_abs_path) do
102
- run_cmd('rails g veritrans:install')
103
- run_cmd('rails g veritrans:payment_form')
104
- end
105
-
106
- config_content = "
107
- development:
108
- client_key: VT-client-NArmatJZqzsmTmzR
109
- server_key: VT-server-9Htb-RxXkg7-7hznSCCjxvoY
110
- api_host: https://api.sandbox.midtrans.com
111
- "
112
-
113
- File.open("#{@app_abs_path}/config/veritrans.yml", 'w') { |f| f.write(config_content) }
114
- end
115
-
116
- def run_rails_app
117
- @rails_port = find_open_port
118
-
119
- server_cmd = "./bin/rails server -p #{@rails_port} -b 127.0.0.1"
120
- server_env = { "RAILS_ENV" => 'development', "BUNDLE_GEMFILE" => @app_abs_path + '/Gemfile' }
121
- spawn_opts = { chdir: @app_abs_path }
122
- spawn_opts[%i[err out]] = '/dev/null' unless ENV['DEBUG']
123
-
124
- Bundler.with_clean_env do
125
- puts "RUN: #{server_cmd} #{spawn_opts}" if ENV['DEBUG']
126
- @runner_pid = spawn(server_env, server_cmd, spawn_opts)
127
- puts "Process running PID: #{@runner_pid}" if ENV['DEBUG']
128
- end
129
-
130
- Capybara.app_host = "http://127.0.0.1:#{@rails_port}"
131
-
132
- # puts "RAILS_DIR: #{@app_abs_path}"
133
-
134
- check_cmd = "curl #{Capybara.app_host}/payments/new"
135
-
136
- failed = 0
137
- while failed < 100
138
- puts "Check if rails server UP (#{Capybara.app_host})" if ENV['DEBUG']
139
- output, status = Open3.capture2e(check_cmd)
140
- if status == 0 && output =~ /credit_card_number/
141
- if ENV['DEBUG']
142
- puts 'Server is running, output:'
143
- puts output[0..300]
144
- end
145
- break
146
- else
147
- failed += 1
148
- sleep 0.3
149
- end
150
- end
151
-
152
- return if failed != 100
153
-
154
- puts `tail -100 #{@app_abs_path}/log/development.log`
155
- raise Exception, 'cannot start rails server'
156
- end
157
-
158
- def stop_rails_app
159
- Dir.chdir(@app_abs_path) do
160
- run_cmd('kill `cat tmp/pids/server.pid`') if File.exist?('./tmp/pids/server.pid')
161
- end
162
- end
163
-
164
- def find_open_port
165
- socket = Socket.new(:INET, :STREAM, 0)
166
- socket.bind(Addrinfo.tcp('127.0.0.1', 0))
167
- socket.local_address.ip_port
168
- ensure
169
- socket.close
170
- end
171
-
172
- after do
173
- stop_rails_app
174
- FileUtils.remove_entry_secure(@rails_dir) if @rails_dir
175
- end
176
-
177
- def submit_payment_form(card_number)
178
- # CREATE PAYMENT 1
179
- visit '/payments/new'
180
-
181
- fill_in 'credit_card_number', with: card_number
182
- click_button 'Pay via VT-Direct'
183
- puts 'Clicked Pay'
184
-
185
- # Waiting for get token request in javascript...
186
- Timeout.timeout(60.seconds) do
187
- loop do
188
- break if current_path != '/payments/new'
189
-
190
- sleep 1
191
- end
192
- end
193
-
194
- Timeout.timeout(10.seconds) do
195
- loop do
196
- break if page.body =~ /<body>/
197
-
198
- sleep 0.1
199
- end
200
- end
201
- end
202
-
203
- RAILS_VERSIONS.each_with_index do |rails_version, spec_index|
204
- next if rails_version.start_with?('5') && RUBY_VERSION < '2.2.2'
205
-
206
- it "should tests plugin (Rails #{rails_version})" do
207
- puts "Testing with Rails #{rails_version} and Ruby #{RUBY_VERSION}"
208
- # PREPARE APP
209
- install_rails_in_tmp(rails_version)
210
- run_rails_app
211
-
212
- card_numbers = [
213
- '5481 1611 1111 1081',
214
- '5410 1111 1111 1116',
215
- '4011 1111 1111 1112',
216
- '4411 1111 1111 1118',
217
- '4811 1111 1111 1114',
218
- '3528 6647 7942 9687',
219
- '3528 2033 2456 4357'
220
- ]
221
- spec_index = (spec_index + RUBY_VERSION.gsub(/[^\d]/, '').to_i) % card_numbers.size
222
- card_number = card_numbers[spec_index]
223
-
224
- submit_payment_form(card_number)
225
-
226
- if page.body =~ /too many transactions/
227
- puts '!!!!'
228
- puts 'Merchant has sent too many transactions to the same card number'
229
- puts '!!!!'
230
- # page.should have_content("Merchant has sent too many transactions to the same card number")
231
- puts 'Wait 10 seconds and retry'
232
- sleep 10
233
- submit_payment_form(card_number)
234
- end
235
-
236
- puts page.body if page.body !~ /transaction is successful/
237
-
238
- page.should have_content('Success, Credit Card transaction is successful')
239
-
240
- order_info = ActiveSupport::JSON.decode(find('pre').text)
241
- puts "Order Info: #{order_info}"
242
- created_order_id = order_info['order_id']
243
- # Capybara::Screenshot.screenshot_and_open_image
244
-
245
- # CREATE PAYMENT 2
246
- visit '/payments/new'
247
- click_link 'Pay via VT-Web'
248
-
249
- page.should have_content('ATM/Bank Transfer')
250
-
251
- # TEST CALLBACK FOR WRONG DATA
252
- stub_const("CONFIG", {})
253
- result1 = capture_stdout do
254
- Veritrans::CLI.test_webhook(["#{Capybara.app_host}/payments/receive_webhook"])
255
- end
256
-
257
- result1.should =~ /status: 404/
258
-
259
- # TEST CALLBACK FOR CORRECT DATA
260
- stub_const('CONFIG', order: created_order_id, config_path: "#{@app_abs_path}/config/veritrans.yml")
261
- result2 = capture_stdout do
262
- Veritrans::CLI.test_webhook(["#{Capybara.app_host}/payments/receive_webhook"])
263
- end
264
-
265
- puts `tail -40 #{@app_abs_path}/log/development.log` if result2 !~ /status: 200/
266
-
267
- result2.should =~ /status: 200/
268
- result2.should =~ /body: ok/
269
- end
270
- end
271
-
272
- it 'should print message if running in staging' do
273
- # PREPARE APP
274
- install_rails_in_tmp
275
- File.open("#{@app_abs_path}/config/database.yml", 'a') { |f|
276
- f.puts
277
- f.puts('staging:')
278
- f.puts(' adapter: sqlite3')
279
- f.puts(" database: ':memory:'")
280
- }
281
-
282
- Bundler.with_clean_env do
283
- ENV['RAILS_ENV'] = 'staging'
284
- Dir.chdir(@app_abs_path) do
285
- stdout_str, stderr_str, status = Open3.capture3(%(./bin/rails r 'p :started'))
286
- stderr_str.should include('Veritrans: Can not find section "staging"')
287
- stderr_str.should include('Available sections: ["development"]')
288
- stderr_str.should include('Veritrans: Using first section "development"')
289
- end
290
- end
291
- end
292
-
293
- it 'should create logs for log/veritrans.log' do
294
- install_rails_in_tmp
295
- FileUtils.rm_rf(@app_abs_path + '/log')
296
- File.open(@app_abs_path + '/config/application.rb', 'a') do |f|
297
- f.write %{
298
- logger = ActiveSupport::Logger.new(STDOUT)
299
- Rails.application.config.logger = ActiveSupport::TaggedLogging.new(logger)
300
- }
301
- end
302
- run_rails_app
303
-
304
- response = Excon.post(
305
- "#{Capybara.app_host}/payments/receive_webhook",
306
- body: { transaction_id: '111' }.to_json,
307
- headers: { 'Content-Type' => 'application/json' }
308
- )
309
- expect(response.body).to eq 'error'
310
- expect(response.status).to eq 404
311
-
312
- expect(File.exist?(@app_abs_path + '/log/development.log')).to eq false
313
- expect(File.exist?(@app_abs_path + '/log/veritrans.log')).to eq true
314
-
315
- File.read(@app_abs_path + '/log/veritrans.log').should include('Callback verification failed for order')
316
- end
317
- end
data/spec/spec_helper.rb DELETED
@@ -1,71 +0,0 @@
1
- require 'bundler/setup'
2
-
3
- $LOAD_PATH.push(File.expand_path('../lib', __dir__))
4
-
5
- require 'rspec'
6
- require 'veritrans'
7
- require 'veritrans/cli'
8
- require 'veritrans/events'
9
- require 'rails'
10
- require 'webmock/rspec'
11
- require 'vcr'
12
- require 'timecop'
13
-
14
- require 'capybara/rspec'
15
- require 'capybara-screenshot/rspec'
16
- require 'capybara/poltergeist'
17
- require 'active_support/testing/stream'
18
-
19
- Capybara.register_driver :poltergeist do |app|
20
- Capybara::Poltergeist::Driver.new(
21
- app,
22
- js_errors: false,
23
- # phantomjs don't much like ssl of cloudfront.net
24
- phantomjs_options: %w[--ignore-ssl-errors=yes --ssl-protocol=any]
25
- # logger: STDOUT
26
- )
27
- end
28
-
29
- Capybara.configure do |config|
30
- config.javascript_driver = :poltergeist
31
- config.default_driver = :poltergeist
32
- config.run_server = false
33
- end
34
-
35
- GEM_ROOT = File.expand_path('..', __dir__)
36
- ENV['RAILS_ENV'] = 'development'
37
-
38
- VCR.configure do |c|
39
- c.cassette_library_dir = 'spec/fixtures'
40
- c.hook_into :webmock # or :fakeweb
41
- # c.debug_logger = STDOUT
42
- end
43
-
44
- module SpecHelper
45
- def show_image
46
- Capybara::Screenshot.screenshot_and_open_image
47
- end
48
- end
49
-
50
- RSpec.configure do |config|
51
- config.mock_with :rspec
52
-
53
- config.expect_with :rspec do |c|
54
- c.syntax = %i[should expect]
55
- end
56
-
57
- config.mock_with :rspec do |c|
58
- c.syntax = %i[should expect]
59
- end
60
-
61
- config.around(:each) do |example|
62
- if example.metadata[:vcr] === false
63
- WebMock.allow_net_connect!
64
- VCR.turned_off { example.run }
65
- WebMock.disable_net_connect!
66
- else
67
- example.run
68
- end
69
- end
70
- config.include(SpecHelper)
71
- end
@@ -1,235 +0,0 @@
1
- describe Veritrans::Client do
2
-
3
- before do
4
- hide_const("Rails")
5
- Veritrans.logger = Logger.new("/dev/null")
6
- Veritrans.setup do
7
- config.load_config "./spec/configs/real_key.yml"
8
- end
9
- end
10
-
11
- def test_card_data
12
- {
13
- card_number: 4811_1111_1111_1114,
14
- card_cvv: 123,
15
- card_exp_month: 1,
16
- card_exp_year: Time.now.year + 1
17
- }
18
- end
19
-
20
- it "should use Veritrans.http_options", vcr: false do
21
- Veritrans::Config.stub(:http_options) do
22
- { omit_default_port: true }
23
- end
24
-
25
- api_request = nil
26
- stub_request(:any, /.*/).to_return(lambda { |request|
27
- api_request = request
28
- { body: request.body }
29
- })
30
-
31
- result = Veritrans.request_with_logging(:get, Veritrans.config.api_host + "/ping", {})
32
-
33
- api_request.headers["Host"].should == "api.sandbox.midtrans.com:443"
34
- end
35
-
36
- it "should use Veritrans.http_options to attach hedaers", vcr: false do
37
- Veritrans.config.stub(:http_options) do
38
- { headers: { "X-Rspec" => "ok" } }
39
- end
40
-
41
- api_request = nil
42
- stub_request(:any, /.*/).to_return(lambda { |request|
43
- api_request = request
44
- { body: request.body }
45
- })
46
-
47
- result = Veritrans.request_with_logging(:get, Veritrans.config.api_host + "/ping", {})
48
-
49
- api_request.headers["X-Rspec"].should == "ok"
50
- end
51
-
52
- it "should be able to create other instance of client" do
53
- #Veritrans.logger = Logger.new(STDOUT)
54
-
55
- VCR.configure do |c|
56
- c.allow_http_connections_when_no_cassette = true
57
- end
58
-
59
- other_client = Veritrans.new(
60
- server_key: "69b61a1b-b0b1-450b-a697-37109dbbecb0",
61
- logger: Logger.new("/dev/null")
62
- ) # M000937
63
-
64
- result = Veritrans.charge(
65
- payment_type: "mandiri_clickpay",
66
- transaction_details: {
67
- gross_amount: 10_000,
68
- order_id: Time.now.to_s
69
- },
70
- mandiri_clickpay: {
71
- card_number: "4111 1111 1111 1111".gsub(/\s/, ''),
72
- input3: "%05d" % (rand * 100000).to_i,
73
- input2: 10000,
74
- input1: "1" * 10,
75
- token: "000000"
76
- },
77
- )
78
-
79
- #p result.request_options
80
-
81
- other_result = other_client.status(result.transaction_id)
82
-
83
- other_result.status_code.should == 404
84
-
85
- other_result.status_message.should == "Transaction doesn't exist."
86
-
87
- #p other_result.request_options
88
-
89
- VCR.configure do |c|
90
- c.allow_http_connections_when_no_cassette = true
91
- end
92
- end
93
-
94
- it "should send charge vt-web request" do
95
- VCR.use_cassette('charge_vtweb') do
96
- result = Veritrans.charge('vtweb', transaction: { order_id: Time.now.to_s, gross_amount: 100_000 })
97
-
98
- result.status_message.should == "OK, success do VTWeb transaction, please go to redirect_url"
99
- result.success?.should == true
100
- result.redirect_url.should be_present
101
- end
102
- end
103
-
104
- it "should send charge vt-web request" do
105
- VCR.use_cassette('charge_direct') do
106
- result = Veritrans.charge("permata", transaction: { order_id: Time.now.to_s, gross_amount: 100_000 })
107
-
108
- result.status_message.should == "Success, PERMATA VA transaction is successful"
109
- result.success?.should == true
110
- result.permata_va_number.should be_present
111
- end
112
- end
113
-
114
- it "should send status request" do
115
- VCR.use_cassette('status_fail') do
116
- result = Veritrans.status("not-exists")
117
- result.success?.should == false
118
- result.status_message.should == "Transaction doesn't exist."
119
- end
120
- end
121
-
122
- it "should send status request and get response" do
123
- VCR.use_cassette('status_success') do
124
- result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 })
125
- result = Veritrans.status(result_charge.order_id)
126
- result.success?.should == true
127
- result.status_message.should == "Success, transaction is found"
128
- result.transaction_status.should == "pending"
129
- end
130
- end
131
-
132
- it "should send status request and get response" do
133
- VCR.use_cassette('cancel_failed') do
134
- result = Veritrans.cancel("not-exists")
135
- result.success?.should == false
136
- result.status_message.should == "Transaction doesn't exist."
137
- end
138
- end
139
-
140
- it "should send status request and get response" do
141
- VCR.use_cassette('cancel_success') do
142
- result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 })
143
- result = Veritrans.cancel(result_charge.order_id)
144
- result.success?.should == true
145
- result.status_message.should == "Success, transaction is canceled"
146
- result.transaction_status.should == "cancel"
147
- end
148
- end
149
-
150
- it "should send approve request" do
151
- VCR.use_cassette('approve_failed') do
152
- result = Veritrans.cancel("not-exists")
153
- result.success?.should == false
154
- result.status_message.should == "The requested resource is not found"
155
- end
156
- end
157
-
158
- it 'should get token for testing' do
159
- VCR.use_cassette('test_token') do
160
- result = Veritrans.test_token(test_card_data)
161
- result.should be_a_kind_of(String)
162
- end
163
- end
164
-
165
- # Can only refund after it has been settled after one day
166
- it 'should send refund request' do
167
- VCR.use_cassette('refund_failed') do
168
- result = Veritrans.refund('1415110696')
169
- result.success?.should == false
170
- result.status_message.should == 'Merchant cannot modify the status of the transaction'
171
- end
172
- end
173
-
174
- it "should send capture request" do
175
- VCR.use_cassette('capture_failed') do
176
- result = Veritrans.capture("not-exists", 1000)
177
- result.success?.should == false
178
- result.status_message.should == "The requested resource is not found"
179
- end
180
- end
181
-
182
- it 'should send deny request' do
183
- VCR.use_cassette('deny_failed') do
184
- Timecop.freeze(Time.utc(2019, 4, 1)) do
185
- order_id = Time.now.to_i.to_s
186
-
187
- charge_result = Veritrans.charge(
188
- payment_type: 'credit_card',
189
- credit_card: {
190
- token_id: Veritrans.test_token(test_card_data)
191
- },
192
- transaction_details: {
193
- order_id: order_id,
194
- gross_amount: 3000
195
- }
196
- )
197
-
198
- charge_result.status_message.should == "Success, Credit Card transaction is successful"
199
-
200
- result = Veritrans.deny(order_id)
201
- result.success?.should == false
202
- result.status_message.should == 'Transaction status cannot be updated.'
203
- end
204
- end
205
- end
206
-
207
- it "should send expire request" do
208
- VCR.use_cassette('expire_success', record: :once) do
209
- result = Veritrans.expire("af3fb136-c405-4103-9a36-5a6a9e2855a9")
210
- result.success?.should == true
211
- result.status_message.should == "Success, transaction has expired"
212
- end
213
- end
214
-
215
- it "should send expire request" do
216
- VCR.use_cassette('expire_failed', record: :once) do
217
- result = Veritrans.expire("not-exists")
218
- result.success?.should == false
219
- result.status_message.should == "The requested resource is not found"
220
- end
221
- end
222
-
223
- it "should handle network exceptions", vcr: false do
224
- Excon::Connection.any_instance.stub(:send) do
225
- raise Excon::Errors::SocketError, Excon::Errors::Error.new("testing exception")
226
- end
227
-
228
- result = Veritrans.expire("not-exists")
229
- result.status.should == "500"
230
- result.data.should == {
231
- status_code: "500",
232
- status_message: "Internal server error, no response from backend. Try again later"
233
- }
234
- end
235
- end
@@ -1,70 +0,0 @@
1
- describe Veritrans::Config do
2
-
3
- before do
4
- hide_const("Rails")
5
- hide_const("ENV")
6
- end
7
-
8
- it "should set Veritras as self inside config block" do
9
- Veritrans.config do
10
- self.should == Veritrans.instance
11
- end
12
- end
13
-
14
- it "should have sandbox api_host by defualt" do
15
- Veritrans.config.api_host.should == "https://api.sandbox.midtrans.com"
16
- end
17
-
18
- it "should set client key and server key" do
19
- Veritrans.config do
20
- config.client_key = "kk-1"
21
- config.server_key = "sk-1"
22
- end
23
-
24
- Veritrans.config.client_key.should == "kk-1"
25
- Veritrans.config.server_key.should == "sk-1"
26
- end
27
-
28
- it "should load config" do
29
- data = Veritrans.config.load_config("./spec/configs/veritrans_flat.yml")
30
- data.should == {"client_key" => "flat_client_key", "server_key" => "flat_server_key"}
31
- end
32
-
33
- it "should load config according to hash" do
34
- data = Veritrans.config.load_config("./spec/configs/veritrans.yml#development")
35
- data.should == {"client_key" => "spec_client_key", "server_key" => "spec_server_key"}
36
- end
37
-
38
- it "should load config for Rails.env" do
39
- stub_const("Rails", Class.new {
40
- def self.env
41
- "test"
42
- end
43
- })
44
-
45
- data = Veritrans.config.load_config("./spec/configs/veritrans.yml")
46
- data.should == {"client_key" => "test_client_key", "server_key" => "test_server_key"}
47
- end
48
-
49
- it "should load config and render erb lines" do
50
- stub_const('ENV', {
51
- 'CLIENT_KEY' => 'test_client_key',
52
- 'SERVER_KEY' => 'test_server_key'
53
- })
54
-
55
- data = Veritrans.config.load_config("./spec/configs/veritrans_with_erb.yml")
56
- data.should == {"client_key" => "test_client_key", "server_key" => "test_server_key"}
57
- end
58
-
59
- it "should validate http_params type" do
60
- expect {
61
- Veritrans.config.http_options = nil
62
- }.to raise_error(ArgumentError, "http_options should be a hash")
63
- end
64
-
65
- it "should validate http_params type" do
66
- expect {
67
- Veritrans.config.http_options = {foo: "bar", tcp_nodelay: true}
68
- }.to raise_error(ArgumentError, /http_options contain unsupported keys: \[:foo\]/)
69
- end
70
- end