veritrans 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.idea/.gitignore +8 -0
- data/.rubocop.yml +1 -1
- data/.travis.yml +2 -1
- data/CHANGELOG.md +13 -0
- data/Gemfile +2 -11
- data/Gemfile.lock +116 -145
- data/Maintaining.MD +8 -0
- data/README.md +247 -278
- data/api_reference.md +482 -173
- data/example/coreapi/core_api_credit_card_example.rb +66 -0
- data/example/coreapi/readme.md +4 -0
- data/example/sinatra/Gemfile +7 -0
- data/example/sinatra/README.md +4 -6
- data/example/sinatra/index.erb +180 -192
- data/example/sinatra/response.erb +1 -40
- data/example/sinatra/snap.erb +33 -0
- data/example/sinatra/snap_redirect.erb +10 -0
- data/example/sinatra/webapp.rb +113 -0
- data/example/snap/readme.md +4 -0
- data/example/snap/snap_example.rb +39 -0
- data/lib/test/all.rb +1 -0
- data/lib/test/api_test.rb +319 -0
- data/lib/test/config_test.rb +26 -0
- data/lib/test/gopay_tokenization_test.rb +80 -0
- data/lib/test/snap_test.rb +79 -0
- data/lib/test/subscription_test.rb +116 -0
- data/lib/test/transaction_test.rb +160 -0
- data/lib/veritrans/api.rb +105 -8
- data/lib/veritrans/client.rb +40 -7
- data/lib/veritrans/config.rb +26 -3
- data/lib/veritrans/midtrans_error.rb +15 -0
- data/lib/veritrans/version.rb +1 -1
- data/lib/veritrans.rb +5 -6
- data/veritrans.gemspec +1 -2
- metadata +25 -248
- data/.rspec +0 -2
- data/Procfile +0 -1
- data/Rakefile +0 -16
- data/bin/midtrans +0 -3
- data/bin/veritrans +0 -68
- data/example/rails/cable/Gemfile +0 -48
- data/example/rails/cable/Gemfile.lock +0 -184
- data/example/rails/cable/README.md +0 -29
- data/example/rails/cable/Rakefile +0 -6
- data/example/rails/cable/app/assets/config/manifest.js +0 -3
- data/example/rails/cable/app/assets/images/.keep +0 -0
- data/example/rails/cable/app/assets/javascripts/application.js +0 -15
- data/example/rails/cable/app/assets/javascripts/cable.js +0 -13
- data/example/rails/cable/app/assets/javascripts/channels/.keep +0 -0
- data/example/rails/cable/app/assets/javascripts/chats.js +0 -39
- data/example/rails/cable/app/assets/javascripts/rooms.js +0 -55
- data/example/rails/cable/app/assets/stylesheets/application.css +0 -16
- data/example/rails/cable/app/assets/stylesheets/chatbox.scss +0 -31
- data/example/rails/cable/app/assets/stylesheets/peoplebox.scss +0 -6
- data/example/rails/cable/app/channels/application_cable/channel.rb +0 -4
- data/example/rails/cable/app/channels/application_cable/connection.rb +0 -4
- data/example/rails/cable/app/channels/rooms_texting_channel.rb +0 -13
- data/example/rails/cable/app/controllers/application_controller.rb +0 -3
- data/example/rails/cable/app/controllers/chats_controller.rb +0 -18
- data/example/rails/cable/app/controllers/concerns/.keep +0 -0
- data/example/rails/cable/app/controllers/pays_controller.rb +0 -28
- data/example/rails/cable/app/controllers/rooms_controller.rb +0 -4
- data/example/rails/cable/app/helpers/application_helper.rb +0 -2
- data/example/rails/cable/app/helpers/chats_helper.rb +0 -2
- data/example/rails/cable/app/helpers/rooms_helper.rb +0 -5
- data/example/rails/cable/app/jobs/application_job.rb +0 -2
- data/example/rails/cable/app/jobs/chat_broadcaster_job.rb +0 -15
- data/example/rails/cable/app/mailers/application_mailer.rb +0 -4
- data/example/rails/cable/app/models/application_record.rb +0 -3
- data/example/rails/cable/app/models/chat.rb +0 -41
- data/example/rails/cable/app/models/concerns/.keep +0 -0
- data/example/rails/cable/app/models/order.rb +0 -2
- data/example/rails/cable/app/models/user.rb +0 -2
- data/example/rails/cable/app/views/chats/_chat.html.erb +0 -18
- data/example/rails/cable/app/views/layouts/application.html.erb +0 -19
- data/example/rails/cable/app/views/layouts/mailer.html.erb +0 -13
- data/example/rails/cable/app/views/layouts/mailer.text.erb +0 -1
- data/example/rails/cable/app/views/rooms/_chatbox.html.erb +0 -13
- data/example/rails/cable/app/views/rooms/_online_people.html.erb +0 -53
- data/example/rails/cable/app/views/rooms/index.html.erb +0 -9
- data/example/rails/cable/bin/bundle +0 -3
- data/example/rails/cable/bin/rails +0 -9
- data/example/rails/cable/bin/rake +0 -9
- data/example/rails/cable/bin/setup +0 -34
- data/example/rails/cable/bin/spring +0 -16
- data/example/rails/cable/bin/update +0 -29
- data/example/rails/cable/config/application.rb +0 -16
- data/example/rails/cable/config/boot.rb +0 -3
- data/example/rails/cable/config/cable.yml +0 -9
- data/example/rails/cable/config/database.yml +0 -20
- data/example/rails/cable/config/environment.rb +0 -5
- data/example/rails/cable/config/environments/development.rb +0 -57
- data/example/rails/cable/config/environments/production.rb +0 -86
- data/example/rails/cable/config/environments/test.rb +0 -42
- data/example/rails/cable/config/initializers/application_controller_renderer.rb +0 -6
- data/example/rails/cable/config/initializers/assets.rb +0 -11
- data/example/rails/cable/config/initializers/backtrace_silencers.rb +0 -7
- data/example/rails/cable/config/initializers/cookies_serializer.rb +0 -5
- data/example/rails/cable/config/initializers/filter_parameter_logging.rb +0 -4
- data/example/rails/cable/config/initializers/inflections.rb +0 -16
- data/example/rails/cable/config/initializers/mime_types.rb +0 -4
- data/example/rails/cable/config/initializers/new_framework_defaults.rb +0 -24
- data/example/rails/cable/config/initializers/session_store.rb +0 -3
- data/example/rails/cable/config/initializers/sidekiq.rb +0 -2
- data/example/rails/cable/config/initializers/veritrans.rb +0 -46
- data/example/rails/cable/config/initializers/wrap_parameters.rb +0 -14
- data/example/rails/cable/config/locales/en.yml +0 -23
- data/example/rails/cable/config/puma.rb +0 -47
- data/example/rails/cable/config/routes.rb +0 -18
- data/example/rails/cable/config/secrets.yml +0 -22
- data/example/rails/cable/config/spring.rb +0 -6
- data/example/rails/cable/config/veritrans.yml +0 -13
- data/example/rails/cable/config.ru +0 -5
- data/example/rails/cable/db/development.sqlite3 +0 -0
- data/example/rails/cable/db/migrate/20161215070044_create_chats.rb +0 -10
- data/example/rails/cable/db/migrate/20161215072021_create_users.rb +0 -10
- data/example/rails/cable/db/migrate/20161219110219_create_orders.rb +0 -11
- data/example/rails/cable/db/schema.rb +0 -37
- data/example/rails/cable/db/seeds.rb +0 -41
- data/example/rails/cable/db/test.sqlite3 +0 -0
- data/example/rails/cable/lib/assets/.keep +0 -0
- data/example/rails/cable/lib/tasks/.keep +0 -0
- data/example/rails/cable/log/.keep +0 -0
- data/example/rails/cable/public/404.html +0 -67
- data/example/rails/cable/public/422.html +0 -67
- data/example/rails/cable/public/500.html +0 -66
- data/example/rails/cable/public/apple-touch-icon-precomposed.png +0 -0
- data/example/rails/cable/public/apple-touch-icon.png +0 -0
- data/example/rails/cable/public/favicon.ico +0 -0
- data/example/rails/cable/public/images/avatar1.jpg +0 -0
- data/example/rails/cable/public/images/avatar2.jpg +0 -0
- data/example/rails/cable/public/images/avatar3.jpg +0 -0
- data/example/rails/cable/public/images/avatar4.jpg +0 -0
- data/example/rails/cable/public/images/avatar5.jpg +0 -0
- data/example/rails/cable/public/images/avatar6.jpg +0 -0
- data/example/rails/cable/public/robots.txt +0 -5
- data/example/rails/cable/vendor/assets/javascripts/.keep +0 -0
- data/example/rails/cable/vendor/assets/stylesheets/.keep +0 -0
- data/example/rails/cable/vendor/assets/stylesheets/photon.css +0 -2333
- data/example/rails/simplepay/Gemfile +0 -54
- data/example/rails/simplepay/Gemfile.lock +0 -178
- data/example/rails/simplepay/README.md +0 -30
- data/example/rails/simplepay/Rakefile +0 -6
- data/example/rails/simplepay/app/assets/config/manifest.js +0 -3
- data/example/rails/simplepay/app/assets/images/.keep +0 -0
- data/example/rails/simplepay/app/assets/javascripts/application.js +0 -16
- data/example/rails/simplepay/app/assets/javascripts/cable.js +0 -13
- data/example/rails/simplepay/app/assets/javascripts/channels/.keep +0 -0
- data/example/rails/simplepay/app/assets/javascripts/pay.js +0 -18
- data/example/rails/simplepay/app/assets/stylesheets/application.css +0 -15
- data/example/rails/simplepay/app/assets/stylesheets/style.css +0 -254
- data/example/rails/simplepay/app/channels/application_cable/channel.rb +0 -4
- data/example/rails/simplepay/app/channels/application_cable/connection.rb +0 -4
- data/example/rails/simplepay/app/controllers/application_controller.rb +0 -3
- data/example/rails/simplepay/app/controllers/concerns/.keep +0 -0
- data/example/rails/simplepay/app/controllers/home_controller.rb +0 -16
- data/example/rails/simplepay/app/controllers/pay_controller.rb +0 -10
- data/example/rails/simplepay/app/helpers/application_helper.rb +0 -2
- data/example/rails/simplepay/app/helpers/pay_helper.rb +0 -2
- data/example/rails/simplepay/app/jobs/application_job.rb +0 -2
- data/example/rails/simplepay/app/mailers/application_mailer.rb +0 -4
- data/example/rails/simplepay/app/models/application_record.rb +0 -3
- data/example/rails/simplepay/app/models/concerns/.keep +0 -0
- data/example/rails/simplepay/app/models/order.rb +0 -2
- data/example/rails/simplepay/app/views/home/index.html.erb +0 -19
- data/example/rails/simplepay/app/views/layouts/application.html.erb +0 -15
- data/example/rails/simplepay/app/views/layouts/mailer.html.erb +0 -13
- data/example/rails/simplepay/app/views/layouts/mailer.text.erb +0 -1
- data/example/rails/simplepay/app/views/pay/notify.html.erb +0 -2
- data/example/rails/simplepay/bin/bundle +0 -3
- data/example/rails/simplepay/bin/rails +0 -9
- data/example/rails/simplepay/bin/rake +0 -9
- data/example/rails/simplepay/bin/setup +0 -34
- data/example/rails/simplepay/bin/spring +0 -16
- data/example/rails/simplepay/bin/update +0 -29
- data/example/rails/simplepay/config/application.rb +0 -15
- data/example/rails/simplepay/config/boot.rb +0 -3
- data/example/rails/simplepay/config/cable.yml +0 -9
- data/example/rails/simplepay/config/database.yml +0 -25
- data/example/rails/simplepay/config/environment.rb +0 -5
- data/example/rails/simplepay/config/environments/development.rb +0 -57
- data/example/rails/simplepay/config/environments/production.rb +0 -86
- data/example/rails/simplepay/config/environments/test.rb +0 -42
- data/example/rails/simplepay/config/initializers/application_controller_renderer.rb +0 -6
- data/example/rails/simplepay/config/initializers/assets.rb +0 -11
- data/example/rails/simplepay/config/initializers/backtrace_silencers.rb +0 -7
- data/example/rails/simplepay/config/initializers/cookies_serializer.rb +0 -5
- data/example/rails/simplepay/config/initializers/filter_parameter_logging.rb +0 -4
- data/example/rails/simplepay/config/initializers/inflections.rb +0 -16
- data/example/rails/simplepay/config/initializers/mime_types.rb +0 -4
- data/example/rails/simplepay/config/initializers/new_framework_defaults.rb +0 -24
- data/example/rails/simplepay/config/initializers/session_store.rb +0 -3
- data/example/rails/simplepay/config/initializers/veritrans.rb +0 -46
- data/example/rails/simplepay/config/initializers/wrap_parameters.rb +0 -14
- data/example/rails/simplepay/config/locales/en.yml +0 -23
- data/example/rails/simplepay/config/puma.rb +0 -47
- data/example/rails/simplepay/config/routes.rb +0 -5
- data/example/rails/simplepay/config/secrets.yml +0 -22
- data/example/rails/simplepay/config/spring.rb +0 -6
- data/example/rails/simplepay/config/veritrans.yml +0 -18
- data/example/rails/simplepay/config.ru +0 -5
- data/example/rails/simplepay/db/development.sqlite3 +0 -0
- data/example/rails/simplepay/db/migrate/20161221090855_create_orders.rb +0 -10
- data/example/rails/simplepay/db/schema.rb +0 -22
- data/example/rails/simplepay/db/seeds.rb +0 -7
- data/example/rails/simplepay/db/test.sqlite3 +0 -0
- data/example/rails/simplepay/lib/assets/.keep +0 -0
- data/example/rails/simplepay/lib/tasks/.keep +0 -0
- data/example/rails/simplepay/log/.keep +0 -0
- data/example/rails/simplepay/public/404.html +0 -67
- data/example/rails/simplepay/public/422.html +0 -67
- data/example/rails/simplepay/public/500.html +0 -66
- data/example/rails/simplepay/public/apple-touch-icon-precomposed.png +0 -0
- data/example/rails/simplepay/public/apple-touch-icon.png +0 -0
- data/example/rails/simplepay/public/favicon.ico +0 -0
- data/example/rails/simplepay/public/robots.txt +0 -5
- data/example/rails/simplepay/vendor/assets/javascripts/.keep +0 -0
- data/example/rails/simplepay/vendor/assets/stylesheets/.keep +0 -0
- data/example/sinatra/config.ru +0 -9
- data/example/sinatra/localization.erb +0 -249
- data/example/sinatra/points.erb +0 -188
- data/example/sinatra/recurring.erb +0 -201
- data/example/sinatra/sinatra.rb +0 -194
- data/example/sinatra/style.css +0 -137
- data/example/sinatra/veritrans.yml +0 -11
- data/example/sinatra/widget.erb +0 -63
- data/lib/generators/templates/assets/credit_card_form.js +0 -57
- data/lib/generators/templates/payments_controller.rb +0 -85
- data/lib/generators/templates/veritrans.rb +0 -46
- data/lib/generators/templates/veritrans.yml +0 -18
- data/lib/generators/templates/views/_credit_card_form.erb +0 -42
- data/lib/generators/templates/views/_veritrans_include.erb +0 -10
- data/lib/generators/templates/views/payments/create.erb +0 -15
- data/lib/generators/templates/views/payments/new.erb +0 -6
- data/lib/generators/veritrans/install_generator.rb +0 -32
- data/lib/generators/veritrans/payment_form_generator.rb +0 -45
- data/lib/veritrans/cli.rb +0 -161
- data/lib/veritrans/testing.rb +0 -156
- data/spec/cli_spec.rb +0 -83
- data/spec/configs/real_key.yml +0 -4
- data/spec/configs/veritrans.yml +0 -7
- data/spec/configs/veritrans_flat.yml +0 -2
- data/spec/configs/veritrans_with_erb.yml +0 -2
- data/spec/fixtures/approve_failed.yml +0 -48
- data/spec/fixtures/cancel_failed.yml +0 -48
- data/spec/fixtures/cancel_success.yml +0 -126
- data/spec/fixtures/capture_failed.yml +0 -48
- data/spec/fixtures/charge.yml +0 -50
- data/spec/fixtures/charge_direct.yml +0 -56
- data/spec/fixtures/charge_vtweb.yml +0 -50
- data/spec/fixtures/cli_test_1111-not-exists.yml +0 -45
- data/spec/fixtures/cli_test_not_exists.yml +0 -45
- data/spec/fixtures/cli_test_real_txn.yml +0 -55
- data/spec/fixtures/cli_test_unauthorized.yml +0 -47
- data/spec/fixtures/deny_failed.yml +0 -144
- data/spec/fixtures/events_test_real_txn.yml +0 -55
- data/spec/fixtures/expire_failed.yml +0 -50
- data/spec/fixtures/expire_success.yml +0 -56
- data/spec/fixtures/midtrans_status.yml +0 -117
- data/spec/fixtures/refund_failed.yml +0 -54
- data/spec/fixtures/status_fail.yml +0 -48
- data/spec/fixtures/status_success.yml +0 -128
- data/spec/fixtures/test_token.yml +0 -49
- data/spec/midtrans_rename_spec.rb +0 -27
- data/spec/rails_plugin_spec.rb +0 -317
- data/spec/spec_helper.rb +0 -71
- data/spec/veritrans_client_spec.rb +0 -235
- data/spec/veritrans_config_spec.rb +0 -70
- data/spec/veritrans_events_spec.rb +0 -72
- data/spec/veritrans_logger_spec.rb +0 -46
- data/spec/veritrans_snap_spec.rb +0 -54
- data/spec/veritrans_testing_spec.rb +0 -184
- data/testing_webhooks.md +0 -78
@@ -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
|
@@ -0,0 +1,160 @@
|
|
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_charge_permata_va
|
17
|
+
result = @mt_test.charge(
|
18
|
+
{
|
19
|
+
"payment_type": "bank_transfer",
|
20
|
+
"transaction_details": {
|
21
|
+
"gross_amount": 10000,
|
22
|
+
"order_id": "ruby-lib-test-#{Time.now.to_i}"
|
23
|
+
},
|
24
|
+
"bank_transfer": {
|
25
|
+
"bank": "permata",
|
26
|
+
"va_number": "1234567891"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
)
|
30
|
+
assert_equal 201, result.status_code
|
31
|
+
assert_equal "pending", result.transaction_status
|
32
|
+
assert_equal "Success, PERMATA VA transaction is successful", result.status_message
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_cancel_permata_va
|
36
|
+
charge = @mt_test.charge(
|
37
|
+
{
|
38
|
+
"payment_type": "bank_transfer",
|
39
|
+
"transaction_details": {
|
40
|
+
"gross_amount": 10000,
|
41
|
+
"order_id": "ruby-lib-test-#{Time.now.to_i}"
|
42
|
+
},
|
43
|
+
"bank_transfer": {
|
44
|
+
"bank": "permata",
|
45
|
+
"va_number": "1234567891"
|
46
|
+
}
|
47
|
+
}
|
48
|
+
)
|
49
|
+
cancel = @mt_test.cancel(charge.transaction_id)
|
50
|
+
assert_equal 200, cancel.status_code
|
51
|
+
assert_equal "cancel", cancel.transaction_status
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_expire_permata_va
|
55
|
+
charge = @mt_test.charge(
|
56
|
+
{
|
57
|
+
"payment_type": "bank_transfer",
|
58
|
+
"transaction_details": {
|
59
|
+
"gross_amount": 10000,
|
60
|
+
"order_id": "ruby-lib-test-#{Time.now.to_i}"
|
61
|
+
},
|
62
|
+
"bank_transfer": {
|
63
|
+
"bank": "permata",
|
64
|
+
"va_number": "1234567891"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
)
|
68
|
+
expire = @mt_test.expire(charge.transaction_id)
|
69
|
+
assert_equal "Success, transaction has expired", expire.status_message
|
70
|
+
assert_equal 407, expire.status_code
|
71
|
+
assert_equal "expire", expire.transaction_status
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_get_status_transaction
|
75
|
+
charge = @mt_test.charge(
|
76
|
+
{
|
77
|
+
"payment_type": "bank_transfer",
|
78
|
+
"transaction_details": {
|
79
|
+
"gross_amount": 10000,
|
80
|
+
"order_id": "ruby-lib-test-#{Time.now.to_i}"
|
81
|
+
},
|
82
|
+
"bank_transfer": {
|
83
|
+
"bank": "permata",
|
84
|
+
"va_number": "1234567891"
|
85
|
+
}
|
86
|
+
}
|
87
|
+
)
|
88
|
+
result = @mt_test.status(charge.transaction_id)
|
89
|
+
assert_equal 201, result.status_code
|
90
|
+
assert_equal "Success, transaction is found", result.status_message
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_approve_transaction
|
94
|
+
card = {
|
95
|
+
card_number: 5510111111111115,
|
96
|
+
card_cvv: 123,
|
97
|
+
card_exp_month: 12,
|
98
|
+
card_exp_year: 2025
|
99
|
+
}
|
100
|
+
get_token = @mt_test.test_token(card)
|
101
|
+
charge = @mt_test.charge(
|
102
|
+
{
|
103
|
+
"payment_type": "credit_card",
|
104
|
+
"transaction_details": {
|
105
|
+
"gross_amount": 10000,
|
106
|
+
"order_id": "ruby-lib-test-#{Time.now.to_i}"
|
107
|
+
},
|
108
|
+
"credit_card": {
|
109
|
+
"token_id": "#{get_token.token_id}",
|
110
|
+
"authentication": "false"
|
111
|
+
}
|
112
|
+
}
|
113
|
+
)
|
114
|
+
result = @mt_test.approve(charge.transaction_id)
|
115
|
+
assert_equal "Success, transaction is approved", result.status_message
|
116
|
+
assert_equal 200, result.status_code
|
117
|
+
assert_equal "accept", result.fraud_status
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_deny_transaction
|
121
|
+
card = {
|
122
|
+
card_number: 5510111111111115,
|
123
|
+
card_cvv: 123,
|
124
|
+
card_exp_month: 12,
|
125
|
+
card_exp_year: 2025
|
126
|
+
}
|
127
|
+
get_token = @mt_test.test_token(card)
|
128
|
+
charge = @mt_test.charge(
|
129
|
+
{
|
130
|
+
"payment_type": "credit_card",
|
131
|
+
"transaction_details": {
|
132
|
+
"gross_amount": 10000,
|
133
|
+
"order_id": "ruby-lib-test-#{Time.now.to_i}"
|
134
|
+
},
|
135
|
+
"credit_card": {
|
136
|
+
"token_id": "#{get_token.token_id}",
|
137
|
+
"authentication": "false"
|
138
|
+
}
|
139
|
+
}
|
140
|
+
)
|
141
|
+
result = @mt_test.deny(charge.transaction_id)
|
142
|
+
assert_equal 200, result.status_code
|
143
|
+
assert_equal "Success, transaction is denied", result.status_message
|
144
|
+
assert_equal "deny", result.fraud_status
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_fail_refund_transaction
|
148
|
+
begin
|
149
|
+
param = {
|
150
|
+
"refund_key": "reference1",
|
151
|
+
"amount": 5000,
|
152
|
+
"reason": "for some reason"
|
153
|
+
}
|
154
|
+
@mt_test.refund("dummy-order-id", param)
|
155
|
+
rescue MidtransError => e
|
156
|
+
assert_equal "404", e.status
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
data/lib/veritrans/api.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Veritrans API methods
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'erb'
|
4
4
|
|
5
5
|
class Veritrans
|
6
6
|
module Api
|
@@ -47,10 +47,13 @@ class Veritrans
|
|
47
47
|
|
48
48
|
def test_token(options = {})
|
49
49
|
options[:client_key] = config.client_key
|
50
|
-
request_with_logging(:get, config.api_host + '/v2/token', options)
|
50
|
+
request_with_logging(:get, config.api_host + '/v2/token', options)
|
51
51
|
end
|
52
52
|
|
53
|
+
alias_method :create_card_token, :test_token
|
54
|
+
|
53
55
|
# POST https://app.sandbox.midtrans.com/snap/v1/transactions
|
56
|
+
# Create Snap payment page, with this version returning full API response
|
54
57
|
def create_snap_token(options = {})
|
55
58
|
result = request_with_logging(:post, config.api_host.sub('//api.', '//app.') + "/snap/v1/transactions", options)
|
56
59
|
Veritrans::SnapResult.new(result.response, result.url, result.request_options, result.time)
|
@@ -59,6 +62,20 @@ class Veritrans
|
|
59
62
|
alias_method :create_widget_token, :create_snap_token
|
60
63
|
alias_method :create_snap_redirect_url, :create_snap_token
|
61
64
|
|
65
|
+
# POST https://app.sandbox.midtrans.com/snap/v1/transactions
|
66
|
+
# Create Snap payment page, with this version returning token
|
67
|
+
def create_snap_token_string(options = {})
|
68
|
+
result = create_snap_token(options)
|
69
|
+
result.token
|
70
|
+
end
|
71
|
+
|
72
|
+
# POST https://app.sandbox.midtrans.com/snap/v1/transactions
|
73
|
+
# Create Snap payment page, with this version returning redirect url
|
74
|
+
def create_snap_redirect_url_str(options = {})
|
75
|
+
result = create_snap_token(options)
|
76
|
+
result.redirect_url
|
77
|
+
end
|
78
|
+
|
62
79
|
# POST /v2/{id}/cancel
|
63
80
|
# Docs https://api-docs.midtrans.com/#cancel-transaction
|
64
81
|
def cancel(payment_id, options = {})
|
@@ -66,7 +83,7 @@ class Veritrans
|
|
66
83
|
raise ArgumentError, "parameter payment_id can not be blank (got #{payment_id.class} : #{payment_id.inspect})"
|
67
84
|
end
|
68
85
|
|
69
|
-
request_with_logging(:post, config.api_host + "/v2/#{
|
86
|
+
request_with_logging(:post, config.api_host + "/v2/#{ERB::Util.url_encode(payment_id)}/cancel", options)
|
70
87
|
end
|
71
88
|
|
72
89
|
# POST /v2/{id}/approve
|
@@ -76,7 +93,7 @@ class Veritrans
|
|
76
93
|
raise ArgumentError, "parameter payment_id can not be blank (got #{payment_id.class} : #{payment_id.inspect})"
|
77
94
|
end
|
78
95
|
|
79
|
-
request_with_logging(:post, config.api_host + "/v2/#{
|
96
|
+
request_with_logging(:post, config.api_host + "/v2/#{ERB::Util.url_encode(payment_id)}/approve", options)
|
80
97
|
end
|
81
98
|
|
82
99
|
# POST /v2/{id}/refund
|
@@ -96,7 +113,7 @@ class Veritrans
|
|
96
113
|
raise ArgumentError, "parameter payment_id can not be blank (got #{payment_id.class} : #{payment_id.inspect})"
|
97
114
|
end
|
98
115
|
|
99
|
-
get(config.api_host + "/v2/#{
|
116
|
+
get(config.api_host + "/v2/#{ERB::Util.url_encode(payment_id)}/status")
|
100
117
|
end
|
101
118
|
|
102
119
|
# POST /v2/capture
|
@@ -126,7 +143,7 @@ class Veritrans
|
|
126
143
|
raise ArgumentError, "parameter payment_id can not be blank (got #{payment_id.class} : #{payment_id.inspect})"
|
127
144
|
end
|
128
145
|
|
129
|
-
request_with_logging(:post, config.api_host + "/v2/#{
|
146
|
+
request_with_logging(:post, config.api_host + "/v2/#{ERB::Util.url_encode(payment_id)}/expire", nil)
|
130
147
|
end
|
131
148
|
|
132
149
|
# POST /v2/charge { payment_type: "vtlink" }
|
@@ -138,7 +155,7 @@ class Veritrans
|
|
138
155
|
|
139
156
|
# DELETE /v2/vtlink/{id}
|
140
157
|
def delete_vtlink(id, options)
|
141
|
-
request_with_logging(:delete, config.api_host + "/v2/vtlink/#{
|
158
|
+
request_with_logging(:delete, config.api_host + "/v2/vtlink/#{ERB::Util.url_encode(id)}", options)
|
142
159
|
end
|
143
160
|
|
144
161
|
# GET /v2/point_inquiry/{token_id}
|
@@ -152,5 +169,85 @@ class Veritrans
|
|
152
169
|
|
153
170
|
alias_method :point_inquiry, :inquiry_points
|
154
171
|
|
155
|
-
|
172
|
+
# POST /v2/pay/account
|
173
|
+
# param create pay account request (more params detail refer to: https://api-docs.midtrans.com/#create-pay-account)
|
174
|
+
def link_payment_account(param)
|
175
|
+
if param == nil
|
176
|
+
raise ArgumentError, "parameter Payment_type gopay cannot be blank"
|
177
|
+
end
|
178
|
+
|
179
|
+
request_with_logging(:post, config.api_host + "/v2/pay/account", param)
|
180
|
+
end
|
181
|
+
|
182
|
+
# GET /v2/pay/account/{account_id}
|
183
|
+
# account_id (more params detail refer to: https://api-docs.midtrans.com/#get-pay-account)
|
184
|
+
def get_payment_account(account_id)
|
185
|
+
if account_id == nil || account_id == ''
|
186
|
+
raise ArgumentError, "account_id cannot be blank"
|
187
|
+
end
|
188
|
+
|
189
|
+
request_with_logging(:get, config.api_host + "/v2/pay/account/#{account_id}", {})
|
190
|
+
end
|
191
|
+
|
192
|
+
# POST /v2/pay/account/{account_id}/unbind
|
193
|
+
# account_id (more params detail refer to: https://api-docs.midtrans.com/#unbind-pay-account)
|
194
|
+
def unlink_payment_account(account_id)
|
195
|
+
if account_id == nil || account_id == ''
|
196
|
+
raise ArgumentError, "parameter account_id cannot be blank"
|
197
|
+
end
|
198
|
+
|
199
|
+
request_with_logging(:post, config.api_host + "/v2/pay/account/#{account_id}/unbind", {})
|
200
|
+
end
|
201
|
+
|
202
|
+
# POST /v1/subscription
|
203
|
+
# param create subscription request (more params detail refer to: https://api-docs.midtrans.com/#create-subscription)
|
204
|
+
def create_subscription(param)
|
205
|
+
if param == nil
|
206
|
+
raise ArgumentError, "parameter subscription cannot be blank"
|
207
|
+
end
|
208
|
+
|
209
|
+
request_with_logging(:post, config.api_host + "/v1/subscriptions", param)
|
210
|
+
end
|
211
|
+
|
212
|
+
# GET /v1/subscription/{subscription_id}
|
213
|
+
# get subscription request (more params detail refer to: https://api-docs.midtrans.com/#get-subscription)
|
214
|
+
def get_subscription(subscription_id)
|
215
|
+
if subscription_id == nil || subscription_id == ''
|
216
|
+
raise ArgumentError, "subscription_id cannot be blank"
|
217
|
+
end
|
218
|
+
|
219
|
+
request_with_logging(:get, config.api_host + "/v1/subscriptions/#{subscription_id}", {})
|
220
|
+
end
|
221
|
+
|
222
|
+
# POST /v1/subscription/{subscription_id}/disable
|
223
|
+
# disable subscription request (more params detail refer to: https://api-docs.midtrans.com/#disable-subscription)
|
224
|
+
def disable_subscription(subscription_id)
|
225
|
+
if subscription_id == nil || subscription_id == ''
|
226
|
+
raise ArgumentError, "subscription_id cannot be blank"
|
227
|
+
end
|
228
|
+
|
229
|
+
request_with_logging(:post, config.api_host + "/v1/subscriptions/#{subscription_id}/disable", {})
|
230
|
+
end
|
231
|
+
|
232
|
+
# POST /v1/subscription/{subscription_id}/disable
|
233
|
+
# enable subscription request (more params detail refer to: https://api-docs.midtrans.com/#enable-subscription)
|
234
|
+
def enable_subscription(subscription_id)
|
235
|
+
if subscription_id == nil || subscription_id == ''
|
236
|
+
raise ArgumentError, "subscription_id cannot be blank"
|
237
|
+
end
|
238
|
+
|
239
|
+
request_with_logging(:post, config.api_host + "/v1/subscriptions/#{subscription_id}/enable", {})
|
240
|
+
end
|
241
|
+
|
242
|
+
# PATCH /v1/subscription/{subscription_id}
|
243
|
+
# update subscription request (more params detail refer to: https://api-docs.midtrans.com/#update-subscription)
|
244
|
+
def update_subscription(subscription_id, param)
|
245
|
+
if subscription_id && param == nil || subscription_id && param == ''
|
246
|
+
raise ArgumentError, "subscription_id and param cannot be blank"
|
247
|
+
end
|
248
|
+
|
249
|
+
request_with_logging(:patch, config.api_host + "/v1/subscriptions/#{subscription_id}", param)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
156
253
|
end
|
data/lib/veritrans/client.rb
CHANGED
@@ -68,27 +68,38 @@ class Veritrans
|
|
68
68
|
make_request(:post, url, params)
|
69
69
|
end
|
70
70
|
|
71
|
+
def patch(url, params)
|
72
|
+
make_request(:patch, url, params)
|
73
|
+
end
|
74
|
+
|
71
75
|
def make_request(method, url, params, auth_header = nil)
|
72
76
|
if !config.server_key || config.server_key == ''
|
73
|
-
raise "Please
|
77
|
+
raise "Please configure your server key"
|
74
78
|
end
|
75
79
|
|
76
80
|
method = method.to_s.upcase
|
77
|
-
logger.info "
|
81
|
+
logger.info "Midtrans: #{method} #{url} #{_json_encode(params)}"
|
78
82
|
#logger.info "Veritrans: Using server key: #{config.server_key}"
|
79
83
|
#puts "Veritrans: #{method} #{url} #{_json_encode(params)}"
|
80
84
|
|
81
85
|
default_options = config.http_options || {}
|
82
86
|
|
87
|
+
idempotency_key = config.idempotency_key
|
88
|
+
append_notif_url = config.append_notif_url
|
89
|
+
override_notif_url = config.override_notif_url
|
90
|
+
|
83
91
|
# Add authentication and content type
|
84
92
|
# Docs https://api-docs.midtrans.com/#http-s-header
|
85
93
|
request_options = {
|
86
94
|
:path => URI.parse(url).path,
|
87
95
|
:headers => {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
96
|
+
"Authorization" => auth_header || basic_auth_header(config.server_key),
|
97
|
+
"Accept" => "application/json",
|
98
|
+
"Content-Type" => "application/json",
|
99
|
+
"User-Agent" => "Veritrans ruby gem #{Veritrans::VERSION}",
|
100
|
+
"Idempotency-Key" => "#{idempotency_key}",
|
101
|
+
"X-Append-Notification" => "#{append_notif_url}",
|
102
|
+
"X-Override-Notification" => "#{override_notif_url}"
|
92
103
|
}
|
93
104
|
}
|
94
105
|
|
@@ -109,7 +120,29 @@ class Veritrans
|
|
109
120
|
|
110
121
|
response = request.send(method.downcase.to_sym, request_options)
|
111
122
|
|
112
|
-
|
123
|
+
if defined?(response.body)
|
124
|
+
response_body = JSON.parse(response.body)
|
125
|
+
if response_body.has_key? 'status_code'
|
126
|
+
status_code = Integer(response_body["status_code"])
|
127
|
+
if status_code >= 400 && status_code != 407
|
128
|
+
raise MidtransError.new(
|
129
|
+
"Midtrans API is returning API error. HTTP status code: #{status_code}",
|
130
|
+
"#{status_code}",
|
131
|
+
"#{response_body}",
|
132
|
+
"#{response}")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
if response.status >= 400
|
138
|
+
raise MidtransError.new(
|
139
|
+
"Midtrans API is returning API error. HTTP status code: #{response.status} API response: #{response.body}",
|
140
|
+
"#{response.status}",
|
141
|
+
"#{response.body}",
|
142
|
+
"#{response}")
|
143
|
+
end
|
144
|
+
|
145
|
+
logger.info "Midtrans: got #{(Time.now - s_time).round(3)} sec #{response.status} #{response.body}"
|
113
146
|
|
114
147
|
Result.new(response, url, request_options, Time.now - s_time)
|
115
148
|
|
data/lib/veritrans/config.rb
CHANGED
@@ -20,7 +20,6 @@ class Veritrans
|
|
20
20
|
@client_key = value
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
23
|
def client_key
|
25
24
|
@client_key
|
26
25
|
end
|
@@ -72,13 +71,37 @@ class Veritrans
|
|
72
71
|
diff = options.keys.map(&:to_sym) - Excon::VALID_CONNECTION_KEYS
|
73
72
|
if diff.size > 0
|
74
73
|
raise ArgumentError,
|
75
|
-
|
76
|
-
|
74
|
+
"http_options contain unsupported keys: #{diff.inspect}\n" +
|
75
|
+
"Supported keys are: #{Excon::VALID_CONNECTION_KEYS.inspect}"
|
77
76
|
end
|
78
77
|
|
79
78
|
@http_options = options
|
80
79
|
end
|
81
80
|
|
81
|
+
def idempotency_key=(value)
|
82
|
+
@idempotency_key = value
|
83
|
+
end
|
84
|
+
|
85
|
+
def idempotency_key
|
86
|
+
@idempotency_key
|
87
|
+
end
|
88
|
+
|
89
|
+
def append_notif_url=(value)
|
90
|
+
@append_notif_url = value
|
91
|
+
end
|
92
|
+
|
93
|
+
def append_notif_url
|
94
|
+
@append_notif_url
|
95
|
+
end
|
96
|
+
|
97
|
+
def override_notif_url=(value)
|
98
|
+
@override_notif_url = value
|
99
|
+
end
|
100
|
+
|
101
|
+
def override_notif_url
|
102
|
+
@override_notif_url
|
103
|
+
end
|
104
|
+
|
82
105
|
def http_options
|
83
106
|
@http_options
|
84
107
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class MidtransError < StandardError
|
2
|
+
attr_reader :status
|
3
|
+
alias_method :http_status_code, :status
|
4
|
+
attr_reader :data
|
5
|
+
alias_method :api_response, :data
|
6
|
+
attr_reader :response
|
7
|
+
alias_method :raw_http_client_data, :response
|
8
|
+
|
9
|
+
def initialize(message, http_status_code = nil, api_response = nil, raw_http_client_data = nil)
|
10
|
+
super(message)
|
11
|
+
@status = http_status_code
|
12
|
+
@data = api_response
|
13
|
+
@response = raw_http_client_data
|
14
|
+
end
|
15
|
+
end
|
data/lib/veritrans/version.rb
CHANGED
data/lib/veritrans.rb
CHANGED
@@ -3,6 +3,7 @@ require 'veritrans/config'
|
|
3
3
|
require 'veritrans/client'
|
4
4
|
require 'veritrans/api'
|
5
5
|
require 'veritrans/result'
|
6
|
+
require 'veritrans/midtrans_error'
|
6
7
|
|
7
8
|
if defined?(::Rails)
|
8
9
|
require 'veritrans/events'
|
@@ -12,18 +13,16 @@ class Veritrans
|
|
12
13
|
include Veritrans::Client
|
13
14
|
include Veritrans::Api
|
14
15
|
|
15
|
-
autoload :Testing, 'veritrans/testing'
|
16
|
-
autoload :TestingLib, 'veritrans/testing'
|
17
|
-
autoload :CLI, 'veritrans/cli'
|
18
16
|
autoload :Events, 'veritrans/events'
|
19
17
|
|
20
18
|
class << self
|
21
19
|
extend Forwardable
|
22
20
|
|
23
21
|
def_delegators :instance, :logger, :logger=, :config, :setup, :file_logger, :file_logger=
|
24
|
-
def_delegators :instance, :request_with_logging, :basic_auth_header, :get, :post, :delete, :make_request
|
25
|
-
def_delegators :instance, :charge, :cancel, :approve, :status, :capture, :expire, :refund, :
|
26
|
-
def_delegators :instance, :create_vtlink, :delete_vtlink, :inquiry_points, :create_widget_token, :create_snap_redirect_url, :create_snap_token
|
22
|
+
def_delegators :instance, :request_with_logging, :basic_auth_header, :get, :post, :delete, :make_request, :patch
|
23
|
+
def_delegators :instance, :charge, :cancel, :approve, :status, :capture, :expire, :refund, :deny
|
24
|
+
def_delegators :instance, :create_vtlink, :delete_vtlink, :inquiry_points, :create_widget_token, :create_snap_redirect_url, :create_snap_token, :create_snap_token_string, :create_snap_redirect_url_str, :test_token, :create_card_token
|
25
|
+
def_delegators :instance, :link_payment_account, :get_payment_account, :unlink_payment_account, :create_subscription, :get_subscription, :disable_subscription, :enable_subscription, :update_subscription
|
27
26
|
def_delegators :instance, :checksum, :events
|
28
27
|
|
29
28
|
# Shortcut for Veritrans::Events
|
data/veritrans.gemspec
CHANGED