Skip to content

Commit

Permalink
Release 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Epigene committed Dec 18, 2017
1 parent ba6d2e8 commit 2e6c428
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
seb_elink (0.1.0)
seb_elink (0.9.0)

GEM
remote: https://rubygems.org/
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[![Version](https://img.shields.io/gem/v/formatador.svg?style=for-the-badge)](TODO)
[![Version](https://badge.fury.io/rb/seb_elink.svg)](https://badge.fury.io/rb/seb_elink)
[![Build](https://circleci.com/gh/CreativeGS/seb_elink/tree/master.svg?style=shield)](https://circleci.com/gh/CreativeGS/seb_elink/tree/master)
[![Coverage](https://coveralls.io/repos/github/CreativeGS/seb_elink/badge.svg?branch=master)](https://coveralls.io/github/CreativeGS/seb_elink?branch=master)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg?style=for-the-badge)](LICENSE.txt)

# SebElink
Lightweight Ruby wrapper for communicating with SEB.lv i-bank payment API.
Expand Down Expand Up @@ -92,6 +91,8 @@ response_body =
end #=> "IB_SND_ID=TEST..."

response_instance = SebElink::Response.new(SEB_LV_GATEWAY, response_body)

# Please note that the :IB_CRC signature values will often end with "==\n" which, when uri-escaped will be "%3D%3D%0A", pass the response just like that into the initializer
```

Instances of `SebElink::Response` have two methods:
Expand All @@ -103,7 +104,7 @@ response_instance.valid?

response_instance.to_h
#=> {IB_SND_ID: "TEST", ...}
# Will raise if called on an ivalid response_instance
# Will raise if called on an invalid response_instance
# to override this default safety setting, call with to_h(:insecure)
```

Expand Down
9 changes: 6 additions & 3 deletions lib/seb_elink/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ def message_0002
})

# 3. Hash-sign the footprint string => obtain "digital signature" of the message
digital_signature = gateway_instance.sign(footprint_string)
digital_signature = gateway_instance.sign({
version: version,
message_footprint: footprint_string
})

# 4. Append IB_CRC key with the "digital signature" and return the hash
spec_set = gateway_instance.spec_for(version: version, message_code: message_code)
spec_set.keys.each_with_object({}) do |k, hash|
gateway_instance.spec_for(version: version, message_code: message_code).
keys.each_with_object({}) do |k, hash|
hash[k] = data_hash[k] if data_hash.has_key?(k)
end.merge(IB_CRC: digital_signature)
end
Expand Down
5 changes: 3 additions & 2 deletions lib/seb_elink/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ def to_h(mode=:secure)
private
def body_hash
@body_hash ||= body.split("&").each_with_object({}) do |q_pair, hash|
split_index = q_pair.index("=")
key, value = q_pair[0..(split_index - 1)], q_pair[split_index.next..-1]
pair = q_pair # CGI.unescape(q_pair)
split_index = CGI.unescape(pair).index("=")
key, value = pair[0..(split_index - 1)], pair[split_index.next..-1]
hash[key.to_sym] = value.to_s
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/seb_elink/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SebElink
VERSION = "0.1.0"
VERSION = "0.9.0"
end
16 changes: 16 additions & 0 deletions spec/seb_elink/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
let(:body_params_0004) { valid_0004_response_body_params }
let(:body) { body_params_0004.map { |k, v| "#{k}=#{v}" }.join("&") }

before do
# binding.pry
end

describe "#valid?" do
subject { response.valid? }

Expand Down Expand Up @@ -93,5 +97,17 @@
expect(subject).to match(valid_0004_response_body_params)
end
end

context "when called leniently with uri-escaped values" do
subject { response.to_h(:insecure) }

let(:validity_status) { false }

let(:body_params_0004) { valid_0004_response_body_params.merge(IB_PAYMENT_DESC: "Cookies+%3D+instawin") }

xit "returns a un unescaped hash representation of it" do
expect(subject).to match(hash_including(IB_PAYMENT_DESC: "Cookies = instawin"))
end
end
end
end

0 comments on commit 2e6c428

Please sign in to comment.