hncb_e_atm 0.0.2 → 0.0.3

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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NTg2MGJiY2YyNzQ0MjVhMmRiMjAyOTk2OWVmZTI2YmE4MTI5NGUyNw==
5
- data.tar.gz: !binary |-
6
- MGNhMGJjN2IyNmU4YjkzNDk5MzliZjA4ODVlNzljOWUwOTgxYWRiZg==
2
+ SHA1:
3
+ metadata.gz: a5ead461780630f5735f7e26ab144ed4f844fa58
4
+ data.tar.gz: 18b00b8cf1c05306794cda3ff65a4e20ca9b943f
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MzU4Yzk0MTAzNDU4NDU2ZmFmMWY3ZGRkY2M1Y2E5YjYzYWU0MGE3ZWM4NTQw
10
- MWZmOGQzYjI0MTA1ZDE1ZGI1OGEyZjJhMzU5ZGI4MWVhMjcxZTNjYzE1MjU3
11
- YTU5YWZiOTY4YjNkZjZkZjJkNmI1MjQ2MjcxZDM1NDUzYzU4NTM=
12
- data.tar.gz: !binary |-
13
- MzFiOTU2ZGViNmZiOWRhMTc5MDkzYjA1OTQ2ZWFmNGM5YWQzMWY4N2VkNzhi
14
- YWU4ZjY5NTFlMmM2OWM0YTE4ZGJlZWU4MWJmZmYwMTI0OTRlZmYwOWNlYWIy
15
- NmMyOWY3ODBkZTY4Mzk1ZGM0MzRiYjZlNzY5NmQzZWI0NjJiM2Q=
6
+ metadata.gz: bea463121db7323fe1469a780b84b0a3b5e9b81cd95039a01243f2341cf72c4c8e34cb87d7192a9a9593c74e9c3f05be9ef13da25c50d3671694ee5c6151e07f
7
+ data.tar.gz: 897e2459d2bd73c1e07ce5113b2b4b4cde841e1b9846e1ac609e96bb95454bc6f60c8f74fe50a458f8da7c80ee754cb047d5149912cbd9ca955f5945011cb975
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use ruby-1.9.3@hncb_e_atm --create
1
+ rvm use ruby-2.0.0@hncb_e_atm --create
data/lib/hncb_e_atm.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require "hncb_e_atm/version"
2
2
  require "hncb_e_atm/utils"
3
3
  require "hncb_e_atm/view_helpers"
4
- require "hncb_e_atm/form"
4
+ require "hncb_e_atm/serialization"
5
+ require "hncb_e_atm/response"
5
6
 
6
7
  if defined?(Rails)
7
8
  require 'hncb_e_atm/railtie'
@@ -0,0 +1,19 @@
1
+ require 'base64'
2
+ require 'uri'
3
+
4
+ module HncbEAtm
5
+ class Response
6
+ def initialize params
7
+ @params = HncbEAtm::Utils.stringfy_keys(params)
8
+ end
9
+
10
+ def parse
11
+ options_string = Base64.decode64 @params["val"]
12
+ Hash[URI::decode_www_form options_string]
13
+ end
14
+
15
+ def success?
16
+ true
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  module HncbEAtm
2
- class Form
2
+ class Serialization
3
3
  REQUIRED_FIELDS = [
4
4
  "store_id",
5
5
  "store_account",
@@ -1,3 +1,3 @@
1
1
  module HncbEAtm
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -7,7 +7,7 @@ module HncbEAtm
7
7
  include ::ActionView::Context
8
8
 
9
9
  def hncb_e_atm_form_for(params, &block)
10
- query_string = HncbEAtm::Form.new(params).serialize
10
+ query_string = HncbEAtm::Serialization.new(params).serialize
11
11
  val = Base64.encode64(query_string)
12
12
  mac = Digest::SHA1.hexdigest(query_string).upcase
13
13
 
@@ -27,5 +27,17 @@ module HncbEAtm
27
27
 
28
28
  nil
29
29
  end
30
+
31
+ def hncb_e_atm_link_for(params)
32
+ query_string = HncbEAtm::Serialization.new(params).serialize
33
+ val = Base64.encode64(query_string)
34
+ mac = Digest::SHA1.hexdigest(query_string).upcase
35
+
36
+ html_link = "#{HncbEAtm.endpoint}?trx=com.eatm.wibc.trx.web.EAtmWShopping&state=prompt&val=#{val}&mac=#{mac}"
37
+
38
+ concat(html_link.respond_to?(:html_safe) ? html_link.html_safe : html_form)
39
+
40
+ nil
41
+ end
30
42
  end
31
43
  end
@@ -1,6 +1,6 @@
1
- require File.expand_path('../../../lib/hncb_e_atm/form', File.dirname(__FILE__))
1
+ require File.expand_path('../../../lib/hncb_e_atm/serialization', File.dirname(__FILE__))
2
2
 
3
- describe HncbEAtm::Form do
3
+ describe HncbEAtm::Serialization do
4
4
  before do
5
5
  @params = {
6
6
  :store_id => "1",
@@ -15,21 +15,21 @@ describe HncbEAtm::Form do
15
15
  }
16
16
  end
17
17
 
18
- HncbEAtm::Form::REQUIRED_FIELDS.each do |field|
18
+ HncbEAtm::Serialization::REQUIRED_FIELDS.each do |field|
19
19
  it "should validate the presence of #{field}" do
20
20
  @params.delete(field.to_sym)
21
21
 
22
22
  lambda do
23
- HncbEAtm::Form.new(@params)
23
+ HncbEAtm::Serialization.new(@params)
24
24
  end.should raise_error(ArgumentError, "#{field} is a required field")
25
25
  end
26
26
  end
27
27
 
28
28
  describe "#serialize" do
29
- it "should serialize the fields for the form" do
30
- form = HncbEAtm::Form.new(@params)
29
+ it "should serialize the fields" do
30
+ serra = HncbEAtm::Serialization.new(@params)
31
31
 
32
- form.serialize.should == "StoreID=1&StoreAcnt=2&StoreTxDate=#{Date.today.strftime("%Y-%m-%d")}&\
32
+ serra.serialize.should == "StoreID=1&StoreAcnt=2&StoreTxDate=#{Date.today.strftime("%Y-%m-%d")}&\
33
33
  OrderNumber=3&Amount=12.44&StoreName=xinqianbi&\
34
34
  StoreURL=http://sandbox.xinqianbi.com&\
35
35
  SuccessURL=http://sandbox.xinqianbi.com/transactions/succeed&\
@@ -6,29 +6,27 @@ require File.expand_path('../../../lib/hncb_e_atm/view_helpers', File.dirname(__
6
6
  describe HncbEAtm::ViewHelpers do
7
7
  include HncbEAtm::ViewHelpers
8
8
 
9
+ let (:params) {
10
+ {
11
+ :store_id => "008757080070001ABCD1310",
12
+ :store_account => "100200000025",
13
+ :store_transaction_date => "2005-11-10",
14
+ :order_number => "00001",
15
+ :amount => "10",
16
+ :store_name => "博客來網絡書店",
17
+ :store_url => "http://10.8.61.71:8080/mctmk/eatm/Shopping_01.jsp",
18
+ :success_url => "http://10.8.61.71:8080/mctmk/eatm/Shopping_03OK.jsp",
19
+ :fail_url => "http://10.8.61.71:8080/mctmk/eatm/Shopping_03NOK.jsp"
20
+ }
21
+ }
22
+
9
23
  before do
24
+ HncbEAtm.debug = true
25
+
10
26
  self.output_buffer = ""
11
27
  end
12
28
 
13
29
  describe "#hncb_e_atm_form_for" do
14
- let (:params) {
15
- {
16
- :store_id => "008757080070001ABCD1310",
17
- :store_account => "100200000025",
18
- :store_transaction_date => "2005-11-10",
19
- :order_number => "00001",
20
- :amount => "10",
21
- :store_name => "博客來網絡書店",
22
- :store_url => "http://10.8.61.71:8080/mctmk/eatm/Shopping_01.jsp",
23
- :success_url => "http://10.8.61.71:8080/mctmk/eatm/Shopping_03OK.jsp",
24
- :fail_url => "http://10.8.61.71:8080/mctmk/eatm/Shopping_03NOK.jsp"
25
- }
26
- }
27
-
28
- before do
29
- HncbEAtm.debug = true
30
- end
31
-
32
30
  it "should generate a HTML form for the given parameters" do
33
31
  expected_output = <<-FORM
34
32
  <form action='https://210.65.217.216/eatm/servlet/TrxDispatcher' method='post'>
@@ -44,6 +42,17 @@ describe HncbEAtm::ViewHelpers do
44
42
  "<%= submit_tag 'Pay Now!' %>"
45
43
  end
46
44
 
45
+ self.output_buffer.should == expected_output.strip
46
+ end
47
+ end
48
+
49
+ describe "#hncb_e_atm_link_for" do
50
+ it "should generate a HTML link for the given parameters" do
51
+ expected_output = <<-LINK
52
+ https://210.65.217.216/eatm/servlet/TrxDispatcher?trx=com.eatm.wibc.trx.web.EAtmWShopping&state=prompt&val=U3RvcmVJRD0wMDg3NTcwODAwNzAwMDFBQkNEMTMxMCZTdG9yZUFjbnQ9MTAw\nMjAwMDAwMDI1JlN0b3JlVHhEYXRlPTIwMDUtMTEtMTAmT3JkZXJOdW1iZXI9\nMDAwMDEmQW1vdW50PTEwJlN0b3JlTmFtZT3ljZrlrqLkvobntrLntaHmm7jl\nupcmU3RvcmVVUkw9aHR0cDovLzEwLjguNjEuNzE6ODA4MC9tY3Rtay9lYXRt\nL1Nob3BwaW5nXzAxLmpzcCZTdWNjZXNzVVJMPWh0dHA6Ly8xMC44LjYxLjcx\nOjgwODAvbWN0bWsvZWF0bS9TaG9wcGluZ18wM09LLmpzcCZGYWlsVVJMPWh0\ndHA6Ly8xMC44LjYxLjcxOjgwODAvbWN0bWsvZWF0bS9TaG9wcGluZ18wM05P\nSy5qc3A=\n&mac=8E446B831D90EF4DC429DAA5FD82979580B53DAD
53
+ LINK
54
+
55
+ hncb_e_atm_link_for(params)
47
56
 
48
57
  self.output_buffer.should == expected_output.strip
49
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hncb_e_atm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hao Liu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-30 00:00:00.000000000 Z
11
+ date: 2013-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,42 +28,42 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: debugger
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: eATM interface for 華南銀行(HNCB)
@@ -83,12 +83,13 @@ files:
83
83
  - lib/generators/hncb_e_atm/install_generator.rb
84
84
  - lib/generators/hncb_e_atm/templates/config.yml
85
85
  - lib/hncb_e_atm.rb
86
- - lib/hncb_e_atm/form.rb
87
86
  - lib/hncb_e_atm/railtie.rb
87
+ - lib/hncb_e_atm/response.rb
88
+ - lib/hncb_e_atm/serialization.rb
88
89
  - lib/hncb_e_atm/utils.rb
89
90
  - lib/hncb_e_atm/version.rb
90
91
  - lib/hncb_e_atm/view_helpers.rb
91
- - spec/lib/hncb_e_atm/form_spec.rb
92
+ - spec/lib/hncb_e_atm/serialization_spec.rb
92
93
  - spec/lib/hncb_e_atm/view_helpers_spec.rb
93
94
  - spec/lib/hncb_e_atm_spec.rb
94
95
  homepage: ''
@@ -101,21 +102,21 @@ require_paths:
101
102
  - lib
102
103
  required_ruby_version: !ruby/object:Gem::Requirement
103
104
  requirements:
104
- - - ! '>='
105
+ - - '>='
105
106
  - !ruby/object:Gem::Version
106
107
  version: '0'
107
108
  required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  requirements:
109
- - - ! '>='
110
+ - - '>='
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
114
  rubyforge_project:
114
- rubygems_version: 2.1.3
115
+ rubygems_version: 2.0.6
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: eATM interface for 華南銀行(HNCB)
118
119
  test_files:
119
- - spec/lib/hncb_e_atm/form_spec.rb
120
+ - spec/lib/hncb_e_atm/serialization_spec.rb
120
121
  - spec/lib/hncb_e_atm/view_helpers_spec.rb
121
122
  - spec/lib/hncb_e_atm_spec.rb