veritrans 2.0.4 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +11 -3
- data/CHANGELOG.md +15 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +136 -97
- data/Procfile +1 -0
- data/README.md +12 -5
- data/Rakefile +7 -5
- data/api_reference.md +21 -1
- data/example/README.md +8 -0
- data/example/config.ru +6 -0
- data/example/index.erb +104 -9
- data/example/localization.erb +248 -0
- data/example/points.erb +187 -0
- data/example/recurring.erb +201 -0
- data/example/response.erb +10 -1
- data/example/sinatra.rb +120 -8
- data/example/style.css +83 -2
- data/example/veritrans.yml +0 -1
- data/example/widget.erb +52 -0
- data/lib/generators/templates/assets/credit_card_form.js +3 -2
- data/lib/generators/templates/payments_controller.rb +5 -0
- data/lib/generators/templates/veritrans.rb +20 -17
- data/lib/generators/veritrans/install_generator.rb +1 -1
- data/lib/generators/veritrans/payment_form_generator.rb +1 -1
- data/lib/veritrans.rb +73 -44
- data/lib/veritrans/api.rb +39 -5
- data/lib/veritrans/cli.rb +1 -1
- data/lib/veritrans/client.rb +15 -10
- data/lib/veritrans/config.rb +11 -4
- data/lib/veritrans/events.rb +4 -4
- data/lib/veritrans/result.rb +28 -7
- data/lib/veritrans/version.rb +2 -2
- data/spec/cli_spec.rb +1 -0
- data/spec/rails_plugin_spec.rb +72 -27
- data/spec/spec_helper.rb +1 -0
- data/spec/veritrans_client_spec.rb +57 -3
- data/spec/veritrans_config_spec.rb +1 -1
- data/spec/veritrans_events_spec.rb +2 -0
- data/spec/veritrans_snap_spec.rb +39 -0
- data/testing_webhooks.md +0 -2
- data/veritrans.gemspec +5 -5
- metadata +29 -15
data/example/README.md
ADDED
data/example/config.ru
ADDED
data/example/index.erb
CHANGED
@@ -1,19 +1,89 @@
|
|
1
|
-
|
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>
|
2
9
|
|
3
10
|
<header>
|
4
11
|
<h3>Veritrans sinatra app</h3>
|
5
12
|
</header>
|
6
13
|
|
7
14
|
<section>
|
8
|
-
<
|
9
|
-
|
10
|
-
|
15
|
+
<h4>VT-Web</h4>
|
16
|
+
<form action="/charge_vtweb" method="GET" id="vtweb_form">
|
17
|
+
<fieldset>
|
18
|
+
<p>
|
19
|
+
<label>Language</label>
|
20
|
+
<select name="locale">
|
21
|
+
<option></option>
|
22
|
+
<option value="id">Indonesian</option>
|
23
|
+
<option value="en">English</option>
|
24
|
+
</select>
|
25
|
+
</p>
|
26
|
+
|
27
|
+
<div class="form-row">
|
28
|
+
<label>Payment Types</label>
|
29
|
+
<ul>
|
30
|
+
<% @payment_types = %w{CREDIT_CARD MANDIRI_CLICKPAY MANDIRI_BILL CIMB_CLICKS INDOMARET BANK_TRANSFER MANDIRI_BILL} %>
|
31
|
+
<% for type in @payment_types %>
|
32
|
+
<li>
|
33
|
+
<label>
|
34
|
+
<input type="checkbox" name="enabled_payments[]" value="<%= type %>">
|
35
|
+
<%= type.split("_").map(&:capitalize).join(' ') %>
|
36
|
+
</label>
|
37
|
+
</li>
|
38
|
+
<% end %>
|
39
|
+
</ul>
|
40
|
+
<br/>
|
41
|
+
<small class="types-hint">By default Veritrans will show all available types</small>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<p>
|
45
|
+
<label>Credit Card BIN promo</label>
|
46
|
+
<input type="text" name="bin_promo" placeholder="411111, 500000, bni, mandiri, 3111">
|
47
|
+
<br/>
|
48
|
+
<small class="bins-hint">
|
49
|
+
<a href="http://docs.veritrans.co.id/en/vtweb/other_features.html#bin-promo">See documentation</a>
|
50
|
+
</small>
|
51
|
+
</p>
|
52
|
+
|
53
|
+
<p>
|
54
|
+
<label>Credit Card 3D Secure</label>
|
55
|
+
<select name="credit_card_3d_secure">
|
56
|
+
<option></option>
|
57
|
+
<option value="true">Yes</option>
|
58
|
+
<option value="false">No</option>
|
59
|
+
</select>
|
60
|
+
</p>
|
61
|
+
|
62
|
+
<div class="form-row">
|
63
|
+
<label>Credit Card Installment</label>
|
64
|
+
<ul>
|
65
|
+
<li>
|
66
|
+
<label><input type="checkbox" name="installment[bni]">BNI</label>
|
67
|
+
</li>
|
68
|
+
<li>
|
69
|
+
<label><input type="checkbox" name="installment[mandiri]">Mandiri</label>
|
70
|
+
</li>
|
71
|
+
<li>
|
72
|
+
<label><input type="checkbox" name="installment[bca]">BCA</label>
|
73
|
+
</li>
|
74
|
+
</ul>
|
75
|
+
</div>
|
76
|
+
|
77
|
+
</fieldset>
|
78
|
+
|
79
|
+
<p>
|
80
|
+
<input type="submit" value="Create payment page">
|
81
|
+
<p>
|
82
|
+
</form>
|
11
83
|
</section>
|
12
84
|
|
13
85
|
<section>
|
14
|
-
<
|
15
|
-
Charge request VT-Direct
|
16
|
-
</p>
|
86
|
+
<h4>VT-Direct</h4>
|
17
87
|
|
18
88
|
<form action="/charge_vtdirect" method="post" id="card_form">
|
19
89
|
<input type="hidden" name="token_id" id="card_token">
|
@@ -33,7 +103,7 @@
|
|
33
103
|
<a onclick="$('#card_number').val('4511 1111 1111 1117')">challenge</a>
|
34
104
|
<a onclick="$('#card_number').val('4611 1111 1111 1116')">Deny by FDS</a>
|
35
105
|
<a onclick="$('#card_number').val('4911 1111 1111 1113')">Deny by bank</a>
|
36
|
-
<a href="http://docs.veritrans.co.id/
|
106
|
+
<a href="http://docs.veritrans.co.id/en/api/test_credentials.html" target="_blank">documentation</a>
|
37
107
|
</small>
|
38
108
|
</p>
|
39
109
|
<p>
|
@@ -56,6 +126,27 @@
|
|
56
126
|
</form>
|
57
127
|
</section>
|
58
128
|
|
129
|
+
<section>
|
130
|
+
<h4>Localization</h4>
|
131
|
+
Indonesian translation for validation messages
|
132
|
+
<a href="/localization">Click here</a>
|
133
|
+
</section>
|
134
|
+
|
135
|
+
<section>
|
136
|
+
<h4>Recurring</h4>
|
137
|
+
<a href="/recurring">Click here</a>
|
138
|
+
</section>
|
139
|
+
|
140
|
+
<section>
|
141
|
+
<h4>Credit Card Points</h4>
|
142
|
+
<a href="/points">Click here</a>
|
143
|
+
</section>
|
144
|
+
|
145
|
+
<section>
|
146
|
+
<h4>Snap</h4>
|
147
|
+
<a href="/widget">Click here</a>
|
148
|
+
</section>
|
149
|
+
|
59
150
|
<script src="//api.sandbox.veritrans.co.id/v2/assets/veritrans.js"></script>
|
60
151
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
61
152
|
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.0.2/jquery.payment.js"></script>
|
@@ -106,6 +197,7 @@
|
|
106
197
|
// if no redirect_url and we have token_id then just make charge request
|
107
198
|
} else if (data.token_id) {
|
108
199
|
$('#card_token').val(data.token_id);
|
200
|
+
$.magnificPopup.close();
|
109
201
|
form.submit();
|
110
202
|
// if no redirect_url and no token_id, then it should be error
|
111
203
|
} else {
|
@@ -115,4 +207,7 @@
|
|
115
207
|
});
|
116
208
|
});
|
117
209
|
});
|
118
|
-
</script>
|
210
|
+
</script>
|
211
|
+
|
212
|
+
</body>
|
213
|
+
</html>
|
@@ -0,0 +1,248 @@
|
|
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
ADDED
@@ -0,0 +1,187 @@
|
|
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>
|