paymob_accept 0.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9be4b1690f4a848451740b6b49bed06814dece0eb6cfc8d4bebb8e0445fbd86f
4
- data.tar.gz: 94ab14e1b12819055f982b23e29e5fb7c8f4a35b87ed18d2f8a122ff5aca2a45
3
+ metadata.gz: 74ac2d808d84a3858e5ea44a1b6db205c28d0f092bc06fac9569766aca7f993a
4
+ data.tar.gz: 0104bfacb501475891edebcdf30f7f68e61ac259b45b75a9c556a0cc917009a4
5
5
  SHA512:
6
- metadata.gz: 86ab02b708a4415b8c1cb4a17d96f7e303472a431653b449c7805a0ae884c512930929c8db34045ab83f470f63f819c0f130acb68bef2e7de594aaa913867353
7
- data.tar.gz: d846e0ccf9ad28d591f923c56193e25d98a073794ec3da2c13dbcd7db6bc2815606a1432422dc4f340119378260571e0785ba706b65c22cb7e619a38efc3917f
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.2.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.0)
12
- public_suffix (>= 2.0.2, < 5.0)
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 (4.0.7)
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
- # PaymobAccept
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
- config.api_key = "######"
30
- config.online_integration_id = "######"
31
- config.kiosk_integration_id = "######"
32
- config.cash_integration_id = "######"
33
- config.wallet_integration_id = "######"
34
- config.auth_integration_id = "######"
35
- config.moto_integration_id = "######"
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
 
@@ -76,7 +77,7 @@ service.online_integration_id = "123"
76
77
  token = service.get_auth_token
77
78
  ```
78
79
 
79
- 2. Create_order
80
+ 2. Create order
80
81
  ```ruby
81
82
  service.create_order(auth_token: token, amount_cents: 1000, amount_currency: 'EGP', items: [])
82
83
  ```
@@ -107,12 +108,16 @@ The `:method` key in the `charge` method could be one of the following:
107
108
  - :kiosk => Aman/Masary kiosk network
108
109
  - :cash => Cash on delivery
109
110
  - :wallet => Vodafone cash
110
- - :moto => Paying with a saved token
111
+ - :moto => Paying with a saved car token
111
112
 
112
113
  Please refer to the official Paymob documentation for in-depth explanation about each payment method.
113
114
 
114
115
  The return value of the `charge` method in general is the response of Paymob's server which varies according to the payment method except in `:online`. In an `:online` payment if an `iframe_id` is provided, the return value is an iFrame URL with an embedded payment token. If the `iframe_id` is not provided, only the payment token is returned
115
116
 
117
+ ### Paying with a saved card token
118
+
119
+ To pre-fill an iFrame with a customer card data or process a MOTO charge, make sure the `customer_data` hash has a `cc_token` key in addition to the fields mentioned above.
120
+
116
121
  ## Dealing with charges
117
122
 
118
123
  - **Initialize your Charge service**
@@ -126,11 +131,21 @@ The return value of the `charge` method in general is the response of Paymob's s
126
131
  - Void a transaction: `service.void!(transaction_id: transaction_id)`
127
132
  - Capture an auth transaction: `service.capture!(transaction_id: transaction_id, amount_cents: amount_cents)`
128
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
+
141
+ ## Roadmap
142
+
143
+ - [x] HMAC validation
129
144
 
130
145
  ## Contributing
131
146
 
132
- Bug reports and pull requests are welcome on [GitHub](https://github.com/oneorder-tech/paymob).
133
- This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/oneorder-tech/paymob/blob/master/CODE_OF_CONDUCT.md).
147
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/oneorder-tech/paymob-accept).
148
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/oneorder-tech/paymob-accept/blob/master/CODE_OF_CONDUCT.md).
134
149
 
135
150
  ## License
136
151
 
@@ -138,4 +153,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
138
153
 
139
154
  ## Code of Conduct
140
155
 
141
- Everyone interacting in the PaymobAccept project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/oneorder-tech/paymob/blob/master/CODE_OF_CONDUCT.md).
156
+ Everyone interacting in the PaymobAccept project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/oneorder-tech/paymob-accept/blob/master/CODE_OF_CONDUCT.md).
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaymobAccept
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/paymob_accept.rb CHANGED
@@ -9,6 +9,7 @@ require 'paymob_accept/api/pay'
9
9
  require 'paymob_accept/api/client'
10
10
  require 'paymob_accept/api/charge'
11
11
 
12
+ require 'paymob_accept/hmac'
12
13
  require 'json'
13
14
  require 'faraday'
14
15
  require 'faraday/net_http'
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OneOrder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-21 00:00:00.000000000 Z
11
+ date: 2022-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -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