veritrans 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,6 +21,12 @@ please use our [documentation](https://api-docs.midtrans.com/)
21
21
  <td>POST</td>
22
22
  <td>api.midtrans.com/v2/charge</td>
23
23
  </tr>
24
+ <tr>
25
+ <td><a href="#token">Veritrans.test_token(data)</a></td>
26
+ <td>Get Token for Card</td>
27
+ <td>GET</td>
28
+ <td>api.midtrans.com/v2/token</td>
29
+ </tr>
24
30
  <tr>
25
31
  <td><a href="#status">Veritrans.status(id)</a></td>
26
32
  <td>Get Last Status</td>
@@ -39,6 +45,12 @@ please use our [documentation](https://api-docs.midtrans.com/)
39
45
  <td>POST</td>
40
46
  <td>api.midtrans.com/v2/{id}/approve</td>
41
47
  </tr>
48
+ <tr>
49
+ <td><a href="#refund">Veritrans.refund(id)</a></td>
50
+ <td>Refund Successful Transaction</td>
51
+ <td>POST</td>
52
+ <td>api.midtrans.com/v2/{id}/refund</td>
53
+ </tr>
42
54
  <tr>
43
55
  <td><a href="#capture">Veritrans.capture(id)</a></td>
44
56
  <td>Capture Authorise Transaction</td>
@@ -51,6 +63,12 @@ please use our [documentation](https://api-docs.midtrans.com/)
51
63
  <td>POST</td>
52
64
  <td>api.midtrans.com/v2/{id}/expire</td>
53
65
  </tr>
66
+ <tr>
67
+ <td><a href="#deny">Veritrans.deny(id)</a></td>
68
+ <td>Deny Challenged Transaction</td>
69
+ <td>POST</td>
70
+ <td>api.midtrans.com/v2/{id}/deny</td>
71
+ </tr>
54
72
  </tbody>
55
73
  </table>
56
74
 
@@ -141,6 +159,24 @@ q.data == {
141
159
  q.success? # => true
142
160
  ```
143
161
 
162
+ <a name="token"></a>
163
+ ### Test Token
164
+
165
+ Get a token from card information for testing. **Not to be used outside of tests**
166
+
167
+ ```ruby
168
+ card =
169
+ {
170
+ card_number: 4_811_111_111_111_114,
171
+ card_cvv: 123,
172
+ card_exp_month: 0o1,
173
+ card_exp_year: 2020
174
+ }
175
+
176
+ q = Veritrans.test_token(card)
177
+
178
+ q == '481111-1114-a901971f-2f1b-4781-802a-df326fbf0e9c'
179
+ ```
144
180
 
145
181
  <a name="status"></a>
146
182
  ### Status
@@ -219,6 +255,30 @@ q.data == {
219
255
  }
220
256
  ```
221
257
 
258
+ <a name="refund"></a>
259
+ ### Refund
260
+
261
+ To be used to refund. Can only be used on transactions that are marked as `successful` which happens automatically after
262
+ one day after charge request. Defaults to full refund if not specified.
263
+
264
+ ```ruby
265
+ q = Veritrans.refund('testing-0.2072-1415086078')
266
+
267
+ q == {
268
+ status_code: "200",
269
+ status_message: "Success, refund request is approved",
270
+ transaction_id: "447e846a-403e-47db-a5da-d7f3f06375d6",
271
+ order_id: "testing-0.2072-1415086078",
272
+ payment_type: "credit_card",
273
+ transaction_time: "2015-06-15 13:36:24",
274
+ transaction_status: "refund",
275
+ gross_amount: "10000.00",
276
+ refund_chargeback_id: 1,
277
+ refund_amount: "10000.00",
278
+ refund_key: "reference1"
279
+ }
280
+ ```
281
+
222
282
  <a name="capture"></a>
223
283
  ### Capture
224
284
 
@@ -232,15 +292,37 @@ q.success? # => true
232
292
  <a name="expire"></a>
233
293
  ### Expire
234
294
 
235
- You can expire pedning transactions. For examople if merchant choose to pay via ATM,
236
- then user change mind and want to pay with credit card.
237
- In this situation you better expire previous transaction, and you can use same order_id again
295
+ To expire pending transactions. For example if a merchant chooses to pay via ATM and
296
+ then the user changes their mind and now wants to pay with credit card.
297
+ In this situation the previous transaction should be expired. The same order_id can be used again.
238
298
 
239
299
  ```ruby
240
300
  q = Veritrans.expire("testing-0.2072-1415086078")
241
301
  q.success? # => true
242
302
  ```
243
303
 
304
+ <a name="deny"></a>
305
+ ### Deny
306
+ Used to deny a card payment transaction in which `fraud_status` is `challenge`
307
+
308
+ ```ruby
309
+ q = Veritrans.deny("testing-0.2072-1415086078")
310
+
311
+ q == {
312
+ status_code: "200",
313
+ status_message: "Success, transaction is denied",
314
+ transaction_id: "ca297170-be4c-45ed-9dc9-be5ba99d30ee",
315
+ masked_card: "451111-1117",
316
+ order_id: "testing-0.2072-1415086078",
317
+ payment_type: "credit_card",
318
+ transaction_time: "2014-10-31 14:46:44",
319
+ transaction_status: "deny",
320
+ fraud_status: "deny",
321
+ bank: "bni",
322
+ gross_amount: "30000.00"
323
+ }
324
+ ```
325
+
244
326
 
245
327
 
246
328
  ### `Veritrans::Result`
@@ -60,7 +60,7 @@ class PaymentsController < ApplicationController # :nodoc:
60
60
  verified_data.body + "\n"
61
61
  )
62
62
 
63
- render plain: "ok", :status => :not_found
63
+ render plain: "error", :status => :not_found
64
64
  end
65
65
 
66
66
  end
@@ -26,7 +26,7 @@
26
26
 
27
27
  <p>
28
28
  <%= label_tag :credit_card_expire %>
29
- <%= text_field_tag :credit_card_expire, '12 / 18', placeholder: "MM / YY", name: nil %>
29
+ <%= text_field_tag :credit_card_expire, '12 / 20', placeholder: "MM / YY", name: nil %>
30
30
  </p>
31
31
 
32
32
  <p>
@@ -22,8 +22,8 @@ class Veritrans
22
22
 
23
23
  def_delegators :instance, :logger, :logger=, :config, :setup, :file_logger, :file_logger=
24
24
  def_delegators :instance, :request_with_logging, :basic_auth_header, :get, :post, :delete, :make_request
25
- def_delegators :instance, :charge, :cancel, :approve, :status, :capture, :expire
26
- def_delegators :instance, :create_vtlink, :delete_vtlink, :inquiry_points, :create_widget_token, :create_snap_token
25
+ def_delegators :instance, :charge, :cancel, :approve, :status, :capture, :expire, :refund, :test_token, :deny
26
+ def_delegators :instance, :create_vtlink, :delete_vtlink, :inquiry_points, :create_widget_token, :create_snap_redirect_url, :create_snap_token
27
27
  def_delegators :instance, :checksum, :events
28
28
 
29
29
  # Shortcut for Veritrans::Events
@@ -182,10 +182,19 @@ class Veritrans
182
182
  # For rails apps it will write log to RAILS_ROOT/log/veritrans.log
183
183
  def file_logger
184
184
  if !@file_logger
185
- if defined?(Rails) && Rails.root
186
- @file_logger = Logger.new(Rails.root.join("log/veritrans.log").to_s)
187
- else
188
- require 'logger'
185
+ require 'logger'
186
+ begin
187
+ if defined?(Rails) && Rails.root
188
+ require 'fileutils'
189
+ FileUtils.mkdir_p(Rails.root.join("log"))
190
+ @file_logger = Logger.new(Rails.root.join("log/veritrans.log").to_s)
191
+ else
192
+ @file_logger = Logger.new("/dev/null")
193
+ end
194
+ rescue => error
195
+ STDERR.puts "Failed to create Midtrans.file_logger, will use /dev/null"
196
+ STDERR.puts "#{error.class}: #{error.message}"
197
+ STDERR.puts error.backtrace
189
198
  @file_logger = Logger.new("/dev/null")
190
199
  end
191
200
  end
@@ -28,7 +28,7 @@ class Veritrans
28
28
  data[:payment_type] = payment_type if payment_type
29
29
 
30
30
  if data.has_key?(:payment_options)
31
- data[ payment_type.to_sym ] = data.delete(:payment_options)
31
+ data[payment_type.to_sym] = data.delete(:payment_options)
32
32
  end
33
33
 
34
34
  # Rename keys:
@@ -37,21 +37,27 @@ class Veritrans
37
37
  # items -> item_details
38
38
  # customer -> customer_details
39
39
 
40
- data[:transaction_details] = data.delete(:payment) if data[:payment]
41
- data[:transaction_details] = data.delete(:transaction) if data[:transaction]
42
- data[:item_details] = data.delete(:items) if data[:items]
43
- data[:customer_details] = data.delete(:customer) if data[:customer]
40
+ data[:transaction_details] = data.delete(:payment) if data[:payment]
41
+ data[:transaction_details] = data.delete(:transaction) if data[:transaction]
42
+ data[:item_details] = data.delete(:items) if data[:items]
43
+ data[:customer_details] = data.delete(:customer) if data[:customer]
44
44
 
45
45
  request_with_logging(:post, config.api_host + "/v2/charge", data)
46
46
  end
47
47
 
48
- # POST https://app.sandbox.veritrans.co.id/snap/v1/transactions
48
+ def test_token(options = {})
49
+ options[:client_key] = config.client_key
50
+ request_with_logging(:get, config.api_host + '/v2/token', options).token_id
51
+ end
52
+
53
+ # POST https://app.sandbox.midtrans.com/snap/v1/transactions
49
54
  def create_snap_token(options = {})
50
55
  result = request_with_logging(:post, config.api_host.sub('//api.', '//app.') + "/snap/v1/transactions", options)
51
56
  Veritrans::SnapResult.new(result.response, result.url, result.request_options, result.time)
52
57
  end
53
58
 
54
59
  alias_method :create_widget_token, :create_snap_token
60
+ alias_method :create_snap_redirect_url, :create_snap_token
55
61
 
56
62
  # POST /v2/{id}/cancel
57
63
  # Docs https://api-docs.midtrans.com/#cancel-transaction
@@ -73,6 +79,16 @@ class Veritrans
73
79
  request_with_logging(:post, config.api_host + "/v2/#{URI.escape(payment_id)}/approve", options)
74
80
  end
75
81
 
82
+ # POST /v2/{id}/refund
83
+ # Docs https://api-docs.midtrans.com/#refund-transaction
84
+ def refund(payment_id, options = {})
85
+ if !payment_id || payment_id.to_s == ''
86
+ raise ArgumentError, "parameter payment_id can not be blank (got #{payment_id.class} : #{payment_id.inspect})"
87
+ end
88
+
89
+ request_with_logging(:post, config.api_host + "/v2/#{ERB::Util.url_encode(payment_id)}/refund", options)
90
+ end
91
+
76
92
  # GET /v2/{id}/status
77
93
  # Docs https://api-docs.midtrans.com/#get-status-transaction
78
94
  def status(payment_id)
@@ -93,6 +109,16 @@ class Veritrans
93
109
  post(config.api_host + "/v2/capture", options.merge(transaction_id: payment_id, gross_amount: gross_amount))
94
110
  end
95
111
 
112
+ # POST /v2/{id}/deny
113
+ # Docs https://api-docs.midtrans.com/#deny-transaction
114
+ def deny(payment_id, options = {})
115
+ if !payment_id || payment_id.to_s == ''
116
+ raise ArgumentError, "parameter payment_id can not be blank (got #{payment_id.class} : #{payment_id.inspect})"
117
+ end
118
+
119
+ request_with_logging(:post, config.api_host + "/v2/#{ERB::Util.url_encode(payment_id)}/deny", options)
120
+ end
121
+
96
122
  # POST /v2/{id}/expire
97
123
  # Docs https://api-docs.midtrans.com/#expire-transaction
98
124
  def expire(payment_id)
@@ -123,6 +149,7 @@ class Veritrans
123
149
 
124
150
  request_with_logging(:get, config.api_host + "/v2/point_inquiry/#{token_id}", {})
125
151
  end
152
+
126
153
  alias_method :point_inquiry, :inquiry_points
127
154
 
128
155
  end
@@ -75,7 +75,7 @@ class Veritrans
75
75
 
76
76
  method = method.to_s.upcase
77
77
  logger.info "Veritrans: #{method} #{url} #{_json_encode(params)}"
78
- logger.info "Veritrans: Using server key: #{config.server_key}"
78
+ #logger.info "Veritrans: Using server key: #{config.server_key}"
79
79
  #puts "Veritrans: #{method} #{url} #{_json_encode(params)}"
80
80
 
81
81
  default_options = config.http_options || {}
@@ -151,6 +151,11 @@ class Veritrans
151
151
  @data[:token]
152
152
  end
153
153
 
154
+ # Acccessor for <tt>redirect_url</tt> value
155
+ def redirect_url
156
+ @data[:redirect_url]
157
+ end
158
+
154
159
  def success?
155
160
  status_code == 201
156
161
  end
@@ -8,7 +8,7 @@ require 'uri'
8
8
  #
9
9
  class Veritrans::TestingLib
10
10
 
11
- def initialize(server_url = "https://api.sandbox.midtrans.com:7676")
11
+ def initialize(server_url = "https://simulator.sandbox.midtrans.com")
12
12
  @server_url = server_url
13
13
  end
14
14
 
@@ -1,3 +1,3 @@
1
1
  class Veritrans
2
- VERSION = "2.2.0"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -8,7 +8,7 @@ http_interactions:
8
8
  string: "{}"
9
9
  headers:
10
10
  User-Agent:
11
- - Veritrans ruby gem 2.0.0beta
11
+ - Veritrans ruby gem 2.3.0
12
12
  Authorization:
13
13
  - Basic VlQtc2VydmVyLTlIdGItUnhYa2c3LTdoem5TQ0NqeHZvWTo=
14
14
  Accept:
@@ -18,31 +18,31 @@ http_interactions:
18
18
  response:
19
19
  status:
20
20
  code: 200
21
- message: ''
21
+ message: OK
22
22
  headers:
23
- Server:
24
- - nginx/1.5.13
25
23
  Date:
26
- - Tue, 04 Nov 2014 14:18:37 GMT
24
+ - Wed, 03 Apr 2019 18:44:32 GMT
27
25
  Content-Type:
28
26
  - application/json
29
27
  Content-Length:
30
- - '87'
28
+ - '111'
31
29
  Connection:
32
30
  - keep-alive
33
- Cache-Control:
34
- - no-cache
35
31
  Pragma:
36
32
  - no-cache
37
- Expires:
38
- - Wed, 31 Dec 1969 17:00:00 GMT
33
+ Cache-Control:
34
+ - no-cache
35
+ X-Kong-Upstream-Latency:
36
+ - '19'
37
+ X-Kong-Proxy-Latency:
38
+ - '94'
39
+ Via:
40
+ - kong/0.14.0
41
+ Strict-Transport-Security:
42
+ - max-age=15724800; includeSubDomains;
39
43
  body:
40
- encoding: UTF-8
41
- string: |-
42
- {
43
- "status_code" : "404",
44
- "status_message" : "The requested resource is not found"
45
- }
44
+ encoding: ASCII-8BIT
45
+ string: '{"status_code":"404","status_message":"Transaction doesn''t exist.","id":"37bb81e3-341f-4730-aaa6-8e985343fbb3"}'
46
46
  http_version:
47
- recorded_at: Tue, 04 Nov 2014 14:17:06 GMT
48
- recorded_with: VCR 2.9.3
47
+ recorded_at: Wed, 03 Apr 2019 18:44:32 GMT
48
+ recorded_with: VCR 4.0.0
@@ -5,10 +5,10 @@ http_interactions:
5
5
  uri: https://api.sandbox.midtrans.com/v2/charge
6
6
  body:
7
7
  encoding: UTF-8
8
- string: '{"payment_type":"permata","transaction_details":{"order_id":1415110696,"gross_amount":100000}}'
8
+ string: '{"payment_type":"permata","transaction_details":{"order_id":1554317097,"gross_amount":100000}}'
9
9
  headers:
10
10
  User-Agent:
11
- - Veritrans ruby gem 2.0.0beta
11
+ - Veritrans ruby gem 2.3.0
12
12
  Authorization:
13
13
  - Basic VlQtc2VydmVyLTlIdGItUnhYa2c3LTdoem5TQ0NqeHZvWTo=
14
14
  Accept:
@@ -18,49 +18,59 @@ http_interactions:
18
18
  response:
19
19
  status:
20
20
  code: 200
21
- message: ''
21
+ message: OK
22
22
  headers:
23
- Server:
24
- - nginx/1.5.13
25
23
  Date:
26
- - Tue, 04 Nov 2014 14:19:48 GMT
24
+ - Wed, 03 Apr 2019 18:44:57 GMT
27
25
  Content-Type:
28
26
  - application/json
29
27
  Content-Length:
30
- - '381'
28
+ - '432'
31
29
  Connection:
32
30
  - keep-alive
31
+ Vary:
32
+ - Accept-Encoding
33
33
  Cache-Control:
34
34
  - no-cache
35
35
  Pragma:
36
36
  - no-cache
37
37
  Expires:
38
38
  - Wed, 31 Dec 1969 17:00:00 GMT
39
+ X-Kong-Upstream-Latency:
40
+ - '200'
41
+ X-Kong-Proxy-Latency:
42
+ - '0'
43
+ Via:
44
+ - kong/0.14.0
45
+ Strict-Transport-Security:
46
+ - max-age=15724800; includeSubDomains;
39
47
  body:
40
- encoding: UTF-8
48
+ encoding: ASCII-8BIT
41
49
  string: |-
42
50
  {
43
51
  "status_code" : "201",
44
52
  "status_message" : "Success, PERMATA VA transaction is successful",
45
- "transaction_id" : "d8757b8a-b97e-4881-9f55-69f6db6f4006",
46
- "order_id" : "1415110696",
53
+ "transaction_id" : "f162dd28-c6a2-4357-a2ff-b942ba33d01e",
54
+ "order_id" : "1554317097",
55
+ "gross_amount" : "100000.00",
56
+ "currency" : "IDR",
47
57
  "payment_type" : "bank_transfer",
48
- "transaction_time" : "2014-11-04 21:20:07",
58
+ "transaction_time" : "2019-04-04 01:44:57",
49
59
  "transaction_status" : "pending",
50
- "permata_va_number" : "8778990000000023",
51
- "gross_amount" : "100000.00"
60
+ "fraud_status" : "accept",
61
+ "permata_va_number" : "8778008906093609"
52
62
  }
53
63
  http_version:
54
- recorded_at: Tue, 04 Nov 2014 14:18:17 GMT
64
+ recorded_at: Wed, 03 Apr 2019 18:44:57 GMT
55
65
  - request:
56
66
  method: post
57
- uri: https://api.sandbox.midtrans.com/v2/1415110696/cancel
67
+ uri: https://api.sandbox.midtrans.com/v2/1554317097/cancel
58
68
  body:
59
69
  encoding: UTF-8
60
70
  string: "{}"
61
71
  headers:
62
72
  User-Agent:
63
- - Veritrans ruby gem 2.0.0beta
73
+ - Veritrans ruby gem 2.3.0
64
74
  Authorization:
65
75
  - Basic VlQtc2VydmVyLTlIdGItUnhYa2c3LTdoem5TQ0NqeHZvWTo=
66
76
  Accept:
@@ -70,37 +80,47 @@ http_interactions:
70
80
  response:
71
81
  status:
72
82
  code: 200
73
- message: ''
83
+ message: OK
74
84
  headers:
75
- Server:
76
- - nginx/1.5.13
77
85
  Date:
78
- - Tue, 04 Nov 2014 14:19:48 GMT
86
+ - Wed, 03 Apr 2019 18:44:58 GMT
79
87
  Content-Type:
80
88
  - application/json
81
89
  Content-Length:
82
- - '323'
90
+ - '374'
83
91
  Connection:
84
92
  - keep-alive
93
+ Vary:
94
+ - Accept-Encoding
85
95
  Cache-Control:
86
96
  - no-cache
87
97
  Pragma:
88
98
  - no-cache
89
99
  Expires:
90
100
  - Wed, 31 Dec 1969 17:00:00 GMT
101
+ X-Kong-Upstream-Latency:
102
+ - '56'
103
+ X-Kong-Proxy-Latency:
104
+ - '87'
105
+ Via:
106
+ - kong/0.14.0
107
+ Strict-Transport-Security:
108
+ - max-age=15724800; includeSubDomains;
91
109
  body:
92
- encoding: UTF-8
110
+ encoding: ASCII-8BIT
93
111
  string: |-
94
112
  {
95
113
  "status_code" : "200",
96
114
  "status_message" : "Success, transaction is canceled",
97
- "transaction_id" : "d8757b8a-b97e-4881-9f55-69f6db6f4006",
98
- "order_id" : "1415110696",
115
+ "transaction_id" : "f162dd28-c6a2-4357-a2ff-b942ba33d01e",
116
+ "order_id" : "1554317097",
117
+ "gross_amount" : "100000.00",
118
+ "currency" : "IDR",
99
119
  "payment_type" : "bank_transfer",
100
- "transaction_time" : "2014-11-04 21:20:07",
120
+ "transaction_time" : "2019-04-04 01:44:57",
101
121
  "transaction_status" : "cancel",
102
- "gross_amount" : "100000.00"
122
+ "fraud_status" : "accept"
103
123
  }
104
124
  http_version:
105
- recorded_at: Tue, 04 Nov 2014 14:18:17 GMT
106
- recorded_with: VCR 2.9.3
125
+ recorded_at: Wed, 03 Apr 2019 18:44:58 GMT
126
+ recorded_with: VCR 4.0.0