veritrans 2.1.3 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) 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 +4 -7
  8. data/Gemfile.lock +24 -163
  9. data/Maintaining.md +17 -0
  10. data/README.md +350 -219
  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/example/subscription/credit_card_subscription_example.rb +138 -0
  24. data/example/subscription/gopay_subscription_example.rb +153 -0
  25. data/example/subscription/readme.md +4 -0
  26. data/example/tokenization/gopay_tokenization_example.rb +144 -0
  27. data/example/tokenization/readme.md +4 -0
  28. data/lib/test/all.rb +1 -0
  29. data/lib/test/api_test.rb +319 -0
  30. data/lib/test/config_test.rb +26 -0
  31. data/lib/test/gopay_tokenization_test.rb +80 -0
  32. data/lib/test/snap_test.rb +79 -0
  33. data/lib/test/subscription_test.rb +116 -0
  34. data/lib/test/transaction_test.rb +160 -0
  35. data/lib/veritrans/api.rb +144 -20
  36. data/lib/veritrans/client.rb +48 -12
  37. data/lib/veritrans/config.rb +31 -6
  38. data/lib/veritrans/events.rb +46 -35
  39. data/lib/veritrans/midtrans_error.rb +15 -0
  40. data/lib/veritrans/result.rb +63 -2
  41. data/lib/veritrans/version.rb +1 -1
  42. data/lib/veritrans.rb +121 -12
  43. data/veritrans.gemspec +2 -9
  44. metadata +35 -146
  45. data/.rspec +0 -2
  46. data/Procfile +0 -1
  47. data/Rakefile +0 -16
  48. data/bin/midtrans +0 -3
  49. data/bin/veritrans +0 -68
  50. data/example/README.md +0 -8
  51. data/example/config.ru +0 -6
  52. data/example/index.erb +0 -213
  53. data/example/localization.erb +0 -248
  54. data/example/points.erb +0 -187
  55. data/example/recurring.erb +0 -201
  56. data/example/response.erb +0 -37
  57. data/example/sinatra.rb +0 -188
  58. data/example/style.css +0 -126
  59. data/example/veritrans.yml +0 -11
  60. data/example/widget.erb +0 -51
  61. data/lib/generators/templates/assets/credit_card_form.js +0 -51
  62. data/lib/generators/templates/payments_controller.rb +0 -85
  63. data/lib/generators/templates/veritrans.rb +0 -46
  64. data/lib/generators/templates/veritrans.yml +0 -18
  65. data/lib/generators/templates/views/_credit_card_form.erb +0 -42
  66. data/lib/generators/templates/views/_veritrans_include.erb +0 -10
  67. data/lib/generators/templates/views/payments/create.erb +0 -15
  68. data/lib/generators/templates/views/payments/new.erb +0 -6
  69. data/lib/generators/veritrans/install_generator.rb +0 -32
  70. data/lib/generators/veritrans/payment_form_generator.rb +0 -45
  71. data/lib/veritrans/cli.rb +0 -155
  72. data/lib/veritrans/core_extensions.rb +0 -32
  73. data/spec/cli_spec.rb +0 -83
  74. data/spec/configs/real_key.yml +0 -4
  75. data/spec/configs/veritrans.yml +0 -7
  76. data/spec/configs/veritrans_flat.yml +0 -2
  77. data/spec/configs/veritrans_with_erb.yml +0 -2
  78. data/spec/fixtures/approve_failed.yml +0 -48
  79. data/spec/fixtures/cancel_failed.yml +0 -48
  80. data/spec/fixtures/cancel_success.yml +0 -106
  81. data/spec/fixtures/capture_failed.yml +0 -48
  82. data/spec/fixtures/charge.yml +0 -50
  83. data/spec/fixtures/charge_direct.yml +0 -56
  84. data/spec/fixtures/charge_vtweb.yml +0 -50
  85. data/spec/fixtures/cli_test_1111-not-exists.yml +0 -45
  86. data/spec/fixtures/cli_test_not_exists.yml +0 -45
  87. data/spec/fixtures/cli_test_real_txn.yml +0 -55
  88. data/spec/fixtures/cli_test_unauthorized.yml +0 -47
  89. data/spec/fixtures/events_test_real_txn.yml +0 -55
  90. data/spec/fixtures/expire_failed.yml +0 -50
  91. data/spec/fixtures/expire_success.yml +0 -56
  92. data/spec/fixtures/midtrans_status.yml +0 -117
  93. data/spec/fixtures/status_fail.yml +0 -46
  94. data/spec/fixtures/status_success.yml +0 -109
  95. data/spec/midtrans_rename_spec.rb +0 -27
  96. data/spec/rails_plugin_spec.rb +0 -281
  97. data/spec/spec_helper.rb +0 -61
  98. data/spec/veritrans_client_spec.rb +0 -184
  99. data/spec/veritrans_config_spec.rb +0 -70
  100. data/spec/veritrans_events_spec.rb +0 -72
  101. data/spec/veritrans_logger_spec.rb +0 -46
  102. data/spec/veritrans_snap_spec.rb +0 -39
  103. data/testing_webhooks.md +0 -78
@@ -1,248 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>veritrans-ruby demo</title>
5
- <link rel="icon" type="image/x-icon" href="https://account.veritrans.co.id/favicon.ico" />
6
- <link rel="stylesheet" href="/style.css">
7
- </head>
8
- <body>
9
-
10
- <header>
11
- <h3>
12
- <a href="/">Veritrans sinatra app</a>
13
- </h3>
14
- </header>
15
-
16
- <section>
17
- <h4>VT-Direct Localization</h4>
18
-
19
- <form action="/charge_vtdirect" method="post" id="card_form">
20
- <input type="hidden" name="format" value="json">
21
- <input type="hidden" name="token_id" id="card_token">
22
- <fieldset>
23
- <legend>Credit Card</legend>
24
- <p>
25
- <label>Language</label>
26
- <select name="locale" id="locale">
27
- <option value="id" selected>Indonesian</option>
28
- <option value="en">English</option>
29
- </select>
30
- </p>
31
- <p>
32
- <label for="gross_amount">Amount, Rp.</label>
33
- <input type="text" name="gross_amount" id="gross_amount" value="30000">
34
- </p>
35
- <p>
36
- <label for="card_number">Card Number</label>
37
- <input type="text" id="card_number" style="width: 150px" value="4811 1111 1111 1114">
38
- <br>
39
- <small style="margin-left: 100px" class="card-numbers">
40
- <a onclick="$('#card_number').val('4811 1111 1111 1114')">success Visa</a>
41
- <a onclick="$('#card_number').val('5810 1111 1111 1112')">success MasterCard</a>
42
- <a onclick="$('#card_number').val('4511 1111 1111 1117')">challenge</a>
43
- <a onclick="$('#card_number').val('4611 1111 1111 1116')">Deny by FDS</a>
44
- <a onclick="$('#card_number').val('4911 1111 1111 1113')">Deny by bank</a>
45
- <a href="http://docs.veritrans.co.id/en/api/test_credentials.html" target="_blank">documentation</a>
46
- </small>
47
- </p>
48
- <p>
49
- <label for="card_cvc">Card CVV</label>
50
- <input type="text" id="card_cvc" style="width: 35px" placeholder="cvc" value="123">
51
- </p>
52
- <p>
53
- <label for="card_exp">Card Expiry Date</label>
54
- <input type="text" id="card_exp" placeholder="MM / YY" value="12 / 16">
55
- </p>
56
-
57
- <p>
58
- <label for="card_secure">3D-Secure</label>
59
- <input type="checkbox" id="card_secure">
60
- </p>
61
-
62
- </fieldset>
63
-
64
- <input id="submit_btn" type="submit">
65
- </form>
66
- </section>
67
-
68
- <script src="https://api.sandbox.veritrans.co.id/v2/assets/veritrans.js"></script>
69
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
70
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.0.2/jquery.payment.js"></script>
71
- <script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
72
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css">
73
-
74
- <script type="text/javascript">
75
- // set Veritrans settings
76
- Veritrans.url = "<%= Veritrans.config.api_host %>/v2/token";
77
- Veritrans.client_key = "<%= Veritrans.config.client_key %>";
78
-
79
- var Translations = {
80
- en: {
81
- "card_cvv does not match with regular expression": "Card CVV is not valid",
82
- "card_cvv must be 3 digits": "Card CVV should be 3 digits",
83
- "card_cvv is required": "Card CVV is required",
84
-
85
- "card_number is required": "Card Number is required",
86
- "card_number must be between 12 to 19 digits": "Card Number must be between 12 to 19 digits",
87
- "card_number does not match with regular expression": "Card Number must contain only numbers",
88
- "Invalid card_number association": "Card Number is not valid",
89
- "card_number does not match with luhn algorithm": "Card Number is not valid",
90
-
91
- "card_exp_month must be between 1 and 12": "Expiry month should be between 1 and 12",
92
- "card_exp_month does not match with regular expression": "Expiry month must contain only numbers",
93
- "card_exp_month must be 2 digits": "Expiry month must be 2 digits",
94
- "card_expire_month must be greater than this year's month": "Expiry month must be greater than this year's month",
95
-
96
- "card_exp_year does not match with regular expression": "Expiry year is not valid",
97
- "card_exp_year must be greater than this year": "Expiry year must be greater than this year",
98
- "card_exp_year must be 4 digits": "Expiry year must be 4 digits",
99
- "card_exp_year is required": "Expiry year is required",
100
-
101
- "gross_amount is required for 3d secure transaction": "Transaction amount is required",
102
-
103
- "Denied by Veritrans Fraud Detection System": "Payment denied by fraud detection system",
104
- "Deny by Bank [X] with code [05] and message [Do not honour]": "Your credit card was rejected by bank",
105
- "Success, Credit Card transaction is successful": "Payment successfuly processed",
106
- "transaction_details.gross_amount must be greater than or equal to 1": "Amount must be greater than or equal to 1",
107
- "transaction_details.gross_amount is required": "Amount is required"
108
- },
109
-
110
- id: {
111
- "card_cvv does not match with regular expression": "Nomor CVV tidak valid",
112
- "card_cvv must be 3 digits": "Nomor CVV harus 3 angka",
113
- "card_cvv is required": "Nomor CVV wajib diisi",
114
-
115
- "card_number is required": "Nomor kartu wajib diisi",
116
- "card_number must be between 12 to 19 digits": "Jumlah nomor kartu harus 12 hingga 19 angka",
117
- "card_number does not match with regular expression": "Nomor kartu harus berupa angka",
118
- "Invalid card_number association": "Nomor kartu tidak valid dengan asosiasinya",
119
- "card_number does not match with luhn algorithm": "Nomor kartu tidak valid",
120
-
121
- "card_exp_month must be between 1 and 12": "Bulan kedaluarsa harus 01 hingga 12",
122
- "card_exp_month does not match with regular expression": "Bulan kedaluarsa tidak valid",
123
- "card_exp_month must be 2 digits": "Bulan kedaluarsa harus 2 digit",
124
- "card_expire_month must be greater than this year's month": "Bulan kedaluarsa harus lebih dari bulan sekarang",
125
- "card_exp_month is required": "Bulan kedaluarsa wajib diisi",
126
-
127
- "card_exp_year does not match with regular expression": "Tahun kedaluarsa tidak valid",
128
- "card_exp_year must be greater than this year": "Tahun kedaluarsa harus lebih dari tahun sekarang",
129
- "card_exp_year must be 4 digits": "Tahun kedaluarsa harus 4 digit",
130
- "card_exp_year is required": "Tahun kedaluarsa wajib diisi",
131
-
132
- "gross_amount is required for 3d secure transaction": "Jumlah transaksi wajib diisi untuk transaksi 3D secure",
133
-
134
- "Denied by Veritrans Fraud Detection System": "Pembayaran ditolak oleh sistem deteksi fraud",
135
- "Deny by Bank [X] with code [05] and message [Do not honour]": "Kartu kredit ditolak oleh bank",
136
- "Success, Credit Card transaction is successful": "Pembayaran berhasil",
137
- "transaction_details.gross_amount must be greater than or equal to 1": "Jumlah transaksi harus lebih besar 0",
138
- "transaction_details.gross_amount is required": "Jumlah transaksi wajib diisi"
139
- }
140
- }
141
-
142
- function createTokenData() {
143
- var date = $('#card_exp').val();
144
- return {
145
- // Optional params:
146
- // secure: true
147
- // bank: 'MANDIRI'
148
-
149
- card_number: $('#card_number').val(),
150
- card_cvv: $('#card_cvc').val(),
151
- card_exp_month: date && date.match(/(\d+) \//)[1],
152
- card_exp_year: date ? '20' + date.match(/\/ (\d+)/)[1] : date,
153
- gross_amount: $('#gross_amount').val(),
154
- secure: $('#card_secure')[0].checked
155
- };
156
- }
157
-
158
- function submitForm(callback) {
159
- var form = $('#card_form');
160
- $.ajax({
161
- url: form.attr('action'),
162
- method: 'POST',
163
- data: form.serialize(),
164
- success: function (data, status, xhr) {
165
- if (data.status_code == "200") {
166
- $.magnificPopup.open({
167
- items: {
168
- src: '<div class="white-popup">' +
169
- '<h1>Successful!</h1>' +
170
- '<code><pre>' + JSON.stringify(data, null, 2) + '</code></pre>' +
171
- '</div>',
172
- type: 'inline'
173
- }
174
- });
175
- } else {
176
- var language = $('#locale').val();
177
- var messages = data.validation_messages || [data.status_message.replace(/Bank \[\w+\]/, 'Bank [X]')];
178
- var localized = [];
179
- messages.forEach(function (message) {
180
- localized.push(Translations[language][message] || message)
181
- });
182
- $.magnificPopup.open({
183
- items: {
184
- src: '<div class="white-popup">' +
185
- '<strong>Localized: ' + localized.join("\n") + '</strong>' +
186
- '<code><pre>' + JSON.stringify(data, null, 2) + '</code></pre>' +
187
- '</div>',
188
- type: 'inline'
189
- }
190
- });
191
- }
192
- callback();
193
- }
194
- });
195
- };
196
-
197
- $(document).ready(function () {
198
- $('#card_number').payment('formatCardNumber');
199
- $('#card_cvc').payment('formatCardCVC');
200
- $('#card_exp').payment('formatCardExpiry');
201
-
202
- $('#card_form').on('submit', function (event) {
203
- var form = this;
204
- $('#submit_btn').attr('disabled', true).val("Processing ...");
205
- event.preventDefault();
206
-
207
- Veritrans.token(createTokenData, function (data) {
208
- console.log('Token data:', data);
209
- // if we get url then it's 3d-secure transaction
210
- // so we need to open that page
211
- // this callback function will be called again after user confirm 3d-secure
212
- // you can also redirect on server side
213
- if (data.redirect_url) {
214
- $.magnificPopup.open({
215
- items: { type: 'iframe', src: data.redirect_url }
216
- });
217
- $.magnificPopup.instance.content.find('iframe').height(590);
218
- // if no redirect_url and we have token_id then just make charge request
219
- } else if (data.token_id) {
220
- $('#card_token').val(data.token_id);
221
- $.magnificPopup.close();
222
- submitForm(function () {
223
- $('#submit_btn').removeAttr('disabled').removeAttr("value");
224
- });
225
- // if no redirect_url and no token_id, then it should be error
226
- } else {
227
- $('#submit_btn').removeAttr('disabled').removeAttr("value");
228
-
229
- var language = $('#locale').val();
230
- var messages = data.validation_messages || [data.status_message];
231
- var localizedMessages = [];
232
- messages.forEach(function (message) {
233
- if (Translations[language] && Translations[language][message]) {
234
- localizedMessages.push(Translations[language][message]);
235
- } else {
236
- console.log("Missing translation", language, message);
237
- localizedMessages.push(message);
238
- }
239
- });
240
- alert(localizedMessages.sort().join("\n"));
241
- }
242
- });
243
- });
244
- });
245
- </script>
246
-
247
- </body>
248
- </html>
data/example/points.erb DELETED
@@ -1,187 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>veritrans-ruby demo</title>
5
- <link rel="icon" type="image/x-icon" href="https://account.veritrans.co.id/favicon.ico" />
6
- <link rel="stylesheet" href="/style.css">
7
- </head>
8
- <body>
9
-
10
- <header>
11
- <h3>
12
- <a href="/">Veritrans sinatra app</a>
13
- </h3>
14
- </header>
15
-
16
- <section>
17
- <h4>VT-Direct Points</h4>
18
-
19
- <form action="/charge_vtdirect" method="post" id="card_form">
20
- <input type="hidden" name="format" value="json">
21
- <input type="hidden" name="token_id" id="card_token">
22
- <fieldset>
23
- <legend>Credit Card Points</legend>
24
- <p>
25
- <label>Language</label>
26
- <select name="locale" id="locale">
27
- <option value="id" selected>Indonesian</option>
28
- <option value="en">English</option>
29
- </select>
30
- </p>
31
- <p>
32
- <label for="gross_amount">Amount, Rp.</label>
33
- <input type="text" name="gross_amount" id="gross_amount" value="30000">
34
- </p>
35
- <p>
36
- <label for="gross_amount">Points, Rp.</label>
37
- <input type="text" name="points_amount" id="points_amount" value="10000">
38
- </p>
39
- <p>
40
- <label for="card_number">Card Number</label>
41
- <input type="text" id="card_number" style="width: 150px" value="4802 0000 0000 0002">
42
- <br>
43
- <small style="margin-left: 100px" class="card-numbers">
44
- <a onclick="$('#card_number').val('4802 0000 0000 0002')">Success</a>
45
- <a onclick="$('#card_number').val('4902 0000 0000 0001')">Deny</a>
46
- <a href="http://docs.veritrans.co.id/en/vtdirect/other_features.html#installment" target="_blank">documentation</a>
47
- </small>
48
- </p>
49
- <p>
50
- <label for="card_exp">Expiry Date</label>
51
- <input type="text" id="card_exp" placeholder="MM / YY" value="12 / 16">
52
- </p>
53
- <p>
54
- <label for="card_cvc">Card CVV</label>
55
- <input type="text" id="card_cvc" style="width: 35px" placeholder="cvc" value="123">
56
- </p>
57
-
58
- <p>
59
- <label for="card_secure">3D-Secure</label>
60
- <input type="checkbox" id="card_secure">
61
- </p>
62
-
63
- </fieldset>
64
-
65
- <input id="points_btn" type="submit" value="Check Points">
66
- <input id="submit_btn" type="submit" value="Charge">
67
- </form>
68
- </section>
69
-
70
- <script src="https://api.sandbox.veritrans.co.id/v2/assets/veritrans.js"></script>
71
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
72
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.0.2/jquery.payment.js"></script>
73
- <script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
74
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css">
75
-
76
- <script type="text/javascript">
77
- // set Veritrans settings
78
- Veritrans.url = "<%= Veritrans.config.api_host %>/v2/token";
79
- Veritrans.client_key = "<%= Veritrans.config.client_key %>";
80
-
81
- function createTokenData() {
82
- var date = $('#card_exp').val();
83
- return {
84
- // Optional params:
85
- // secure: true
86
- // bank: 'MANDIRI'
87
-
88
- card_number: $('#card_number').val(),
89
- card_cvv: $('#card_cvc').val(),
90
- card_exp_month: date && date.match(/(\d+) \//)[1],
91
- card_exp_year: date ? '20' + date.match(/\/ (\d+)/)[1] : date,
92
- gross_amount: $('#gross_amount').val()
93
- };
94
- }
95
-
96
- function submitForm(callback) {
97
- var form = $('#card_form');
98
- $.ajax({
99
- url: form.attr('action'),
100
- method: 'POST',
101
- data: form.serialize(),
102
- success: function (data, status, xhr) {
103
- $.magnificPopup.open({
104
- items: {
105
- src: '<div class="white-popup">' +
106
- '<h1>Successful!</h1>' +
107
- '<code><pre>' + JSON.stringify(data, null, 2) + '</code></pre>' +
108
- '</div>',
109
- type: 'inline'
110
- }
111
- });
112
- callback();
113
- }
114
- });
115
- };
116
-
117
- $(document).ready(function () {
118
- $('#card_number').payment('formatCardNumber');
119
- $('#card_cvc').payment('formatCardCVC');
120
- $('#card_exp').payment('formatCardExpiry');
121
-
122
- $('#points_btn').on('click', function (e) {
123
- e.preventDefault();
124
- e.stopPropagation();
125
- $('#points_btn').attr('disabled', true);
126
- Veritrans.token(createTokenData, function (data) {
127
- if (data.token_id) {
128
- $.ajax({
129
- url: "/check_points/" + data.token_id,
130
- method: 'GET',
131
- success: function (data, status, xhr) {
132
- $('#points_btn').removeAttr('disabled');
133
- $.magnificPopup.open({
134
- items: {
135
- src: '<div class="white-popup">' +
136
- '<h1>Successful!</h1>' +
137
- '<code><pre>' + JSON.stringify(data, null, 2) + '</code></pre>' +
138
- '</div>',
139
- type: 'inline'
140
- }
141
- });
142
- }
143
- });
144
- } else {
145
- $('#points_btn').removeAttr('disabled');
146
- alert(data.validation_messages ? data.validation_messages.join("\n") : data.status_message);
147
- }
148
- console.log(data);
149
- });
150
- });
151
-
152
- $('#card_form').on('submit', function (event) {
153
- var form = this;
154
- $('#submit_btn').attr('disabled', true).val("Processing ...");
155
- event.preventDefault();
156
-
157
- Veritrans.token(createTokenData, function (data) {
158
- console.log('Token data:', data);
159
- // if we get url then it's 3d-secure transaction
160
- // so we need to open that page
161
- // this callback function will be called again after user confirm 3d-secure
162
- // you can also redirect on server side
163
- if (data.redirect_url) {
164
- $.magnificPopup.open({
165
- items: { type: 'iframe', src: data.redirect_url }
166
- });
167
- $.magnificPopup.instance.content.find('iframe').height(590);
168
- // if no redirect_url and we have token_id then just make charge request
169
- } else if (data.token_id) {
170
- $('#card_token').val(data.token_id);
171
- $.magnificPopup.close();
172
- submitForm(function () {
173
- $('#submit_btn').removeAttr('disabled').removeAttr("value");
174
- });
175
- //form.submit();
176
- // if no redirect_url and no token_id, then it should be error
177
- } else {
178
- $('#submit_btn').removeAttr('disabled').removeAttr("value");
179
- alert(data.validation_messages ? data.validation_messages.join("\n") : data.status_message);
180
- }
181
- });
182
- });
183
- });
184
- </script>
185
-
186
- </body>
187
- </html>
@@ -1,201 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <title>veritrans-ruby demo</title>
5
- <link rel="icon" type="image/x-icon" href="https://account.veritrans.co.id/favicon.ico" />
6
- <link rel="stylesheet" href="/style.css">
7
- </head>
8
- <body>
9
-
10
- <header>
11
- <h3>
12
- <a href="/">Veritrans sinatra app</a>
13
- <link rel="icon" type="image/x-icon" href="https://account.veritrans.co.id/favicon.ico" />
14
- </h3>
15
- </header>
16
-
17
- <section class="recurring-page">
18
- <h4>Recurring / One Click</h4>
19
-
20
- <section class="cards">
21
- Saved cards:
22
- <ul>
23
-
24
- </ul>
25
- </section>
26
-
27
- <form id="add_card_form">
28
- <input type="hidden" name="token_id" id="card_token">
29
- <fieldset>
30
- <legend>Credit Card Recurring</legend>
31
- <p>
32
- <label for="card_number">Card number</label>
33
- <input type="text" id="card_number" style="width: 150px" value="4811 1111 1111 1114">
34
- <br>
35
- <small style="margin-left: 100px" class="card-numbers">
36
- <a onclick="$('#card_number').val('4811 1111 1111 1114')">success Visa 1</a>
37
- <a onclick="$('#card_number').val('4411 1111 1111 1118')">success Visa 2</a>
38
- <a onclick="$('#card_number').val('5810 1111 1111 1112')">success MasterCard 1</a>
39
- <a onclick="$('#card_number').val('5410 1111 1111 1116')">success MasterCard 2</a>
40
- <a href="http://docs.veritrans.co.id/en/api/test_credentials.html" target="_blank">documentation</a>
41
- </small>
42
- </p>
43
-
44
- <p>
45
- <label for="card_cvc">Security Code</label>
46
- <input type="text" id="card_cvc" style="width: 30px" placeholder="cvc" value="123">
47
- </p>
48
-
49
- <p>
50
- <label for="card_exp">Expiration date</label>
51
- <input type="text" id="card_exp" placeholder="MM / YY" value="12 / 16">
52
- </p>
53
-
54
- </fieldset>
55
-
56
- <input id="add_card_btn" type="submit" value="Add Card">
57
- </form>
58
-
59
- <script src="//api.sandbox.veritrans.co.id/v2/assets/veritrans.js"></script>
60
- <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
61
- <script src="//cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.0.2/jquery.payment.js"></script>
62
- <script src="//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.1/jquery.magnific-popup.js"></script>
63
- <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/0.9.9/magnific-popup.css">
64
-
65
- <script type="text/javascript">
66
- Veritrans.client_key = "<%= Veritrans.config.client_key %>";
67
-
68
- // Here is a difference, for
69
- Veritrans.url = "<%= Veritrans.config.api_host %>/v2/card/register";
70
-
71
-
72
- function createTokenData() {
73
- return {
74
- card_number: $('#card_number').val().replace(/\s/g, ''),
75
- card_cvv: $('#card_cvc').val(),
76
- card_exp_month: $('#card_exp').val().match(/(\d+) \//)[1],
77
- card_exp_year: '20' + $('#card_exp').val().match(/\/ (\d+)/)[1]
78
- };
79
- }
80
-
81
- $(document).ready(function () {
82
- $('#card_number').payment('formatCardNumber');
83
- $('#card_cvc').payment('formatCardCVC');
84
- $('#card_exp').payment('formatCardExpiry');
85
-
86
- renderCards();
87
-
88
- $('#add_card_form').on('submit', function (event) {
89
- var form = this;
90
- $('#submit_btn').attr('disabled', true).val("Processing ...");
91
- event.preventDefault();
92
-
93
- Veritrans.token(createTokenData, function (data) {
94
- console.log('Token data:', data);
95
- // if we get url then it's 3d-secure transaction
96
- // so we need to open that page
97
- // this callback function will be called again after user confirm 3d-secure
98
- // you can also redirect on server side
99
- if (data.redirect_url) {
100
- $.magnificPopup.open({
101
- items: { type: 'iframe', src: data.redirect_url }
102
- });
103
- $.magnificPopup.instance.content.find('iframe').height(590);
104
- // if no redirect_url and we have token_id then just make charge request
105
- } else if (data.saved_token_id) {
106
- $('#card_token').val(data.saved_token_id);
107
- //form.submit();
108
- $.magnificPopup.close();
109
- saveCard(data, createTokenData());
110
- renderCards();
111
- // if no redirect_url and no token_id, then it should be error
112
- } else {
113
- alert(data.validation_messages ? data.validation_messages.join("\n") : data.status_message);
114
- $('#submit_btn').removeAttr('disabled').removeAttr("value");
115
- }
116
- });
117
- });
118
- });
119
-
120
- function loadCards () {
121
- return localStorage.recurring ? JSON.parse(localStorage.recurring) : [];
122
- }
123
-
124
- function saveCard (tokenInfo, cardInfo) {
125
- var data = loadCards();
126
-
127
- var row = {
128
- token_id: tokenInfo.saved_token_id,
129
- card_number: tokenInfo.masked_card,
130
- card_expiry: cardInfo.card_exp_month + " / " + cardInfo.card_exp_year
131
- };
132
- data.push(row);
133
-
134
- localStorage.recurring = JSON.stringify(data);
135
- }
136
-
137
- function renderCards () {
138
- var cards = loadCards();
139
-
140
- var container = $('section.cards ul');
141
- container.empty();
142
- cards.forEach(function (card) {
143
- var el = $('<li>').html(
144
- "Card Number: <code>" + card.card_number + "</code> " +
145
- "Expiry: <i>" + card.card_expiry + "</i> "
146
- );
147
- el.attr('data-id', card.id);
148
- el.attr('token-id', card.token_id);
149
- $('<a>').text('Charge card').bind('click', chargeSavedCard).attr('href', '#').appendTo(el);
150
- $('<a>').text('Remove').bind('click', removeSavedCard).attr('href', '#').appendTo(el);
151
- $('<small>').text('Token ' + card.token_id).appendTo(el);
152
- el.appendTo(container);
153
- })
154
- }
155
-
156
- function chargeSavedCard (e) {
157
- e.preventDefault();
158
- var token = $(e.target).closest('li').attr('token-id');
159
- var amount = prompt("Please enter amount (Rp.)", 15000);
160
-
161
- if (amount === "" || amount === null || parseInt(amount, 10) <= 0) {
162
- console.log("Canceled");
163
- return;
164
- }
165
-
166
- // Create iFrame and submit form in it
167
- var html = '<form action="' + window.location.protocol + '//' + window.location.host + '/charge_vtdirect" method="post">' +
168
- '<input type=hidden name=recurring value=1>' +
169
- '<input type=hidden name=token_id value="' + token + '">' +
170
- '<input type=hidden name=gross_amount value="' + parseInt(amount, 10) + '">' +
171
- '<input type=submit style="display: none">' +
172
- '</form>' + "<script>console.log(document.forms[0]); document.forms[0].submit()<\/script>";
173
-
174
- var content = 'data:text/html;charset=utf-8,' + encodeURI(html);
175
- $.magnificPopup.open({
176
- items: { type: 'iframe', src: content}
177
- });
178
- }
179
-
180
- function removeSavedCard (e) {
181
- e.preventDefault();
182
- var tokenId = $(e.target).closest('li').attr('token-id');
183
- var cards = loadCards();
184
-
185
- cards.forEach(function (card, index) {
186
- if (card.token_id == tokenId) {
187
- if (confirm("Remove card " + card.card_number + "?")) {
188
- cards.splice(index, 1);
189
- console.log(cards);
190
- }
191
- }
192
- });
193
-
194
- localStorage.recurring = JSON.stringify(cards);
195
- renderCards();
196
- }
197
-
198
- </script>
199
-
200
- </body>
201
- </html>
data/example/response.erb DELETED
@@ -1,37 +0,0 @@
1
- <link rel="stylesheet" href="/style.css">
2
-
3
- <header>
4
- <h3>Veritrans sinatra app</h3>
5
- </header>
6
-
7
- <% if @result.redirect_url %>
8
- <section>
9
- <p>Here's redirect url <a href='<%= @vtweb_url %>'><%= @vtweb_url %></a> </p>
10
- </section>
11
- <% end %>
12
-
13
- <section>
14
- <strong>
15
- Veritrans response:
16
- <% if @result.success? %>
17
- <span style="color: green">success</span>
18
- <% end %>
19
- </strong>
20
-
21
- <code>
22
- <pre>
23
- <%= JSON.pretty_generate(JSON.parse(@result.response.body)) %>
24
- </pre>
25
- </code>
26
-
27
- <% if @cahrge_params %>
28
- <strong>Request Body</strong>
29
- <code>
30
- <pre>
31
- <%= JSON.pretty_generate(@cahrge_params) %>
32
- </pre>
33
- </code>
34
- <% end %>
35
-
36
- <a href="/">Go back</a>
37
- </section>