veritrans 2.1.2 → 2.4.0

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 (98) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +10 -1
  3. data/.idea/.gitignore +8 -0
  4. data/.rubocop.yml +35 -0
  5. data/.travis.yml +10 -5
  6. data/CHANGELOG.md +45 -0
  7. data/Gemfile +6 -7
  8. data/Gemfile.lock +134 -146
  9. data/Maintaining.MD +8 -0
  10. data/README.md +266 -226
  11. data/api_reference.md +534 -143
  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 +6 -0
  16. data/example/sinatra/index.erb +202 -0
  17. data/example/sinatra/response.erb +1 -0
  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 +146 -22
  31. data/lib/veritrans/client.rb +48 -12
  32. data/lib/veritrans/config.rb +31 -6
  33. data/lib/veritrans/events.rb +46 -35
  34. data/lib/veritrans/midtrans_error.rb +15 -0
  35. data/lib/veritrans/result.rb +66 -5
  36. data/lib/veritrans/version.rb +1 -1
  37. data/lib/veritrans.rb +121 -12
  38. data/veritrans.gemspec +2 -9
  39. metadata +30 -146
  40. data/.rspec +0 -2
  41. data/Procfile +0 -1
  42. data/Rakefile +0 -16
  43. data/bin/midtrans +0 -3
  44. data/bin/veritrans +0 -68
  45. data/example/README.md +0 -8
  46. data/example/config.ru +0 -6
  47. data/example/index.erb +0 -213
  48. data/example/localization.erb +0 -248
  49. data/example/points.erb +0 -187
  50. data/example/recurring.erb +0 -201
  51. data/example/response.erb +0 -37
  52. data/example/sinatra.rb +0 -188
  53. data/example/style.css +0 -126
  54. data/example/veritrans.yml +0 -11
  55. data/example/widget.erb +0 -51
  56. data/lib/generators/templates/assets/credit_card_form.js +0 -51
  57. data/lib/generators/templates/payments_controller.rb +0 -85
  58. data/lib/generators/templates/veritrans.rb +0 -46
  59. data/lib/generators/templates/veritrans.yml +0 -18
  60. data/lib/generators/templates/views/_credit_card_form.erb +0 -42
  61. data/lib/generators/templates/views/_veritrans_include.erb +0 -10
  62. data/lib/generators/templates/views/payments/create.erb +0 -15
  63. data/lib/generators/templates/views/payments/new.erb +0 -6
  64. data/lib/generators/veritrans/install_generator.rb +0 -32
  65. data/lib/generators/veritrans/payment_form_generator.rb +0 -45
  66. data/lib/veritrans/cli.rb +0 -155
  67. data/lib/veritrans/core_extensions.rb +0 -32
  68. data/spec/cli_spec.rb +0 -83
  69. data/spec/configs/real_key.yml +0 -4
  70. data/spec/configs/veritrans.yml +0 -7
  71. data/spec/configs/veritrans_flat.yml +0 -2
  72. data/spec/configs/veritrans_with_erb.yml +0 -2
  73. data/spec/fixtures/approve_failed.yml +0 -48
  74. data/spec/fixtures/cancel_failed.yml +0 -48
  75. data/spec/fixtures/cancel_success.yml +0 -106
  76. data/spec/fixtures/capture_failed.yml +0 -48
  77. data/spec/fixtures/charge.yml +0 -50
  78. data/spec/fixtures/charge_direct.yml +0 -56
  79. data/spec/fixtures/charge_vtweb.yml +0 -50
  80. data/spec/fixtures/cli_test_1111-not-exists.yml +0 -45
  81. data/spec/fixtures/cli_test_not_exists.yml +0 -45
  82. data/spec/fixtures/cli_test_real_txn.yml +0 -55
  83. data/spec/fixtures/cli_test_unauthorized.yml +0 -47
  84. data/spec/fixtures/events_test_real_txn.yml +0 -55
  85. data/spec/fixtures/expire_failed.yml +0 -50
  86. data/spec/fixtures/expire_success.yml +0 -56
  87. data/spec/fixtures/midtrans_status.yml +0 -117
  88. data/spec/fixtures/status_fail.yml +0 -46
  89. data/spec/fixtures/status_success.yml +0 -109
  90. data/spec/midtrans_rename_spec.rb +0 -27
  91. data/spec/rails_plugin_spec.rb +0 -281
  92. data/spec/spec_helper.rb +0 -61
  93. data/spec/veritrans_client_spec.rb +0 -184
  94. data/spec/veritrans_config_spec.rb +0 -70
  95. data/spec/veritrans_events_spec.rb +0 -72
  96. data/spec/veritrans_logger_spec.rb +0 -46
  97. data/spec/veritrans_snap_spec.rb +0 -39
  98. data/testing_webhooks.md +0 -78
@@ -1,27 +0,0 @@
1
- describe Veritrans::Client do
2
-
3
- before do
4
- hide_const("Rails")
5
- Midtrans.logger = Logger.new("/dev/null")
6
- Midtrans.setup do
7
- config.load_config "./spec/configs/real_key.yml"
8
- end
9
- end
10
-
11
- it "should create alias constant for Midtrans" do
12
- Midtrans.should == Veritrans
13
- end
14
-
15
- it "should work with Midtrans" do
16
- VCR.use_cassette('midtrans_status') do
17
- txn_result = Veritrans.charge("permata", transaction: { order_id: Time.now.to_s, gross_amount: 100_000 })
18
- txn_result.success?.should == true
19
- txn_result.status_message.should == "Success, PERMATA VA transaction is successful"
20
-
21
- cancel_result = Midtrans.status(txn_result.order_id)
22
- cancel_result.success?.should == true
23
- cancel_result.status_message.should == "Success, transaction is found"
24
- end
25
- end
26
-
27
- end
@@ -1,281 +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.0.0.1"
10
- APP_DIR = "plugin_test"
11
- PLUGIN_DIR = File.expand_path("..", File.dirname(__FILE__))
12
-
13
- RAILS_VERSIONS = ["4.0.13", "4.1.16", "4.2.7.1", "5.0.0.1"]
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
- stdout_str, stderr_str, status = Open3.capture3(full_cmd)
35
-
36
- if status != 0
37
- puts "CMD: #{full_cmd}"
38
- puts "FAILED"
39
- puts stderr_str
40
-
41
- exit 1
42
- end
43
-
44
- #puts stdout_str
45
-
46
- return stdout_str
47
- end
48
-
49
- def install_rails_in_tmp(rails_version = MAIN_RAILS_VER)
50
- @rails_dir = Dir.mktmpdir()
51
- @app_abs_path = "#{@rails_dir}/#{APP_DIR}"
52
-
53
- Dir.chdir(@rails_dir) do
54
- Bundler.with_clean_env do
55
- ENV["RAILS_ENV"] = "development"
56
- find_or_install_rails(rails_version)
57
- generate_rails_app(rails_version)
58
- generate_plugin_things
59
- end
60
- end
61
- end
62
-
63
- def find_or_install_rails(rails_version)
64
- response = run_cmd('gem list \^rails\$ -q')
65
- if response =~ /[^\d]#{rails_version}[^\d]/
66
- return true
67
- else
68
- run_cmd("gem install rails -v #{rails_version} --no-ri --no-rdoc")
69
- end
70
- end
71
-
72
- def generate_rails_app(rails_version)
73
- gen = "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"
74
- run_cmd(gen)
75
-
76
- gemfile_content = "
77
- source 'https://rubygems.org'
78
-
79
- gem 'rails', '#{rails_version}'
80
- gem 'sqlite3'
81
- gem 'turbolinks'
82
- gem 'jquery-rails'
83
- gem 'veritrans', path: '#{PLUGIN_DIR}'
84
- ".gsub(/^\s+/, '')
85
-
86
- File.open("#{@app_abs_path}/Gemfile", "w") {|f| f.write(gemfile_content) }
87
-
88
- Dir.chdir(@app_abs_path) do
89
- run_cmd("bundle")
90
- end
91
- end
92
-
93
- def generate_plugin_things
94
- Dir.chdir(@app_abs_path) do
95
- run_cmd("rails g veritrans:install")
96
- run_cmd("rails g veritrans:payment_form")
97
- end
98
-
99
- config_content = "
100
- development:
101
- client_key: VT-client-NArmatJZqzsmTmzR
102
- server_key: VT-server-9Htb-RxXkg7-7hznSCCjxvoY
103
- api_host: https://api.sandbox.veritrans.co.id
104
- "
105
-
106
- File.open("#{@app_abs_path}/config/veritrans.yml", "w") {|f| f.write(config_content) }
107
- end
108
-
109
- def run_rails_app
110
- @rails_port = find_open_port
111
-
112
- Bundler.with_clean_env do
113
- ENV["RAILS_ENV"] = "development"
114
- Dir.chdir(@app_abs_path) do
115
- run_cmd("./bin/rails server -d -p #{@rails_port} --bind 127.0.0.1")
116
- end
117
- end
118
-
119
- Capybara.app_host = "http://127.0.0.1:#{@rails_port}"
120
-
121
- #puts "RAILS_DIR: #{@app_abs_path}"
122
-
123
- failed = 0
124
- while failed < 10
125
- begin
126
- run_cmd("curl #{Capybara.app_host}/payments/new > /dev/null")
127
- break
128
- rescue Object => error
129
- failed += 1
130
- p error
131
- puts "Retry"
132
- sleep 0.3
133
- end
134
- end
135
-
136
- if failed == 10
137
- puts `tail -100 #{@app_abs_path}/log/development.log`
138
- raise Exception, "can not start rails server"
139
- end
140
- end
141
-
142
- def stop_rails_app
143
- Dir.chdir(@app_abs_path) do
144
- if File.exist?("./tmp/pids/server.pid")
145
- run_cmd("kill `cat tmp/pids/server.pid`")
146
- end
147
- end
148
- end
149
-
150
- def find_open_port
151
- socket = Socket.new(:INET, :STREAM, 0)
152
- socket.bind(Addrinfo.tcp("127.0.0.1", 0))
153
- return socket.local_address.ip_port
154
- ensure
155
- socket.close
156
- end
157
-
158
- after do
159
- stop_rails_app
160
- FileUtils.remove_entry_secure(@rails_dir) if @rails_dir
161
- end
162
-
163
- def submit_payment_form(card_number)
164
- # CREATE PAYMENT 1
165
- visit "/payments/new"
166
-
167
- fill_in 'credit_card_number', with: card_number
168
-
169
- click_button "Pay via VT-Direct"
170
- puts "Clicked Pay"
171
-
172
- # Waiting for get token request in javascript...
173
- Timeout.timeout(60.seconds) do
174
- loop do
175
- #puts "Path: #{current_path}"
176
- break if current_path != "/payments/new"
177
- sleep 1
178
- end
179
- end
180
-
181
- Timeout.timeout(10.seconds) do
182
- loop do
183
- break if page.body =~ /<body>/
184
- sleep 0.1
185
- end
186
- end
187
- end
188
-
189
- RAILS_VERSIONS.each_with_index do |rails_version, spec_index|
190
- next if rails_version.start_with?("5") && RUBY_VERSION < "2.2.2"
191
-
192
- it "should tests plugin (Rails #{rails_version})" do
193
- # PREPARE APP
194
- install_rails_in_tmp(rails_version)
195
- run_rails_app
196
-
197
- card_numbers = [
198
- "5481 1611 1111 1081",
199
- "5410 1111 1111 1116",
200
- "4011 1111 1111 1112",
201
- "4411 1111 1111 1118",
202
- "4811 1111 1111 1114",
203
- "3528 6647 7942 9687",
204
- "3528 2033 2456 4357"
205
- ]
206
- spec_index = (spec_index + RUBY_VERSION.gsub(/[^\d]/, '').to_i) % card_numbers.size
207
- card_number = card_numbers[spec_index]
208
-
209
- submit_payment_form(card_number)
210
-
211
- if page.body =~ /too many transactions/
212
- puts "!!!!"
213
- puts "Merchant has sent too many transactions to the same card number"
214
- puts "!!!!"
215
- #page.should have_content("Merchant has sent too many transactions to the same card number")
216
- puts "Wait 10 seconds and retry"
217
- sleep 10
218
- submit_payment_form(card_number)
219
- end
220
-
221
- if page.body !~ /transaction is successful/
222
- puts page.body
223
- end
224
- page.should have_content("Success, Credit Card transaction is successful")
225
-
226
- order_info = ActiveSupport::JSON.decode(find("pre").text)
227
- puts "Order Info: #{order_info}"
228
- created_order_id = order_info["order_id"]
229
- #Capybara::Screenshot.screenshot_and_open_image
230
-
231
- # CREATE PAYMENT 2
232
- visit "/payments/new"
233
- click_link "Pay via VT-Web"
234
-
235
- page.should have_content("Payment is securely processed by Veritrans")
236
- #Capybara::Screenshot.screenshot_and_open_image
237
-
238
- # TEST CALLBACK FOR WRONG DATA
239
- stub_const("CONFIG", {})
240
- result1 = capture_stdout do
241
- Veritrans::CLI.test_webhook(["#{Capybara.app_host}/payments/receive_webhook"])
242
- end
243
-
244
- result1.should =~ /status: 404/
245
-
246
- # TEST CALLBACK FOR CORRECT DATA
247
- stub_const("CONFIG", {order: created_order_id, config_path: "#{@app_abs_path}/config/veritrans.yml"})
248
- result2 = capture_stdout do
249
- Veritrans::CLI.test_webhook(["#{Capybara.app_host}/payments/receive_webhook"])
250
- end
251
-
252
- if result2 !~ /status: 200/
253
- puts `tail -40 #{@app_abs_path}/log/development.log`
254
- end
255
-
256
- result2.should =~ /status: 200/
257
- result2.should =~ /body: ok/
258
- end
259
- end
260
-
261
- it "should print message if running in staging" do
262
- # PREPARE APP
263
- install_rails_in_tmp
264
- File.open("#{@app_abs_path}/config/database.yml", 'a') {|f|
265
- f.puts
266
- f.puts("staging:")
267
- f.puts(" adapter: sqlite3")
268
- f.puts(" database: ':memory:'")
269
- }
270
-
271
- Bundler.with_clean_env do
272
- ENV["RAILS_ENV"] = "staging"
273
- Dir.chdir(@app_abs_path) do
274
- stdout_str, stderr_str, status = Open3.capture3(%{./bin/rails r 'p :started'})
275
- stderr_str.should include('Veritrans: Can not find section "staging"')
276
- stderr_str.should include('Available sections: ["development"]')
277
- stderr_str.should include('Veritrans: Using first section "development"')
278
- end
279
- end
280
- end
281
- end
data/spec/spec_helper.rb DELETED
@@ -1,61 +0,0 @@
1
- require 'bundler/setup'
2
-
3
- $:.push(File.expand_path("../../lib", __FILE__))
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
-
13
- require 'capybara/rspec'
14
- require 'capybara/poltergeist'
15
- require 'active_support/testing/stream'
16
-
17
- Capybara.register_driver :poltergeist do |app|
18
- Capybara::Poltergeist::Driver.new(app,
19
- # phantomjs don't much like ssl of cloudfront.net
20
- phantomjs_options: ['--ignore-ssl-errors=yes', '--ssl-protocol=any'],
21
- # logger: STDOUT
22
- )
23
- end
24
-
25
- Capybara.configure do |config|
26
- config.javascript_driver = :poltergeist
27
- config.default_driver = :poltergeist
28
- config.app_host = ""
29
- config.run_server = false
30
- end
31
-
32
- GEM_ROOT = File.expand_path("../..", __FILE__)
33
- ENV['RAILS_ENV'] = 'development'
34
-
35
- VCR.configure do |c|
36
- c.cassette_library_dir = 'spec/fixtures'
37
- c.hook_into :webmock # or :fakeweb
38
- #c.debug_logger = STDOUT
39
- end
40
-
41
- RSpec.configure do |config|
42
- config.mock_with :rspec
43
-
44
- config.expect_with :rspec do |c|
45
- c.syntax = [:should, :expect]
46
- end
47
-
48
- config.mock_with :rspec do |c|
49
- c.syntax = [:should, :expect]
50
- end
51
-
52
- config.around(:each) do |example|
53
- if example.metadata[:vcr] === false
54
- WebMock.allow_net_connect!
55
- VCR.turned_off { example.run }
56
- WebMock.disable_net_connect!
57
- else
58
- example.run
59
- end
60
- end
61
- end
@@ -1,184 +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
- it "should use Veritrans.http_options", vcr: false do
12
- Veritrans::Config.stub(:http_options) do
13
- { omit_default_port: true }
14
- end
15
-
16
- api_request = nil
17
- stub_request(:any, /.*/).to_return(lambda { |request|
18
- api_request = request
19
- {body: request.body}
20
- })
21
-
22
- result = Veritrans.request_with_logging(:get, Veritrans.config.api_host + "/ping", {})
23
-
24
- api_request.headers["Host"].should == "api.sandbox.veritrans.co.id:443"
25
- end
26
-
27
- it "should use Veritrans.http_options to attach hedaers", vcr: false do
28
- Veritrans.config.stub(:http_options) do
29
- { headers: { "X-Rspec" => "ok" } }
30
- end
31
-
32
- api_request = nil
33
- stub_request(:any, /.*/).to_return(lambda { |request|
34
- api_request = request
35
- {body: request.body}
36
- })
37
-
38
- result = Veritrans.request_with_logging(:get, Veritrans.config.api_host + "/ping", {})
39
-
40
- api_request.headers["X-Rspec"].should == "ok"
41
- end
42
-
43
- it "should be able to create other instance of client" do
44
- #Veritrans.logger = Logger.new(STDOUT)
45
-
46
- VCR.configure do |c|
47
- c.allow_http_connections_when_no_cassette = true
48
- end
49
-
50
- other_client = Veritrans.new(
51
- server_key: "69b61a1b-b0b1-450b-a697-37109dbbecb0",
52
- logger: Logger.new("/dev/null")
53
- ) # M000937
54
-
55
- result = Veritrans.charge(
56
- payment_type: "mandiri_clickpay",
57
- transaction_details: {
58
- gross_amount: 10_000,
59
- order_id: Time.now.to_s
60
- },
61
- mandiri_clickpay: {
62
- card_number: "4111 1111 1111 1111".gsub(/\s/, ''),
63
- input3: "%05d" % (rand * 100000).to_i,
64
- input2: 10000,
65
- input1: "1" * 10,
66
- token: "000000"
67
- },
68
- )
69
-
70
- #p result.request_options
71
-
72
- other_result = other_client.status(result.transaction_id)
73
-
74
- other_result.status_code.should == 404
75
- other_result.status_message.should == "The requested resource is not found"
76
-
77
- #p other_result.request_options
78
-
79
- VCR.configure do |c|
80
- c.allow_http_connections_when_no_cassette = true
81
- end
82
- end
83
-
84
- it "should send charge vt-web request" do
85
- VCR.use_cassette('charge_vtweb') do
86
- result = Veritrans.charge('vtweb', transaction: { order_id: Time.now.to_s, gross_amount: 100_000 } )
87
-
88
- result.status_message.should == "OK, success do VTWeb transaction, please go to redirect_url"
89
- result.success?.should == true
90
- result.redirect_url.should be_present
91
- end
92
- end
93
-
94
- it "should send charge vt-web request" do
95
- VCR.use_cassette('charge_direct') do
96
- result = Veritrans.charge("permata", transaction: { order_id: Time.now.to_s, gross_amount: 100_000 })
97
-
98
- result.status_message.should == "Success, PERMATA VA transaction is successful"
99
- result.success?.should == true
100
- result.permata_va_number.should be_present
101
- end
102
- end
103
-
104
- it "should send status request" do
105
- VCR.use_cassette('status_fail') do
106
- result = Veritrans.status("not-exists")
107
- result.success?.should == false
108
- result.status_message.should == "The requested resource is not found"
109
- end
110
- end
111
-
112
- it "should send status request and get response" do
113
- VCR.use_cassette('status_success') do
114
- result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 } )
115
- result = Veritrans.status(result_charge.order_id)
116
- result.success?.should == true
117
- result.status_message.should == "Success, transaction found"
118
- result.transaction_status.should == "pending"
119
- end
120
- end
121
-
122
- it "should send status request and get response" do
123
- VCR.use_cassette('cancel_failed') do
124
- result = Veritrans.cancel("not-exists")
125
- result.success?.should == false
126
- result.status_message.should == "The requested resource is not found"
127
- end
128
- end
129
-
130
- it "should send status request and get response" do
131
- VCR.use_cassette('cancel_success') do
132
- result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 } )
133
- result = Veritrans.cancel(result_charge.order_id)
134
- result.success?.should == true
135
- result.status_message.should == "Success, transaction is canceled"
136
- result.transaction_status.should == "cancel"
137
- end
138
- end
139
-
140
- it "should send approve request" do
141
- VCR.use_cassette('approve_failed') do
142
- result = Veritrans.cancel("not-exists")
143
- result.success?.should == false
144
- result.status_message.should == "The requested resource is not found"
145
- end
146
- end
147
-
148
- it "should send capture request" do
149
- VCR.use_cassette('capture_failed') do
150
- result = Veritrans.capture("not-exists", 1000)
151
- result.success?.should == false
152
- result.status_message.should == "The requested resource is not found"
153
- end
154
- end
155
-
156
- it "should send expire request" do
157
- VCR.use_cassette('expire_success', record: :once) do
158
- result = Veritrans.expire("af3fb136-c405-4103-9a36-5a6a9e2855a9")
159
- result.success?.should == true
160
- result.status_message.should == "Success, transaction has expired"
161
- end
162
- end
163
-
164
- it "should send expire request" do
165
- VCR.use_cassette('expire_failed', record: :once) do
166
- result = Veritrans.expire("not-exists")
167
- result.success?.should == false
168
- result.status_message.should == "The requested resource is not found"
169
- end
170
- end
171
-
172
- it "should handle network exceptions", vcr: false do
173
- Excon::Connection.any_instance.stub(:send) do
174
- raise Excon::Errors::SocketError, Excon::Errors::Error.new("testing exception")
175
- end
176
-
177
- result = Veritrans.expire("not-exists")
178
- result.status.should == "500"
179
- result.data.should == {
180
- status_code: "500",
181
- status_message: "Internal server error, no response from backend. Try again later"
182
- }
183
- end
184
- 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.veritrans.co.id"
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
@@ -1,72 +0,0 @@
1
- describe Veritrans do
2
- include ActiveSupport::Testing::Stream
3
-
4
- before do
5
- stub_const("CONFIG", {})
6
- Veritrans.logger = Logger.new(STDOUT)
7
- Veritrans.file_logger = Logger.new(STDOUT)
8
- Veritrans.setup do
9
- config.load_yml "./example/veritrans.yml#development"
10
- end
11
- end
12
-
13
- after do
14
- if Veritrans.events.listeners
15
- Veritrans.events.listeners.clear
16
- end
17
- end
18
-
19
- JSON_RESPONSE = '{
20
- "status_code": "200",
21
- "status_message": "Success, transaction found",
22
- "transaction_id": "b1cbcc66-5608-4af1-a3ed-0f152f9ed871",
23
- "order_id": "testing-0.2703-1415600236",
24
- "payment_type": "credit_card",
25
- "transaction_time": "2014-11-10 13:17:33",
26
- "transaction_status": "settlement",
27
- "gross_amount": "30000.00",
28
- "masked_card": "481111-1114",
29
- "fraud_status": "accept",
30
- "approval_code": "1415600254322",
31
- "bank": "bni"
32
- }'
33
-
34
- DOUBLE_ENCODED_JSON_RESPONSE = JSON.dump(JSON_RESPONSE)
35
-
36
- def stub_vt_status_response
37
- stub_request(:any, /.*veritrans.*/).to_return(lambda {|request|
38
- {status: 200, body: JSON_RESPONSE}
39
- })
40
- end
41
-
42
- it "should work with single encoded json" do
43
- Veritrans.events.subscribe('payment.success') do |payment|
44
- @payment = payment
45
- end
46
-
47
- stub_vt_status_response
48
-
49
- handler = Rack::MockRequest.new(Veritrans::Events.new)
50
- silence_stream(STDOUT) do
51
- handler.post("http://example.com/", input: JSON_RESPONSE)
52
- end
53
-
54
- @payment.order_id.should == "testing-0.2703-1415600236"
55
- end
56
-
57
- it "should work with double encoded json" do
58
- Veritrans.events.subscribe('payment.success') do |payment|
59
- @payment = payment
60
- end
61
-
62
- stub_vt_status_response
63
-
64
- handler = Rack::MockRequest.new(Veritrans::Events.new)
65
- silence_stream(STDOUT) do
66
- handler.post("http://example.com/", input: DOUBLE_ENCODED_JSON_RESPONSE)
67
- end
68
-
69
- @payment.order_id.should == "testing-0.2703-1415600236"
70
- end
71
-
72
- end