csob_payment_gateway 0.0.6 → 0.0.7

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: 1c0bee3b98710c1fae26c1b3abe89d092c150832
4
- data.tar.gz: 19753128bd905c65b03d24957effa168c3e1ed9b
3
+ metadata.gz: ea96e4d46b6839e5e205077cc4352872285c63c1
4
+ data.tar.gz: 1274cd423da2d02c103f3b1427a31cdd69a5fee0
5
5
  SHA512:
6
- metadata.gz: 22d7eb333e19ca4bc954ef82f288853d647e6514325575e1b4c3d49cd0d12fa64332639ed1a837762e20b1cb55518e64d660750b9c3b73ef2eccbc00deb2c025
7
- data.tar.gz: 34bbbace3c9ac224247c68a89e6be00c2b3807ff1ee3016e8b9d6b6a7faa9c2f345e54481c756ef844fd6a8e3660303ab0bb4733ae17caaab7ffe3c3f0087a88
6
+ metadata.gz: 449d92efc5d3860a825ed2d7df4045b09ed81d8a74775a63659e2ee086ac0abac509506a4c03adcd39289b849c46930d58754ce36d0f69582ce4209de0a84719
7
+ data.tar.gz: 80d961e87befeef2238ff097ed349bcccbae2d86a09f40b30ba163436bf9dd3c2bca62de44c420be5ae18f070d74f161fa6091eefa11e55bba91914c91620a07
@@ -31,6 +31,10 @@ module CsobPaymentGateway
31
31
  ::Rails.root.join(CsobPaymentGateway.configuration.keys_directory.to_s, CsobPaymentGateway.configuration.private_key.to_s)
32
32
  end
33
33
 
34
+ def public_key_url
35
+ ::Rails.root.join(CsobPaymentGateway.configuration.keys_directory.to_s, CsobPaymentGateway.configuration.public_key.to_s)
36
+ end
37
+
34
38
  def sign(data, method)
35
39
  data_to_sign = prepare_data_to_sign(data, method)
36
40
  key = OpenSSL::PKey::RSA.new(File.read(private_key_url))
@@ -40,5 +44,16 @@ module CsobPaymentGateway
40
44
 
41
45
  Base64.encode64(signature).gsub("\n","")
42
46
  end
47
+
48
+ def verify(data, signature_64)
49
+ key = OpenSSL::PKey::RSA.new(File.read(public_key_url))
50
+ signature = Base64.decode64(signature_64)
51
+ digest = OpenSSL::Digest::SHA1.new
52
+ if key.verify digest, signature, data
53
+ "Valid"
54
+ else
55
+ "Invalid"
56
+ end
57
+ end
43
58
  end
44
59
  end
@@ -64,6 +64,23 @@ module CsobPaymentGateway
64
64
  JSON.parse(refund_response)
65
65
  end
66
66
 
67
+ def verify_response
68
+ text = [
69
+ response["payId"],
70
+ response["dttm"],
71
+ response["resultCode"],
72
+ response["resultMessage"]
73
+ ].map { |param| param.is_a?(Hash) ? "" : param.to_s }.join("|")
74
+
75
+ text = text + "|" + response["paymentStatus"].to_s if !response["paymentStatus"].nil?
76
+
77
+ text = text + "|" + response["authCode"].to_s if response["authCode"] and !response["authCode"].nil?
78
+
79
+ text = text + "|" + response["merchantData"].to_s if response["merchantData"] and !response["merchantData"].nil?
80
+
81
+ CsobPaymentGateway::Crypt.verify(text, response["signature"])
82
+ end
83
+
67
84
  def get_data
68
85
  text = [
69
86
  merchant_id,
@@ -1,3 +1,3 @@
1
1
  module CsobPaymentGateway
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csob_payment_gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jiří Kratochvíl