paymob_accept 0.3.2 → 0.3.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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a858f0d51d53e165acf7bb759286fd6d3ffba067068342e1356d98edf9523652
4
- data.tar.gz: 05d5404002d4ff545c32c67f310d1c42cdb0ea6869fa03f46938a1cf9d15638f
3
+ metadata.gz: beebd510c172fc729ba4dbbd07646a2d1863364581a505e1b46db855cb4e243e
4
+ data.tar.gz: 958f6cc877b89a37fa367369b1856e33807c0deae2fed33f61ddfc0e5fd7deb0
5
5
  SHA512:
6
- metadata.gz: 130578e9ccb379fc2b8bd76a22d149502d8177a52026abffca362456f30341055979f2b8478322ef55e1edd1408cf124916c6a885be23aa229d36cc02b4bc0c3
7
- data.tar.gz: 793edd6500af9628d4746bb40c9b824e035e05bf3ddb819dfc546d41f82d1d6d44f98e7db5407fc0506184fe43f2c598771f14bd4f24b96f879648bf744e324c
6
+ metadata.gz: dc4667a2a84e21a8bd461543fc5a2decf3a61fb517a69aaf50f4230ce5aaad4d201c12751a27da7cd0760c03f9aceb9e85cf0b5c741d44681cd5eefc26a906e9
7
+ data.tar.gz: 216f96de1a00cfbe165f8d9b08015676eb6a12f3075ecd334a0bb9ecd3fcc9eb95dc5e0fee5ee91dd40f37542429cb8eddcfbb34254e4103d44e3c0773a6edc2
@@ -1,16 +1,30 @@
1
1
  module PaymobAccept
2
2
  module Hmac
3
- FILTERED_KEYS = %w[amount_cents created_at currency error_occured has_parent_transaction id
3
+ FILTERED_TRANSACTION_KEYS = %w[amount_cents created_at currency error_occured has_parent_transaction id
4
4
  integration_id is_3d_secure is_auth is_capture is_refunded is_standalone_payment
5
5
  is_voided order.id owner
6
6
  pending source_data.pan source_data.sub_type source_data.type success].freeze
7
7
 
8
+ FILTERED_TOKEN_KEYS = %w[card_subtype created_at email id masked_pan merchant_id order_id token].freeze
9
+
8
10
  class << self
11
+
9
12
  def validate(paymob_response:, hmac_key: PaymobAccept.configuration.hmac_key)
10
- raise ArgumentError, 'hmac_key is required' if hmac_key.nil?
13
+ validate_transaction?(paymob_response: paymob_response, hmac_key: hmac_key) || validate_token?(paymob_response: paymob_response, hmac_key: hmac_key)
14
+ end
15
+
16
+ def validate_transaction?(paymob_response:, hmac_key: PaymobAccept.configuration.hmac_key)
17
+ digest = OpenSSL::Digest.new('sha512')
18
+ concatenated_str = FILTERED_TRANSACTION_KEYS.map do |element|
19
+ paymob_response.dig('obj', *element.split('.'))
20
+ end.join
21
+ secure_hash = OpenSSL::HMAC.hexdigest(digest, hmac_key, concatenated_str)
22
+ secure_hash == paymob_response['hmac']
23
+ end
11
24
 
25
+ def validate_token?(paymob_response:, hmac_key: PaymobAccept.configuration.hmac_key)
12
26
  digest = OpenSSL::Digest.new('sha512')
13
- concatenated_str = FILTERED_KEYS.map do |element|
27
+ concatenated_str = FILTERED_TOKEN_KEYS.map do |element|
14
28
  paymob_response.dig('obj', *element.split('.'))
15
29
  end.join
16
30
  secure_hash = OpenSSL::HMAC.hexdigest(digest, hmac_key, concatenated_str)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaymobAccept
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymob_accept
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - OneOrder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-10 00:00:00.000000000 Z
11
+ date: 2022-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday