veritrans 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/veritrans +79 -0
- data/config/veritrans.yml +15 -0
- data/lib/generators/install_generator.rb +61 -0
- data/lib/generators/templates/app/controllers/merchant_controller.rb +7 -0
- data/lib/generators/templates/app/controllers/veritrans_controller.rb +110 -0
- data/lib/generators/templates/app/views/layouts/layout_auto_post.html.erb +15 -0
- data/lib/generators/templates/app/views/merchant/checkout.html.erb +46 -0
- data/lib/generators/templates/app/views/veritrans/cancel.html.erb +2 -0
- data/lib/generators/templates/app/views/veritrans/confirm.html.erb +13 -0
- data/lib/generators/templates/app/views/veritrans/error.html.erb +2 -0
- data/lib/generators/templates/app/views/veritrans/finish.html.erb +2 -0
- data/lib/generators/templates/app/views/veritrans/pay.html.erb +2 -0
- data/lib/generators/templates/config/veritrans.yml +15 -0
- data/lib/veritrans.rb +18 -0
- data/lib/veritrans/client.rb +156 -0
- data/lib/veritrans/config.rb +46 -0
- data/lib/veritrans/hash_generator.rb +19 -0
- data/lib/veritrans/post_data.rb +144 -0
- data/lib/veritrans/version.rb +43 -0
- metadata +116 -0
data/bin/veritrans
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path(
|
2
|
+
File.join(File.dirname(__FILE__),%w[.. lib veritrans]))
|
3
|
+
wpath= File.dirname(__FILE__).gsub(/bin$/,'')
|
4
|
+
|
5
|
+
def howto_veritrans
|
6
|
+
puts <<END
|
7
|
+
|
8
|
+
How to Veritrans:
|
9
|
+
~~~~~~~~~~~~~~~~~~~~~~~
|
10
|
+
syntax:
|
11
|
+
veritrans -irb
|
12
|
+
|
13
|
+
example:
|
14
|
+
veritrans -irb #=> Start IRB
|
15
|
+
|
16
|
+
Enjoy...
|
17
|
+
END
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
arg = ARGV
|
22
|
+
if arg.size==0
|
23
|
+
howto_veritrans
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
|
27
|
+
if arg.select{|x|x=='-irb'} != []
|
28
|
+
ARGV.reject!{|x|x=='-irb'}
|
29
|
+
|
30
|
+
require 'irb'
|
31
|
+
puts <<EOF
|
32
|
+
example:
|
33
|
+
require 'veritrans'
|
34
|
+
|
35
|
+
client = Veritrans::Client.new
|
36
|
+
client.order_id = "#{(0...4).map{65.+(rand(25))}.join}"
|
37
|
+
client.session_id = "#{(0...4).map{65.+(rand(25))}.join}"
|
38
|
+
client.gross_amount = "10"
|
39
|
+
client.commodity = [
|
40
|
+
{"COMMODITY_ID" => "IDxx1", "COMMODITY_UNIT" => "10", "COMMODITY_NUM" => "1", "COMMODITY_NAME1" => "Waterbotle", "COMMODITY_NAME2" => "Waterbottle in Indonesian"}
|
41
|
+
]
|
42
|
+
client.shipping_flag = "1"
|
43
|
+
client.shipping_first_name = "Sam"
|
44
|
+
client.shipping_last_name = "Anthony"
|
45
|
+
client.shipping_address1 = "Buaran I"
|
46
|
+
client.shipping_address2 = "Pulogadung"
|
47
|
+
client.shipping_city = "Jakarta"
|
48
|
+
client.shipping_country_code = "IDN"
|
49
|
+
client.shipping_postal_code = "16954"
|
50
|
+
client.shipping_phone = "0123456789123"
|
51
|
+
client.shipping_method = "N"
|
52
|
+
client.get_keys
|
53
|
+
client
|
54
|
+
|
55
|
+
OR
|
56
|
+
|
57
|
+
client = Veritrans::Client.new do |me|
|
58
|
+
me.order_id = "dummy#{(0...12).map{65.+(rand(25))}.join}"
|
59
|
+
me.session_id = "session#{(0...12).map{65.+(rand(25))}.join}"
|
60
|
+
me.gross_amount = "10"
|
61
|
+
me.commodity = [
|
62
|
+
{"COMMODITY_ID" => "IDxx1", "COMMODITY_UNIT" => "10", "COMMODITY_NUM" => "1", "COMMODITY_NAME1" => "Waterbotle", "COMMODITY_NAME2" => "Waterbottle in Indonesian"}
|
63
|
+
]
|
64
|
+
me.shipping_flag = "1"
|
65
|
+
me.shipping_first_name = "Sam"
|
66
|
+
me.shipping_last_name = "Anthony"
|
67
|
+
me.shipping_address1 = "Buaran I"
|
68
|
+
me.shipping_address2 = "Pulogadung"
|
69
|
+
me.shipping_city = "Jakarta"
|
70
|
+
me.shipping_country_code = "IDN"
|
71
|
+
me.shipping_postal_code = "16954"
|
72
|
+
me.shipping_phone = "0123456789123"
|
73
|
+
me.shipping_method = "N"
|
74
|
+
end
|
75
|
+
|
76
|
+
EOF
|
77
|
+
|
78
|
+
IRB.start
|
79
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
development:
|
2
|
+
merchant_id: "test_id"
|
3
|
+
merchant_hash_key: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789012345678901"
|
4
|
+
finish_payment_return_url: "http://localhost/finish"
|
5
|
+
unfinish_payment_return_url: "http://localhost/cancel"
|
6
|
+
error_payment_return_url: "http://localhost/error"
|
7
|
+
# server_host: "http://192.168.10.250:80"
|
8
|
+
|
9
|
+
production:
|
10
|
+
merchant_id: "production_id"
|
11
|
+
merchant_hash_key: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789012345678901"
|
12
|
+
finish_payment_return_url: "http://mydomain/finish"
|
13
|
+
unfinish_payment_return_url: "http://mydomain/cancel"
|
14
|
+
error_payment_return_url: "http://mydomain/error"
|
15
|
+
# server_host: "http://192.168.10.250:80"
|
@@ -0,0 +1,61 @@
|
|
1
|
+
if ::Object.const_defined?(:Rails)
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module Veritrans
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < ::Rails::Generators::Base
|
8
|
+
|
9
|
+
desc <<DESC
|
10
|
+
Description:
|
11
|
+
Copy templates need for veritrans weblinktype payment:
|
12
|
+
0. app/controllers/merchant_controller.rb + views
|
13
|
+
1. app/controllers/veritrans_controller.rb + views
|
14
|
+
2. config/veritrans.yml
|
15
|
+
3. config/routes.rb
|
16
|
+
DESC
|
17
|
+
def create_controller_file
|
18
|
+
acts = "app/controllers/"
|
19
|
+
path = __FILE__.sub(__FILE__.split('/').pop,"templates/#{acts}")
|
20
|
+
create_file("#{acts}merchant_controller.rb", IO.read("#{path}merchant_controller.rb"))
|
21
|
+
create_file("#{acts}veritrans_controller.rb",IO.read("#{path}veritrans_controller.rb"))
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_view_files
|
25
|
+
acts = "app/views/layouts/"
|
26
|
+
path = __FILE__.sub(__FILE__.split('/').pop,"templates/#{acts}")
|
27
|
+
create_file("#{acts}layout_auto_post.html.erb",IO.read("#{path}layout_auto_post.html.erb" ))
|
28
|
+
|
29
|
+
acts = "app/views/merchant/"
|
30
|
+
path = __FILE__.sub(__FILE__.split('/').pop,"templates/#{acts}")
|
31
|
+
create_file("#{acts}checkout.html.erb",IO.read("#{path}checkout.html.erb" ))
|
32
|
+
|
33
|
+
acts = "app/views/veritrans/"
|
34
|
+
path = __FILE__.sub(__FILE__.split('/').pop,"templates/#{acts}")
|
35
|
+
create_file("#{acts}confirm.html.erb", IO.read("#{path}confirm.html.erb"))
|
36
|
+
create_file("#{acts}cancel.html.erb", IO.read("#{path}cancel.html.erb" ))
|
37
|
+
create_file("#{acts}pay.html.erb", IO.read("#{path}pay.html.erb" ))
|
38
|
+
create_file("#{acts}finish.html.erb", IO.read("#{path}finish.html.erb" ))
|
39
|
+
create_file("#{acts}error.html.erb", IO.read("#{path}error.html.erb" ))
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_or_update_config_files
|
43
|
+
path = __FILE__.sub(__FILE__.split('/').pop,'templates/config/')
|
44
|
+
create_file("config/veritrans.yml",IO.read("#{path}veritrans.yml"))
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_routes
|
48
|
+
route("match 'checkout' => 'merchant#checkout', :via => :get # show checkout form")
|
49
|
+
route("match 'confirm' => 'veritrans#confirm', :via => :post # pay-confirmation autosubmit to veritrans server")
|
50
|
+
route("match 'cancel' => 'veritrans#cancel', :via => :post # canceling transaction redirect back to merchant-web")
|
51
|
+
route("match 'pay' => 'veritrans#pay', :via => :post # server to server pay-notification to merchant-web")
|
52
|
+
route("match 'finish' => 'veritrans#finish', :via => :post # successfull transaction redirect back to merchant-web")
|
53
|
+
route("match 'error' => 'veritrans#error', :via => :post # error transaction redirect back to merchant-web")
|
54
|
+
end
|
55
|
+
|
56
|
+
hook_for :test_framework
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
class VeritransController < ApplicationController
|
2
|
+
|
3
|
+
# post action after user submit checkout-form
|
4
|
+
# Ex POST:
|
5
|
+
# {"gross_amount" => "7000000",
|
6
|
+
# "commodity"=>[
|
7
|
+
# {
|
8
|
+
# "COMMODITY_ID" => "Espirit",
|
9
|
+
# "COMMODITY_UNIT" => "500000",
|
10
|
+
# "COMMODITY_NUM" => "4",
|
11
|
+
# "COMMODITY_NAME1" => "Espirit"
|
12
|
+
# },
|
13
|
+
# {
|
14
|
+
# "COMMODITY_ID" => "Tablet",
|
15
|
+
# "COMMODITY_UNIT" => "2500000",
|
16
|
+
# "COMMODITY_NUM" => "2",
|
17
|
+
# "COMMODITY_NAME1" => "Tablet"
|
18
|
+
# }]}
|
19
|
+
# Return from get_keys:
|
20
|
+
# TOKEN_MERCHANT = dYWRjRr2ZbJEqMQaqDLIaWeoLl1Tuk3g7g3T1gKGrE5ibYJoZ4
|
21
|
+
# TOKEN_BROWSER = lh4TxpAyB2NhrKTlqGbW1LRPoA6RgyI6roJ2EIII6J29j7gYoP
|
22
|
+
def confirm
|
23
|
+
puts params.inspect
|
24
|
+
client = ::Veritrans::Client.new
|
25
|
+
client.order_id = "dummy#{(0...12).map{65.+(rand(25))}.join}"
|
26
|
+
client.session_id = "session#{(0...12).map{65.+(rand(25))}.join}"
|
27
|
+
client.gross_amount = params["gross_amount"]
|
28
|
+
client.commodity = params["commodity"]
|
29
|
+
|
30
|
+
client.customer_specification_flag = "1" #'1':Different Address with shipping
|
31
|
+
client.shipping_flag = "0" #'0':Not required shipping address
|
32
|
+
|
33
|
+
client.first_name = "Sam"
|
34
|
+
client.last_name = "Anthony"
|
35
|
+
client.address1 = "Buaran I"
|
36
|
+
client.address2 = "Pulogadung"
|
37
|
+
client.city = "Jakarta"
|
38
|
+
client.country_code = "IDN"
|
39
|
+
client.postal_code = "16954"
|
40
|
+
client.phone = "0123456789123"
|
41
|
+
client.email = "sam.anthony@gmail.com" # pay-notification email
|
42
|
+
|
43
|
+
client.get_keys
|
44
|
+
@client = client
|
45
|
+
|
46
|
+
puts client.inspect
|
47
|
+
# puts params.inspect
|
48
|
+
|
49
|
+
render :layout => 'layout_auto_post'
|
50
|
+
end
|
51
|
+
|
52
|
+
# post-redirection from Veritrans to Merchants Web
|
53
|
+
# Ex: {"orderId" =>"dummy877684698685878869896765",
|
54
|
+
# "sessionId"=>"session837985748788668181718189"}
|
55
|
+
def cancel
|
56
|
+
# logic after user cancel the transaction
|
57
|
+
|
58
|
+
puts "cccccccccccccc"
|
59
|
+
puts params.inspect
|
60
|
+
|
61
|
+
render :text => "CANCEL_PAY"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Server to Server post-notification(action) from Veritrans to Merchants Server
|
65
|
+
# Ex: {"mErrMsg"=>"",
|
66
|
+
# "mStatus"=>"success",
|
67
|
+
# "TOKEN_MERCHANT"=>"dYWRjRr2ZbJEqMQaqDLIaWeoLl1Tuk3g7g3T1gKGrE5ibYJoZ4",
|
68
|
+
# "vResultCode"=>"C001000000000000",
|
69
|
+
# "orderId"=>"dummy877684698685878869896765"}
|
70
|
+
def pay
|
71
|
+
# logic to check:
|
72
|
+
# 1.validate request
|
73
|
+
# 2.update db if valid
|
74
|
+
|
75
|
+
puts "vvvvvvvvvvvvvv"
|
76
|
+
puts params.inspect
|
77
|
+
|
78
|
+
render :text => "OK"
|
79
|
+
end
|
80
|
+
|
81
|
+
# post-redirection from Veritrans to Merchants Web
|
82
|
+
# Ex: {"orderId"=>"dummy877684698685878869896765",
|
83
|
+
# "mStatus"=>"success",
|
84
|
+
# "vResultCode"=>"C001000000000000",
|
85
|
+
# "sessionId"=>"session837985748788668181718189"}
|
86
|
+
def finish
|
87
|
+
# logic after success transaction occured
|
88
|
+
|
89
|
+
puts "ffffffffffffff"
|
90
|
+
puts params.inspect
|
91
|
+
|
92
|
+
render :text => "FINISH"
|
93
|
+
end
|
94
|
+
|
95
|
+
# need scenario that could be try
|
96
|
+
# post-redirection from Veritrans to Merchants Web
|
97
|
+
# Ex: {"orderId"=>"dummy877684698685878869896765",
|
98
|
+
# "mStatus"=>"failure",
|
99
|
+
# "vResultCode"=>"NH13000000000000",
|
100
|
+
# "sessionId"=>"session837985748788668181718189"}
|
101
|
+
def error
|
102
|
+
# logic after error transaction occured
|
103
|
+
|
104
|
+
puts "eeeeeeeeeeeeee"
|
105
|
+
puts params.inspect
|
106
|
+
|
107
|
+
render :text => "ERROR"
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<script language="javascript" type="text/javascript">
|
5
|
+
<!--
|
6
|
+
function onloadEvent() {
|
7
|
+
document.form_auto_post.submit();
|
8
|
+
}
|
9
|
+
//-->
|
10
|
+
</script>
|
11
|
+
</head>
|
12
|
+
<body onload="onloadEvent();">
|
13
|
+
<%= yield %>
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<%= form_tag('/confirm', :id =>"cart_form") do -%>
|
2
|
+
<table border=1>
|
3
|
+
<tbody>
|
4
|
+
<tr>
|
5
|
+
<th>Product Image</th>
|
6
|
+
<th>Product Info</th>
|
7
|
+
<th>Price</th>
|
8
|
+
<th align="center">Qty</th>
|
9
|
+
<th>Total Price</th>
|
10
|
+
</tr>
|
11
|
+
<tr>
|
12
|
+
<td><img src="/assets/esprit.png" title="Esprit"></td>
|
13
|
+
<td>Red Esprint</td>
|
14
|
+
<td align="right">Rp 500,000</td>
|
15
|
+
<td align="center">4</td>
|
16
|
+
<td align="right">Rp 2,000,000</td>
|
17
|
+
</tr>
|
18
|
+
<tr>
|
19
|
+
<td><img src="/assets/tablet.jpg" title="Tablet"></td>
|
20
|
+
<td>Android Tablet</td>
|
21
|
+
<td align="right">Rp 2,500,000</td>
|
22
|
+
<td align="center">2</td>
|
23
|
+
<td align="right">Rp 5,000,000</td>
|
24
|
+
</tr>
|
25
|
+
<tr class="subtotal">
|
26
|
+
<td colspan="3">
|
27
|
+
<input class="checkout" name="commit" type="submit" value="Checkout">
|
28
|
+
</td>
|
29
|
+
<td><strong>Subtotal:</strong></td>
|
30
|
+
<td align="right"><strong>Rp 7,000,000</strong></td>
|
31
|
+
</tr>
|
32
|
+
</tbody>
|
33
|
+
</table>
|
34
|
+
|
35
|
+
<input type="hidden" name="commodity[][COMMODITY_ID]" value="Espirit"/>
|
36
|
+
<input type="hidden" name="commodity[][COMMODITY_UNIT]" value="500000"/>
|
37
|
+
<input type="hidden" name="commodity[][COMMODITY_NUM]" value="4"/>
|
38
|
+
<input type="hidden" name="commodity[][COMMODITY_NAME1]" value="Espirit"/>
|
39
|
+
|
40
|
+
<input type="hidden" name="commodity[][COMMODITY_ID]" value="Tablet"/>
|
41
|
+
<input type="hidden" name="commodity[][COMMODITY_UNIT]" value="2500000"/>
|
42
|
+
<input type="hidden" name="commodity[][COMMODITY_NUM]" value="2"/>
|
43
|
+
<input type="hidden" name="commodity[][COMMODITY_NAME1]" value="Tablet"/>
|
44
|
+
|
45
|
+
<input type="hidden" name="gross_amount" value="7000000"/>
|
46
|
+
<% end %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<h1 align="center">Go to select payment options</h1>
|
2
|
+
|
3
|
+
<%= form_tag(@client.redirect_url, :name => "form_auto_post") do -%>
|
4
|
+
<input type="hidden" name="MERCHANT_ID" value="<%= @client.merchant_id %>">
|
5
|
+
<input type="hidden" name="ORDER_ID" value="<%= @client.order_id %>">
|
6
|
+
<input type="hidden" name="TOKEN_BROWSER" value="<%= @client.token["TOKEN_BROWSER"] %>">
|
7
|
+
<table border="1" align="center" width="80%" cellpadding="10" bgcolor="#FFFFCC">
|
8
|
+
</table>
|
9
|
+
<br><br>
|
10
|
+
<div align="center">
|
11
|
+
<input type="submit" value="submit">
|
12
|
+
</div>
|
13
|
+
<% end %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
development:
|
2
|
+
merchant_id: "test_id"
|
3
|
+
merchant_hash_key: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789012345678901"
|
4
|
+
unfinish_payment_return_url: "http://localhost/cancel"
|
5
|
+
finish_payment_return_url: "http://localhost/finish"
|
6
|
+
error_payment_return_url: "http://localhost/error"
|
7
|
+
# server_host: "http://192.168.10.250:80"
|
8
|
+
|
9
|
+
production:
|
10
|
+
merchant_id: "production_id"
|
11
|
+
merchant_hash_key: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789012345678901"
|
12
|
+
unfinish_payment_return_url: "http://mydomain/cancel"
|
13
|
+
finish_payment_return_url: "http://mydomain/finish"
|
14
|
+
error_payment_return_url: "http://mydomain/error"
|
15
|
+
# server_host: "http://192.168.10.250:80"
|
data/lib/veritrans.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
# Required gems
|
4
|
+
require 'rubygems'
|
5
|
+
require 'digest/sha2'
|
6
|
+
require "addressable/uri"
|
7
|
+
require 'faraday'
|
8
|
+
|
9
|
+
# root namespace
|
10
|
+
module Veritrans
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'veritrans/hash_generator'
|
14
|
+
require 'veritrans/post_data'
|
15
|
+
require 'veritrans/version'
|
16
|
+
require 'veritrans/config'
|
17
|
+
require 'veritrans/client'
|
18
|
+
require 'generators/install_generator.rb'
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
module Veritrans
|
3
|
+
|
4
|
+
# :nodoc:
|
5
|
+
class Client
|
6
|
+
include Config
|
7
|
+
|
8
|
+
# constructor to create instance of Veritrans::Client
|
9
|
+
def initialize(&block)
|
10
|
+
class <<self
|
11
|
+
self
|
12
|
+
end.class_eval do
|
13
|
+
attr_accessor(:commodity, *PostData::PostParam)
|
14
|
+
end
|
15
|
+
|
16
|
+
# return-back to merchant-web
|
17
|
+
self.customer_specification_flag = Config::CUSTOMER_SPECIFICATION_FLAG
|
18
|
+
self.settlement_type = Config::SETTLEMENT_TYPE_CARD
|
19
|
+
|
20
|
+
if block_given?
|
21
|
+
yield(self) #self.instance_eval(&block)
|
22
|
+
return self.get_keys
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Example:
|
28
|
+
#
|
29
|
+
# client = Veritrans::Client.new
|
30
|
+
# client.order_id = "dummy#{(0...12).map{65.+(rand(25))}.join}"
|
31
|
+
# client.session_id = "session#{(0...12).map{65.+(rand(25))}.join}"
|
32
|
+
# client.gross_amount = "10"
|
33
|
+
# client.commodity = [{
|
34
|
+
# "COMMODITY_ID" => "IDxx1",
|
35
|
+
# "COMMODITY_UNIT" => "10",
|
36
|
+
# "COMMODITY_NUM" => "1",
|
37
|
+
# "COMMODITY_NAME1" => "Waterbotle",
|
38
|
+
# "COMMODITY_NAME2" => "Waterbottle in Indonesian"}]
|
39
|
+
# client.get_keys
|
40
|
+
#
|
41
|
+
def get_keys
|
42
|
+
init_instance
|
43
|
+
|
44
|
+
params = prepare_params(PostData::ServerParam,PostData::PostParam)
|
45
|
+
|
46
|
+
if @commodity.class == Array
|
47
|
+
commodity = @commodity.collect do |data|
|
48
|
+
uri = Addressable::URI.new
|
49
|
+
uri.query_values = data
|
50
|
+
uri.query
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
uri = Addressable::URI.new
|
55
|
+
uri.query_values = params
|
56
|
+
query_string = "#{uri.query}&REPEAT_LINE=#{@commodity.length}&#{commodity.join('&')}"
|
57
|
+
# puts query_string
|
58
|
+
|
59
|
+
conn = Faraday.new(:url => server_host)
|
60
|
+
@resp = conn.post do |req|
|
61
|
+
req.url(Config::REQUEST_KEY_URL)
|
62
|
+
req.body = query_string
|
63
|
+
end.env
|
64
|
+
# puts query_string
|
65
|
+
|
66
|
+
delete_keys
|
67
|
+
@resp[:url] = @resp[:url].to_s
|
68
|
+
|
69
|
+
@token = parse_body(@resp[:body])
|
70
|
+
end
|
71
|
+
|
72
|
+
# :nodoc:
|
73
|
+
def server_host
|
74
|
+
return Client.config["server_host"] ? Client.config["server_host"] : Config::SERVER_HOST
|
75
|
+
end
|
76
|
+
|
77
|
+
def redirect_url
|
78
|
+
"#{server_host}/web1/paymentStart.action"
|
79
|
+
end
|
80
|
+
|
81
|
+
# :nodoc:
|
82
|
+
def merchant_id
|
83
|
+
return Client.config["merchant_id"]
|
84
|
+
end
|
85
|
+
|
86
|
+
# :nodoc:
|
87
|
+
def merchant_id= new_merchant_id
|
88
|
+
Client.config["merchant_id"] = new_merchant_id
|
89
|
+
end
|
90
|
+
|
91
|
+
# :nodoc:
|
92
|
+
def merchant_hash_key
|
93
|
+
return Client.config["merchant_hash_key"]
|
94
|
+
end
|
95
|
+
|
96
|
+
# :nodoc:
|
97
|
+
def merchant_hash_key= new_merchant_hash_key
|
98
|
+
Client.config["merchant_hash_key"] = new_merchant_hash_key
|
99
|
+
end
|
100
|
+
|
101
|
+
# :nodoc:
|
102
|
+
def error_payment_return_url
|
103
|
+
return Client.config["error_payment_return_url"]
|
104
|
+
end
|
105
|
+
|
106
|
+
# :nodoc:
|
107
|
+
def finish_payment_return_url
|
108
|
+
return Client.config["finish_payment_return_url"]
|
109
|
+
end
|
110
|
+
|
111
|
+
# :nodoc:
|
112
|
+
def unfinish_payment_return_url
|
113
|
+
return Client.config["unfinish_payment_return_url"]
|
114
|
+
end
|
115
|
+
|
116
|
+
# :nodoc:
|
117
|
+
def token
|
118
|
+
return @token
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def merchanthash
|
124
|
+
# Generate merchant hash code
|
125
|
+
return HashGenerator::generate(merchant_id, merchant_hash_key, settlement_type, order_id, gross_amount);
|
126
|
+
end
|
127
|
+
|
128
|
+
def parse_body(body)
|
129
|
+
arrs = body.split("\r\n")
|
130
|
+
arrs = arrs[-2,2] if arrs.length > 1
|
131
|
+
return Hash[arrs.collect{|x|x.split("=")}]
|
132
|
+
end
|
133
|
+
|
134
|
+
def init_instance
|
135
|
+
@token = nil
|
136
|
+
end
|
137
|
+
|
138
|
+
def prepare_params(*arg)
|
139
|
+
params = {}
|
140
|
+
arg.flatten.each do |key|
|
141
|
+
value = self.send(key)
|
142
|
+
params[key.upcase] = value if value
|
143
|
+
end
|
144
|
+
return params
|
145
|
+
end
|
146
|
+
|
147
|
+
def delete_keys
|
148
|
+
@resp.delete(:ssl)
|
149
|
+
@resp.delete(:request)
|
150
|
+
@resp.delete(:response)
|
151
|
+
@resp.delete(:request_headers)
|
152
|
+
@resp.delete(:parallel_manager)
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Veritrans
|
5
|
+
|
6
|
+
# hold constants configuration define in server merchant
|
7
|
+
module Config
|
8
|
+
|
9
|
+
# server Veritrans - defined in gem - no change!
|
10
|
+
SERVER_HOST = 'https://payments.veritrans.co.id' #'http://192.168.10.250:80'
|
11
|
+
|
12
|
+
# Request Key Url - use in #get_keys - defined in gem - no change!
|
13
|
+
REQUEST_KEY_URL = "/web1/commodityRegist.action"
|
14
|
+
|
15
|
+
# Payment Redirect Url - defined in gem - no change!
|
16
|
+
PAYMENT_REDIRECT_URL = "/web1/deviceCheck.action"
|
17
|
+
|
18
|
+
# :nodoc:
|
19
|
+
CUSTOMER_SPECIFICATION_FLAG = '0' #Billing same as shipping address '1' Different, manually input in Veritrans-web
|
20
|
+
|
21
|
+
# Default Settlement method:
|
22
|
+
SETTLEMENT_TYPE_CARD = "01" #Paymanet Type
|
23
|
+
|
24
|
+
# Flag: Sales and Sales Credit, 0: only 1 credit. If not specified, 0
|
25
|
+
CARD_CAPTURE_FLAG = "1"
|
26
|
+
|
27
|
+
def Config.included(mod)
|
28
|
+
class <<self
|
29
|
+
@@config_env = ::Object.const_defined?(:Rails) ? Rails.env : "development"
|
30
|
+
@@config = File.exists?("./config/veritrans.yml") ? YAML.load_file("./config/veritrans.yml") : nil
|
31
|
+
end
|
32
|
+
|
33
|
+
mod.instance_eval <<CODE
|
34
|
+
|
35
|
+
def self.config_env=(env)
|
36
|
+
@@config_env = env
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.config
|
40
|
+
@@config[@@config_env]
|
41
|
+
end
|
42
|
+
CODE
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
module Veritrans
|
3
|
+
|
4
|
+
# :nodoc:
|
5
|
+
module HashGenerator
|
6
|
+
|
7
|
+
# Generate hash using SHA-512.
|
8
|
+
#
|
9
|
+
# Parameters:
|
10
|
+
# * <tt>[String]merchant_id</tt> - Merchant ID
|
11
|
+
# * <tt>[String]merchant_hash_key</tt> - Merchant Hash key
|
12
|
+
# * <tt>[String]settlement_method</tt> - '01' Credit Card
|
13
|
+
# * <tt>[String]order_id</tt>
|
14
|
+
# * <tt>[String]amount</tt>
|
15
|
+
def self.generate(merchant_id, merchant_hash_key, settlement_method, order_id, amount)
|
16
|
+
Digest::SHA512.hexdigest("#{merchant_hash_key},#{merchant_id},#{settlement_method},#{order_id},#{amount}")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
module Veritrans
|
3
|
+
|
4
|
+
# hold information of "post data" need to pass when server need to get_keys
|
5
|
+
module PostData
|
6
|
+
|
7
|
+
# +:merchant_id,+
|
8
|
+
# +:merchant_url,+
|
9
|
+
# +:session_id,+
|
10
|
+
# +:finish_payment_return_url,+
|
11
|
+
# +:unfinish_payment_return_url,+
|
12
|
+
# +:error_payment_return_url
|
13
|
+
Merchant =[
|
14
|
+
:merchant_id,
|
15
|
+
:merchant_url,
|
16
|
+
:finish_payment_return_url,
|
17
|
+
:unfinish_payment_return_url,
|
18
|
+
:error_payment_return_url
|
19
|
+
]
|
20
|
+
|
21
|
+
# +:settlement_type,+
|
22
|
+
# +:gross_amount,+
|
23
|
+
# +:card_no,+
|
24
|
+
# +:card_exp_date,+
|
25
|
+
# +:customer_id,+
|
26
|
+
# +:previous_customer_flag,+
|
27
|
+
# +:customer_status,+
|
28
|
+
Payment =[
|
29
|
+
:settlement_type,
|
30
|
+
:gross_amount,
|
31
|
+
:card_no,
|
32
|
+
:card_exp_date, # mm/yy
|
33
|
+
:customer_id,
|
34
|
+
:previous_customer_flag,
|
35
|
+
:customer_status,
|
36
|
+
]
|
37
|
+
|
38
|
+
# +:first_name,+
|
39
|
+
# +:last_name,+
|
40
|
+
# +:address1,+
|
41
|
+
# +:address2,+
|
42
|
+
# +:city,+
|
43
|
+
# +:country_code,+
|
44
|
+
# +:postal_code,+
|
45
|
+
# +:phone,+
|
46
|
+
# +:email,+
|
47
|
+
# customer_specification_flag,
|
48
|
+
Personal =[
|
49
|
+
:first_name,
|
50
|
+
:last_name,
|
51
|
+
:address1,
|
52
|
+
:address2,
|
53
|
+
:city,
|
54
|
+
:country_code,
|
55
|
+
:postal_code,
|
56
|
+
:phone,
|
57
|
+
:email,
|
58
|
+
:customer_specification_flag
|
59
|
+
]
|
60
|
+
|
61
|
+
# +:shipping_flag,
|
62
|
+
# +:shipping_first_name,
|
63
|
+
# +:shipping_last_name,
|
64
|
+
# +:shipping_address1,
|
65
|
+
# +:shipping_address2,
|
66
|
+
# +:shipping_city,
|
67
|
+
# +:shipping_country_code,
|
68
|
+
# +:shipping_postal_code,
|
69
|
+
# +:shipping_phone,
|
70
|
+
# +:shipping_method,
|
71
|
+
Shipping =[
|
72
|
+
:shipping_flag,
|
73
|
+
:shipping_first_name,
|
74
|
+
:shipping_last_name,
|
75
|
+
:shipping_address1,
|
76
|
+
:shipping_address2,
|
77
|
+
:shipping_city,
|
78
|
+
:shipping_country_code,
|
79
|
+
:shipping_postal_code,
|
80
|
+
:shipping_phone,
|
81
|
+
:shipping_method
|
82
|
+
]
|
83
|
+
|
84
|
+
# +:lang_enable_flag,+
|
85
|
+
# +:lang+
|
86
|
+
Language =[
|
87
|
+
:lang_enable_flag,
|
88
|
+
:lang
|
89
|
+
]
|
90
|
+
|
91
|
+
# +:repeat_line,+
|
92
|
+
# +:purchases,+
|
93
|
+
Purchases =[
|
94
|
+
:repeat_line,
|
95
|
+
:purchases
|
96
|
+
]
|
97
|
+
|
98
|
+
# +:commodity_id,+
|
99
|
+
# +:commodity_unit,+
|
100
|
+
# +:commodity_num,+
|
101
|
+
# +:commodity_name1,+
|
102
|
+
# +:commodity_name2+
|
103
|
+
PurchaseParam =[
|
104
|
+
:commodity_id,
|
105
|
+
:commodity_unit,
|
106
|
+
:commodity_num,
|
107
|
+
:commodity_name1,
|
108
|
+
:commodity_name2
|
109
|
+
]
|
110
|
+
|
111
|
+
# +:order_id,+
|
112
|
+
# +:session_id,+
|
113
|
+
# +:merchanthash,+
|
114
|
+
# +:card_capture_flag+
|
115
|
+
OtherParam =[
|
116
|
+
:order_id,
|
117
|
+
:session_id,
|
118
|
+
:merchanthash,
|
119
|
+
:card_capture_flag
|
120
|
+
]
|
121
|
+
|
122
|
+
# +:merchant_id,+
|
123
|
+
# +:merchanthash,+
|
124
|
+
# +:finish_payment_return_url,+
|
125
|
+
# +:unfinish_payment_return_url,+
|
126
|
+
# +:error_payment_return_url+
|
127
|
+
ServerParam =[
|
128
|
+
:merchant_id,
|
129
|
+
:merchanthash,
|
130
|
+
:finish_payment_return_url,
|
131
|
+
:unfinish_payment_return_url,
|
132
|
+
:error_payment_return_url
|
133
|
+
]
|
134
|
+
|
135
|
+
# Params are the combination of this group:
|
136
|
+
PostParam = (Merchant + Payment + Personal + Shipping + Language + Purchases + OtherParam) - ServerParam
|
137
|
+
end
|
138
|
+
|
139
|
+
# Sample of Array of purchase commodity
|
140
|
+
# [
|
141
|
+
# {"COMMODITY_ID" => "1233", "COMMODITY_UNIT" => "1", "COMMODITY_NUM" => "1", "COMMODITY_NAME1" => "BUKU", "COMMODITY_NAME2" => "BOOK"},
|
142
|
+
# {"COMMODITY_ID" => "1243", "COMMODITY_UNIT" => "9", "COMMODITY_NUM" => "1", "COMMODITY_NAME1" => "BUKU Sembilan", "COMMODITY_NAME2" => "BOOK NINE"}
|
143
|
+
# ]
|
144
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
module Veritrans
|
3
|
+
# hold version number of this library
|
4
|
+
# it use class methods to generate it
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# Veritrans::Version.to_s
|
9
|
+
class Version
|
10
|
+
|
11
|
+
class <<self
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# :nodoc:
|
16
|
+
def major
|
17
|
+
1
|
18
|
+
end
|
19
|
+
|
20
|
+
# :nodoc:
|
21
|
+
def minor
|
22
|
+
0
|
23
|
+
end
|
24
|
+
|
25
|
+
# :nodoc:
|
26
|
+
def patch
|
27
|
+
0
|
28
|
+
end
|
29
|
+
|
30
|
+
# :nodoc:
|
31
|
+
def pre
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# ==== Return:
|
37
|
+
#
|
38
|
+
# * <tt>String</tt> - version information
|
39
|
+
def self.to_s
|
40
|
+
[major, minor, patch, pre].compact.join('.')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: veritrans
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Veritrans Dev Team
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: addressable
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description:
|
63
|
+
email:
|
64
|
+
- dev@veritrans.co.id
|
65
|
+
executables:
|
66
|
+
- veritrans
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- config/veritrans.yml
|
71
|
+
- bin/veritrans
|
72
|
+
- lib/veritrans.rb
|
73
|
+
- lib/veritrans/client.rb
|
74
|
+
- lib/veritrans/config.rb
|
75
|
+
- lib/veritrans/hash_generator.rb
|
76
|
+
- lib/veritrans/post_data.rb
|
77
|
+
- lib/veritrans/version.rb
|
78
|
+
- lib/generators/install_generator.rb
|
79
|
+
- lib/generators/templates/app/controllers/merchant_controller.rb
|
80
|
+
- lib/generators/templates/app/controllers/veritrans_controller.rb
|
81
|
+
- lib/generators/templates/app/views/layouts/layout_auto_post.html.erb
|
82
|
+
- lib/generators/templates/app/views/merchant/checkout.html.erb
|
83
|
+
- lib/generators/templates/app/views/veritrans/confirm.html.erb
|
84
|
+
- lib/generators/templates/app/views/veritrans/error.html.erb
|
85
|
+
- lib/generators/templates/app/views/veritrans/finish.html.erb
|
86
|
+
- lib/generators/templates/app/views/veritrans/pay.html.erb
|
87
|
+
- lib/generators/templates/app/views/veritrans/cancel.html.erb
|
88
|
+
- lib/generators/templates/config/veritrans.yml
|
89
|
+
homepage: http://veritrans.co.id
|
90
|
+
licenses: []
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: -1916124557783123575
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project: veritrans
|
112
|
+
rubygems_version: 1.8.24
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Veritrans Webclient wrapper
|
116
|
+
test_files: []
|