vtweb_json 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed044ee130377f58a8ca9e87ef8ea5474ba53132
4
+ data.tar.gz: c6d1203f233954872e81cafd3ccbbd75860838ee
5
+ SHA512:
6
+ metadata.gz: d408d2fbc48ed25fdd5387920203e5dad6b8f5c42a77d8f57184ab4a290e004537b5a75bc61acced5ac056fb00ca4b83ea1fc9806a2ee55fbeae363f81494e8c
7
+ data.tar.gz: 5be42f911e4f7591fde9f0fd4daa2359d1efd273cad37d7548abaf5698432f54c696860764e150eacf41148779f09df5a02900adedc75d4385d849624c799709
data/.gitignore ADDED
@@ -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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vtweb_json.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # Veritrans VT-Web Ruby wrapper using JSON request
2
+
3
+ Ruby Wrapper for Veritrans VT-Web. Visit https://www.veritrans.co.id for more information about the product and see documentation at http://docs.veritrans.co.id/vtweb/index.html for more technical details.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'vtweb_json'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install vtweb_json
18
+
19
+ ## Usage
20
+
21
+ In your Rails app, create 'vtweb.yml' at config directory (config/vtweb.yml) with this code:
22
+
23
+ development:
24
+ merchant_id: "T100000000000001XXXXXX"
25
+ merchant_hash_key: "yourmerchanthashkey"
26
+ unfinish_payment_return_url: "http://localhost:3000/cancel_pay"
27
+ finish_payment_return_url: "http://localhost:3000/finish"
28
+ error_payment_return_url: "http://localhost:3000/error"
29
+ vtweb_server: "http://127.0.0.1:4000"
30
+
31
+ production:
32
+ merchant_id: "A100000000000001XXXXXX"
33
+ merchant_hash_key: "yourmerchanthashkey"
34
+ unfinish_payment_return_url: "http://yourweb.com/canceled"
35
+ finish_payment_return_url: "http://yourweb.com/thank_you"
36
+ error_payment_return_url: "http://yourweb.com/shop_again"
37
+
38
+ Create a file in 'config/initializers' to set config to vtweb.yml, for example 'store_config.rb':
39
+
40
+ raw_config = File.read("#{Rails.root}/config/vtweb.yml")
41
+ CONFIG = YAML.load(raw_config)[Rails.env].symbolize_keys
42
+
43
+
44
+ In your controller, create a method to use the gem. I took the code from https://github.com/veritrans/veritrans-rails-sample-cart for the example with some modification:
45
+
46
+ def confirm
47
+ client = ::VtwebJson::Client.new
48
+ client.order_id = SecureRandom.hex(5)
49
+ client.merchant_hash_key = CONFIG[:merchant_hash_key]
50
+
51
+ # Example
52
+ @carts = Cart.all
53
+ @total = Cart.select(:sub_total).sum(:sub_total)
54
+
55
+ params["item"] = []
56
+
57
+ @carts.each do |item|
58
+ params["item"] << { "item_id" => item.product_id, "price" => item.product.price.to_s, "quantity" => item.quantity.to_s,
59
+ "item_name1" => item.product.name, "item_name2" => item.product.name }
60
+ end
61
+
62
+ client.item = params["item"]
63
+ client.billing_different_with_shipping = 1
64
+ client.required_shipping_address = 1
65
+ client.first_name = params[:shipping_first_name]
66
+ client.last_name = params[:shipping_last_name]
67
+ client.address1 = params[:shipping_address1]
68
+ client.address2 = params[:shipping_address2]
69
+ client.city = params[:shipping_city]
70
+ client.country_code = "IDN"
71
+ client.postal_code = params[:shipping_postal_code]
72
+ client.phone = params[:shipping_phone]
73
+ client.shipping_first_name = params[:shipping_first_name]
74
+ client.shipping_last_name = params[:shipping_last_name]
75
+ client.shipping_address1 = params[:shipping_address1]
76
+ client.shipping_address2 = params[:shipping_address2]
77
+ client.shipping_city = params[:shipping_city]
78
+ client.shipping_country_code = "IDN"
79
+ client.shipping_postal_code = params[:shipping_postal_code]
80
+ client.shipping_phone = params[:shipping_phone]
81
+ client.email = params[:email]
82
+
83
+ # Payment Options
84
+ client.promo_bins = ['411111', '510510']
85
+ client.enable_3d_secure = 1
86
+ client.installment_banks = ['bni', 'cimb', 'mandiri']
87
+ client.installment_terms = { bni: [3,12,2], cimb: [3,6,12] }
88
+ client.point_banks = ['cimb', 'bni']
89
+ client.bank = 'bni'
90
+ client.payment_methods = ['credit_card', 'mandiri_clickpay']
91
+
92
+ client.tokens
93
+ @client = client
94
+ @tokens = JSON.parse client.tokens.body
95
+ render :layout => 'application'
96
+ end
97
+
98
+ After you get TOKEN_BROWSER and TOKEN_MERCHANT, you have to send a http post request merchant_id, order_id and TOKEN_BROWSER to redirection url of vtweb. This code was also taken from https://github.com/veritrans/veritrans-rails-sample-cart :
99
+
100
+ <h1 align="center">Confirm Purchase Items</h1>
101
+ <%= form_tag(@client.redirection_url, :name => "form_auto_post") do -%>
102
+ <input type="hidden" name="merchant_id" value="<%= @client.merchant_id %>">
103
+ <input type="hidden" name="order_id" value="<%= @client.order_id %>">
104
+ <input type="hidden" name="token_browser" value="<%= @tokens["token_browser"] %>">
105
+ <table border="1" align="center" width="80%" cellpadding="10" bgcolor="#FFFFCC">
106
+ <tr>
107
+ <th>Name</th>
108
+ <th>Price</th>
109
+ <th>Quantity</th>
110
+ <th>Sub Total</th>
111
+ </tr>
112
+
113
+ <% for cart in @carts %>
114
+ <tr>
115
+ <td><%= cart.product.name %></td>
116
+ <td><%= cart.product.price %></td>
117
+ <td><%= cart.quantity %></td>
118
+ <td><%= cart.sub_total %></td>
119
+ </tr>
120
+ <% end %>
121
+ <tr>
122
+ <td colspan="2"></td>
123
+ <td style="text-align=right"><strong>Total</strong></td>
124
+ <td style="text-align=right"><strong><%= @total %> </strong></td>
125
+ </tr>
126
+ </table>
127
+ <br><br>
128
+ <div align="center">
129
+ <input type="submit" value="Go to payment page">
130
+ </div>
131
+ <% end %>
132
+
133
+ ## Contributing
134
+
135
+ 1. Fork it http://github.com/panggi/vtweb_json/fork
136
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
137
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
138
+ 4. Push to the branch (`git push origin my-new-feature`)
139
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,47 @@
1
+ require "yaml"
2
+
3
+ module VtwebJson
4
+
5
+ module Config
6
+
7
+ # Server
8
+ VTWEB_SERVER = "https://vtweb.veritrans.co.id"
9
+ GET_TOKENS_URL = "/v1/tokens.json"
10
+ REDIRECTION_URL = "/v1/payments.json"
11
+
12
+ # Params Config
13
+ BILLING_DIFFERENT_WITH_SHIPPING = '0'
14
+
15
+ def Config.included(mod)
16
+ class <<self
17
+ template = {
18
+ 'merchant_id' => nil,
19
+ 'merchant_hash_key' => nil,
20
+ 'finish_payment_return_url' => nil,
21
+ 'unfinish_payment_return_url' => nil,
22
+ 'error_payment_return_url' => nil,
23
+ 'vtweb_server' => 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 VtwebJson
2
+ module MerchantHashGenerator
3
+ def self.generate(merchant_id, merchant_hash_key, order_id)
4
+ Digest::SHA512.hexdigest("#{merchant_hash_key},#{merchant_id},#{order_id}")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module VtwebJson
2
+ VERSION = "0.0.1"
3
+ end
data/lib/vtweb_json.rb ADDED
@@ -0,0 +1,135 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ # Required gems
4
+ require 'jbuilder'
5
+ require 'faraday'
6
+ require 'digest/sha2'
7
+
8
+ # Other Requirements
9
+ require "vtweb_json/config"
10
+ require "vtweb_json/merchant_hash_generator"
11
+ require "vtweb_json/version"
12
+
13
+ module VtwebJson
14
+ class Client
15
+ include Config
16
+ def initialize(&block)
17
+ class <<self
18
+ self
19
+ end.class_eval do
20
+ attr_accessor :version, :merchant_id, :merchant_hash_key, :order_id, :billing_different_with_shipping, :required_shipping_address,
21
+ :repeat_line, :item_id, :item_name1, :item_name2, :price, :quantity, :shipping_address1, :shipping_address2, :shipping_city,
22
+ :shipping_country_code, :shipping_first_name, :shipping_last_name, :shipping_phone, :shipping_postal_code, :email,
23
+ :payment_methods, :enable_3d_secure, :address1, :address2, :city, :country_code, :first_name, :last_name, :phone, :postal_code,
24
+ :finish_payment_return_url, :error_payment_return_url, :unfinish_payment_return_url, :bank, :installment_banks, :installment_terms,
25
+ :point_banks, :promo_bins, :item
26
+ end
27
+ end
28
+
29
+ # Define params
30
+
31
+ def vtweb_server
32
+ return Client.config["vtweb_server"] ? Client.config["vtweb_server"] : Config::VTWEB_SERVER
33
+ end
34
+
35
+ def redirection_url
36
+ "#{vtweb_server}#{Config::REDIRECTION_URL}"
37
+ end
38
+
39
+ def _merchant_id
40
+ return Client.config["merchant_id"]
41
+ end
42
+
43
+ def _merchant_hash_key
44
+ return Client.config["merchant_hash_key"]
45
+ end
46
+
47
+ def _error_payment_return_url
48
+ return Client.config["error_payment_return_url"]
49
+ end
50
+
51
+ def _finish_payment_return_url
52
+ return Client.config["finish_payment_return_url"]
53
+ end
54
+
55
+ def _unfinish_payment_return_url
56
+ return Client.config["unfinish_payment_return_url"]
57
+ end
58
+
59
+ # Calculate Merchant Hash
60
+
61
+ def merchanthash
62
+ return MerchantHashGenerator::generate(_merchant_id, _merchant_hash_key, self.order_id);
63
+ end
64
+
65
+ # Build JSON from defined params
66
+
67
+ def build_json
68
+
69
+ Jbuilder.encode do |json|
70
+ # Required Params
71
+ json.version 1
72
+ json.merchant_id _merchant_id
73
+ json.merchanthash merchanthash
74
+ json.order_id self.order_id
75
+ json.billing_different_with_shipping self.billing_different_with_shipping
76
+ json.required_shipping_address self.required_shipping_address
77
+ json.repeat_line self.item.length
78
+ self.item.each do |item|
79
+ json.item_id [item['item_id']]
80
+ json.item_name1 [item['item_name1']]
81
+ json.item_name2 [item['item_name2']]
82
+ json.price [item['price']]
83
+ json.quantity [item['quantity']]
84
+ end
85
+
86
+ # Required if required_shipping_address = 1
87
+ json.shipping_address1 self.shipping_address1
88
+ json.shipping_address2 self.shipping_address2
89
+ json.shipping_city self.shipping_city
90
+ json.shipping_country_code self.shipping_country_code
91
+ json.shipping_first_name self.shipping_first_name
92
+ json.shipping_last_name self.shipping_last_name
93
+ json.shipping_phone self.shipping_phone
94
+ json.shipping_postal_code self.shipping_postal_code
95
+ json.email self.email
96
+
97
+ # Optional Params
98
+ json.payment_methods self.payment_methods
99
+ json.enable_3d_secure self.enable_3d_secure
100
+ json.address1 self.address1
101
+ json.address2 self.address2
102
+ json.city self.city
103
+ json.country_code self.country_code
104
+ json.first_name self.first_name
105
+ json.last_name self.last_name
106
+ json.phone self.phone
107
+ json.postal_code self.postal_code
108
+ json.finish_payment_return_url _finish_payment_return_url
109
+ json.error_payment_return_url _error_payment_return_url
110
+ json.unfinish_payment_return_url _unfinish_payment_return_url
111
+ json.bank self.bank
112
+ json.installment_banks self.installment_banks
113
+ json.installment_terms self.installment_terms
114
+ json.point_banks self.point_banks
115
+ json.promo_bins self.promo_bins
116
+ end
117
+ end
118
+
119
+ # Get Token
120
+
121
+ def tokens
122
+ conn = Faraday.new(:url => vtweb_server) do |faraday|
123
+ faraday.adapter Faraday.default_adapter
124
+ end
125
+
126
+ response = conn.post do |request|
127
+ request.url GET_TOKENS_URL
128
+ request.headers['Content-Type'] = 'application/json'
129
+ request.headers['Accept'] = 'application/json'
130
+ request.body = build_json
131
+ end
132
+
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vtweb_json/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vtweb_json"
8
+ spec.version = VtwebJson::VERSION
9
+ spec.authors = ["Panggi Libersa Jasri Akadol"]
10
+ spec.email = ["panggi@me.com"]
11
+ spec.summary = %q{Ruby wrapper for Veritrans VT-Web using JSON Request.}
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 = "https://github.com/panggi/vtweb-json"
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 "faraday", "0.8.8"
22
+ spec.add_runtime_dependency "jbuilder", "1.5.3"
23
+ spec.add_runtime_dependency "rake"
24
+ spec.add_runtime_dependency "pry"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.5"
27
+ spec.add_development_dependency "rake"
28
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vtweb_json
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-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: jbuilder
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.3
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: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: VT-Web makes accepting online payments simple because the whole payment
98
+ process is handled by Veritrans, and we take care most of the information security
99
+ compliance requirements from the bank (Veritrans is certified as a PCI-DSS Level
100
+ 1 Service Provider). Merchants focus on their core business, while we take care
101
+ of the rest.
102
+ email:
103
+ - panggi@me.com
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - .gitignore
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/vtweb_json.rb
114
+ - lib/vtweb_json/config.rb
115
+ - lib/vtweb_json/merchant_hash_generator.rb
116
+ - lib/vtweb_json/version.rb
117
+ - vtweb_json.gemspec
118
+ homepage: https://github.com/panggi/vtweb-json
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.0.0
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Ruby wrapper for Veritrans VT-Web using JSON Request.
142
+ test_files: []