paymob_accept 0.3.1 → 0.3.3

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: 3f07b80f4fe23b6ca6da25649d650917ebf48802ce93903ca44dde300acf0f89
4
- data.tar.gz: 4238ee5fa6e5267b27deac4b3f45701759515420ae4cfc255621691ef8f9b616
3
+ metadata.gz: beebd510c172fc729ba4dbbd07646a2d1863364581a505e1b46db855cb4e243e
4
+ data.tar.gz: 958f6cc877b89a37fa367369b1856e33807c0deae2fed33f61ddfc0e5fd7deb0
5
5
  SHA512:
6
- metadata.gz: f29651bddc3f492f908304e0aa1f552b597ba9e8feeaff5f67f1bb045b2b8791f5bf66cf72a16291ae43b7036da4277dc5276dd75550351a4fe476396e7af127
7
- data.tar.gz: f761e0b4eb1faafd6688beafdf195416ec2db6160265d9227b3e94c332bddf5c4f493965d2a3ce2767c0f9622ad36b90a5e699e21b7d1307f7c85c1ebe499d91
6
+ metadata.gz: dc4667a2a84e21a8bd461543fc5a2decf3a61fb517a69aaf50f4230ce5aaad4d201c12751a27da7cd0760c03f9aceb9e85cf0b5c741d44681cd5eefc26a906e9
7
+ data.tar.gz: 216f96de1a00cfbe165f8d9b08015676eb6a12f3075ecd334a0bb9ecd3fcc9eb95dc5e0fee5ee91dd40f37542429cb8eddcfbb34254e4103d44e3c0773a6edc2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paymob_accept (0.3.1)
4
+ paymob_accept (0.3.2)
5
5
  faraday
6
6
  json-schema
7
7
 
@@ -30,9 +30,9 @@ module PaymobAccept
30
30
 
31
31
  private
32
32
 
33
- def pay_auth(customer:, address:, amount_cents:, amount_currency:)
33
+ def pay_auth(customer:, address:, amount_cents:, amount_currency:, iframe_id: nil, cc_token: nil)
34
34
  generate_payment_intent(customer: customer, address: address, amount_cents: amount_cents, amount_currency: amount_currency,
35
- integration_id: auth_integration_id)
35
+ integration_id: auth_integration_id, iframe_id: iframe_id, cc_token: cc_token)
36
36
  end
37
37
 
38
38
  # Return an iFrame URL if an iframe_id is provided. Otherwise, returns a payment token
@@ -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.1'
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.1
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-05 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