paymob_accept 0.2.1 → 0.3.0
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 +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +17 -9
- data/lib/paymob_accept/configuration.rb +1 -1
- data/lib/paymob_accept/hmac.rb +21 -0
- data/lib/paymob_accept/version.rb +1 -1
- data/lib/paymob_accept.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74ac2d808d84a3858e5ea44a1b6db205c28d0f092bc06fac9569766aca7f993a
|
4
|
+
data.tar.gz: 0104bfacb501475891edebcdf30f7f68e61ac259b45b75a9c556a0cc917009a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
12
|
-
public_suffix (>= 2.0.2, <
|
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 (
|
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
|
-
#
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
- [
|
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
|
data/lib/paymob_accept.rb
CHANGED
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.
|
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
|