kasikornbank 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +153 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/kasikornbank.gemspec +28 -0
- data/lib/generators/kasikornbank/install_generator.rb +16 -0
- data/lib/generators/kasikornbank/templates/config/initializers/kasikornbank.rb +30 -0
- data/lib/kasikornbank/configuration.rb +18 -0
- data/lib/kasikornbank/response.rb +55 -0
- data/lib/kasikornbank/version.rb +3 -0
- data/lib/kasikornbank.rb +100 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24b6b6162bb8f90cfb3e111aefb7c6651cf0b8d6
|
4
|
+
data.tar.gz: ba537aaf1ed98e2b038fc41ac8631e7e7f1d6359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1d6d43d71f7b9d085ea466cdb38154e4a46227e33a513552d44b1b1e9ffa10a6a82350714cc503148a29145df02f5076a5e64d7a03bc3cc7bd277bb1fafecf6
|
7
|
+
data.tar.gz: f48e9ecc30ff56f23a52d7d6e50abcd5eb4a3d2652c4f835e561e75a0a9db28421c26a26ebcc9686df09411ab8c06d019f23227795e10bc4ea6563afadbdc06d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at frizbee@vivaldi.net. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Frizbee Vivaldi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/frizbee/kasikornbank.svg?branch=master)](https://travis-ci.org/frizbee/kasikornbank)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/kasikornbank.svg)](https://badge.fury.io/rb/kasikornbank)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/frizbee/kasikornbank/badges/gpa.svg)](https://codeclimate.com/github/frizbee/kasikornbank)
|
4
|
+
[![Issue Count](https://codeclimate.com/github/frizbee/kasikornbank/badges/issue_count.svg)](https://codeclimate.com/github/frizbee/kasikornbank)
|
5
|
+
|
6
|
+
# Kasikorn Bank Payment Gateway (Thailand)
|
7
|
+
|
8
|
+
This gem provides support for the accepting a credit cards payments with
|
9
|
+
K-Payment Gateway (Kasikorn Bank Payment Gateway)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'kasikornbank', '~> 0.1.3'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install kasikornbank
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
### 1 - Configuration
|
30
|
+
|
31
|
+
Generate initializer
|
32
|
+
|
33
|
+
```
|
34
|
+
rails g kasikornbank:install
|
35
|
+
```
|
36
|
+
Set credentials and other options in `config/initializers/kasikornbank.rb`
|
37
|
+
```
|
38
|
+
Kasikornbank.configure do |config|
|
39
|
+
config.merchant2 = ENV["KBANK_MERCHANT2"]
|
40
|
+
config.term2 = ENV["KBANK_TERM2"]
|
41
|
+
config.kbank_secret = ENV["KBANK_SECRET"]
|
42
|
+
config.url2 = "https://www.example.com/kbank_back_url"
|
43
|
+
config.respurl = "https://www.example.com/kbank_notify_url"
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
`config.merchant2` = Merchant ID Your merchant number issued by KBank. Numeric 15 digits e.g. 401001234567001.
|
48
|
+
`config.term2` = Terminal ID Your terminal ID issued by KBank. Numeric 8 digits e.g. 70123456.
|
49
|
+
`config.kbank_secret` = Secret key (salt) to make md5 hash. Issued by KBank.
|
50
|
+
`config.url2` = URL where cardholder will be redirected back to merchant website.
|
51
|
+
`config.respurl` = Notify url. Must be SSL/TLS URL where KBank will send a variable PMGWRESP2.
|
52
|
+
|
53
|
+
### 2 - Render Form
|
54
|
+
|
55
|
+
In your `checkout#create` method call
|
56
|
+
```
|
57
|
+
kbank = Kasikornbank::Render.new({
|
58
|
+
invmerchant: "987",
|
59
|
+
details2: "Electric Fan = Model XYZ103",
|
60
|
+
ip_address: "111.111.111.205",
|
61
|
+
amount: 10.99,
|
62
|
+
shop_id: "00",
|
63
|
+
payterm2: "10"
|
64
|
+
})
|
65
|
+
```
|
66
|
+
|
67
|
+
`invmerchant` = Invoice number, should be a unique number.
|
68
|
+
`details2` = Product description.
|
69
|
+
`ip_address` = IP address of merchant's server.
|
70
|
+
`amount` = Total amount of purchased order.
|
71
|
+
`shop_id` = <**Optional**> Shop ID, for payment template, see documentation.
|
72
|
+
`payterm2` = <**Optional**> Number of month for installment.
|
73
|
+
|
74
|
+
> :exclamation: Unfortunately, Kasikorn Bank doesn't have a proper way to handle payment API. In this case `Kasikornbank::Render.new()` will generage auto submit form and return it with `form` method. This form should be placed in `checkout#create` view file.
|
75
|
+
|
76
|
+
#### Example
|
77
|
+
|
78
|
+
_\# app/controllers/checkout_controller.rb_
|
79
|
+
```
|
80
|
+
require 'kasikornbank'
|
81
|
+
|
82
|
+
....
|
83
|
+
|
84
|
+
def create
|
85
|
+
kbank = Kasikornbank::Render.new({
|
86
|
+
invmerchant: "987",
|
87
|
+
details2: "Electric Fan = Model XYZ103",
|
88
|
+
ip_address: "111.111.111.205",
|
89
|
+
amount: 10.99
|
90
|
+
})
|
91
|
+
@form = kbank.form
|
92
|
+
end
|
93
|
+
```
|
94
|
+
_\# app/views/checkout/create.html.erb_
|
95
|
+
```
|
96
|
+
<%= @form.html_safe if @form.present? %>
|
97
|
+
```
|
98
|
+
|
99
|
+
### 3 - Response
|
100
|
+
|
101
|
+
To be able to receive response from KBank you have to create another action in your checkout controller with post request as it is mandatory by KBank.
|
102
|
+
|
103
|
+
In your `routes.rb` file add `post 'checkout/kbank_response', to: 'checkout#kbank_response'` make sure that this line is out of scope of your locale.
|
104
|
+
|
105
|
+
Next step is to avoid blocking request by CSRF rule. This post request will come directly from KBank server, you need to make sure that `checkout#kbank_response` action is not blocked by CSRF. To do that, go to `checkout_controller.rb` and add this line: `skip_before_action :verify_authenticity_token, :only => [:kbank_response]` this will give access to post anything to your action. Scary huh?
|
106
|
+
|
107
|
+
KBank will send response to your `checkout#kbank_response` action to
|
108
|
+
catch that respose use `Kasikornbank::Response.new(request.POST)` method
|
109
|
+
in your controller. You will be provided with hash of data `{:response=>"success", :invoice=>"17", :amount=>874.0, :auth_code=>nil}` use it to update your database.
|
110
|
+
|
111
|
+
#### Example
|
112
|
+
|
113
|
+
_\# config/routes.rb_
|
114
|
+
```
|
115
|
+
scope "/:locale", locale: /en|th|zh/ do
|
116
|
+
...
|
117
|
+
resources :checkout, only: [:new, :create]
|
118
|
+
...
|
119
|
+
end
|
120
|
+
post "checkout/kbank_response", to: "checkout#kbank_response"
|
121
|
+
```
|
122
|
+
|
123
|
+
_\# app/controllers/checkout_controller.rb_
|
124
|
+
```
|
125
|
+
require 'kasikornbank'
|
126
|
+
skip_before_action :verify_authenticity_token, :only => [:kbank_response]
|
127
|
+
|
128
|
+
...
|
129
|
+
|
130
|
+
def kbank_response
|
131
|
+
response = Kasikornbank::Response.new(request.POST)
|
132
|
+
kbank = response.kbank_response
|
133
|
+
checkout = Checkout.find(kbank[:invoice])
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
> Controller name, routes, response url can be replaced with name you like.
|
138
|
+
|
139
|
+
## Development
|
140
|
+
|
141
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
142
|
+
|
143
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
144
|
+
|
145
|
+
## Contributing
|
146
|
+
|
147
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/frizbee/kasikornbank. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
148
|
+
|
149
|
+
|
150
|
+
## License
|
151
|
+
|
152
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
153
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "kasikornbank"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -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 'kasikornbank/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kasikornbank"
|
8
|
+
spec.version = Kasikornbank::VERSION
|
9
|
+
spec.authors = ["Andre Antonov"]
|
10
|
+
spec.email = ["mail2andrewa@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This gem provides support for the accepting a credit cards payments with K-Payment Gatewak (Kasikorn bank)}
|
13
|
+
spec.description = %q{K-Payment Gateway is a payment service for processing credit card transactions that accept VISA Cards, MasterCard Cards, American Express, JCB Cards and China UnionPay Cards issued by banks worldwide. Participating online merchants can receive real time approval of credit card online transactions 24 hours a day in 35 different currencies.}
|
14
|
+
spec.homepage = "https://github.com/frizbee/kasikornbank"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module Kasikornbank
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
# include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates',__FILE__)
|
8
|
+
|
9
|
+
desc "Creates KBank initializer to your application"
|
10
|
+
|
11
|
+
def generate_initializer
|
12
|
+
template "config/initializers/kasikornbank.rb", 'config/initializers/kasikornbank.rb'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Cardholder/customer checks out from the merchant website and merchant website redirects
|
2
|
+
# cardholder to K-Payment Gateway with pre-agreed parameters. The following parameters need to
|
3
|
+
# be passed to K-Payment Gateway to process the transaction with Method = POST.
|
4
|
+
|
5
|
+
# Use this hook to configure KBank variables
|
6
|
+
Kasikornbank.configure do |config|
|
7
|
+
|
8
|
+
# Merchant ID Your merchant number issued by KBank
|
9
|
+
# Numeric 15 digits e.g. 401001234567001
|
10
|
+
config.merchant2 = ENV["KBANK_MERCHANT2"]
|
11
|
+
|
12
|
+
# Terminal ID Your terminal ID issued by KBank
|
13
|
+
# Numeric 8 digits e.g. 70123456
|
14
|
+
config.term2 = ENV["KBANK_TERM2"]
|
15
|
+
|
16
|
+
# Secret key (salt) to make md5 hash
|
17
|
+
# Issued by KBank Merchant must keep „MD5 Secret Key‟
|
18
|
+
# as secret between merchant and Kbank.
|
19
|
+
# Please strictly do not reveal this key to any other
|
20
|
+
# persons who are not concerned.
|
21
|
+
# MD5 Key issued by Kasikorn Bank
|
22
|
+
config.kbank_secret = ENV["KBANK_SECRET"]
|
23
|
+
|
24
|
+
# URL where cardholder will be redirected
|
25
|
+
# back to merchant website
|
26
|
+
config.url2 = "https://www.example.com"
|
27
|
+
|
28
|
+
# Must be SSL/TLS URL where KBank will send a variable PMGWRESP2
|
29
|
+
config.respurl = "https://www.example.com"
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Configuration
|
2
|
+
attr_accessor :merchant2
|
3
|
+
attr_accessor :term2
|
4
|
+
attr_accessor :kbank_secret
|
5
|
+
attr_accessor :url2
|
6
|
+
attr_accessor :respurl
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
# Those are testing details
|
10
|
+
# provided by KBanks documentation
|
11
|
+
# for testing purpose only
|
12
|
+
@merchant2 = '401001234567001'
|
13
|
+
@term2 = '70123456'
|
14
|
+
@kbank_secret = 'Rtn6DPfR7XCPpc_v8Fx0Fcv40m0XtcVR'
|
15
|
+
@url2 = 'https://www.example.com'
|
16
|
+
@respurl = 'https://www.example.com'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Kasikornbank
|
2
|
+
class Response
|
3
|
+
attr_accessor :params
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
@params = params
|
7
|
+
end
|
8
|
+
|
9
|
+
def kbank_response
|
10
|
+
response = Hash.new
|
11
|
+
if @params[:PMGWRESP2]
|
12
|
+
str = @params[:PMGWRESP2]
|
13
|
+
response[:response] = response_code(str[97...99])
|
14
|
+
response[:invoice] = remove_lead_zero(str[32...44])
|
15
|
+
response[:amount] = amount(str[85...97])
|
16
|
+
response[:auth_code] = nil
|
17
|
+
elsif @params[:HOSTRESP]
|
18
|
+
response[:response] = response_code(@params[:HOSTRESP])
|
19
|
+
response[:invoice] = remove_lead_zero(@params[:RETURNINV])
|
20
|
+
response[:amount] = amount(@params[:AMOUNT])
|
21
|
+
response[:auth_code] = @params[:AUTHCODE]
|
22
|
+
elsif @params[:PMGWRESP]
|
23
|
+
str = @params[:PMGWRESP]
|
24
|
+
response[:response] = response_code(str[0...2])
|
25
|
+
response[:invoice] = remove_lead_zero(str[56...68])
|
26
|
+
response[:amount] = amount(str[82...94])
|
27
|
+
response[:auth_code] = str[14...20]
|
28
|
+
end
|
29
|
+
response
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Converting amount and
|
35
|
+
# returning in decimal
|
36
|
+
def amount(value)
|
37
|
+
value = remove_lead_zero(value)
|
38
|
+
value.to_f / 100
|
39
|
+
end
|
40
|
+
|
41
|
+
# Removing all leading zeros
|
42
|
+
def remove_lead_zero(value)
|
43
|
+
value.sub!(/^[0]+/,'')
|
44
|
+
end
|
45
|
+
|
46
|
+
def response_code(value)
|
47
|
+
case value
|
48
|
+
when "00"
|
49
|
+
"success"
|
50
|
+
else
|
51
|
+
"fail"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/kasikornbank.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require "kasikornbank/version"
|
2
|
+
require "kasikornbank/response"
|
3
|
+
require "kasikornbank/configuration"
|
4
|
+
require 'digest/md5'
|
5
|
+
|
6
|
+
module Kasikornbank
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
self.configuration ||= Configuration.new
|
13
|
+
yield(configuration)
|
14
|
+
end
|
15
|
+
|
16
|
+
class Render
|
17
|
+
@@fillspace = "Y"
|
18
|
+
@@kbank_url = "https://rt05.kasikornbank.com/pggroup/payment.aspx"
|
19
|
+
attr_accessor :args
|
20
|
+
|
21
|
+
def initialize(*args)
|
22
|
+
@args = args
|
23
|
+
end
|
24
|
+
|
25
|
+
def form
|
26
|
+
form = "<form name='sendform' method='post' action='#{@@kbank_url}'>"
|
27
|
+
form << "<input type='hidden' id=MERCHANT2 name=MERCHANT2 value='#{Kasikornbank.configuration.merchant2}'>"
|
28
|
+
form << "<input type='hidden' id=TERM2 name=TERM2 value='#{Kasikornbank.configuration.term2}'>"
|
29
|
+
form << "<input type='hidden' id=AMOUNT2 name=AMOUNT2 value='#{amount_in_cents}'>"
|
30
|
+
form << "<input type='hidden' id=URL2 name=URL2 value='#{Kasikornbank.configuration.url2}'>"
|
31
|
+
form << "<input type='hidden' id=RESPURL name=RESPURL value='#{Kasikornbank.configuration.respurl}'>"
|
32
|
+
form << "<input type='hidden' id=IPCUST2 name=IPCUST2 value='#{remote_ip}'>"
|
33
|
+
form << "<input type='hidden' id=DETAIL2 name=DETAIL2 value='#{order_details}'>"
|
34
|
+
form << "<input type='hidden' id=INVMERCHANT name=INVMERCHANT value='#{invoice_number}'>"
|
35
|
+
form << "<input type='hidden' id=FILLSPACE name=FILLSPACE value='#{@@fillspace}'>"
|
36
|
+
form << "<input type='text' name='SHOPID' id='SHOPID' value='#{shop_id}'>"
|
37
|
+
form << "<input type='text' id=Payterm2 name=Payterm2 value='#{payterm2}'>"
|
38
|
+
form << "<input type='text' id='CHECKSUM' name='CHECKSUM' value='#{checksum}'>"
|
39
|
+
form << "</form>"
|
40
|
+
form << "<script>"
|
41
|
+
form << "window.onload = function(){document.forms['sendform'].submit()}"
|
42
|
+
form << "</script>"
|
43
|
+
form
|
44
|
+
end
|
45
|
+
|
46
|
+
def checksum
|
47
|
+
# Accoording to the documentation we have to create
|
48
|
+
# MD5 checksum. Should be in this order:
|
49
|
+
# MERCHANT2 + TERM2 + AMOUNT2 + URL2 + RESURL + IPCUST2 + DETAIL2 + INVMERCHANT + FILLSPACE + SHOPID + PAYTERM2 + MD5 Key
|
50
|
+
# Optional fields can be skipped (Fillspace, ShopId, payterm2)
|
51
|
+
Digest::MD5.hexdigest(
|
52
|
+
"#{Kasikornbank.configuration.merchant2}#{Kasikornbank.configuration.term2}#{amount_in_cents}#{Kasikornbank.configuration.url2}#{Kasikornbank.configuration.respurl}#{remote_ip}#{order_details}#{invoice_number}#{@@fillspace}#{shop_id}#{payterm2}#{Kasikornbank.configuration.kbank_secret}"
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Invoice numebr
|
57
|
+
# should be Numeric
|
58
|
+
# should be 12 digits long
|
59
|
+
def invoice_number
|
60
|
+
sprintf("%012d",@args[0][:invmerchant])
|
61
|
+
end
|
62
|
+
|
63
|
+
# Field DETAIL2
|
64
|
+
# Order detail name
|
65
|
+
# e.g. Electric Fan - Toshiba Model CM203
|
66
|
+
def order_details
|
67
|
+
@args[0][:details2]
|
68
|
+
end
|
69
|
+
|
70
|
+
# Optional
|
71
|
+
# Shop ID. for payment template
|
72
|
+
def shop_id
|
73
|
+
@args[0][:shop_id]
|
74
|
+
end
|
75
|
+
|
76
|
+
# Optional
|
77
|
+
# Number of month for installment
|
78
|
+
# 2 digits = 3,6,10 month
|
79
|
+
def payterm2
|
80
|
+
@args[0][:payterm2]
|
81
|
+
end
|
82
|
+
|
83
|
+
# Get the client's IP address
|
84
|
+
def remote_ip
|
85
|
+
# This can be used with api.ipify.org service
|
86
|
+
# public_ip = `curl https://api.ipify.org`
|
87
|
+
# Extra call not worth it
|
88
|
+
@args[0][:ip_address]
|
89
|
+
end
|
90
|
+
|
91
|
+
# Amount should be converted
|
92
|
+
# to be in cents before send to KBank
|
93
|
+
# 10.99 * 100 = 1099
|
94
|
+
# Should be 12 digits number
|
95
|
+
def amount_in_cents
|
96
|
+
amount = (@args[0][:amount].to_f * 100).to_i
|
97
|
+
sprintf("%012d",amount)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kasikornbank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andre Antonov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,7 +76,24 @@ email:
|
|
76
76
|
executables: []
|
77
77
|
extensions: []
|
78
78
|
extra_rdoc_files: []
|
79
|
-
files:
|
79
|
+
files:
|
80
|
+
- ".gitignore"
|
81
|
+
- ".rspec"
|
82
|
+
- ".travis.yml"
|
83
|
+
- CODE_OF_CONDUCT.md
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- kasikornbank.gemspec
|
91
|
+
- lib/generators/kasikornbank/install_generator.rb
|
92
|
+
- lib/generators/kasikornbank/templates/config/initializers/kasikornbank.rb
|
93
|
+
- lib/kasikornbank.rb
|
94
|
+
- lib/kasikornbank/configuration.rb
|
95
|
+
- lib/kasikornbank/response.rb
|
96
|
+
- lib/kasikornbank/version.rb
|
80
97
|
homepage: https://github.com/frizbee/kasikornbank
|
81
98
|
licenses:
|
82
99
|
- MIT
|