vtweb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9811dce97b3c3a4f22aea8378027c63269f815ea
4
+ data.tar.gz: 529bc8a947783c58cd172d17d94dd9f348bb1b4b
5
+ SHA512:
6
+ metadata.gz: 965169d5e8e592e807346bf6fc0695b9e7a679a34cea8231c9d49de949431555df6dfcbfc59241dcb22c3b1a413ce27aa3565ee0ea652abaf38821db2c1d121a
7
+ data.tar.gz: 795f55451f3a594574e35d2d5d8e331e05be5d29adf2cfe0e0de26d6b848f9ee4d36dc4e4238ed4319958b7320d85a1d73199ca43c447d8bc0637f2f643551eb
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Panggi Libersa Jasri Akadol
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Veritrans VT-Web Ruby Wrapper
2
+
3
+ Ruby Wrapper for Veritrans VT-Web. Visit https://www.veritrans.co.id for more information.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'vtweb'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install vtweb
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it http://github.com/panggi/vtweb/fork
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,206 @@
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
+ # Other Requirements
10
+ require "vtweb/config"
11
+ require "vtweb/merchant_hash_generator"
12
+ require "vtweb/post_params"
13
+ require "vtweb/version"
14
+
15
+ module Vtweb
16
+ class Client
17
+ include RbConfig
18
+
19
+ def initialize(&block)
20
+ class <<self
21
+ self
22
+ end.class_eval do
23
+ attr_accessor(:item, *PostParams::AllParam)
24
+ end
25
+
26
+ self.billing_different_with_shipping = Config::BILLING_DIFFERENT_WITH_SHIPPING
27
+ self.payment_type = Config::PAYMENT_TYPE
28
+ end
29
+
30
+ def get_keys
31
+ init_instance
32
+
33
+ if billing_different_with_shipping == "0" && required_shipping_address == "0"
34
+ raise "required_shipping_address must be '1'"
35
+ end
36
+
37
+ params = prepare_params(PostParams::ServerParams,PostParams::AllParam)
38
+
39
+ # Payment Options
40
+ if !params[:promo_bins].blank?
41
+ params.merge!({ "promo_bins[]" => params[:promo_bins]})
42
+ params.delete :promo_bins
43
+ end
44
+
45
+ if !params[:point_banks].blank?
46
+ params.merge!({ "point_banks[]" => params[:point_banks]})
47
+ params.delete :point_banks
48
+ end
49
+
50
+ if !params[:installment_banks].blank?
51
+ params.merge!({ "installment_banks[]" => params[:installment_banks]})
52
+ params.delete :installment_banks
53
+ end
54
+
55
+ if !params[:installment_terms].blank?
56
+ params.merge!({ "installment_terms" => params[:installment_terms].to_json })
57
+ params.delete :installment_terms
58
+ end
59
+
60
+ if !params[:payment_methods].blank?
61
+ params.merge!({ "payment_methods[]" => params[:payment_methods]})
62
+ params.delete :payment_methods
63
+ end
64
+
65
+ # Items
66
+ item = @item.collect do |data|
67
+ data.keys.map do |key|
68
+ if key.downcase == "item_id"
69
+ data["item_id[]"] = data[key]
70
+ end
71
+
72
+ if key.downcase == "price"
73
+ data["price[]"] = data[key]
74
+ end
75
+
76
+ if key.downcase == "quantity"
77
+ data["quantity[]"] = data[key]
78
+ end
79
+
80
+ if key.downcase == "item_name1"
81
+ data["item_name1[]"] = data[key]
82
+ end
83
+
84
+ if key.downcase == "item_name2"
85
+ data["item_name2[]"] = data[key]
86
+ end
87
+
88
+ data.delete key
89
+ end
90
+
91
+ orders_uri = Addressable::URI.new
92
+ orders_uri.query_values = data
93
+ orders_uri.query
94
+
95
+ end
96
+
97
+ uri = Addressable::URI.new
98
+ uri.query_values = params
99
+ query_string = "#{uri.query}&repeat_line=#{item.length}&#{item.join('&')}"
100
+
101
+ conn = Faraday.new(:url => vtweb_server)
102
+ @resp = conn.post do |req|
103
+ req.url(Config::GET_TOKENS_URL)
104
+ req.body = query_string
105
+ end.env
106
+
107
+ delete_keys
108
+ @resp[:url] = @resp[:url].to_s
109
+
110
+ @token = parse_body(@resp[:body])
111
+ end
112
+
113
+ def server_host
114
+ return Client.config["vtweb_server"] ? Client.config["vtweb_server"] : Config::VTWEB_SERVER
115
+ end
116
+
117
+ def redirection_url
118
+ "#{vtweb_server}#{redirection_url}"
119
+ end
120
+
121
+ def merchant_id
122
+ return Client.config["merchant_id"]
123
+ end
124
+
125
+ def merchant_id= new_merchant_id
126
+ Client.config["merchant_id"] = new_merchant_id
127
+ end
128
+
129
+ def merchant_hash_key
130
+ return Client.config["merchant_hash_key"]
131
+ end
132
+
133
+ def merchant_hash_key= new_merchant_hash_key
134
+ Client.config["merchant_hash_key"] = new_merchant_hash_key
135
+ end
136
+
137
+ def error_payment_return_url
138
+ return Client.config["error_payment_return_url"]
139
+ end
140
+
141
+ def finish_payment_return_url
142
+ return Client.config["finish_payment_return_url"]
143
+ end
144
+
145
+ def unfinish_payment_return_url
146
+ return Client.config["unfinish_payment_return_url"]
147
+ end
148
+
149
+ def token
150
+ return @token
151
+ end
152
+
153
+ def billing_different_with_shipping
154
+ @billing_different_with_shipping
155
+ end
156
+
157
+ def billing_different_with_shipping=(flag)
158
+ @billing_different_with_shipping = billing_different_with_shipping
159
+ end
160
+
161
+ def required_shipping_address
162
+ @required_shipping_address
163
+ end
164
+
165
+ def required_shipping_address=(flag)
166
+ @required_shipping_address = flag
167
+ end
168
+
169
+ def new_api
170
+ return true
171
+ end
172
+
173
+ private
174
+
175
+ def merchanthash
176
+ return MerchantHashGenerator::generate(merchant_id, merchant_hash_key, payment_type, order_id);
177
+ end
178
+
179
+ def parse_body(body)
180
+ arrs = body.split("\r\n")
181
+ arrs = arrs[-2,2] if arrs.length > 1
182
+ return Hash[arrs.collect{|x|x.split("=")}]
183
+ end
184
+
185
+ def init_instance
186
+ @token = nil
187
+ end
188
+
189
+ def prepare_params(*arg)
190
+ params = {}
191
+ arg.flatten.each do |key|
192
+ value = self.send(key)
193
+ params[key.downcase] = value if value
194
+ end
195
+ return params
196
+ end
197
+
198
+ def delete_keys
199
+ @resp.delete(:ssl)
200
+ @resp.delete(:request)
201
+ @resp.delete(:response)
202
+ @resp.delete(:request_headers)
203
+ @resp.delete(:parallel_manager)
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,47 @@
1
+ require "yaml"
2
+
3
+ module Vtweb
4
+
5
+ module Config
6
+
7
+ # Server
8
+ VTWEB_SERVER = "https://vtweb.veritrans.co.id"
9
+ GET_TOKENS_URL = "/v1/tokens"
10
+ REDIRECTION_URL = "/v1/payments"
11
+
12
+ # Params Config
13
+ BILLING_DIFFERENT_WITH_SHIPPING = '0'
14
+ PAYMENT_TYPE = "01"
15
+
16
+ def Config.included(mod)
17
+ class <<self
18
+ template = {
19
+ 'merchant_id' => nil,
20
+ 'merchant_hash_key' => nil,
21
+ 'finish_payment_return_url' => nil,
22
+ 'unfinish_payment_return_url' => nil,
23
+ 'error_payment_return_url' => nil
24
+ }
25
+
26
+ @@config_env = ::Object.const_defined?(:Rails) ? Rails.env : "development"
27
+ @@config = File.exists?("./config/vtweb.yml") ? YAML.load_file("./config/vtweb.yml") : {}
28
+ @@config['development'] = {} if !@@config['development']
29
+ @@config['production' ] = {} if !@@config['production']
30
+ @@config['development'] = template.clone.merge(@@config['development'])
31
+ @@config['production'] = template.clone.merge(@@config['production'])
32
+ end
33
+
34
+ mod.instance_eval <<CODE
35
+
36
+ def self.config_env=(env)
37
+ @@config_env = env
38
+ end
39
+
40
+ def self.config
41
+ @@config[@@config_env]
42
+ end
43
+ CODE
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,7 @@
1
+ module Vtweb
2
+ module MerchantHashGenerator
3
+ def self.generate(merchant_id, merchant_hash_key, payment_type, order_id)
4
+ Digest::SHA512.hexdigest("#{merchant_hash_key},#{merchant_id},#{payment_type},#{order_id}")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,72 @@
1
+ module Vtweb
2
+
3
+ module PostParams
4
+
5
+ Merchant =[
6
+ :merchant_id,
7
+ :merchanthash,
8
+ :finish_payment_return_url,
9
+ :unfinish_payment_return_url,
10
+ :error_payment_return_url
11
+ ]
12
+
13
+ Payment =[
14
+ :payment_type,
15
+ :installment_type,
16
+ :installment_banks,
17
+ :installment_terms,
18
+ :point_banks,
19
+ :payment_methods,
20
+ :promo_bins,
21
+ :enable_3d_secure,
22
+ :bank
23
+ ]
24
+
25
+ Personal =[
26
+ :first_name,
27
+ :last_name,
28
+ :address1,
29
+ :address2,
30
+ :city,
31
+ :country_code,
32
+ :postal_code,
33
+ :phone,
34
+ :email,
35
+ :billing_different_with_shipping
36
+ ]
37
+
38
+ Shipping =[
39
+ :required_shipping_address,
40
+ :shipping_first_name,
41
+ :shipping_last_name,
42
+ :shipping_address1,
43
+ :shipping_address2,
44
+ :shipping_city,
45
+ :shipping_country_code,
46
+ :shipping_postal_code,
47
+ :shipping_phone,
48
+ :shipping_email
49
+ ]
50
+
51
+ Purchases =[
52
+ :repeat_line
53
+ ]
54
+
55
+ OtherParams =[
56
+ :order_id,
57
+ :new_api
58
+ ]
59
+
60
+ ServerParams =[
61
+ :merchant_id,
62
+ :merchanthash,
63
+ :finish_payment_return_url,
64
+ :unfinish_payment_return_url,
65
+ :error_payment_return_url,
66
+ :new_api
67
+ ]
68
+
69
+ AllParam = (Merchant + Payment + Personal + Shipping + Purchases + OtherParams) - ServerParams
70
+ end
71
+
72
+ end
@@ -0,0 +1,3 @@
1
+ module Vtweb
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vtweb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vtweb"
8
+ spec.version = Vtweb::VERSION
9
+ spec.authors = ["Panggi Libersa Jasri Akadol"]
10
+ spec.email = ["panggi@me.com"]
11
+ spec.summary = %q{Ruby wrapper for Veritrans VT-Web.}
12
+ spec.description = %q{VT-Web makes accepting online payments simple because the whole payment process is handled by Veritrans, and we take care most of the information security compliance requirements from the bank (Veritrans is certified as a PCI-DSS Level 1 Service Provider). Merchants focus on their core business, while we take care of the rest.}
13
+ spec.homepage = "http://panggi.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "addressable"
22
+ spec.add_runtime_dependency "faraday"
23
+ spec.add_runtime_dependency "rake"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "rake"
27
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vtweb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Panggi Libersa Jasri Akadol
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: VT-Web makes accepting online payments simple because the whole payment
84
+ process is handled by Veritrans, and we take care most of the information security
85
+ compliance requirements from the bank (Veritrans is certified as a PCI-DSS Level
86
+ 1 Service Provider). Merchants focus on their core business, while we take care
87
+ of the rest.
88
+ email:
89
+ - panggi@me.com
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - .gitignore
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - lib/vtweb.rb
100
+ - lib/vtweb/config.rb
101
+ - lib/vtweb/merchant_hash_generator.rb
102
+ - lib/vtweb/post_params.rb
103
+ - lib/vtweb/version.rb
104
+ - vtweb.gemspec
105
+ homepage: http://panggi.com
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.0.0
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Ruby wrapper for Veritrans VT-Web.
129
+ test_files: []