kasikornbank 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9d8c9665a7b2e1714923778958d9e969f9aa3d3
4
- data.tar.gz: a491fbc6e3bdb79d76f440bfa6edaddc420b67a2
3
+ metadata.gz: d49b76c4be7a7943bd2b304ab5cc1e5b7791e965
4
+ data.tar.gz: a61f414ad87932b228fad277bf1e921699b7094a
5
5
  SHA512:
6
- metadata.gz: c9cb2f53ca6f9c513eae1617f66216548b6f67c40d17adab2020ea3480c33b4637e7e74e53f9be6c221ce6d8e34730626e0c5461e26388e5051fb59614df0ed9
7
- data.tar.gz: cfd3cc9c611af14315b7ae61b6821a07305ad390161511b32ef47e8bf98166339975d13a5b738798b48e66f270fd1624a9a6fb45b7dd5a9724c73071960b34e1
6
+ metadata.gz: '0579d5e8a4fe8287dd1ee9acd6ddf0bb78eb3658ab4d78556e46a43fdc38204971cd24db27392b951ea0d87a9c6bfa22b62d367a48dd19e708017c7c64d91a1d'
7
+ data.tar.gz: 69ae41cbff865fd6392b14f48432bcc6d71807246dc499d7bf7dcb3f0693cb36430a982300eb17bec665db76beecfa4356fd300715921be85ae4b8df43b82e01
data/README.md CHANGED
@@ -13,7 +13,7 @@ K-Payment Gateway (Kasikorn Bank Payment Gateway)
13
13
  Add this line to your application's Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'kasikornbank', '~> 0.1.4'
16
+ gem 'kasikornbank', '~> 0.1.5'
17
17
  ```
18
18
 
19
19
  And then execute:
@@ -44,11 +44,11 @@ Kasikornbank.configure do |config|
44
44
  end
45
45
  ```
46
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.
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
52
 
53
53
  ### 2 - Render Form
54
54
 
@@ -64,12 +64,12 @@ kbank = Kasikornbank::Render.new({
64
64
  })
65
65
  ```
66
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.
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
73
 
74
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 `post` method. This form should be placed in `checkout#create` view file.
75
75
 
@@ -123,17 +123,32 @@ post "checkout/kbank_response", to: "checkout#kbank_response"
123
123
  _\# app/controllers/checkout_controller.rb_
124
124
  ```
125
125
  require 'kasikornbank'
126
- skip_before_action :verify_authenticity_token, :only => [:kbank_response]
126
+ skip_before_action :verify_authenticity_token, :only => [:kbank_response, :kbank_notification]
127
127
 
128
128
  ...
129
-
129
+ _\# This is where cardholder will be re-directed back to merchant's website (POST request)_
130
130
  def kbank_response
131
131
  response = Kasikornbank::Response.new(request.POST)
132
132
  kbank = response.kbank_response
133
133
  checkout = Checkout.find(kbank[:invoice])
134
+ ...
135
+ # Here update your DB
136
+ # and send confirmation emails
137
+ ...
138
+ end
139
+
140
+ _\# This URI where kbank will send a variable 'PMGWRESP2' to merchant's server (POST requrest)_
141
+ def kbank_notification
142
+ response = Kasikornbank::Response.new(request.POST)
143
+ kbank = response.kbank_response
144
+ checkout = Checkout.find(kbank[:invoice])
145
+ ...
146
+ # Here update your DB
147
+ # and send confirmation emails
148
+ ...
134
149
  end
135
150
  ```
136
- _\# Response will be `{:respcode=>"00", :response=>"success", :invoice=>"21", :amount=>1.0, :auth_code=>"140580"}`_
151
+ _\# Response will be `{:respcode=>"00", :response=>"success", :invoice=>"21", :amount=>211.0, :auth_code=>"140580", :card=>"4751XXXXXXXX1452", :card_type=>"VISA"}`_
137
152
  > Controller name, routes, response url can be replaced with name you like.
138
153
 
139
154
  ## Development
@@ -14,13 +14,17 @@ module Kasikornbank
14
14
  response[:response] = response_code(str[97...99])
15
15
  response[:invoice] = remove_lead_zero(str[32...44])
16
16
  response[:amount] = amount(str[85...97])
17
- response[:auth_code] = nil
17
+ response[:auth_code] = 'N/A'
18
+ response[:card] = str[58...77]
19
+ response[:card_type] = card_type(str[105...108])
18
20
  elsif @params[:HOSTRESP]
19
21
  response[:respcode] = @params[:HOSTRESP]
20
22
  response[:response] = response_code(@params[:HOSTRESP])
21
23
  response[:invoice] = remove_lead_zero(@params[:RETURNINV])
22
24
  response[:amount] = amount(@params[:AMOUNT])
23
25
  response[:auth_code] = @params[:AUTHCODE]
26
+ response[:card] = 'N/A'
27
+ response[:card_type] = 'N/A'
24
28
  elsif @params[:PMGWRESP]
25
29
  str = @params[:PMGWRESP]
26
30
  response[:respcode] = str[0...2]
@@ -28,6 +32,8 @@ module Kasikornbank
28
32
  response[:invoice] = remove_lead_zero(str[56...68])
29
33
  response[:amount] = amount(str[82...94])
30
34
  response[:auth_code] = str[14...20]
35
+ response[:card] = 'N/A'
36
+ response[:card_type] = 'N/A'
31
37
  end
32
38
  response
33
39
  end
@@ -54,5 +60,24 @@ module Kasikornbank
54
60
  "fail"
55
61
  end
56
62
  end
63
+
64
+ def card_type(value)
65
+ case value.to_i
66
+ when 001
67
+ "VISA"
68
+ when 002
69
+ "MasterCard"
70
+ when 003
71
+ "KBank"
72
+ when 004
73
+ "JCB"
74
+ when 005
75
+ "CUP"
76
+ when 007
77
+ "AMEX"
78
+ else
79
+ "N/A"
80
+ end
81
+ end
57
82
  end
58
83
  end
@@ -1,3 +1,3 @@
1
1
  module Kasikornbank
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  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.5
4
+ version: 0.1.6
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-04-06 00:00:00.000000000 Z
11
+ date: 2017-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler