veritrans 1.2.6 → 2.0.0beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +111 -0
- data/README.md +258 -0
- data/Rakefile +7 -0
- data/api_reference.md +219 -0
- data/bin/veritrans +59 -48
- data/example/index.erb +118 -0
- data/example/response.erb +28 -0
- data/example/sinatra.rb +76 -0
- data/example/style.css +45 -0
- data/example/veritrans.yml +12 -0
- data/lib/generators/templates/assets/credit_card_form.js +50 -0
- data/lib/generators/templates/payments_controller.rb +81 -0
- data/lib/generators/templates/veritrans.rb +43 -0
- data/lib/generators/templates/veritrans.yml +13 -0
- data/lib/generators/templates/views/_credit_card_form.erb +42 -0
- data/lib/generators/templates/views/_veritrans_include.erb +10 -0
- data/lib/generators/templates/views/payments/create.erb +15 -0
- data/lib/generators/templates/views/payments/new.erb +6 -0
- data/lib/generators/veritrans/install_generator.rb +32 -0
- data/lib/generators/veritrans/payment_form_generator.rb +45 -0
- data/lib/veritrans/api.rb +90 -0
- data/lib/veritrans/cli.rb +166 -0
- data/lib/veritrans/client.rb +77 -209
- data/lib/veritrans/config.rb +48 -62
- data/lib/veritrans/events.rb +125 -0
- data/lib/veritrans/result.rb +81 -0
- data/lib/veritrans/version.rb +1 -41
- data/lib/veritrans.rb +79 -15
- data/license.txt +202 -0
- data/spec/cli_spec.rb +86 -0
- data/spec/configs/veritrans.yml +7 -0
- data/spec/configs/veritrans_flat.yml +2 -0
- data/spec/fixtures/approve_failed.yml +48 -0
- data/spec/fixtures/cancel_failed.yml +48 -0
- data/spec/fixtures/cancel_success.yml +106 -0
- data/spec/fixtures/capture_failed.yml +48 -0
- data/spec/fixtures/charge.yml +50 -0
- data/spec/fixtures/charge_direct.yml +56 -0
- data/spec/fixtures/charge_vtweb.yml +50 -0
- data/spec/fixtures/cli_test_1111-not-exists.yml +45 -0
- data/spec/fixtures/cli_test_not_exists.yml +45 -0
- data/spec/fixtures/cli_test_real_txn.yml +55 -0
- data/spec/fixtures/cli_test_unauthorized.yml +47 -0
- data/spec/fixtures/events_test_real_txn.yml +55 -0
- data/spec/fixtures/status_fail.yml +46 -0
- data/spec/fixtures/status_success.yml +109 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/veritrans_client_spec.rb +83 -0
- data/spec/veritrans_config_spec.rb +48 -0
- data/spec/veritrans_events_spec.rb +70 -0
- data/spec/veritrans_logger_spec.rb +46 -0
- data/testing_webhooks.md +80 -0
- data/veritrans.gemspec +23 -0
- metadata +82 -31
- data/config/veritrans.yml +0 -24
- data/lib/generators/install_generator.rb +0 -78
- data/lib/generators/templates/app/controllers/vtlink/merchant_controller.rb +0 -7
- data/lib/generators/templates/app/controllers/vtlink/veritrans_controller.rb +0 -112
- data/lib/generators/templates/app/views/layouts/layout_auto_post.html.erb +0 -15
- data/lib/generators/templates/app/views/vtlink/merchant/checkout.html.erb +0 -43
- data/lib/generators/templates/app/views/vtlink/veritrans/cancel.html.erb +0 -2
- data/lib/generators/templates/app/views/vtlink/veritrans/confirm.html.erb +0 -13
- data/lib/generators/templates/app/views/vtlink/veritrans/error.html.erb +0 -2
- data/lib/generators/templates/app/views/vtlink/veritrans/finish.html.erb +0 -2
- data/lib/generators/templates/app/views/vtlink/veritrans/pay.html.erb +0 -2
- data/lib/generators/templates/config/veritrans.yml +0 -13
- data/lib/veritrans/hash_generator.rb +0 -19
- data/lib/veritrans/post_data.rb +0 -163
- data/lib/veritrans/v_t_direct.rb +0 -145
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.sandbox.veritrans.co.id/v2/1111-not-exists/status
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Veritrans ruby gem 2.0.0beta
|
12
|
+
Authorization:
|
13
|
+
- Basic c3BlY19zZXJ2ZXJfa2V5Og==
|
14
|
+
Accept:
|
15
|
+
- application/json
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: ''
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx
|
25
|
+
Date:
|
26
|
+
- Mon, 01 Dec 2014 08:12:49 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/json
|
29
|
+
Content-Length:
|
30
|
+
- '132'
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Cache-Control:
|
34
|
+
- no-cache
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Expires:
|
38
|
+
- Wed, 31 Dec 1969 17:00:00 GMT
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=31536000; includeSubdomains;
|
41
|
+
body:
|
42
|
+
encoding: US-ASCII
|
43
|
+
string: ! "{\n \"status_code\" : \"401\",\n \"status_message\" : \"Access
|
44
|
+
denied due to unauthorized transaction, please check client or server key\"\n}"
|
45
|
+
http_version:
|
46
|
+
recorded_at: Mon, 01 Dec 2014 08:13:09 GMT
|
47
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.sandbox.veritrans.co.id/v2/testing-0.2703-1415600236/status
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Veritrans ruby gem 2.0.0beta
|
12
|
+
Authorization:
|
13
|
+
- Basic VlQtc2VydmVyLTlIdGItUnhYa2c3LTdoem5TQ0NqeHZvWTo=
|
14
|
+
Accept:
|
15
|
+
- application/json
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: ''
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx
|
25
|
+
Date:
|
26
|
+
- Mon, 01 Dec 2014 08:35:12 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/json
|
29
|
+
Content-Length:
|
30
|
+
- '602'
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Cache-Control:
|
34
|
+
- no-cache
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Expires:
|
38
|
+
- Wed, 31 Dec 1969 17:00:00 GMT
|
39
|
+
Vary:
|
40
|
+
- Accept-Encoding, User-Agent
|
41
|
+
Strict-Transport-Security:
|
42
|
+
- max-age=31536000; includeSubdomains;
|
43
|
+
body:
|
44
|
+
encoding: US-ASCII
|
45
|
+
string: ! "{\n \"status_code\" : \"200\",\n \"status_message\" : \"Success,
|
46
|
+
transaction found\",\n \"transaction_id\" : \"b1cbcc66-5608-4af1-a3ed-0f152f9ed871\",\n
|
47
|
+
\ \"masked_card\" : \"481111-1114\",\n \"order_id\" : \"testing-0.2703-1415600236\",\n
|
48
|
+
\ \"payment_type\" : \"credit_card\",\n \"transaction_time\" : \"2014-11-10
|
49
|
+
13:17:33\",\n \"transaction_status\" : \"settlement\",\n \"fraud_status\"
|
50
|
+
: \"accept\",\n \"approval_code\" : \"1415600254322\",\n \"signature_key\"
|
51
|
+
: \"90da23d37a4ba8fc717990c35240948ab5a97cad71e46777de77b0fe468ffac8624dc09a80a422671f1f9a56f20956ccbe16c91074327c0ba5a33c8974c8973c\",\n
|
52
|
+
\ \"bank\" : \"bni\",\n \"gross_amount\" : \"30000.00\"\n}"
|
53
|
+
http_version:
|
54
|
+
recorded_at: Mon, 01 Dec 2014 08:35:32 GMT
|
55
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.sandbox.veritrans.co.id/v2/not-exists/status
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Veritrans ruby gem 2.0.0beta
|
12
|
+
Authorization:
|
13
|
+
- Basic VlQtc2VydmVyLTlIdGItUnhYa2c3LTdoem5TQ0NqeHZvWTo=
|
14
|
+
Accept:
|
15
|
+
- application/json
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: ''
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx/1.5.13
|
25
|
+
Date:
|
26
|
+
- Tue, 04 Nov 2014 14:11:31 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/json
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Cache-Control:
|
32
|
+
- no-cache
|
33
|
+
Pragma:
|
34
|
+
- no-cache
|
35
|
+
Expires:
|
36
|
+
- Wed, 31 Dec 1969 17:00:00 GMT
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: |-
|
40
|
+
{
|
41
|
+
"status_code" : "404",
|
42
|
+
"status_message" : "The requested resource is not found"
|
43
|
+
}
|
44
|
+
http_version:
|
45
|
+
recorded_at: Tue, 04 Nov 2014 14:10:00 GMT
|
46
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,109 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.sandbox.veritrans.co.id/v2/charge
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"payment_type":"permata","transaction_details":{"order_id":1415110500,"gross_amount":100000}}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Veritrans ruby gem 2.0.0beta
|
12
|
+
Authorization:
|
13
|
+
- Basic VlQtc2VydmVyLTlIdGItUnhYa2c3LTdoem5TQ0NqeHZvWTo=
|
14
|
+
Accept:
|
15
|
+
- application/json
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: ''
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- nginx/1.5.13
|
25
|
+
Date:
|
26
|
+
- Tue, 04 Nov 2014 14:16:31 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/json
|
29
|
+
Content-Length:
|
30
|
+
- '381'
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Cache-Control:
|
34
|
+
- no-cache
|
35
|
+
Pragma:
|
36
|
+
- no-cache
|
37
|
+
Expires:
|
38
|
+
- Wed, 31 Dec 1969 17:00:00 GMT
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: |-
|
42
|
+
{
|
43
|
+
"status_code" : "201",
|
44
|
+
"status_message" : "Success, PERMATA VA transaction is successful",
|
45
|
+
"transaction_id" : "2e008228-43cf-4f49-9299-329fa239e48b",
|
46
|
+
"order_id" : "1415110500",
|
47
|
+
"payment_type" : "bank_transfer",
|
48
|
+
"transaction_time" : "2014-11-04 21:16:51",
|
49
|
+
"transaction_status" : "pending",
|
50
|
+
"permata_va_number" : "8778990000000021",
|
51
|
+
"gross_amount" : "100000.00"
|
52
|
+
}
|
53
|
+
http_version:
|
54
|
+
recorded_at: Tue, 04 Nov 2014 14:15:00 GMT
|
55
|
+
- request:
|
56
|
+
method: get
|
57
|
+
uri: https://api.sandbox.veritrans.co.id/v2/1415110500/status
|
58
|
+
body:
|
59
|
+
encoding: US-ASCII
|
60
|
+
string: ''
|
61
|
+
headers:
|
62
|
+
User-Agent:
|
63
|
+
- Veritrans ruby gem 2.0.0beta
|
64
|
+
Authorization:
|
65
|
+
- Basic VlQtc2VydmVyLTlIdGItUnhYa2c3LTdoem5TQ0NqeHZvWTo=
|
66
|
+
Accept:
|
67
|
+
- application/json
|
68
|
+
Content-Type:
|
69
|
+
- application/json
|
70
|
+
response:
|
71
|
+
status:
|
72
|
+
code: 200
|
73
|
+
message: ''
|
74
|
+
headers:
|
75
|
+
Server:
|
76
|
+
- nginx/1.5.13
|
77
|
+
Date:
|
78
|
+
- Tue, 04 Nov 2014 14:16:32 GMT
|
79
|
+
Content-Type:
|
80
|
+
- application/json
|
81
|
+
Content-Length:
|
82
|
+
- '470'
|
83
|
+
Connection:
|
84
|
+
- keep-alive
|
85
|
+
Cache-Control:
|
86
|
+
- no-cache
|
87
|
+
Pragma:
|
88
|
+
- no-cache
|
89
|
+
Expires:
|
90
|
+
- Wed, 31 Dec 1969 17:00:00 GMT
|
91
|
+
Vary:
|
92
|
+
- Accept-Encoding, User-Agent
|
93
|
+
body:
|
94
|
+
encoding: UTF-8
|
95
|
+
string: |-
|
96
|
+
{
|
97
|
+
"status_code" : "201",
|
98
|
+
"status_message" : "Success, transaction found",
|
99
|
+
"transaction_id" : "2e008228-43cf-4f49-9299-329fa239e48b",
|
100
|
+
"order_id" : "1415110500",
|
101
|
+
"payment_type" : "bank_transfer",
|
102
|
+
"transaction_time" : "2014-11-04 21:16:51",
|
103
|
+
"transaction_status" : "pending",
|
104
|
+
"signature_key" : "6a79b17ff900a9f991b7b16c693e4a8b00843c65d09657fdf586be77597f87fa573c9b8e9aad78784f3208a1ab61f005cc337ef6f763235e282e975bbbf2e0ce",
|
105
|
+
"gross_amount" : "100000.00"
|
106
|
+
}
|
107
|
+
http_version:
|
108
|
+
recorded_at: Tue, 04 Nov 2014 14:15:01 GMT
|
109
|
+
recorded_with: VCR 2.9.3
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
$:.push(File.expand_path("../../lib", __FILE__))
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
require 'veritrans'
|
7
|
+
require 'veritrans/cli'
|
8
|
+
require 'veritrans/events'
|
9
|
+
require 'rails'
|
10
|
+
require 'webmock/rspec'
|
11
|
+
require 'vcr'
|
12
|
+
|
13
|
+
VCR.configure do |c|
|
14
|
+
c.cassette_library_dir = 'spec/fixtures'
|
15
|
+
c.hook_into :webmock # or :fakeweb
|
16
|
+
#c.debug_logger = STDOUT
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.mock_with :rspec
|
21
|
+
|
22
|
+
config.expect_with :rspec do |c|
|
23
|
+
c.syntax = [:should, :expect]
|
24
|
+
end
|
25
|
+
|
26
|
+
config.mock_with :rspec do |c|
|
27
|
+
c.syntax = [:should, :expect]
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
describe Veritrans do
|
2
|
+
|
3
|
+
before do
|
4
|
+
hide_const("Rails")
|
5
|
+
Veritrans.logger = Logger.new("/dev/null")
|
6
|
+
Veritrans.setup do
|
7
|
+
config.load_config "./example/veritrans.yml#development"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should send charge vt-web request" do
|
12
|
+
VCR.use_cassette('charge_vtweb') do
|
13
|
+
result = Veritrans.charge('vtweb', transaction: { order_id: Time.now.to_s, gross_amount: 100_000 } )
|
14
|
+
|
15
|
+
result.status_message.should == "OK, success do VTWeb transaction, please go to redirect_url"
|
16
|
+
result.success?.should == true
|
17
|
+
result.redirect_url.should be_present
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should send charge vt-web request" do
|
22
|
+
VCR.use_cassette('charge_direct') do
|
23
|
+
result = Veritrans.charge("permata", transaction: { order_id: Time.now.to_s, gross_amount: 100_000 })
|
24
|
+
|
25
|
+
result.status_message.should == "Success, PERMATA VA transaction is successful"
|
26
|
+
result.success?.should == true
|
27
|
+
result.permata_va_number.should be_present
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should send status request" do
|
32
|
+
VCR.use_cassette('status_fail') do
|
33
|
+
result = Veritrans.status("not-exists")
|
34
|
+
result.success?.should == false
|
35
|
+
result.status_message.should == "The requested resource is not found"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should send status request and get response" do
|
40
|
+
VCR.use_cassette('status_success') do
|
41
|
+
result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 } )
|
42
|
+
result = Veritrans.status(result_charge.order_id)
|
43
|
+
result.success?.should == true
|
44
|
+
result.status_message.should == "Success, transaction found"
|
45
|
+
result.transaction_status.should == "pending"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should send status request and get response" do
|
50
|
+
VCR.use_cassette('cancel_failed') do
|
51
|
+
result = Veritrans.cancel("not-exists")
|
52
|
+
result.success?.should == false
|
53
|
+
result.status_message.should == "The requested resource is not found"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should send status request and get response" do
|
58
|
+
VCR.use_cassette('cancel_success') do
|
59
|
+
result_charge = Veritrans.charge('permata', transaction: { order_id: Time.now.to_i, gross_amount: 100_000 } )
|
60
|
+
result = Veritrans.cancel(result_charge.order_id)
|
61
|
+
result.success?.should == true
|
62
|
+
result.status_message.should == "Success, transaction is canceled"
|
63
|
+
result.transaction_status.should == "cancel"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should send approve request" do
|
68
|
+
VCR.use_cassette('approve_failed') do
|
69
|
+
result = Veritrans.cancel("not-exists")
|
70
|
+
result.success?.should == false
|
71
|
+
result.status_message.should == "The requested resource is not found"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should send capture request" do
|
76
|
+
VCR.use_cassette('capture_failed') do
|
77
|
+
result = Veritrans.capture("not-exists", 1000)
|
78
|
+
result.success?.should == false
|
79
|
+
result.status_message.should == "The requested resource is not found"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
describe Veritrans::Config do
|
2
|
+
|
3
|
+
before do
|
4
|
+
hide_const("Rails")
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should set Veritras as self inside config block" do
|
8
|
+
Veritrans.config do
|
9
|
+
self.should == Veritrans
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have sandbox api_host by defualt" do
|
14
|
+
Veritrans.config.api_host.should == "https://api.sandbox.veritrans.co.id"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set client key and server key" do
|
18
|
+
Veritrans.config do
|
19
|
+
config.client_key = "kk-1"
|
20
|
+
config.server_key = "sk-1"
|
21
|
+
end
|
22
|
+
|
23
|
+
Veritrans.config.client_key.should == "kk-1"
|
24
|
+
Veritrans.config.server_key.should == "sk-1"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should load config" do
|
28
|
+
data = Veritrans.config.load_config("./spec/configs/veritrans_flat.yml")
|
29
|
+
data.should == {"client_key" => "flat_client_key", "server_key" => "flat_server_key"}
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should load config according to hash" do
|
33
|
+
data = Veritrans.config.load_config("./spec/configs/veritrans.yml#development")
|
34
|
+
data.should == {"client_key" => "spec_client_key", "server_key" => "spec_server_key"}
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should load config for Rails.env" do
|
38
|
+
stub_const("Rails", Class.new {
|
39
|
+
def self.env
|
40
|
+
"test"
|
41
|
+
end
|
42
|
+
})
|
43
|
+
|
44
|
+
data = Veritrans.config.load_config("./spec/configs/veritrans.yml")
|
45
|
+
data.should == {"client_key" => "test_client_key", "server_key" => "test_server_key"}
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
describe Veritrans do
|
2
|
+
before do
|
3
|
+
stub_const("CONFIG", {})
|
4
|
+
Veritrans.logger = Logger.new(STDOUT)
|
5
|
+
Veritrans.file_logger = Logger.new(STDOUT)
|
6
|
+
Veritrans.setup do
|
7
|
+
config.load_yml "./example/veritrans.yml#development"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
if Veritrans.events.listeners
|
13
|
+
Veritrans.events.listeners.clear
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
JSON_RESPONSE = '{
|
18
|
+
"status_code": "200",
|
19
|
+
"status_message": "Success, transaction found",
|
20
|
+
"transaction_id": "b1cbcc66-5608-4af1-a3ed-0f152f9ed871",
|
21
|
+
"order_id": "testing-0.2703-1415600236",
|
22
|
+
"payment_type": "credit_card",
|
23
|
+
"transaction_time": "2014-11-10 13:17:33",
|
24
|
+
"transaction_status": "settlement",
|
25
|
+
"gross_amount": "30000.00",
|
26
|
+
"masked_card": "481111-1114",
|
27
|
+
"fraud_status": "accept",
|
28
|
+
"approval_code": "1415600254322",
|
29
|
+
"bank": "bni"
|
30
|
+
}'
|
31
|
+
|
32
|
+
DOUBLE_ENCODED_JSON_RESPONSE = JSON.dump(JSON_RESPONSE)
|
33
|
+
|
34
|
+
def stub_vt_status_response
|
35
|
+
stub_request(:any, /.*veritrans.*/).to_return(lambda {|request|
|
36
|
+
{status: 200, body: JSON_RESPONSE}
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should work with single encoded json" do
|
41
|
+
Veritrans.events.subscribe('payment.success') do |payment|
|
42
|
+
@payment = payment
|
43
|
+
end
|
44
|
+
|
45
|
+
stub_vt_status_response
|
46
|
+
|
47
|
+
handler = Rack::MockRequest.new(Veritrans::Events.new)
|
48
|
+
silence_stream(STDOUT) do
|
49
|
+
handler.post("http://example.com/", input: JSON_RESPONSE)
|
50
|
+
end
|
51
|
+
|
52
|
+
@payment.order_id.should == "testing-0.2703-1415600236"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should work with double encoded json" do
|
56
|
+
Veritrans.events.subscribe('payment.success') do |payment|
|
57
|
+
@payment = payment
|
58
|
+
end
|
59
|
+
|
60
|
+
stub_vt_status_response
|
61
|
+
|
62
|
+
handler = Rack::MockRequest.new(Veritrans::Events.new)
|
63
|
+
silence_stream(STDOUT) do
|
64
|
+
handler.post("http://example.com/", input: DOUBLE_ENCODED_JSON_RESPONSE)
|
65
|
+
end
|
66
|
+
|
67
|
+
@payment.order_id.should == "testing-0.2703-1415600236"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
describe Veritrans do
|
2
|
+
|
3
|
+
after do
|
4
|
+
Veritrans.logger = nil
|
5
|
+
Veritrans.file_logger = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should set logger" do
|
9
|
+
Veritrans.logger = :nothing
|
10
|
+
Veritrans.logger.should == :nothing
|
11
|
+
|
12
|
+
Veritrans.file_logger = :nothing2
|
13
|
+
Veritrans.file_logger.should == :nothing2
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "widthout rails" do
|
17
|
+
before do
|
18
|
+
hide_const("Rails")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should log to stdout when there is no rails" do
|
22
|
+
Veritrans.logger.instance_variable_get(:@logdev).dev.should == $stdout
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set file_logger" do
|
26
|
+
Veritrans.file_logger.instance_variable_get(:@logdev).filename.should == "/dev/null"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "width rails" do
|
32
|
+
before do
|
33
|
+
FileUtils.mkdir_p("/tmp/log")
|
34
|
+
allow(Rails).to receive(:logger).and_return(Logger.new(STDERR))
|
35
|
+
allow(Rails).to receive(:root).and_return(Pathname.new("/tmp"))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should use rails logger" do
|
39
|
+
Veritrans.logger.should == Rails.logger
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should set file_logger" do
|
43
|
+
Veritrans.file_logger.instance_variable_get(:@logdev).filename.should == "/tmp/log/veritrans.log"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/testing_webhooks.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Webhooks
|
2
|
+
|
3
|
+
For better security we recommend to use webhooks and check status of transaction via api.
|
4
|
+
|
5
|
+
Webhook is http post request that veritrans send to merchant's server when any transaction change status.
|
6
|
+
It can be success transaction, can be failed transaction, and when transaction settled.
|
7
|
+
|
8
|
+
Now you can set webhook url at https://my.sandbox.veritrans.co.id/settings/vtweb_configuration
|
9
|
+
|
10
|
+
## Veritrans command line tool
|
11
|
+
|
12
|
+
You can send testing request from command line:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
gem install veritrans
|
16
|
+
|
17
|
+
# Send default data, payment which not exists
|
18
|
+
veritrans testhook http://localhost:3000/vt_events
|
19
|
+
|
20
|
+
# Get fetch real payment information and send
|
21
|
+
veritrans testhook -o my-order-1 -c ~/path/to/veritrans.yml http://localhost:3000/vt_events
|
22
|
+
```
|
23
|
+
|
24
|
+
## Test locally
|
25
|
+
|
26
|
+
Most of computers don't have public ip address, in that case you can't simply receive http requests on your computer.
|
27
|
+
If you're using wi-fi router you need to change router settings to make a route from router to your local computer.
|
28
|
+
To check if your ip is public, you can open http://www.whatismyip.com/, make some local http server and try to open it.
|
29
|
+
For example if your IP address is `117.102.113.10` and you started rails on port 3000, try to open http://117.102.113.10:3000 in your browser;
|
30
|
+
if you able to see your application, then your IP is public.
|
31
|
+
|
32
|
+
There are several tools to accept http requests if you can't do it directly.
|
33
|
+
|
34
|
+
* npm localtunnel
|
35
|
+
* gem [proxylocal](http://proxylocal.com/)
|
36
|
+
* https://ngrok.com/
|
37
|
+
* gem [ultrahook](http://www.ultrahook.com/)
|
38
|
+
* gem [forward](https://forwardhq.com/)
|
39
|
+
|
40
|
+
Or you can make ssh tunnel to your globally accessible server (if you have one)
|
41
|
+
|
42
|
+
ssh -N -R 127.0.0.1:13000:localhost:3000 remoteuser@remote-host.com
|
43
|
+
# 3000 - port on your local computer
|
44
|
+
# 13000 - port witch will be accessible on remote computer
|
45
|
+
# remoteuser@remote-host.com - your user and host
|
46
|
+
|
47
|
+
Also you can collect requests online for further inspection.
|
48
|
+
|
49
|
+
* http://requestb.in/
|
50
|
+
* http://httpi.pe/
|
51
|
+
* http://respondto.it/
|
52
|
+
|
53
|
+
|
54
|
+
## Trigger callback
|
55
|
+
|
56
|
+
To receive http notification from veritrans you can try to make transaction or use callback tester in merchant portal
|
57
|
+
|
58
|
+
https://my.sandbox.veritrans.co.id/settings/vtweb_configuration/test_callback
|
59
|
+
|
60
|
+
|
61
|
+
## Format
|
62
|
+
|
63
|
+
Veritrans will try to send message in JSON format:
|
64
|
+
|
65
|
+
```js
|
66
|
+
// Content-Type: application/json
|
67
|
+
{
|
68
|
+
"status_code": "200",
|
69
|
+
"status_message": "Veritrans payment notification",
|
70
|
+
"transaction_id": "826acc53-14e0-4ae7-95e2-845bf0311579",
|
71
|
+
"order_id": "2014040745",
|
72
|
+
"payment_type": "credit_card",
|
73
|
+
"transaction_time": "2014-04-07 16:22:36",
|
74
|
+
"transaction_status": "capture",
|
75
|
+
"fraud_status": "accept",
|
76
|
+
"masked_card": "411111-1111",
|
77
|
+
"gross_amount": "2700"
|
78
|
+
}
|
79
|
+
|
80
|
+
```
|
data/veritrans.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.push(File.expand_path("../lib", __FILE__))
|
2
|
+
require 'veritrans/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "veritrans"
|
6
|
+
s.version = Veritrans::VERSION
|
7
|
+
s.author = ["Veritrans Dev Team"]
|
8
|
+
s.email = ["dev@veritrans.co.id"]
|
9
|
+
s.homepage = "https://github.com/veritrans/veritrans-ruby"
|
10
|
+
s.summary = %q{Veritrans ruby library}
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = []
|
14
|
+
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.executables = ["veritrans"]
|
17
|
+
|
18
|
+
s.add_runtime_dependency "excon", "~> 0.20"
|
19
|
+
|
20
|
+
s.add_development_dependency "rspec", ">= 2.9.0"
|
21
|
+
s.add_development_dependency "rails"
|
22
|
+
s.add_development_dependency 'webmock'
|
23
|
+
end
|