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
@@ -0,0 +1,319 @@
1
+ require 'veritrans'
2
+ require 'minitest/autorun'
3
+
4
+ class TestVeritrans < Minitest::Test
5
+
6
+ def setup
7
+ @mt_test = Veritrans.new(
8
+ server_key: "SB-Mid-server-uQmMImQMeo0Ky3Svl90QTUj2",
9
+ client_key: "SB-Mid-client-ArNfhrh7st9bQKmz",
10
+ api_host: "https://api.sandbox.midtrans.com",
11
+ logger: Logger.new(STDOUT),
12
+ file_logger: Logger.new(STDOUT)
13
+ )
14
+
15
+ @mt_test_invalid_key = Veritrans.new(
16
+ server_key: "invalid server key",
17
+ client_key: "invalid client key",
18
+ api_host: "https://api.sandbox.midtrans.com",
19
+ logger: Logger.new(STDOUT),
20
+ file_logger: Logger.new(STDOUT)
21
+ )
22
+ end
23
+
24
+ def test_get_token_credit_card
25
+ card = {
26
+ card_number: 4811111111111114,
27
+ card_cvv: 123,
28
+ card_exp_month: 12,
29
+ card_exp_year: 2025
30
+ }
31
+ result = @mt_test.test_token(card)
32
+ assert_equal 200, result.status_code
33
+ assert_equal "Credit card token is created as Token ID.", result.status_message
34
+ end
35
+
36
+ def test_charge_credit_card
37
+ card = {
38
+ card_number: 5211111111111117,
39
+ card_cvv: 123,
40
+ card_exp_month: 12,
41
+ card_exp_year: 2025
42
+ }
43
+ get_token = @mt_test.test_token(card)
44
+ result = @mt_test.charge(
45
+ {
46
+ "payment_type": "credit_card",
47
+ "transaction_details": {
48
+ "gross_amount": 10000,
49
+ "order_id": "ruby-lib-test-creditcard-#{Time.now.to_i}"
50
+ },
51
+ "credit_card": {
52
+ "token_id": "#{get_token.token_id}"
53
+ }
54
+ }
55
+ )
56
+ assert_equal "Success, Credit Card transaction is successful", result.status_message
57
+ assert_equal 200, result.status_code
58
+ assert_equal "Approved", result.channel_response_message
59
+ end
60
+
61
+ def test_charge_bca_va
62
+ result = @mt_test.charge(
63
+ {
64
+ "payment_type": "bank_transfer",
65
+ "transaction_details": {
66
+ "gross_amount": 10000,
67
+ "order_id": "ruby-lib-test-bcava#{Time.now.to_i}"
68
+ },
69
+ "bank_transfer": {
70
+ "bank": "bca",
71
+ "va_number": "1234567891"
72
+ }
73
+ }
74
+ )
75
+ assert_equal 201, result.status_code
76
+ assert_equal "Success, Bank Transfer transaction is created", result.status_message
77
+ end
78
+
79
+ def test_charge_bni_va
80
+ result = @mt_test.charge(
81
+ {
82
+ "payment_type": "bank_transfer",
83
+ "transaction_details": {
84
+ "gross_amount": 10000,
85
+ "order_id": "ruby-lib-test-bniva-#{Time.now.to_i}"
86
+ },
87
+ "bank_transfer": {
88
+ "bank": "bni",
89
+ "va_number": "1234567891"
90
+ }
91
+ }
92
+ )
93
+ assert_equal 201, result.status_code
94
+ assert_equal "Success, Bank Transfer transaction is created", result.status_message
95
+ end
96
+
97
+ def test_point_inquiry
98
+ card = {
99
+ card_number: 4617006959746656,
100
+ card_cvv: 123,
101
+ card_exp_month: 12,
102
+ card_exp_year: 2026
103
+ }
104
+ result = @mt_test.test_token(card)
105
+ card_point_response = @mt_test.point_inquiry(result.token_id)
106
+ assert_equal 200, card_point_response.status_code
107
+ end
108
+
109
+ def test_charge_cimb_clicks
110
+ result = @mt_test.charge(
111
+ {
112
+ "payment_type": "cimb_clicks",
113
+ "transaction_details": {
114
+ "order_id": "ruby-lib-test-cimbclicks-#{Time.now.to_i}",
115
+ "gross_amount": 44000
116
+ },
117
+ "cimb_clicks": {
118
+ "description": "Purchase of a Food Delivery"
119
+ }
120
+ }
121
+ )
122
+ assert_equal 201, result.status_code
123
+ assert_equal "Success, CIMB Clicks transaction is successful", result.status_message
124
+ end
125
+
126
+ def test_charge_epay_bri
127
+ result = @mt_test.charge(
128
+ {
129
+ "payment_type": "bri_epay",
130
+ "transaction_details": {
131
+ "order_id": "ruby-lib-test-epaybri-#{Time.now.to_i}",
132
+ "gross_amount": 44000
133
+ }
134
+ }
135
+ )
136
+ assert_equal 201, result.status_code
137
+ assert_equal "Success, BRI E-Pay transaction is successful", result.status_message
138
+ assert_equal "pending", result.transaction_status
139
+ end
140
+
141
+ def test_charge_mandiri_bill
142
+ result = @mt_test.charge(
143
+ "payment_type": "echannel",
144
+ "transaction_details": {
145
+ "order_id": "ruby-lib-test-mandiribill-#{Time.now.to_i}",
146
+ "gross_amount": 44000
147
+ },
148
+ "echannel": {
149
+ "bill_info1": "Payment for:",
150
+ "bill_info2": "Item descriptions"
151
+ }
152
+ )
153
+ assert_equal 201, result.status_code
154
+ assert_equal "OK, Mandiri Bill transaction is successful", result.status_message
155
+ assert_equal "pending", result.transaction_status
156
+ end
157
+
158
+ def test_charge_indomaret
159
+ result = @mt_test.charge(
160
+ "payment_type": "cstore",
161
+ "transaction_details": {
162
+ "order_id": "ruby-lib-test-indomaret-#{Time.now.to_i}",
163
+ "gross_amount": 44000
164
+ },
165
+ "cstore": {
166
+ "store": "Indomaret",
167
+ "message": "Message to display"
168
+ }
169
+ )
170
+ assert_equal 201, result.status_code
171
+ assert_equal "Success, cstore transaction is successful", result.status_message
172
+ assert_equal "indomaret", result.store
173
+ end
174
+
175
+ def test_charge_alfamart
176
+ result = @mt_test.charge(
177
+ "payment_type": "cstore",
178
+ "transaction_details": {
179
+ "order_id": "ruby-lib-test-alfamart-#{Time.now.to_i}",
180
+ "gross_amount": 44000
181
+ },
182
+ "cstore": {
183
+ "store": "alfamart",
184
+ "alfamart_free_text_1": "1st row of receipt",
185
+ "alfamart_free_text_2": "2nd row",
186
+ "alfamart_free_text_3": "3rd row"
187
+ }
188
+ )
189
+ assert_equal 201, result.status_code
190
+ assert_equal "Success, cstore transaction is successful", result.status_message
191
+ assert_equal "alfamart", result.store
192
+ end
193
+
194
+ def test_charge_gopay
195
+ result = @mt_test.charge(
196
+ "payment_type": "gopay",
197
+ "transaction_details": {
198
+ "order_id": "ruby-lib-test-gopay-#{Time.now.to_i}",
199
+ "gross_amount": 44000
200
+ },
201
+ "gopay": {
202
+ "enable_callback": "true",
203
+ "callback_url": "someapps://callback"
204
+ }
205
+ )
206
+ assert_equal 201, result.status_code
207
+ assert_equal "GoPay transaction is created", result.status_message
208
+ assert_equal "pending", result.transaction_status
209
+ end
210
+
211
+ def test_charge_bcaklikpay
212
+ result = @mt_test.charge(
213
+ "payment_type": "bca_klikpay",
214
+ "transaction_details": {
215
+ "order_id": "ruby-lib-test-bcaklikpay-#{Time.now.to_i}",
216
+ "gross_amount": 44000
217
+ },
218
+ "bca_klikpay": {
219
+ "type": "1",
220
+ "description": "pembelian produk"
221
+ }
222
+ )
223
+ assert_equal 201, result.status_code
224
+ assert_equal "OK, BCA KlikPay transaction is successful", result.status_message
225
+ assert_equal "pending", result.transaction_status
226
+ end
227
+
228
+ def test_charge_akulaku
229
+ result = @mt_test.charge(
230
+ "payment_type": "akulaku",
231
+ "transaction_details": {
232
+ "order_id": "ruby-lib-test-#{Time.now.to_i}",
233
+ "gross_amount": 44000
234
+ }
235
+ )
236
+ assert_equal 201, result.status_code
237
+ assert_equal "Success, Akulaku transaction is created", result.status_message
238
+ assert_equal "pending", result.transaction_status
239
+ end
240
+
241
+ def test_charge_danamon_online
242
+ result = @mt_test.charge(
243
+ "payment_type": "danamon_online",
244
+ "transaction_details": {
245
+ "order_id": "ruby-lib-test-#{Time.now.to_i}",
246
+ "gross_amount": 44000
247
+ }
248
+ )
249
+ assert_equal "Success, Danamon Online transaction is successful", result.status_message
250
+ assert_equal 201, result.status_code
251
+ assert_equal "pending", result.transaction_status
252
+ end
253
+
254
+ def test_create_widget_token
255
+ result = @mt_test.create_widget_token(
256
+ transaction_details: {
257
+ order_id: "ruby-lib-test-#{Time.now.to_i}",
258
+ gross_amount: 200000
259
+ },
260
+ "credit_card": {
261
+ "secure": true
262
+ }
263
+ )
264
+ assert_equal 201, result.status_code
265
+ end
266
+
267
+ def test_fail_charge_invalid_key
268
+ @mt_test_invalid_key = Veritrans.new(
269
+ server_key: "invalid server key",
270
+ client_key: "invalid client key",
271
+ api_host: "https://api.sandbox.midtrans.com",
272
+ logger: Logger.new(STDOUT),
273
+ file_logger: Logger.new(STDOUT)
274
+ )
275
+
276
+ begin
277
+ @mt_test_invalid_key.charge(
278
+ {
279
+ "payment_type": "bank_transfer",
280
+ "transaction_details": {
281
+ "gross_amount": 10000,
282
+ "order_id": "ruby-lib-test-bcava-#{Time.now.to_i}"
283
+ },
284
+ "bank_transfer": {
285
+ "bank": "bca",
286
+ "va_number": "1234567891"
287
+ }
288
+ }
289
+ )
290
+ rescue MidtransError => e
291
+ assert_equal "401", e.status
292
+ assert_match "Transaction cannot be authorized with the current client/server key.", e.data
293
+ end
294
+ end
295
+
296
+ def test_fail_get_token
297
+ @mt_test_invalid_key = Veritrans.new(
298
+ server_key: "invalid server key",
299
+ client_key: "invalid client key",
300
+ api_host: "https://api.sandbox.midtrans.com",
301
+ logger: Logger.new(STDOUT),
302
+ file_logger: Logger.new(STDOUT)
303
+ )
304
+
305
+ card = {
306
+ card_number: 4617006959746656,
307
+ card_cvv: 123,
308
+ card_exp_month: 12,
309
+ card_exp_year: 2026
310
+ }
311
+ begin
312
+ @mt_test_invalid_key.test_token(card)
313
+ rescue MidtransError => e
314
+ assert_equal "401", e.status
315
+ assert_match "Transaction cannot be authorized with the current client/server key.", e.data
316
+ end
317
+ end
318
+
319
+ end
@@ -0,0 +1,26 @@
1
+ require 'veritrans'
2
+ require 'minitest/autorun'
3
+
4
+ class TestVeritrans < Minitest::Test
5
+ def setup
6
+ @mt_test = Veritrans.new(
7
+ server_key: "SB-Mid-server-uQmMImQMeo0Ky3Svl90QTUj2",
8
+ client_key: "SB-Mid-client-ArNfhrh7st9bQKmz",
9
+ api_host: "https://api.sandbox.midtrans.com",
10
+ logger: Logger.new(STDOUT),
11
+ file_logger: Logger.new(STDOUT)
12
+ )
13
+ end
14
+
15
+ def test_api_host
16
+ assert_equal "https://api.sandbox.midtrans.com", Veritrans.config.api_host
17
+ end
18
+
19
+ def test_client_key_server_key
20
+ Veritrans.config.client_key = "kk-1"
21
+ Veritrans.config.server_key = "sk-1"
22
+
23
+ assert_equal "kk-1", Veritrans.config.client_key
24
+ assert_equal "sk-1", Veritrans.config.server_key
25
+ end
26
+ end
@@ -0,0 +1,80 @@
1
+ require 'veritrans'
2
+ require 'minitest/autorun'
3
+
4
+ class TestVeritrans < Minitest::Test
5
+ i_suck_and_my_tests_are_order_dependent!
6
+
7
+ def setup
8
+ @mt_test = Veritrans.new(
9
+ server_key: "SB-Mid-server-uQmMImQMeo0Ky3Svl90QTUj2",
10
+ client_key: "SB-Mid-client-ArNfhrh7st9bQKmz",
11
+ api_host: "https://api.sandbox.midtrans.com",
12
+ logger: Logger.new(STDOUT),
13
+ file_logger: Logger.new(STDOUT)
14
+ )
15
+ end
16
+
17
+ def test_link_payment_account
18
+ p 1
19
+ param = {
20
+ "payment_type": "gopay",
21
+ "gopay_partner": {
22
+ "phone_number": "81987654321",
23
+ "country_code": "62",
24
+ "redirect_url": "https://www.gojek.com"
25
+ }
26
+ }
27
+ result = @mt_test.link_payment_account(param)
28
+ assert_equal 201, result.status_code
29
+ assert_equal "PENDING", result.account_status
30
+ $test_gopay_id = result.account_id
31
+ end
32
+
33
+ def test_get_payment_account
34
+ p 2
35
+ param = {
36
+ "payment_type": "gopay",
37
+ "gopay_partner": {
38
+ "phone_number": "81987654321",
39
+ "country_code": "62",
40
+ "redirect_url": "https://www.gojek.com"
41
+ }
42
+ }
43
+ charge = @mt_test.link_payment_account(param)
44
+ result = @mt_test.get_payment_account(charge.account_id)
45
+ assert_equal 201, result.status_code
46
+ assert_equal "PENDING", result.account_status
47
+ end
48
+
49
+ def test_unlink_payment_account
50
+ #expected the API call will fail because of not click activation from link_payment_account
51
+ p 3
52
+ begin
53
+ @mt_test.unlink_payment_account($test_gopay_id)
54
+ rescue MidtransError => e
55
+ assert_equal "412", e.status
56
+ assert_match "Account status cannot be updated.", e.data
57
+ end
58
+ end
59
+
60
+ def test_get_payment_acc_dummy
61
+ p 4
62
+ begin
63
+ @mt_test.get_payment_account("dummy")
64
+ rescue MidtransError => e
65
+ assert_equal "404", e.status
66
+ assert_match "Account doesn't exist.", e.data
67
+ end
68
+ end
69
+
70
+ def test_unlink_dummy_account
71
+ p 5
72
+ begin
73
+ @mt_test.unlink_payment_account("dummy")
74
+ rescue MidtransError => e
75
+ assert_equal "404", e.status
76
+ assert_match "Account doesn't exist.", e.data
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,79 @@
1
+ require 'veritrans'
2
+ require 'minitest/autorun'
3
+
4
+ class TestVeritrans < Minitest::Test
5
+
6
+ def setup
7
+ @mt_test = Veritrans.new(
8
+ server_key: "SB-Mid-server-uQmMImQMeo0Ky3Svl90QTUj2",
9
+ client_key: "SB-Mid-client-ArNfhrh7st9bQKmz",
10
+ api_host: "https://api.sandbox.midtrans.com",
11
+ logger: Logger.new(STDOUT),
12
+ file_logger: Logger.new(STDOUT)
13
+ )
14
+ end
15
+
16
+ def test_create_widget_token
17
+ result = @mt_test.create_widget_token(
18
+ transaction_details: {
19
+ order_id: "ruby-lib-test-#{Time.now.to_i}",
20
+ gross_amount: 200000
21
+ },
22
+ "credit_card": {
23
+ "secure": true
24
+ }
25
+ )
26
+ assert_equal 201, result.status_code
27
+ end
28
+
29
+ def test_create_snap_token_string
30
+ result = @mt_test.create_snap_token_string(
31
+ transaction_details: {
32
+ order_id: "ruby-lib-test-snap-#{Time.now.to_i}",
33
+ gross_amount: 200000
34
+ },
35
+ "credit_card": {
36
+ "secure": true
37
+ }
38
+ )
39
+ assert result != nil
40
+ end
41
+
42
+ def test_snap_redirect_url_str
43
+ result = @mt_test.create_snap_redirect_url_str(
44
+ transaction_details: {
45
+ order_id: "ruby-lib-test-snap#{Time.now.to_i}",
46
+ gross_amount: 200000
47
+ },
48
+ "credit_card": {
49
+ "secure": true
50
+ }
51
+ )
52
+ assert_match "https://", result
53
+ end
54
+
55
+ def test_snap_invalid_serverkey
56
+ @mt_test_invalid_key = Veritrans.new(
57
+ server_key: "invalid server key",
58
+ client_key: "invalid client key",
59
+ api_host: "https://api.sandbox.midtrans.com",
60
+ logger: Logger.new(STDOUT),
61
+ file_logger: Logger.new(STDOUT)
62
+ )
63
+ begin
64
+ @mt_test_invalid_key.create_widget_token(
65
+ transaction_details: {
66
+ order_id: "ruby-lib-test-#{Time.now.to_i}",
67
+ gross_amount: 200000
68
+ },
69
+ "credit_card": {
70
+ "secure": true
71
+ }
72
+ )
73
+ rescue MidtransError => e
74
+ assert_equal "401", e.status
75
+ assert_match "please check client or server key", e.data
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,116 @@
1
+ require 'veritrans'
2
+ require 'minitest/autorun'
3
+
4
+ class TestVeritrans < Minitest::Test
5
+ i_suck_and_my_tests_are_order_dependent!
6
+
7
+ def setup
8
+ @mt_test = Veritrans.new(
9
+ server_key: "SB-Mid-server-uQmMImQMeo0Ky3Svl90QTUj2",
10
+ client_key: "SB-Mid-client-ArNfhrh7st9bQKmz",
11
+ api_host: "https://api.sandbox.midtrans.com",
12
+ logger: Logger.new(STDOUT),
13
+ file_logger: Logger.new(STDOUT)
14
+ )
15
+ end
16
+
17
+ def test_create_subscription
18
+ p 1
19
+ param = {
20
+ "name": "MONTHLY_2021",
21
+ "amount": "17000",
22
+ "currency": "IDR",
23
+ "payment_type": "credit_card",
24
+ "token": "dummy",
25
+ "schedule": {
26
+ "interval": 1,
27
+ "interval_unit": "month",
28
+ "max_interval": 12,
29
+ "start_time": "2022-10-10 07:25:01 +0700"
30
+ },
31
+ "metadata": {
32
+ "description": "Recurring payment for A"
33
+ },
34
+ "customer_details": {
35
+ "first_name": "John",
36
+ "last_name": "Doe",
37
+ "email": "johndoe@email.com",
38
+ "phone": "+62812345678"
39
+ }
40
+ }
41
+ result = @mt_test.create_subscription(param)
42
+ assert_equal 200, result.status
43
+ $testsubsid = result.id
44
+ end
45
+
46
+ def test_get_subscription
47
+ p 2
48
+ result = @mt_test.get_subscription($testsubsid)
49
+ assert_equal 200, result.status
50
+ end
51
+
52
+ def test_disable_subscription
53
+ p 3
54
+ result = @mt_test.disable_subscription($testsubsid)
55
+ assert_equal "Subscription is updated.", result.status_message
56
+ end
57
+
58
+ def test_enable_subscription
59
+ p 4
60
+ result = @mt_test.enable_subscription($testsubsid)
61
+ assert_equal "Subscription is updated.", result.status_message
62
+ end
63
+
64
+ def test_update_subscription
65
+ p 5
66
+ param = {
67
+ "name": "MONTHLY_2021",
68
+ "amount": "21000",
69
+ "currency": "IDR",
70
+ "token": "dummy",
71
+ "schedule": {
72
+ "interval": 1
73
+ }
74
+ }
75
+ result = @mt_test.update_subscription($testsubsid, param)
76
+ assert_equal "Subscription is updated.", result.status_message
77
+ end
78
+
79
+ def test_get_subscription_none_acc
80
+ begin
81
+ @mt_test.get_subscription("dummy")
82
+ rescue MidtransError => e
83
+ assert_equal "404", e.status
84
+ assert_match "Subscription doesn't exist.", e.data
85
+ end
86
+ end
87
+
88
+ def test_disable_subscription_none
89
+ begin
90
+ @mt_test.disable_subscription("dummy")
91
+ rescue MidtransError => e
92
+ assert_equal "404", e.status
93
+ assert_match "Subscription doesn't exist.", e.data
94
+ end
95
+ end
96
+
97
+ def test_enable_subscription_none
98
+ begin
99
+ @mt_test.enable_subscription("dummy")
100
+ rescue MidtransError => e
101
+ assert_equal "404", e.status
102
+ assert_match "Subscription doesn't exist.", e.data
103
+ end
104
+ end
105
+
106
+ def test_update_subscription_none
107
+ begin
108
+ param = {}
109
+ @mt_test.update_subscription("dummy", param)
110
+ rescue MidtransError => e
111
+ assert_equal "404", e.status
112
+ assert_match "Subscription doesn't exist.", e.data
113
+ end
114
+ end
115
+
116
+ end