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
data/api_reference.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # API Reference
2
2
 
3
- Here is only reference for API of this gem, to see complete information
4
- please use our [documentation](http://docs.veritrans.co.id/en/api/introduction.html)
3
+ This is only partial reference of the APIs that are implemented in this Ruby Gem. For more details refer to [documentation](https://api-docs.midtrans.com/)
5
4
 
6
5
 
7
6
  <table>
@@ -16,118 +15,170 @@ please use our [documentation](http://docs.veritrans.co.id/en/api/introduction.h
16
15
 
17
16
  <tbody>
18
17
  <tr>
19
- <td><a href="#charge">Veritrans.charge(data)</a></td>
20
- <td>Charge Transaction</td>
18
+ <td><a href="#charge">Midtrans.charge(data)</a></td>
19
+ <td>Charge Transaction (Core API)</td>
21
20
  <td>POST</td>
22
- <td>api.veritrans.co.id/v2/charge</td>
21
+ <td>api.midtrans.com/v2/charge</td>
23
22
  </tr>
24
23
  <tr>
25
- <td><a href="#status">Veritrans.status(id)</a></td>
24
+ <td><a href="#token">Midtrans.create_card_token(data)</a></td>
25
+ <td>Get Token for Card</td>
26
+ <td>GET</td>
27
+ <td>api.midtrans.com/v2/token</td>
28
+ </tr>
29
+ <tr>
30
+ <td><a href="#status">Midtrans.status(id)</a></td>
26
31
  <td>Get Last Status</td>
27
32
  <td>GET</td>
28
- <td>api.veritrans.co.id/v2/{id}/status</td>
33
+ <td>api.midtrans.com/v2/{id}/status</td>
29
34
  </tr>
30
35
  <tr>
31
- <td><a href="#cancel">Veritrans.cancel(id)</a></td>
36
+ <td><a href="#cancel">Midtrans.cancel(id)</a></td>
32
37
  <td>Cancel Transaction</td>
33
38
  <td>POST</td>
34
- <td>api.veritrans.co.id/v2/{id}/cancel</td>
39
+ <td>api.midtrans.com/v2/{id}/cancel</td>
35
40
  </tr>
36
41
  <tr>
37
- <td><a href="#approve">Veritrans.approve(id)</a></td>
42
+ <td><a href="#approve">Midtrans.approve(id)</a></td>
38
43
  <td>Approve Challenge Transaction</td>
39
44
  <td>POST</td>
40
- <td>api.veritrans.co.id/v2/{id}/approve</td>
45
+ <td>api.midtrans.com/v2/{id}/approve</td>
46
+ </tr>
47
+ <tr>
48
+ <td><a href="#refund">Midtrans.refund(id)</a></td>
49
+ <td>Refund Successful Transaction</td>
50
+ <td>POST</td>
51
+ <td>api.midtrans.com/v2/{id}/refund</td>
41
52
  </tr>
42
53
  <tr>
43
- <td><a href="#capture">Veritrans.capture(id)</a></td>
54
+ <td><a href="#capture">Midtrans.capture(id)</a></td>
44
55
  <td>Capture Authorise Transaction</td>
45
56
  <td>POST</td>
46
- <td>api.veritrans.co.id/v2/{id}/capture</td>
57
+ <td>api.midtrans.com/v2/{id}/capture</td>
47
58
  </tr>
48
59
  <tr>
49
- <td><a href="#expire">Veritrans.expire(id)</a></td>
60
+ <td><a href="#expire">Midtrans.expire(id)</a></td>
50
61
  <td>Expire Pending Transaction</td>
51
62
  <td>POST</td>
52
- <td>api.veritrans.co.id/v2/{id}/expire</td>
63
+ <td>api.midtrans.com/v2/{id}/expire</td>
64
+ </tr>
65
+ <tr>
66
+ <td><a href="#deny">Midtrans.deny(id)</a></td>
67
+ <td>Deny Challenged Transaction</td>
68
+ <td>POST</td>
69
+ <td>api.midtrans.com/v2/{id}/deny</td>
70
+ </tr>
71
+ <tr>
72
+ <td><a href="#snap">Midtrans.create_snap_token(data)</a></td>
73
+ <td>Charge Transaction (SNAP)</td>
74
+ <td>POST</td>
75
+ <td>app.midtrans.com/snap/v1/transactions</td>
76
+ </tr>
77
+ <tr>
78
+ <td><a href="#link">Midtrans.link_payment_account(data)</a></td>
79
+ <td>Link the customer's payment provider account to be used for payments using specific payment channel.</td>
80
+ <td>POST</td>
81
+ <td>api.midtrans.com/v2/pay/account</td>
82
+ </tr>
83
+ <tr>
84
+ <td><a href="#get_payment_account">Midtrans.get_payment_account(id)</a></td>
85
+ <td>Get account to use for specific payment channel.</td>
86
+ <td>GET</td>
87
+ <td>api.midtrans.com/v2/pay/account/{account_id}</td>
88
+ </tr>
89
+ <tr>
90
+ <td><a href="#unlink_payment_account">Midtrans.unlink_payment_account(id)</a></td>
91
+ <td>Unlink the linked customer account.</td>
92
+ <td>POST</td>
93
+ <td>api.midtrans.com/v2/pay/account/{account_id}/unbind</td>
94
+ </tr>
95
+ <tr>
96
+ <td><a href="#create_subscription">Midtrans.create_subscription(data)</a></td>
97
+ <td>Create a subscription transaction</td>
98
+ <td>POST</td>
99
+ <td>api.midtrans.com/v1/subscriptions</td>
100
+ </tr>
101
+ <tr>
102
+ <td><a href="#get_subscription">Midtrans.get_subscription(id)</a></td>
103
+ <td>Retrieve the subscription details of a customer</td>
104
+ <td>GET</td>
105
+ <td>api.midtrans.com/v1/subscriptions/{subscription_id}</td>
106
+ </tr>
107
+ <tr>
108
+ <td><a href="#disable_subscription">Midtrans.disable_subscription(id)</a></td>
109
+ <td>Disable a customer's subscription account</td>
110
+ <td>POST</td>
111
+ <td>api.midtrans.com/v1/subscriptions/{subscription_id}/disable</td>
112
+ </tr>
113
+ <tr>
114
+ <td><a href="#enable_subscription">Midtrans.enable_subscription(id)</a></td>
115
+ <td>Enable a customer's subscription account</td>
116
+ <td>POST</td>
117
+ <td>api.midtrans.com/v1/subscriptions/{subscription_id}/enable</td>
118
+ </tr>
119
+ <tr>
120
+ <td><a href="#update_subscription">Midtrans.update_subscription(data)</a></td>
121
+ <td>Update the details of a customer's existing subscription account</td>
122
+ <td>PATCH</td>
123
+ <td>api.midtrans.com/v1/subscriptions/{subscription_id}</td>
53
124
  </tr>
54
125
  </tbody>
55
126
  </table>
56
127
 
57
128
 
58
- <a name="charge"></a>
59
-
60
- ### Charge
61
-
62
- Actually make transaction. But for vt-web create a redirect url, and for vt-link creates payment page
63
-
64
- **For VT-Web:**
129
+ ## Usage Example
65
130
 
66
- ```ruby
67
- q = Veritrans.charge({
68
- payment_type: "VTWEB",
69
- transaction_details: {
70
- order_id: "order-1",
71
- gross_amount: 100_000
72
- }
73
- })
74
-
75
- q.class # => Veritrans::Result
76
- q.data == {
77
- status_code: "201",
78
- status_message: "OK, success do VTWeb transaction, please go to redirect_url",
79
- redirect_url: "https://vtweb.sandbox.veritrans.co.id/v2/vtweb/b27d421f-90ff-4427-83d2-fbe8acbbce89"
80
- }
81
- ```
131
+ ### Create Transaction
82
132
 
83
- **For VT-Direct:**
133
+ <a name="charge"></a>
134
+ #### Core API
84
135
 
136
+ Perform a transaction with various available payment methods and features. Example below: credit card charge.
85
137
  ```ruby
86
- q = Veritrans.charge({
87
- # *required
88
- payment_type: "credit_card",
89
- # *required
90
- transaction_details: {
91
- order_id: "order-2",
92
- gross_amount: 100_000
93
- },
94
- # *required (but different for different payment type)
95
- credit_card: {
96
- token_id: "dcd6cd71-bc4c-4f4b-8752-49cb0a3f204c",
97
- bank: "cimb"
98
- },
99
- # optional
100
- item_details: [
101
- {
102
- id: "ITEM1",
103
- price: 100_000,
104
- quantity: 1,
105
- name: "T-Short Infinity"
106
- }
107
- ],
108
- # optional
109
- customer_details: {
110
- first_name: "Nadia",
111
- last_name: "Modjo",
112
- email: "noreply@veritrans.co.id",
113
- phone: "+6281 123 12345",
114
- billing_address: {
115
- address: "Jalan Raya Kalijati",
116
- city: "Subang",
117
- postal_code: "41271",
118
- },
119
- },
120
- # optional
121
- custom_field1: "age: 25",
122
- custom_field2: "new_year_promo",
123
- custom_field3: "submerchant_id: 23"
124
- });
125
-
126
- q.class # => Veritrans::Result
127
- q.data == {
138
+ response = Midtrans.charge({
139
+ # *required
140
+ payment_type: "credit_card",
141
+ # *required
142
+ transaction_details: {
143
+ order_id: "order-2",
144
+ gross_amount: 100_000
145
+ },
146
+ # *required (but different for different payment type)
147
+ credit_card: {
148
+ token_id: "dcd6cd71-bc4c-4f4b-8752-49cb0a3f204c",
149
+ bank: "cimb"
150
+ },
151
+ # optional
152
+ item_details: [
153
+ {
154
+ id: "ITEM1",
155
+ price: 100_000,
156
+ quantity: 1,
157
+ name: "T-Short Infinity"
158
+ }
159
+ ],
160
+ # optional
161
+ customer_details: {
162
+ first_name: "Nadia",
163
+ last_name: "Modjo",
164
+ email: "noreply@midtrans.com",
165
+ phone: "+6281 123 12345",
166
+ billing_address: {
167
+ address: "Jalan Raya Kalijati",
168
+ city: "Subang",
169
+ postal_code: "41271",
170
+ },
171
+ },
172
+ # optional
173
+ custom_field1: "age: 25",
174
+ custom_field2: "new_year_promo",
175
+ custom_field3: "submerchant_id: 23"
176
+ });
177
+ # this will be Hash representation of the API JSON response:
178
+ puts response.data == {
128
179
  status_code: "200",
129
180
  status_message: "Success, Credit Card transaction is successful",
130
- transaction_id: "20bcc3dd-6fa5-4a9a-a9ad-615af992aa3d",
181
+ transaction_id: "20bcc3dd-6fa5-4a9a-a9ad-615af992aa3d",
131
182
  masked_card: "481111-1114",
132
183
  order_id: "order-2",
133
184
  payment_type: "credit_card",
@@ -137,126 +188,466 @@ q.data == {
137
188
  approval_code: "1415006572598",
138
189
  gross_amount: "100000.00"
139
190
  }
191
+ ```
140
192
 
141
- q.success? # => true
193
+ <a name="snap"></a>
194
+ #### Snap
195
+ Snap allows you (as a merchant) to easily integrate with Midtrans payment system to start accepting payments. Snap payment page can be displayed as a seamless pop-up within your web/app during checkout, or as a (Midtrans hosted) web page url redirect.
196
+ Example below: create Snap transaction.
197
+ ```ruby
198
+ response = Midtrans.create_snap_token(
199
+ transaction_details: {
200
+ order_id: generate_order_id,
201
+ gross_amount: 100000
202
+ })
203
+ # this will be Hash representation of the API JSON response:
204
+ puts response.data == {
205
+ status_code: "201",
206
+ "token": "2b3ccb6c-d0fb-499a-9d46-ef53ad51fe62",
207
+ "redirect_url": "https://app.sandbox.midtrans.com/snap/v2/vtweb/2b3ccb6c-d0fb-499a-9d46-ef53ad51fe62"
208
+ }
142
209
  ```
143
210
 
211
+ <a name="token"></a>
144
212
 
145
- <a name="status"></a>
146
- ### Status
213
+ ### Create card token
147
214
 
148
- Return current status of transaction.
215
+ Creating card token, in production create token should be handled on Frontend please refer to [API docs](https://docs.midtrans.com/en/core-api/credit-card).
149
216
 
150
217
  ```ruby
151
- q = Veritrans.status("order-2")
218
+ card =
219
+ {
220
+ card_number: 4_811_111_111_111_114,
221
+ card_cvv: 123,
222
+ card_exp_month: 12,
223
+ card_exp_year: 2025
224
+ }
152
225
 
153
- q.data == {
154
- status_code: "200",
155
- status_message: "Success, transaction found",
156
- transaction_id: "20bcc3dd-6fa5-4a9a-a9ad-615af992aa3d",
157
- masked_card: "481111-1114",
158
- order_id: "order-2",
159
- payment_type: "credit_card",
160
- transaction_time: "2014-11-03 16:22:52",
161
- transaction_status: "settlement",
226
+ result = Midtrans.create_card_token(card)
227
+
228
+ result.token_id == "481111-1114-a901971f-2f1b-4781-802a-df326fbf0e9c"
229
+ ```
230
+
231
+ <a name="status"></a>
232
+
233
+ ### Status
234
+
235
+ Get Transaction Status is triggered to obtain the transaction_status and other details of a specific transaction.
236
+ ```ruby
237
+ response = Midtrans.status("ruby-lib-test-1633926689")
238
+
239
+ # this will be Hash representation of the API JSON response:
240
+ puts response.data == {
241
+ transaction_time: "2021-10-11 11:31:29",
242
+ gross_amount: "10000.00",
243
+ currency: "IDR",
244
+ order_id: "ruby-lib-test-1633926689",
245
+ payment_type: "bank_transfer",
246
+ signature_key: "412c0a69df9c74d05666ffb079d09b404e3d596b927dbb027bd470d072401a767b0f9ad4659248118979ce274e5bcec3dd683abf9e279ce001eab67f49de5866",
247
+ status_code: "201",
248
+ transaction_id: "569a305d-9fec-4fa1-a707-294ee97f7b2a",
249
+ transaction_status: "pending",
162
250
  fraud_status: "accept",
163
- signature_key: "639af8e985f68526839e6ed04c1...",
164
- bank: "bni",
165
- gross_amount: "100000.00"
251
+ status_message: "Success, transaction is found",
252
+ merchant_id: "G686051436",
253
+ permata_va_number: "514003740741123"
166
254
  }
167
255
  ```
168
256
 
169
-
170
257
  <a name="cancel"></a>
171
- ### Cancel
172
258
 
173
- Cancel transaction, before it was settled. For credit card payments you can cancel it before we trigger settlement in bank.
174
- Usually we do settlement next day after payment happen, about 4pm.
259
+ ### Cancel
175
260
 
176
- For internet banking, bank transfer, mobile payments, convenient store payments if user already made payment,
177
- you can't cancel it as simple as credit card, but before user sent money you can cancel pending transactions.
261
+ Cancel a transaction with a specific order_id. Cancelation can only be done before settlement process.
178
262
 
179
263
  ```ruby
180
- q = Veritrans.cancel("testing-0.2072-1415086078")
264
+ response = Midtrans.cancel("ruby-lib-test-1633926562")
181
265
 
182
- q.data == {
266
+ # this will be Hash representation of the API JSON response:
267
+ puts response.data == {
183
268
  status_code: "200",
184
269
  status_message: "Success, transaction is canceled",
185
- transaction_id: "b38f598a-59ab-4850-b311-2aa14c78bc45",
186
- masked_card: "481111-1114",
187
- order_id: "testing-0.2072-1415086078",
188
- payment_type: "credit_card",
189
- transaction_time: "2014-11-04 14:29:47",
270
+ transaction_id: "7e75d03e-54a4-44c6-a385-6bbdd28d85c3",
271
+ order_id: "ruby-lib-test-1633926562",
272
+ gross_amount: "10000.00",
273
+ currency: "IDR",
274
+ payment_type: "bank_transfer",
275
+ transaction_time: "2021-10-11 11:29:23",
190
276
  transaction_status: "cancel",
191
277
  fraud_status: "accept",
192
- bank: "bni",
193
- gross_amount: "100000.00"
278
+ merchant_id: "G686051436"
194
279
  }
195
280
  ```
196
281
 
197
-
198
282
  <a name="approve"></a>
283
+
199
284
  ### Approve
200
285
 
201
- Some transactions marked as challenge. If challenge you can approve it or cancel it. Usual way is to use our dashboard web interface,
202
- but you also can do it programatically, via API
286
+ Approve transaction is triggered to accept the card payment transaction with `fraud_status:challenge`
203
287
 
204
288
  ```ruby
205
- q = Veritrans.cancel("testing-0.2072-1415086078")
289
+ response = Midtrans.approve("ruby-lib-test-1633926990")
206
290
 
207
- q.data == {
291
+ # this will be Hash representation of the API JSON response:
292
+ puts response.data == {
208
293
  status_code: "200",
209
294
  status_message: "Success, transaction is approved",
210
- transaction_id: "8492c240-1600-465a-9bf1-808863410b0e",
211
- masked_card: "451111-1117",
212
- order_id: "testing-0.0501-1415086808",
295
+ bank: "bni",
296
+ transaction_id: "23e5ad9a-c28c-466c-8894-cbbc5445eb97",
297
+ masked_card: "551011-1115",
298
+ order_id: "ruby-lib-test-1633926990",
299
+ merchant_id: "G686051436",
213
300
  payment_type: "credit_card",
214
- transaction_time: "2014-11-04 14:41:58",
301
+ transaction_time: "2021-10-11 11:36:33",
215
302
  transaction_status: "capture",
216
303
  fraud_status: "accept",
304
+ gross_amount: "10000.00",
305
+ currency: "IDR",
306
+ approval_code: "1633926993796"
307
+ }
308
+ ```
309
+
310
+ <a name="refund"></a>
311
+
312
+ ### Refund
313
+
314
+ Refund transaction is triggered to update the transaction status to refund, when the customer decides to cancel a completed transaction or a payment that is settled.
315
+
316
+ ```ruby
317
+ response = Midtrans.refund("ruby-example-coreapi-creditcard-1633678954")
318
+
319
+ # this will be Hash representation of the API JSON response:
320
+ puts response.data == {
321
+ status_code: "200",
322
+ status_message: "Success, refund offline request is approved",
217
323
  bank: "bni",
218
- gross_amount: "100000.00"
324
+ transaction_id: "b2a62a3d-03e1-4232-b6b4-5832d5aa7eeb",
325
+ order_id: "ruby-example-coreapi-creditcard-1633678954",
326
+ merchant_id: "G686051436",
327
+ gross_amount: "10000.00",
328
+ currency: "IDR",
329
+ payment_type: "credit_card",
330
+ transaction_time: "2021-10-08 14:42:34",
331
+ transaction_status: "partial_refund",
332
+ fraud_status: "accept",
333
+ approval_code: "1633678955297",
334
+ masked_card: "521111-1117",
335
+ refund_chargeback_id: 101293,
336
+ refund_chargeback_uuid: "c720cb44-272d-4b64-b97d-47d89e86da02",
337
+ refund_amount: "2000.00",
338
+ settlement_time: "2021-10-09 16:35:04",
339
+ refund_key: "reference1"
219
340
  }
220
341
  ```
221
342
 
222
343
  <a name="capture"></a>
344
+
223
345
  ### Capture
224
346
 
225
347
  This API method is only for merchants who have pre-authorise feature (can be requested) and have pre-authorise payments.
226
348
 
227
349
  ```ruby
228
- q = Veritrans.capture("testing-0.2072-1415086078", 101_000)
229
- q.success? # => true
350
+ response = Midtrans.capture("testing-0.2072-1415086078", 101_000)
351
+ response.success? # => true
230
352
  ```
231
353
 
232
354
  <a name="expire"></a>
355
+
233
356
  ### Expire
234
357
 
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
358
+ To expire pending transactions. For example if a merchant chooses to pay via ATM and then the user changes their mind
359
+ and now wants to pay with credit card. In this situation the previous transaction should be expired. The same order_id
360
+ can be used again.
238
361
 
239
362
  ```ruby
240
- q = Veritrans.expire("testing-0.2072-1415086078")
241
- q.success? # => true
363
+ response = Midtrans.expire("ruby-lib-test-1633927809")
364
+ # this will be Hash representation of the API JSON response:
365
+ puts response.data == {
366
+ status_code: "407",
367
+ status_message: "Success, transaction has expired",
368
+ transaction_id: "6ff22198-875e-4a6d-a15d-e23ab3345a4d",
369
+ order_id: "ruby-lib-test-1633927809",
370
+ gross_amount: "10000.00",
371
+ currency: "IDR",
372
+ payment_type: "bank_transfer",
373
+ transaction_time: "2021-10-11 11:50:09",
374
+ transaction_status: "expire",
375
+ fraud_status: "accept",
376
+ merchant_id: "G686051436"
377
+ }
242
378
  ```
243
379
 
380
+ <a name="deny"></a>
244
381
 
382
+ ### Deny
245
383
 
246
- ### `Veritrans::Result`
384
+ Deny transaction is triggered to immediately deny the card payment transaction with `fraud_status:challenge`
385
+ ```ruby
386
+ response = Midtrans.deny("ruby-lib-test-1633927987")
247
387
 
388
+ # this will be Hash representation of the API JSON response:
389
+ puts response.data == {
390
+ status_code: "200",
391
+ status_message: "Success, transaction is denied",
392
+ bank: "bni",
393
+ transaction_id: "91cf84b9-1523-45b4-adf7-cd76751f71c6",
394
+ masked_card: "551011-1115",
395
+ order_id: "ruby-lib-test-1633927987",
396
+ merchant_id: "G686051436",
397
+ payment_type: "credit_card",
398
+ transaction_time: "2021-10-11 11:53:07",
399
+ transaction_status: "cancel",
400
+ fraud_status: "deny",
401
+ gross_amount: "10000.00",
402
+ currency: "IDR",
403
+ approval_code: "1633927988537"
404
+ }
405
+ ```
406
+
407
+ <a name="link"></a>
408
+ ### Link payment account
409
+ Link the customer account to be used for specific payment channels.
410
+
411
+ ```ruby
412
+ param = {
413
+ "payment_type": "gopay",
414
+ "gopay_partner": {
415
+ "phone_number": "81987654321",
416
+ "country_code": "62",
417
+ "redirect_url": "https://www.gojek.com"
418
+ }
419
+ }
420
+
421
+ response = Midtrans.link_payment_account(param)
422
+
423
+ # this will be Hash representation of the API JSON response:
424
+ puts response.data == {
425
+ "status_code": "201",
426
+ "payment_type": "gopay",
427
+ "account_id": "f2b21e66-c72d-4fc2-9296-7b2682c82a96",
428
+ "account_status": "PENDING",
429
+ "actions": [
430
+ {
431
+ "name": "activation-deeplink",
432
+ "method": "GET",
433
+ "url": "https://api.sandbox.midtrans.com/v2/pay/account/gpar_8a719131-cd69-44ca-bd12-5c134f925f06/link"
434
+ },
435
+ {
436
+ "name": "activation-link-url",
437
+ "method": "GET",
438
+ "url": "https://api.sandbox.midtrans.com/v2/pay/account/gpar_8a719131-cd69-44ca-bd12-5c134f925f06/link"
439
+ },
440
+ {
441
+ "name": "activation-link-app",
442
+ "method": "GET",
443
+ "url": "https://simulator.sandbox.midtrans.com/gopay/partner/web/otp?id=18060c31-2542-43be-a1b5-bd5c0cdd1f8d"
444
+ }
445
+ ],
446
+ "metadata": {
447
+ "reference_id": "ec20c478-f81a-4f60-91a8-725cf0c1fd94"
448
+ }
449
+ }
450
+ ```
451
+
452
+ <a name="get_payment_account"></a>
453
+ ### Get payment account
454
+ Get Pay Account is triggered to get a customer account to use for specific payment channel.
248
455
  ```ruby
249
- result = Veritrans.charge(...)
456
+ response = Midtrans.get_payment_account("f2b21e66-c72d-4fc2-9296-7b2682c82a96")
457
+
458
+ # this will be Hash representation of the API JSON response:
459
+ puts response.data == {
460
+ "status_code": "201",
461
+ "payment_type": "gopay",
462
+ "account_id": "f2b21e66-c72d-4fc2-9296-7b2682c82a96",
463
+ "account_status": "PENDING"
464
+ }
465
+ ```
466
+
467
+ <a name="unlink_payment_account"></a>
468
+ ### Unlink payment account
469
+ Unbind Pay Account is triggered to remove the linked customer account.
470
+ ```ruby
471
+ response = Midtrans.unlink_payment_account("f2b21e66-c72d-4fc2-9296-7b2682c82a96")
472
+
473
+ # this will be Hash representation of the API JSON response:
474
+ puts response.data == {
475
+ "status_code": "204",
476
+ "payment_type": "gopay",
477
+ "account_id": "f2b21e66-c72d-4fc2-9296-7b2682c82a96",
478
+ "account_status": "DISABLED",
479
+ "channel_response_code": "0",
480
+ "channel_response_message": "Process service request successfully."
481
+ }
482
+ ```
483
+
484
+ <a name="create_subscription"></a>
485
+ ### Create subscription
486
+ Create a subscription transaction by sending all the details required to create a transaction. The details such as name, amount, currency, payment_type, token, and schedule are sent in the request. Successful request returns id status:active, and other subscription details.
487
+
488
+ ```ruby
489
+ param = {
490
+ "name": "MONTHLY_2021",
491
+ "amount": "17000",
492
+ "currency": "IDR",
493
+ "payment_type": "credit_card",
494
+ "token": "dummy",
495
+ "schedule": {
496
+ "interval": 1,
497
+ "interval_unit": "month",
498
+ "max_interval": 12,
499
+ "start_time": "2021-10-10 07:25:01 +0700"
500
+ },
501
+ "metadata": {
502
+ "description": "Recurring payment for A"
503
+ },
504
+ "customer_details": {
505
+ "first_name": "John",
506
+ "last_name": "Doe",
507
+ "email": "johndoe@email.com",
508
+ "phone": "+62812345678"
509
+ }
510
+ }
511
+
512
+ response = Midtrans.create_subscription(param)
513
+
514
+ # this will be Hash representation of the API JSON response:
515
+ puts response.data == {
516
+ "id": "d137e7f4-9474-4fc2-9847-672e09cb16f6",
517
+ "name": "MONTHLY_2021",
518
+ "amount": "17000",
519
+ "currency": "IDR",
520
+ "created_at": "2021-09-28 10:40:29",
521
+ "schedule": {
522
+ "interval": 1,
523
+ "current_interval": 0,
524
+ "max_interval": 12,
525
+ "interval_unit": "month",
526
+ "start_time": "2021-10-10 07:25:01",
527
+ "next_execution_at": "2021-10-10 07:25:01"
528
+ },
529
+ "status": "active",
530
+ "token": "dummy",
531
+ "payment_type": "credit_card",
532
+ "transaction_ids": [
533
+
534
+ ],
535
+ "metadata": {
536
+ "description": "Recurring payment for A"
537
+ },
538
+ "customer_details": {
539
+ "email": "johndoe@email.com",
540
+ "first_name": "John",
541
+ "last_name": "Doe",
542
+ "phone": "+62812345678"
543
+ }
544
+ }
545
+ ```
546
+
547
+ <a name="get_subscription"></a>
548
+ ### Get subscription
549
+ Retrieve the subscription details of a customer using the subscription_id. Successful request returns subscription object and status:active.
550
+ ```ruby
551
+ response = Midtrans.get_subscription("d137e7f4-9474-4fc2-9847-672e09cb16f6")
552
+
553
+ # this will be Hash representation of the API JSON response:
554
+ puts response.data == {
555
+ "id": "d137e7f4-9474-4fc2-9847-672e09cb16f6",
556
+ "name": "MONTHLY_2021",
557
+ "amount": "17000",
558
+ "currency": "IDR",
559
+ "created_at": "2021-09-28 10:40:30",
560
+ "schedule": {
561
+ "interval": 1,
562
+ "current_interval": 0,
563
+ "max_interval": 12,
564
+ "interval_unit": "month",
565
+ "start_time": "2021-10-10 07:25:01",
566
+ "next_execution_at": "2021-10-10 07:25:01"
567
+ },
568
+ "status": "active",
569
+ "token": "dummy",
570
+ "payment_type": "credit_card",
571
+ "transaction_ids": [
572
+
573
+ ],
574
+ "metadata": {
575
+ "description": "Recurring payment for A"
576
+ },
577
+ "customer_details": {
578
+ "email": "johndoe@email.com",
579
+ "first_name": "John",
580
+ "last_name": "Doe",
581
+ "phone": "+62812345678"
582
+ }
583
+ }
584
+ ```
585
+
586
+ <a name="disable_subscription"></a>
587
+ ### Disable subscription
588
+ Disable a customer's subscription account with a specific subscription_id so that the customer is not charged for the subscription in the future. Successful request returns status_message indicating that the subscription details are updated.
589
+
590
+ ```ruby
591
+ response = Midtrans.disable_subscription("d137e7f4-9474-4fc2-9847-672e09cb16f6")
592
+
593
+ # this will be Hash representation of the API JSON response:
594
+ puts response.data == {
595
+ "status_message": "Subscription is updated."
596
+ }
597
+ ```
598
+
599
+ <a name="enable_subscription"></a>
600
+ ### Enable subscription
601
+ Activate a customer's subscription account with a specific subscription_id, so that the customer can start paying for the subscription immediately. Successful request returns status_message indicating that the subscription details are updated.
602
+ ```ruby
603
+ response = Midtrans.enable_subscription("d137e7f4-9474-4fc2-9847-672e09cb16f6")
604
+
605
+ # this will be Hash representation of the API JSON response:
606
+ puts response.data == {
607
+ "status_message": "Subscription is updated."
608
+ }
609
+ ```
610
+
611
+ <a name="update_subscription"></a>
612
+ ### Update subscription
613
+ Update the details of a customer's existing subscription account with the specific subscription_id. Successful request returns status_message indicating that the subscription details are updated.
614
+ ```ruby
615
+ param = {
616
+ "name": "MONTHLY_2021",
617
+ "amount": "21000",
618
+ "currency": "IDR",
619
+ "token": "dummy",
620
+ "schedule": {
621
+ "interval": 1
622
+ }
623
+ }
624
+
625
+ response = Midtrans.update_subscription("d137e7f4-9474-4fc2-9847-672e09cb16f6", param)
626
+
627
+ # this will be Hash representation of the API JSON response:
628
+ puts response.data == {
629
+ "status_message": "Subscription is updated."
630
+ }
631
+ ```
632
+
633
+ ## Get json field value from Midtrans API result
634
+ ```ruby
635
+ result = Midtrans.charge(...)
636
+
637
+ # If in the future there is a new attribute in the Midtrans Result.
638
+ # The recommended way to retrieve the value is like example below.
639
+ # :new_attribute is the new field name in API response JSON
640
+ result.data[:new_attribute]
250
641
 
251
- result.class # => Veritrans::Result
642
+ # Alternatively you can also retrieve the value like below.
643
+ # When the field name is not actually exists on the API response JSON, it will trigger an error. Make sure to handle it.
644
+ result.new_attribute
252
645
  ```
253
646
 
254
- * `Veritrans::Result#success?` - `boolean`, base on `status_code` field in json
255
- * `Veritrans::Result#created?` - `boolean`, for VT-Link
256
- * `Veritrans::Result#status_code` - `integer`, e.g. 200, 402. Documentation http://docs.veritrans.co.id/en/api/status_code.html
257
- * `Veritrans::Result#status_message` - `string`, e.g. "OK, success do VTWeb transaction, please go to redirect_url"
258
- * `Veritrans::Result#redirect_url` - `string`, redirect URL for VT-Web and VT-Link
259
- * `Veritrans::Result#body` - `string`, raw HTTP request body
260
- * `Veritrans::Result#data` - `hash`, parsed json body as hash
261
- * `Veritrans::Result#response` - `Excon::Response` instance
262
- * `Veritrans::Result#method_mising` - acessing fields of `data`. E.g. `result.transction_status`, `result.masked_card`, `result.approval_code`
647
+ * `Midtrans::Result#success?` - `boolean`, Based on `status_code` field in API response JSON
648
+ * `Midtrans::Result#status_code` - `integer`, e.g. 200, 402. Documentation https://api-docs.midtrans.com/#status-code
649
+ * `Midtrans::Result#status_message` - `string`, e.g."Success, Credit Card transaction is successful"
650
+ * `Midtrans::Result#redirect_url` - `string`, For Snap payment page, where customer can be redirected to complete the payment
651
+ * `Midtrans::Result#body` - `string`, Raw HTTP response body
652
+ * `Midtrans::Result#data` - `hash`, Parsed API response JSON body as hash
653
+ * `Midtrans::Result#response` - Raw `Excon::Response` instance