paymob_ruby 0.1.2 → 0.1.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: 750c9f04ad4dbc611da0fb7ddbd90b2a92487fe7721d996ce52a0bfa564817b0
4
- data.tar.gz: 184bf8bed0172cfde51e056c043e73530fd43b760e2fd2693bd5e405f93ad7b4
3
+ metadata.gz: 24822d16f0b04315481dd8af2d517107854013214adf5132f2fc94b3dcd681c1
4
+ data.tar.gz: cad7e761eadcda83ff6decd31471d8b03f9a373b5d97c236c260ecbcce5649e6
5
5
  SHA512:
6
- metadata.gz: aab1bfc777adc31cfbd2f25c18d9d0951f165fde6756de153ed392a89be0570e0749db475f4a464de3ff69b7766333c8ee369325b3c8b90b1d1d73e7c065e4b1
7
- data.tar.gz: 71602fa03c0ef3253b1f71126e48f2933ce18d3503d6a8026272d6013fb647341de2649ee3b58887abe291626fdd3c3f3f1a93850510d5958341c57c9088d493
6
+ metadata.gz: 77b525f1ed5b776d363a912f456eb8b38e7de4b34c6ec34ef8b4b226f8c6a9082b04a683e3e21a9bf1361e699f298b60d7b6eec080d78dc3ddb45ef741490ae3
7
+ data.tar.gz: 566567124158c1af278e874fae4056e2f15285e57264c2b73cf995542a6b94e0fc498143fc166aa00c528434ee1af9ec125035868b5f3f1f91054efa554ede7a
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paymob_accept_ruby (0.1.0)
5
- activesupport (~> 7.0)
4
+ paymob_ruby (0.1.2)
6
5
  faraday (~> 2.7.5)
7
6
 
8
7
  GEM
@@ -74,6 +73,8 @@ GEM
74
73
  i18n (1.14.1)
75
74
  concurrent-ruby (~> 1.0)
76
75
  json (2.6.3)
76
+ json-schema (4.1.1)
77
+ addressable (>= 2.8)
77
78
  listen (3.8.0)
78
79
  rb-fsevent (~> 0.10, >= 0.10.3)
79
80
  rb-inotify (~> 0.9, >= 0.9.10)
@@ -180,7 +181,8 @@ DEPENDENCIES
180
181
  fuubar (~> 2.5.1)
181
182
  generator_spec
182
183
  guard-rspec
183
- paymob_accept_ruby!
184
+ json-schema
185
+ paymob_ruby!
184
186
  rake (~> 13.0)
185
187
  rspec (~> 3.0)
186
188
  rubocop (~> 1.52.0)
data/README.md CHANGED
@@ -25,6 +25,7 @@ Configure the gem with your configuration
25
25
  ```ruby
26
26
  PaymobRuby.configure do |config|
27
27
  config.api_key = "api_key"
28
+ config.hmac_key = "hmac_key"
28
29
  end
29
30
  ```
30
31
 
@@ -58,6 +59,11 @@ user = { first_name: "John", last_name: "Doe", email: "johndoe@test.com", phone_
58
59
  result = PaymobRuby::PayToken.call(user:, amount: 10, integration_id: 12345678, token: "abc123")
59
60
  ```
60
61
 
62
+ ### Calculating hash
63
+ ```ruby
64
+ PaymobRuby::Hmac.valid_signature?(paymob_response)
65
+ ```
66
+
61
67
  ## Errors:
62
68
  Errors could be one of the following:
63
69
 
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "bundler/gem_tasks"
4
2
 
5
3
  require "rake"
@@ -2,4 +2,5 @@ require "paymob_ruby"
2
2
 
3
3
  PaymobRuby.configure do |config|
4
4
  config.api_key = "your_api_key"
5
+ config.hmac_key = "your_hmac_key"
5
6
  end
@@ -7,6 +7,7 @@ module PaymobRuby
7
7
  @integration_id = integration_id
8
8
  @commission_fees = commission_fees
9
9
 
10
+ user_valid?
10
11
  sanity_checks!
11
12
 
12
13
  # Paymob order id
@@ -0,0 +1,5 @@
1
+ module PaymobRuby
2
+ class Configuration
3
+ attr_accessor :api_key, :hmac_key
4
+ end
5
+ end
@@ -22,6 +22,9 @@ module PaymobRuby
22
22
  end
23
23
  end
24
24
 
25
+ # ConfigurationMissingError is raised when a configuration is missing
26
+ class ConfigurationMissingError < StandardError; end
27
+
25
28
  # AuthenticationError is raised when invalid credentials are used to connect
26
29
  # to Paymob's servers.
27
30
  class AuthenticationError < PaymobError
@@ -0,0 +1,20 @@
1
+ module PaymobRuby
2
+ module Hmac
3
+ FILTERED_TRANSACTION_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 pending
6
+ source_data.pansource_data.sub_type source_data.type success].freeze
7
+
8
+ class << self
9
+ def valid_signature?(paymob_response)
10
+ digest = ::OpenSSL::Digest.new("sha512")
11
+
12
+ concatenated_str = FILTERED_TRANSACTION_KEYS.map do |element|
13
+ paymob_response.dig("obj", *element.split("."))
14
+ end.join
15
+ secure_hash = ::OpenSSL::HMAC.hexdigest(digest, PaymobRuby.hmac_key, concatenated_str)
16
+ secure_hash == paymob_response["hmac"]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module PaymobRuby
2
+ module JsonSchemas
3
+ module User
4
+ extend ActiveSupport::Concern
5
+
6
+ def user_valid?
7
+ JSON::Validator.validate!(customer_schema, @user)
8
+ rescue JSON::Schema::ValidationError => e
9
+ raise InvalidRequestError.new("Customer hash has the following error: #{e.message}", :user)
10
+ end
11
+
12
+ private
13
+
14
+ def customer_schema
15
+ {
16
+ type: "object",
17
+ "$schema": "http://json-schema.org/draft-04/schema",
18
+ properties: {
19
+ first_name: { type: "string" },
20
+ last_name: { type: "string" },
21
+ email: { type: "string" },
22
+ phone_number: { type: "string" }
23
+ },
24
+ required: %w[first_name last_name email phone_number]
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module PaymobRuby
4
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3".freeze
5
3
  end
data/lib/paymob_ruby.rb CHANGED
@@ -1,12 +1,13 @@
1
- # frozen_string_literal: true
2
-
3
- require "faraday"
4
1
  require "active_support"
2
+ require "faraday"
3
+ require "json-schema"
5
4
 
6
5
  require_relative "paymob_ruby/version"
7
6
 
8
7
  # API resource support classes
9
8
  require "paymob_ruby/errors"
9
+ require "paymob_ruby/configuration"
10
+ require "paymob_ruby/hmac"
10
11
 
11
12
  # API operations
12
13
  require "paymob_ruby/api/application_service"
@@ -15,14 +16,20 @@ require "paymob_ruby/api/payment_token"
15
16
  require "paymob_ruby/api/pay_card"
16
17
  require "paymob_ruby/api/pay_token"
17
18
 
19
+ require "paymob_ruby/json_schemas/user"
20
+
18
21
  module PaymobRuby
19
- BASE_URI = "https://accept.paymobsolutions.com/api"
22
+ BASE_URI = "https://accept.paymobsolutions.com/api".freeze
20
23
 
21
24
  class << self
22
- attr_accessor :api_key
23
- end
25
+ attr_accessor :api_key, :hmac_key
26
+
27
+ def configure
28
+ yield configuration
29
+ end
24
30
 
25
- def self.configure
26
- yield self
31
+ def configuration
32
+ @configuration ||= Configuration.new
33
+ end
27
34
  end
28
35
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymob_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Kaldas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-18 00:00:00.000000000 Z
11
+ date: 2023-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: faraday
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: 2.7.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: json-schema
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.1.1
27
55
  description:
28
56
  email:
29
57
  - joekaldas8@gmail.com
@@ -42,7 +70,6 @@ files:
42
70
  - LICENSE.txt
43
71
  - README.md
44
72
  - Rakefile
45
- - config/initializers/paymob.rb
46
73
  - lib/generators/paymob_ruby/install_generator.rb
47
74
  - lib/generators/paymob_ruby/templates/paymob.rb
48
75
  - lib/paymob_ruby.rb
@@ -51,10 +78,11 @@ files:
51
78
  - lib/paymob_ruby/api/pay_card.rb
52
79
  - lib/paymob_ruby/api/pay_token.rb
53
80
  - lib/paymob_ruby/api/payment_token.rb
81
+ - lib/paymob_ruby/configuration.rb
54
82
  - lib/paymob_ruby/errors.rb
83
+ - lib/paymob_ruby/hmac.rb
84
+ - lib/paymob_ruby/json_schemas/user.rb
55
85
  - lib/paymob_ruby/version.rb
56
- - paymob_ruby-0.1.0.gem
57
- - paymob_ruby-0.1.1.gem
58
86
  - sig/paymob.rbs
59
87
  homepage: https://github.com/JoeKaldas/paymob
60
88
  licenses:
@@ -1,5 +0,0 @@
1
- require "paymob_ruby"
2
-
3
- PaymobRuby.configure do |config|
4
- config.api_key = "your_api_key"
5
- end
Binary file
Binary file