paymob_accept 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6ebddca8de134c54bbf5d5f8dceecde5ae4f65cc735f403e40c04afa13e3f5e
4
- data.tar.gz: f635a17547b178a9ed8428d1fccf8a8157440e1656b6808375d5984b4e26a8e4
3
+ metadata.gz: 74ac2d808d84a3858e5ea44a1b6db205c28d0f092bc06fac9569766aca7f993a
4
+ data.tar.gz: 0104bfacb501475891edebcdf30f7f68e61ac259b45b75a9c556a0cc917009a4
5
5
  SHA512:
6
- metadata.gz: 3925164b5d6519cf7216d719222c79c3882a70e88d56b1227c59a9c6bec93e4c9e499f22a7351620eb66c320550104615dddd2bc99b9da03fc82335c41d0c3b1
7
- data.tar.gz: 6009edcbbbc9f9feeaad04f26169cd14b9131102fb651944fee152b4c8c2b2bd62e109a1030b87ee5be5831faea4f0077bff157add1535a0cd87e5d9343616b1
6
+ metadata.gz: 52bc4b9d8af84a9df149edf279aa782391346bcd1de3adfe21ec4416c39f625b2dc5afa7b12b1e74a4fde43ed4575ec07bfbea292818403df5796c5e0a0f9096
7
+ data.tar.gz: 959e4ab4f5257eb40d115d2e70edc43e593b52acba626a5eed866df261f0b2171648c48231f191c33bf019c5cf2c48fe4c7c9f170f0d4d616fa55aabbb0e9579
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paymob_accept (0.2.0)
4
+ paymob_accept (0.3.0)
5
5
  faraday
6
6
  json-schema
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.8.0)
12
- public_suffix (>= 2.0.2, < 5.0)
11
+ addressable (2.8.1)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
13
  diff-lcs (1.5.0)
14
14
  faraday (2.5.2)
15
15
  faraday-net_http (>= 2.0, < 3.1)
@@ -17,7 +17,7 @@ GEM
17
17
  faraday-net_http (3.0.0)
18
18
  json-schema (3.0.0)
19
19
  addressable (>= 2.8)
20
- public_suffix (4.0.7)
20
+ public_suffix (5.0.0)
21
21
  rake (13.0.6)
22
22
  rspec (3.11.0)
23
23
  rspec-core (~> 3.11.0)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # PaymobAccept
1
+ # Paymob Accept
2
2
 
3
3
  `paymob_accept` is a Ruby gem created by [OneOrder](https://www.oneorder.net/) for integrating [Paymob](https://paymob.com/en) payment solutions with your Ruby application.
4
4
 
@@ -26,13 +26,14 @@ Configure the gem with your configuration
26
26
 
27
27
  ```ruby
28
28
  PaymobAccept.configure do |config|
29
- config.api_key = "######"
30
- config.online_integration_id = "######"
31
- config.kiosk_integration_id = "######"
32
- config.cash_integration_id = "######"
33
- config.wallet_integration_id = "######"
34
- config.auth_integration_id = "######"
35
- config.moto_integration_id = "######"
29
+ config.api_key = "######"
30
+ config.hmac_key = "######"
31
+ config.online_integration_id = "######"
32
+ config.kiosk_integration_id = "######"
33
+ config.cash_integration_id = "######"
34
+ config.wallet_integration_id = "######"
35
+ config.auth_integration_id = "######"
36
+ config.moto_integration_id = "######"
36
37
  end
37
38
  ```
38
39
 
@@ -130,9 +131,16 @@ To pre-fill an iFrame with a customer card data or process a MOTO charge, make s
130
131
  - Void a transaction: `service.void!(transaction_id: transaction_id)`
131
132
  - Capture an auth transaction: `service.capture!(transaction_id: transaction_id, amount_cents: amount_cents)`
132
133
 
134
+ ## HMAC validation
135
+
136
+ `PaymobAccept::Hmac.validate(paymob_response: , hmac_key:)`
137
+
138
+ `hmac_key` can be either passed once to the configuration block, otherwise, it must be passed to the `validate` function.
139
+
140
+
133
141
  ## Roadmap
134
142
 
135
- - [ ] HMAC validation
143
+ - [x] HMAC validation
136
144
 
137
145
  ## Contributing
138
146
 
@@ -1,7 +1,7 @@
1
1
  module PaymobAccept
2
2
  class Configuration
3
3
  attr_accessor :api_key, :online_integration_id, :cash_integration_id, :kiosk_integration_id,
4
- :auth_integration_id, :wallet_integration_id, :moto_integration_id
4
+ :auth_integration_id, :wallet_integration_id, :moto_integration_id, :hmac_key
5
5
  end
6
6
 
7
7
  class ConfigurationMissingError < StandardError; end
@@ -0,0 +1,21 @@
1
+ module PaymobAccept
2
+ module Hmac
3
+ FILTERED_KEYS = %w[amount_cents created_at currency error_occured has_parent_transaction id
4
+ integration_id is_3d_secure is_auth is_capture is_refunded is_standalone_payment
5
+ is_voided order.id owner
6
+ pending source_data.pan source_data.sub_type source_data.type success].freeze
7
+
8
+ class << self
9
+ def validate(paymob_response:, hmac_key: PaymobAccept.configuration.hmac_key)
10
+ raise ArgumentError, 'hmac_key is required' if hmac_key.nil?
11
+
12
+ digest = OpenSSL::Digest.new('sha512')
13
+ concatenated_str = FILTERED_KEYS.map do |element|
14
+ paymob_response.dig('obj', *element.split('.'))
15
+ end.join
16
+ secure_hash = OpenSSL::HMAC.hexdigest(digest, hmac_key, concatenated_str)
17
+ secure_hash == paymob_response['hmac']
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaymobAccept
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/paymob_accept.rb CHANGED
@@ -9,6 +9,7 @@ require 'paymob_accept/api/pay'
9
9
  require 'paymob_accept/api/client'
10
10
  require 'paymob_accept/api/charge'
11
11
 
12
+ require 'paymob_accept/hmac'
12
13
  require 'json'
13
14
  require 'faraday'
14
15
  require 'faraday/net_http'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymob_accept
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OneOrder
@@ -63,6 +63,7 @@ files:
63
63
  - lib/paymob_accept/api/pay.rb
64
64
  - lib/paymob_accept/configuration.rb
65
65
  - lib/paymob_accept/errors/bad_gateway.rb
66
+ - lib/paymob_accept/hmac.rb
66
67
  - lib/paymob_accept/version.rb
67
68
  - paymob_accept.gemspec
68
69
  homepage: https://github.com/oneorder-tech/paymob-accept