veritrans 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,18 +3,18 @@ require 'open3'
3
3
  require 'shellwords'
4
4
  require 'socket'
5
5
 
6
- describe "Rails plugin", vcr: false do
6
+ describe 'Rails plugin', vcr: false do
7
7
  include Capybara::DSL
8
8
 
9
- MAIN_RAILS_VER = "5.1.0"
10
- APP_DIR = "plugin_test"
11
- PLUGIN_DIR = File.expand_path("..", File.dirname(__FILE__))
9
+ MAIN_RAILS_VER = '5.2.3'.freeze
10
+ APP_DIR = 'plugin_test'.freeze
11
+ PLUGIN_DIR = File.expand_path('..', File.dirname(__FILE__))
12
12
 
13
- RAILS_VERSIONS = ["4.1.16", "4.2.8", "5.0.2", "5.1.0"]
13
+ RAILS_VERSIONS = %w[4.2.11.1 5.0.7.2 5.1.7 5.2.3].freeze
14
14
 
15
15
  before :all do
16
16
  FileUtils.mkdir_p("#{PLUGIN_DIR}/tmp")
17
- #Capybara::Screenshot.instance_variable_set(:@capybara_root, "#{PLUGIN_DIR}/tmp")
17
+ # Capybara::Screenshot.instance_variable_set(:@capybara_root, "#{PLUGIN_DIR}/tmp")
18
18
  end
19
19
 
20
20
  def capture_stdout(&block)
@@ -37,24 +37,21 @@ describe "Rails plugin", vcr: false do
37
37
 
38
38
  if status != 0
39
39
  puts "CMD: #{full_cmd}"
40
- puts "FAILED"
40
+ puts 'FAILED'
41
41
  puts output
42
42
 
43
43
  exit 1
44
44
  end
45
-
46
- #puts stdout_str
47
-
48
- return output
45
+ output
49
46
  end
50
47
 
51
48
  def install_rails_in_tmp(rails_version = MAIN_RAILS_VER)
52
- @rails_dir = Dir.mktmpdir()
49
+ @rails_dir = Dir.mktmpdir
53
50
  @app_abs_path = "#{@rails_dir}/#{APP_DIR}"
54
51
 
55
52
  Dir.chdir(@rails_dir) do
56
53
  Bundler.with_clean_env do
57
- ENV["RAILS_ENV"] = "development"
54
+ ENV['RAILS_ENV'] = 'development'
58
55
  find_or_install_rails(rails_version)
59
56
  generate_rails_app(rails_version)
60
57
  generate_plugin_things
@@ -64,11 +61,10 @@ describe "Rails plugin", vcr: false do
64
61
 
65
62
  def find_or_install_rails(rails_version)
66
63
  response = run_cmd('gem list \^rails\$ -q')
67
- if response =~ /[^\d]#{rails_version}[^\d]/
68
- return true
69
- else
70
- run_cmd("gem install rails -v #{rails_version} --no-ri --no-rdoc")
71
- end
64
+
65
+ return true if response =~ /[^\d]#{rails_version}[^\d]/
66
+
67
+ run_cmd("gem install rails -v #{rails_version}")
72
68
  end
73
69
 
74
70
  def generate_rails_app(rails_version)
@@ -76,30 +72,35 @@ describe "Rails plugin", vcr: false do
76
72
  source 'https://rubygems.org'
77
73
 
78
74
  gem 'rails', '#{rails_version}'
79
- gem 'sqlite3'
75
+ gem 'sqlite3', '~> 1.3.13'
80
76
  gem 'turbolinks'
81
77
  gem 'jquery-rails'
82
78
  gem 'veritrans', path: '#{PLUGIN_DIR}'
83
79
  ".gsub(/^\s+/, '')
84
80
 
85
- File.open("./Gemfile", "w") {|f| f.write(gemfile_content) }
86
- run_cmd("bundle")
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
87
88
 
88
- 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"
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(' ')}"
89
90
 
90
91
  run_cmd(gen)
91
92
 
92
- File.open("#{@app_abs_path}/Gemfile", "w") {|f| f.write(gemfile_content) }
93
+ File.open("#{@app_abs_path}/Gemfile", 'w') { |f| f.write(gemfile_content) }
93
94
 
94
95
  Dir.chdir(@app_abs_path) do
95
- run_cmd("bundle")
96
+ run_cmd('bundle _1.17.3_')
96
97
  end
97
98
  end
98
99
 
99
100
  def generate_plugin_things
100
101
  Dir.chdir(@app_abs_path) do
101
- run_cmd("rails g veritrans:install")
102
- run_cmd("rails g veritrans:payment_form")
102
+ run_cmd('rails g veritrans:install')
103
+ run_cmd('rails g veritrans:payment_form')
103
104
  end
104
105
 
105
106
  config_content = "
@@ -109,26 +110,26 @@ development:
109
110
  api_host: https://api.sandbox.midtrans.com
110
111
  "
111
112
 
112
- File.open("#{@app_abs_path}/config/veritrans.yml", "w") {|f| f.write(config_content) }
113
+ File.open("#{@app_abs_path}/config/veritrans.yml", 'w') { |f| f.write(config_content) }
113
114
  end
114
115
 
115
116
  def run_rails_app
116
117
  @rails_port = find_open_port
117
118
 
118
119
  server_cmd = "./bin/rails server -p #{@rails_port} -b 127.0.0.1"
119
- server_env = {"RAILS_ENV" => "development", "BUNDLE_GEMFILE" => @app_abs_path + "/Gemfile"}
120
- spawn_opts = {chdir: @app_abs_path}
121
- spawn_opts.merge!([:err, :out] => "/dev/null") unless ENV['DEBUG']
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']
122
123
 
123
124
  Bundler.with_clean_env do
124
125
  puts "RUN: #{server_cmd} #{spawn_opts}" if ENV['DEBUG']
125
126
  @runner_pid = spawn(server_env, server_cmd, spawn_opts)
126
- puts "Process running PID: #{$runner_pid}" if ENV['DEBUG']
127
+ puts "Process running PID: #{@runner_pid}" if ENV['DEBUG']
127
128
  end
128
129
 
129
130
  Capybara.app_host = "http://127.0.0.1:#{@rails_port}"
130
131
 
131
- #puts "RAILS_DIR: #{@app_abs_path}"
132
+ # puts "RAILS_DIR: #{@app_abs_path}"
132
133
 
133
134
  check_cmd = "curl #{Capybara.app_host}/payments/new"
134
135
 
@@ -137,35 +138,33 @@ development:
137
138
  puts "Check if rails server UP (#{Capybara.app_host})" if ENV['DEBUG']
138
139
  output, status = Open3.capture2e(check_cmd)
139
140
  if status == 0 && output =~ /credit_card_number/
140
- puts "Server is running, output:"
141
- puts output
141
+ if ENV['DEBUG']
142
+ puts 'Server is running, output:'
143
+ puts output[0..300]
144
+ end
142
145
  break
143
146
  else
144
147
  failed += 1
145
- #p error
146
- #puts "Retry"
147
148
  sleep 0.3
148
149
  end
149
150
  end
150
151
 
151
- if failed == 100
152
- puts `tail -100 #{@app_abs_path}/log/development.log`
153
- raise Exception, "can not start rails server"
154
- end
152
+ return if failed != 100
153
+
154
+ puts `tail -100 #{@app_abs_path}/log/development.log`
155
+ raise Exception, 'cannot start rails server'
155
156
  end
156
157
 
157
158
  def stop_rails_app
158
159
  Dir.chdir(@app_abs_path) do
159
- if File.exist?("./tmp/pids/server.pid")
160
- run_cmd("kill `cat tmp/pids/server.pid`")
161
- end
160
+ run_cmd('kill `cat tmp/pids/server.pid`') if File.exist?('./tmp/pids/server.pid')
162
161
  end
163
162
  end
164
163
 
165
164
  def find_open_port
166
165
  socket = Socket.new(:INET, :STREAM, 0)
167
- socket.bind(Addrinfo.tcp("127.0.0.1", 0))
168
- return socket.local_address.ip_port
166
+ socket.bind(Addrinfo.tcp('127.0.0.1', 0))
167
+ socket.local_address.ip_port
169
168
  ensure
170
169
  socket.close
171
170
  end
@@ -177,18 +176,17 @@ development:
177
176
 
178
177
  def submit_payment_form(card_number)
179
178
  # CREATE PAYMENT 1
180
- visit "/payments/new"
179
+ visit '/payments/new'
181
180
 
182
181
  fill_in 'credit_card_number', with: card_number
183
-
184
- click_button "Pay via VT-Direct"
185
- puts "Clicked Pay"
182
+ click_button 'Pay via VT-Direct'
183
+ puts 'Clicked Pay'
186
184
 
187
185
  # Waiting for get token request in javascript...
188
186
  Timeout.timeout(60.seconds) do
189
187
  loop do
190
- #puts "Path: #{current_path}"
191
- break if current_path != "/payments/new"
188
+ break if current_path != '/payments/new'
189
+
192
190
  sleep 1
193
191
  end
194
192
  end
@@ -196,14 +194,14 @@ development:
196
194
  Timeout.timeout(10.seconds) do
197
195
  loop do
198
196
  break if page.body =~ /<body>/
197
+
199
198
  sleep 0.1
200
199
  end
201
200
  end
202
201
  end
203
202
 
204
203
  RAILS_VERSIONS.each_with_index do |rails_version, spec_index|
205
- next if rails_version.start_with?("5") && RUBY_VERSION < "2.2.2"
206
- next if RUBY_VERSION >= "2.4.0" && rails_version < "4.2.0"
204
+ next if rails_version.start_with?('5') && RUBY_VERSION < '2.2.2'
207
205
 
208
206
  it "should tests plugin (Rails #{rails_version})" do
209
207
  puts "Testing with Rails #{rails_version} and Ruby #{RUBY_VERSION}"
@@ -212,13 +210,13 @@ development:
212
210
  run_rails_app
213
211
 
214
212
  card_numbers = [
215
- "5481 1611 1111 1081",
216
- "5410 1111 1111 1116",
217
- "4011 1111 1111 1112",
218
- "4411 1111 1111 1118",
219
- "4811 1111 1111 1114",
220
- "3528 6647 7942 9687",
221
- "3528 2033 2456 4357"
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'
222
220
  ]
223
221
  spec_index = (spec_index + RUBY_VERSION.gsub(/[^\d]/, '').to_i) % card_numbers.size
224
222
  card_number = card_numbers[spec_index]
@@ -226,31 +224,29 @@ development:
226
224
  submit_payment_form(card_number)
227
225
 
228
226
  if page.body =~ /too many transactions/
229
- puts "!!!!"
230
- puts "Merchant has sent too many transactions to the same card number"
231
- puts "!!!!"
232
- #page.should have_content("Merchant has sent too many transactions to the same card number")
233
- puts "Wait 10 seconds and retry"
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'
234
232
  sleep 10
235
233
  submit_payment_form(card_number)
236
234
  end
237
235
 
238
- if page.body !~ /transaction is successful/
239
- puts page.body
240
- end
241
- page.should have_content("Success, Credit Card transaction is successful")
236
+ puts page.body if page.body !~ /transaction is successful/
237
+
238
+ page.should have_content('Success, Credit Card transaction is successful')
242
239
 
243
- order_info = ActiveSupport::JSON.decode(find("pre").text)
240
+ order_info = ActiveSupport::JSON.decode(find('pre').text)
244
241
  puts "Order Info: #{order_info}"
245
- created_order_id = order_info["order_id"]
246
- #Capybara::Screenshot.screenshot_and_open_image
242
+ created_order_id = order_info['order_id']
243
+ # Capybara::Screenshot.screenshot_and_open_image
247
244
 
248
245
  # CREATE PAYMENT 2
249
- visit "/payments/new"
250
- click_link "Pay via VT-Web"
246
+ visit '/payments/new'
247
+ click_link 'Pay via VT-Web'
251
248
 
252
- page.should have_content("Payment is securely processed by Midtrans")
253
- #Capybara::Screenshot.screenshot_and_open_image
249
+ page.should have_content('ATM/Bank Transfer')
254
250
 
255
251
  # TEST CALLBACK FOR WRONG DATA
256
252
  stub_const("CONFIG", {})
@@ -261,38 +257,61 @@ development:
261
257
  result1.should =~ /status: 404/
262
258
 
263
259
  # TEST CALLBACK FOR CORRECT DATA
264
- stub_const("CONFIG", {order: created_order_id, config_path: "#{@app_abs_path}/config/veritrans.yml"})
260
+ stub_const('CONFIG', order: created_order_id, config_path: "#{@app_abs_path}/config/veritrans.yml")
265
261
  result2 = capture_stdout do
266
262
  Veritrans::CLI.test_webhook(["#{Capybara.app_host}/payments/receive_webhook"])
267
263
  end
268
264
 
269
- if result2 !~ /status: 200/
270
- puts `tail -40 #{@app_abs_path}/log/development.log`
271
- end
265
+ puts `tail -40 #{@app_abs_path}/log/development.log` if result2 !~ /status: 200/
272
266
 
273
267
  result2.should =~ /status: 200/
274
268
  result2.should =~ /body: ok/
275
269
  end
276
270
  end
277
271
 
278
- it "should print message if running in staging" do
272
+ it 'should print message if running in staging' do
279
273
  # PREPARE APP
280
274
  install_rails_in_tmp
281
- File.open("#{@app_abs_path}/config/database.yml", 'a') {|f|
275
+ File.open("#{@app_abs_path}/config/database.yml", 'a') { |f|
282
276
  f.puts
283
- f.puts("staging:")
284
- f.puts(" adapter: sqlite3")
277
+ f.puts('staging:')
278
+ f.puts(' adapter: sqlite3')
285
279
  f.puts(" database: ':memory:'")
286
280
  }
287
281
 
288
282
  Bundler.with_clean_env do
289
- ENV["RAILS_ENV"] = "staging"
283
+ ENV['RAILS_ENV'] = 'staging'
290
284
  Dir.chdir(@app_abs_path) do
291
- stdout_str, stderr_str, status = Open3.capture3(%{./bin/rails r 'p :started'})
285
+ stdout_str, stderr_str, status = Open3.capture3(%(./bin/rails r 'p :started'))
292
286
  stderr_str.should include('Veritrans: Can not find section "staging"')
293
287
  stderr_str.should include('Available sections: ["development"]')
294
288
  stderr_str.should include('Veritrans: Using first section "development"')
295
289
  end
296
290
  end
297
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
298
317
  end
@@ -1,6 +1,6 @@
1
1
  require 'bundler/setup'
2
2
 
3
- $:.push(File.expand_path("../../lib", __FILE__))
3
+ $LOAD_PATH.push(File.expand_path('../lib', __dir__))
4
4
 
5
5
  require 'rspec'
6
6
  require 'veritrans'
@@ -9,15 +9,19 @@ require 'veritrans/events'
9
9
  require 'rails'
10
10
  require 'webmock/rspec'
11
11
  require 'vcr'
12
+ require 'timecop'
12
13
 
13
14
  require 'capybara/rspec'
15
+ require 'capybara-screenshot/rspec'
14
16
  require 'capybara/poltergeist'
15
17
  require 'active_support/testing/stream'
16
18
 
17
19
  Capybara.register_driver :poltergeist do |app|
18
- Capybara::Poltergeist::Driver.new(app,
20
+ Capybara::Poltergeist::Driver.new(
21
+ app,
22
+ js_errors: false,
19
23
  # phantomjs don't much like ssl of cloudfront.net
20
- phantomjs_options: ['--ignore-ssl-errors=yes', '--ssl-protocol=any'],
24
+ phantomjs_options: %w[--ignore-ssl-errors=yes --ssl-protocol=any]
21
25
  # logger: STDOUT
22
26
  )
23
27
  end
@@ -28,24 +32,30 @@ Capybara.configure do |config|
28
32
  config.run_server = false
29
33
  end
30
34
 
31
- GEM_ROOT = File.expand_path("../..", __FILE__)
35
+ GEM_ROOT = File.expand_path('..', __dir__)
32
36
  ENV['RAILS_ENV'] = 'development'
33
37
 
34
38
  VCR.configure do |c|
35
39
  c.cassette_library_dir = 'spec/fixtures'
36
40
  c.hook_into :webmock # or :fakeweb
37
- #c.debug_logger = STDOUT
41
+ # c.debug_logger = STDOUT
42
+ end
43
+
44
+ module SpecHelper
45
+ def show_image
46
+ Capybara::Screenshot.screenshot_and_open_image
47
+ end
38
48
  end
39
49
 
40
50
  RSpec.configure do |config|
41
51
  config.mock_with :rspec
42
52
 
43
53
  config.expect_with :rspec do |c|
44
- c.syntax = [:should, :expect]
54
+ c.syntax = %i[should expect]
45
55
  end
46
56
 
47
57
  config.mock_with :rspec do |c|
48
- c.syntax = [:should, :expect]
58
+ c.syntax = %i[should expect]
49
59
  end
50
60
 
51
61
  config.around(:each) do |example|
@@ -57,4 +67,5 @@ RSpec.configure do |config|
57
67
  example.run
58
68
  end
59
69
  end
70
+ config.include(SpecHelper)
60
71
  end
@@ -8,6 +8,15 @@ describe Veritrans::Client do
8
8
  end
9
9
  end
10
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
+
11
20
  it "should use Veritrans.http_options", vcr: false do
12
21
  Veritrans::Config.stub(:http_options) do
13
22
  { omit_default_port: true }
@@ -16,7 +25,7 @@ describe Veritrans::Client do
16
25
  api_request = nil
17
26
  stub_request(:any, /.*/).to_return(lambda { |request|
18
27
  api_request = request
19
- {body: request.body}
28
+ { body: request.body }
20
29
  })
21
30
 
22
31
  result = Veritrans.request_with_logging(:get, Veritrans.config.api_host + "/ping", {})
@@ -32,7 +41,7 @@ describe Veritrans::Client do
32
41
  api_request = nil
33
42
  stub_request(:any, /.*/).to_return(lambda { |request|
34
43
  api_request = request
35
- {body: request.body}
44
+ { body: request.body }
36
45
  })
37
46
 
38
47
  result = Veritrans.request_with_logging(:get, Veritrans.config.api_host + "/ping", {})
@@ -72,7 +81,8 @@ describe Veritrans::Client do
72
81
  other_result = other_client.status(result.transaction_id)
73
82
 
74
83
  other_result.status_code.should == 404
75
- other_result.status_message.should == "The requested resource is not found"
84
+
85
+ other_result.status_message.should == "Transaction doesn't exist."
76
86
 
77
87
  #p other_result.request_options
78
88
 
@@ -83,7 +93,7 @@ describe Veritrans::Client do
83
93
 
84
94
  it "should send charge vt-web request" do
85
95
  VCR.use_cassette('charge_vtweb') do
86
- result = Veritrans.charge('vtweb', transaction: { order_id: Time.now.to_s, gross_amount: 100_000 } )
96
+ result = Veritrans.charge('vtweb', transaction: { order_id: Time.now.to_s, gross_amount: 100_000 })
87
97
 
88
98
  result.status_message.should == "OK, success do VTWeb transaction, please go to redirect_url"
89
99
  result.success?.should == true
@@ -105,16 +115,16 @@ describe Veritrans::Client do
105
115
  VCR.use_cassette('status_fail') do
106
116
  result = Veritrans.status("not-exists")
107
117
  result.success?.should == false
108
- result.status_message.should == "The requested resource is not found"
118
+ result.status_message.should == "Transaction doesn't exist."
109
119
  end
110
120
  end
111
121
 
112
122
  it "should send status request and get response" do
113
123
  VCR.use_cassette('status_success') do
114
- result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 } )
124
+ result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 })
115
125
  result = Veritrans.status(result_charge.order_id)
116
126
  result.success?.should == true
117
- result.status_message.should == "Success, transaction found"
127
+ result.status_message.should == "Success, transaction is found"
118
128
  result.transaction_status.should == "pending"
119
129
  end
120
130
  end
@@ -123,13 +133,13 @@ describe Veritrans::Client do
123
133
  VCR.use_cassette('cancel_failed') do
124
134
  result = Veritrans.cancel("not-exists")
125
135
  result.success?.should == false
126
- result.status_message.should == "The requested resource is not found"
136
+ result.status_message.should == "Transaction doesn't exist."
127
137
  end
128
138
  end
129
139
 
130
140
  it "should send status request and get response" do
131
141
  VCR.use_cassette('cancel_success') do
132
- result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 } )
142
+ result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 })
133
143
  result = Veritrans.cancel(result_charge.order_id)
134
144
  result.success?.should == true
135
145
  result.status_message.should == "Success, transaction is canceled"
@@ -145,6 +155,22 @@ describe Veritrans::Client do
145
155
  end
146
156
  end
147
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
+
148
174
  it "should send capture request" do
149
175
  VCR.use_cassette('capture_failed') do
150
176
  result = Veritrans.capture("not-exists", 1000)
@@ -153,6 +179,31 @@ describe Veritrans::Client do
153
179
  end
154
180
  end
155
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
+
156
207
  it "should send expire request" do
157
208
  VCR.use_cassette('expire_success', record: :once) do
158
209
  result = Veritrans.expire("af3fb136-c405-4103-9a36-5a6a9e2855a9")