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 +4 -4
- data/Gemfile.lock +5 -3
- data/README.md +6 -0
- data/Rakefile +0 -2
- data/lib/generators/paymob_ruby/templates/paymob.rb +1 -0
- data/lib/paymob_ruby/api/payment_token.rb +1 -0
- data/lib/paymob_ruby/configuration.rb +5 -0
- data/lib/paymob_ruby/errors.rb +3 -0
- data/lib/paymob_ruby/hmac.rb +20 -0
- data/lib/paymob_ruby/json_schemas/user.rb +29 -0
- data/lib/paymob_ruby/version.rb +1 -3
- data/lib/paymob_ruby.rb +15 -8
- metadata +33 -5
- data/config/initializers/paymob.rb +0 -5
- data/paymob_ruby-0.1.0.gem +0 -0
- data/paymob_ruby-0.1.1.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24822d16f0b04315481dd8af2d517107854013214adf5132f2fc94b3dcd681c1
|
4
|
+
data.tar.gz: cad7e761eadcda83ff6decd31471d8b03f9a373b5d97c236c260ecbcce5649e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
data/lib/paymob_ruby/errors.rb
CHANGED
@@ -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
|
data/lib/paymob_ruby/version.rb
CHANGED
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
|
-
|
25
|
+
attr_accessor :api_key, :hmac_key
|
26
|
+
|
27
|
+
def configure
|
28
|
+
yield configuration
|
29
|
+
end
|
24
30
|
|
25
|
-
|
26
|
-
|
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.
|
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-
|
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:
|
data/paymob_ruby-0.1.0.gem
DELETED
Binary file
|
data/paymob_ruby-0.1.1.gem
DELETED
Binary file
|