paymob-engine 0.1.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +136 -0
- data/Rakefile +10 -0
- data/app/controllers/paymob/engine/application_controller.rb +8 -0
- data/app/jobs/paymob/engine/application_job.rb +8 -0
- data/app/mailers/paymob/engine/application_mailer.rb +10 -0
- data/app/models/paymob/engine/application_record.rb +9 -0
- data/config/routes.rb +5 -0
- data/lib/generators/paymob/controller_generator.rb +20 -0
- data/lib/generators/paymob/install_generator.rb +13 -0
- data/lib/generators/paymob/templates/paymob.rb +13 -0
- data/lib/generators/paymob/templates/paymob_controller.rb +42 -0
- data/lib/paymob/accept_api.rb +97 -0
- data/lib/paymob/base.rb +42 -0
- data/lib/paymob/engine/engine.rb +14 -0
- data/lib/paymob/engine/version.rb +7 -0
- data/lib/paymob/engine.rb +48 -0
- data/lib/paymob/errors.rb +14 -0
- data/lib/paymob/hmac.rb +30 -0
- data/lib/paymob/payment_types/installment.rb +19 -0
- data/lib/paymob/payment_types/onetime.rb +19 -0
- data/lib/paymob/payment_types/wallet.rb +20 -0
- data/lib/tasks/paymob/engine_tasks.rake +5 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a3e4df4a19b1a3cb0417a74cb8e05064e1e1bf1dfde8b12aaccda2783ff23b47
|
4
|
+
data.tar.gz: a1509ce73483cb1ba4ee219ba9dcce33b68eec998051ffbd1513a908a425dcd8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 714108de060266323360bda539af81ccb95b24c8899e9550467979e97a219eeea278f72a980619374dd3cab9184955ee8e79f3c142dabf42dfbb382f9bcd03da
|
7
|
+
data.tar.gz: f0ac43884c533019bbff7841e117feff52a0a72abffd9d7fddf12243689f4f211eed6a4405809b9c5eadffab837e499f3c1d2b7ea04f5bb7090ded7da1718e8e
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2024 khaledmustafa91
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# Paymob::Engine
|
2
|
+
This gem simplifies the integration of your application with the [Paymob](https://paymob.com/) payment gateway. It offers a set of user-friendly methods for creating one-time payments, wallet payments, and installment payments, streamlining the payment process for your application. By using this gem, developers can easily implement a robust payment solution in their projects.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem "paymob-engine"
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
```bash
|
13
|
+
bundle
|
14
|
+
```
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
```bash
|
18
|
+
gem install paymob-engine
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
### 1. Set the Gem Configuration Variables
|
23
|
+
you must configure it with the necessary credentials and settings. you will find all variables in `config/initializers/paymob.rb` file
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Paymob.setup do |config|
|
27
|
+
config.base_url = 'https://accept.paymobsolutions.com/api'
|
28
|
+
config.api_key = ''
|
29
|
+
config.hmac_secret = ''
|
30
|
+
config.onetime_integration_id = ''
|
31
|
+
config.wallet_integration_id = ''
|
32
|
+
config.installment_integration_id = ''
|
33
|
+
config.ifream_link = 'https://accept.paymobsolutions.com/api/acceptance/iframes/'
|
34
|
+
config.onetime_ifream_number = ''
|
35
|
+
config.installment_ifream_number = ''
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
**Note**: `api_key`, `hmac_secret` are mandatory and each payment type variables are mandatory if you need use this payment type.
|
40
|
+
|
41
|
+
You can found all information in your [dashboard](https://accept.paymob.com/portal2/en/home).
|
42
|
+
|
43
|
+
|
44
|
+
### 2. How to Initialize an Order for new payment
|
45
|
+
|
46
|
+
Each payment method class inherits from a base class. To initiate a payment, select the class corresponding to the desired payment type. Start by invoking the `initialize_order` method with essential attributes, including a float `amount`, a string `payment_reference`, and a hash for `billing_data` containing required keys: `first_name`, `last_name`, `email`, and `phone_number`. Subsequently, use the `payment_link` method to obtain the payment link.
|
47
|
+
|
48
|
+
The available class for each payment type are:
|
49
|
+
- `Paymob::PaymentTypes::Onetime`
|
50
|
+
- `Paymob::PaymentTypes::Wallet`
|
51
|
+
- `Paymob::PaymentTypes::Installment`
|
52
|
+
|
53
|
+
### 3. Create an One-Time Payment
|
54
|
+
Use the `Paymob::PaymentTypes::Onetime` class:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
payment_data = {
|
58
|
+
amount: "Your value in numbers",
|
59
|
+
billing_data: {
|
60
|
+
first_name: "Test",
|
61
|
+
last_name: "Account",
|
62
|
+
email: "test@email.com",
|
63
|
+
phone_number:"01111111111"
|
64
|
+
},
|
65
|
+
payment_reference: "Your generated payment reference"
|
66
|
+
}
|
67
|
+
onetime = Paymob::PaymentTypes::Onetime.new
|
68
|
+
onetime.initialize_order(payment_data)
|
69
|
+
onetime.payment_link
|
70
|
+
```
|
71
|
+
|
72
|
+
### 4. Create a Wallet Payment
|
73
|
+
Use the `Paymob::PaymentTypes::Wallet` class:
|
74
|
+
|
75
|
+
`Note`: you must pass the mobile number wallet you need to pay from it
|
76
|
+
```ruby
|
77
|
+
payment_data = {
|
78
|
+
amount: "Your value in numbers",
|
79
|
+
billing_data: {
|
80
|
+
first_name: "Test",
|
81
|
+
last_name: "Account",
|
82
|
+
email: "test@email.com",
|
83
|
+
phone_number:"01111111111"
|
84
|
+
},
|
85
|
+
payment_reference: "Your generated payment reference"
|
86
|
+
}
|
87
|
+
onetime = Paymob::PaymentTypes::Wallet.new
|
88
|
+
onetime.initialize_order(payment_data)
|
89
|
+
onetime.payment_link(mobile_number: '01010101010')
|
90
|
+
```
|
91
|
+
|
92
|
+
### 5. Create an Installment Payment
|
93
|
+
Use the `Paymob::PaymentTypes::Installment` class:
|
94
|
+
```ruby
|
95
|
+
payment_data = {
|
96
|
+
amount: "10",
|
97
|
+
billing_data: {
|
98
|
+
first_name: "Test",
|
99
|
+
last_name: "Account",
|
100
|
+
email: "test@email.com",
|
101
|
+
phone_number:"01111111111"
|
102
|
+
},
|
103
|
+
payment_reference: "ERTY"
|
104
|
+
}
|
105
|
+
onetime = Paymob::PaymentTypes::Installment.new
|
106
|
+
onetime.initialize_order(payment_data)
|
107
|
+
onetime.payment_link
|
108
|
+
```
|
109
|
+
|
110
|
+
## How to evaluate the HMAC
|
111
|
+
The `Paymob::Hmac` class provides helpful methods for handling HMAC operations. Below are the explanations of each method:
|
112
|
+
|
113
|
+
`calculate`
|
114
|
+
|
115
|
+
This method accepts a hash of parameters and returns the HMAC for these parameters.
|
116
|
+
|
117
|
+
Example:
|
118
|
+
```ruby
|
119
|
+
hmac = Paymob::Hmac.calculate(params_hash) # 6d9bb40e5b46b7166bb032cb075c8921
|
120
|
+
```
|
121
|
+
|
122
|
+
`matches_original?`
|
123
|
+
|
124
|
+
This method compares the HMAC generated from the provided parameters with an original HMAC and returns a boolean value indicating whether they match.
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
match = Paymob::Hmac.matches_original?(response_params, original_hmac) # true
|
128
|
+
```
|
129
|
+
## Contributing
|
130
|
+
|
131
|
+
We welcome contributions to improve paymob-rails! Whether you want to fix a bug, implement a new feature, or suggest improvements, we appreciate your efforts.
|
132
|
+
|
133
|
+
Feel free to customize this template to suit the specific guidelines and processes of your project.
|
134
|
+
|
135
|
+
## License
|
136
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/config/routes.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paymob
|
4
|
+
module Generators
|
5
|
+
class ControllerGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
argument :mount_path, type: :string, default: ''
|
9
|
+
|
10
|
+
def create_initializer_file
|
11
|
+
destination_path = if mount_path.present?
|
12
|
+
"app/controllers/#{mount_path}/paymob_controller.rb"
|
13
|
+
else
|
14
|
+
'app/controllers/paymob_controller.rb'
|
15
|
+
end
|
16
|
+
copy_file('paymob_controller.rb', destination_path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paymob
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
def create_initializer_file
|
9
|
+
copy_file('paymob.rb', 'config/initializers/paymob.rb')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Paymob.setup do |config|
|
4
|
+
config.base_url = 'https://accept.paymobsolutions.com/api'
|
5
|
+
config.api_key = ''
|
6
|
+
config.hmac_secret = ''
|
7
|
+
config.onetime_integration_id = ''
|
8
|
+
config.wallet_integration_id = ''
|
9
|
+
config.installment_integration_id = ''
|
10
|
+
config.ifream_link = 'https://accept.paymobsolutions.com/api/acceptance/iframes/'
|
11
|
+
config.onetime_ifream_number = ''
|
12
|
+
config.installment_ifream_number = ''
|
13
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# class PaymobController < ActionController::API
|
4
|
+
# def transaction_response
|
5
|
+
# if params[:success] && Hmac.matches_original?(transaction_response_params.to_h, params[:hmac])
|
6
|
+
# # Success logic
|
7
|
+
# else
|
8
|
+
# # Failure logic
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
|
12
|
+
# def transaction_callback
|
13
|
+
# if params[:success] && Hmac.matches_original?(transaction_callback_params.to_h, params[:hmac])
|
14
|
+
# # Success logic
|
15
|
+
# else
|
16
|
+
# # Failure logic
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
|
20
|
+
# private
|
21
|
+
|
22
|
+
# def transaction_response_params
|
23
|
+
# params
|
24
|
+
# .permit(
|
25
|
+
# :amount_cents, :created_at, :currency, :error_occured,
|
26
|
+
# :has_parent_transaction, :id, :integration_id, :is_3d_secure, :is_auth, :is_capture,
|
27
|
+
# :is_refunded, :is_standalone_payment, :is_voided, :owner, :pending, :success,
|
28
|
+
# :'source_data.pan', :'source_data.sub_type', :'source_data.type', :order
|
29
|
+
# )
|
30
|
+
# end
|
31
|
+
|
32
|
+
# def transaction_callback_params
|
33
|
+
# params
|
34
|
+
# .require(:obj)
|
35
|
+
# .permit(
|
36
|
+
# :amount_cents, :created_at, :currency, :error_occured,
|
37
|
+
# :has_parent_transaction, :id, :integration_id, :is_3d_secure, :is_auth, :is_capture,
|
38
|
+
# :is_refunded, :is_standalone_payment, :is_voided, :owner, :pending, :success, source_data:
|
39
|
+
# %i[pan sub_type type], order: %i[id]
|
40
|
+
# )
|
41
|
+
# end
|
42
|
+
# end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'paymob/errors'
|
4
|
+
require 'httparty'
|
5
|
+
|
6
|
+
module Paymob
|
7
|
+
class AcceptAPI
|
8
|
+
include HTTParty
|
9
|
+
attr_reader :auth_token, :merchant_id, :amount, :order_id, :payment_key, :billing_data,
|
10
|
+
:user, :payment_reference, :payment_type, :wallet_redirect_url
|
11
|
+
|
12
|
+
def initialize(amount:, billing_data:, payment_reference:, payment_type: :onetime)
|
13
|
+
@amount = amount
|
14
|
+
@billing_data = billing_data
|
15
|
+
@payment_reference = payment_reference
|
16
|
+
@payment_type = payment_type
|
17
|
+
self.class.base_uri Paymob.base_url
|
18
|
+
self.class.headers 'Content-Type' => 'application/json'
|
19
|
+
end
|
20
|
+
|
21
|
+
# def self.new_payment(amount:, payment_reference:, payment_type:, billing_data: {})
|
22
|
+
# api = new(amount: amount, billing_data: billing_data, payment_reference: payment_reference,
|
23
|
+
# payment_type: payment_type)
|
24
|
+
# api.authenticate
|
25
|
+
# api.create_order
|
26
|
+
# api.request_payment_key
|
27
|
+
# api
|
28
|
+
# end
|
29
|
+
|
30
|
+
def authenticate
|
31
|
+
response = self.class.post('/auth/tokens', { body: { api_key: api_key }.to_json }).parsed_response
|
32
|
+
@auth_token = response['token']
|
33
|
+
@merchant_id = response['profile']['id']
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_order
|
37
|
+
response = self.class.post('/ecommerce/orders',
|
38
|
+
body: {
|
39
|
+
auth_token: auth_token,
|
40
|
+
merchant_id: merchant_id,
|
41
|
+
delivery_needed: false,
|
42
|
+
currency: 'EGP',
|
43
|
+
amount_cents: amount.to_i * 100,
|
44
|
+
merchant_order_id: payment_reference
|
45
|
+
}.to_json)
|
46
|
+
body = response.parsed_response
|
47
|
+
|
48
|
+
@order_id = body['id']
|
49
|
+
raise Errors::PaymobRequestError, body if @order_id.blank?
|
50
|
+
end
|
51
|
+
|
52
|
+
def request_payment_key(integration_id)
|
53
|
+
response = self.class.post('/acceptance/payment_keys', body: {
|
54
|
+
auth_token: auth_token,
|
55
|
+
amount_cents: amount.to_i * 100,
|
56
|
+
order_id: order_id,
|
57
|
+
currency: 'EGP',
|
58
|
+
integration_id: integration_id,
|
59
|
+
billing_data: {
|
60
|
+
email: billing_data[:email],
|
61
|
+
first_name: billing_data[:first_name],
|
62
|
+
last_name: billing_data[:last_name],
|
63
|
+
building: billing_data[:building] || 'NA',
|
64
|
+
apartment: billing_data[:apartment] || 'NA',
|
65
|
+
street: billing_data[:street] || 'NA',
|
66
|
+
floor: billing_data[:floor] || 'NA',
|
67
|
+
city: billing_data[:city] || 'NA',
|
68
|
+
country: billing_data[:country] || 'NA',
|
69
|
+
phone_number: billing_data[:phone_number]
|
70
|
+
}
|
71
|
+
}.to_json).parsed_response
|
72
|
+
|
73
|
+
@payment_key = response['token']
|
74
|
+
end
|
75
|
+
|
76
|
+
def wallet_payment(phone_number)
|
77
|
+
response = self.class.post('/acceptance/payments/pay',
|
78
|
+
body: {
|
79
|
+
payment_token: payment_key,
|
80
|
+
source: {
|
81
|
+
identifier: phone_number,
|
82
|
+
subtype: 'WALLET'
|
83
|
+
}
|
84
|
+
}.to_json).parsed_response
|
85
|
+
|
86
|
+
@wallet_redirect_url = response['redirect_url']
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def api_key
|
92
|
+
raise Errors::PaymobCredentialsMissing, 'API Key is required' if Paymob.api_key.blank?
|
93
|
+
|
94
|
+
Paymob.api_key
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/paymob/base.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paymob
|
4
|
+
class Base
|
5
|
+
REQUIRED_BILLING_DATA_FIELDS = %i[first_name last_name email phone_number].freeze
|
6
|
+
REQUIRED_PAYMENT_FIELDS = %i[amount billing_data payment_reference].freeze
|
7
|
+
attr_accessor :accept_api
|
8
|
+
|
9
|
+
def initialize_order(payment_params)
|
10
|
+
validate_payment_params(payment_params)
|
11
|
+
@accept_api = AcceptAPI.new(amount: payment_params[:amount], billing_data: payment_params[:billing_data],
|
12
|
+
payment_reference: payment_params[:payment_reference])
|
13
|
+
@accept_api.authenticate
|
14
|
+
@accept_api.create_order
|
15
|
+
@accept_api.request_payment_key(integration_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def validate_payment_params(payment_params)
|
21
|
+
required_keys = REQUIRED_PAYMENT_FIELDS - payment_params.keys
|
22
|
+
if required_keys.blank?
|
23
|
+
validate_billing_data(payment_params[:billing_data])
|
24
|
+
else
|
25
|
+
raise Errors::PaymentArgumentsMissing,
|
26
|
+
"Missing #{required_keys} keys"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_billing_data(billing_data)
|
31
|
+
missing_keys = REQUIRED_BILLING_DATA_FIELDS - billing_data.keys
|
32
|
+
return if missing_keys.blank?
|
33
|
+
|
34
|
+
raise Errors::PaymentArgumentsMissing,
|
35
|
+
"Missing #{missing_keys} in billing data"
|
36
|
+
end
|
37
|
+
|
38
|
+
def integration_id
|
39
|
+
raise NotImplementedError
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'paymob/engine/version'
|
4
|
+
require 'paymob/engine/engine'
|
5
|
+
require 'paymob/errors'
|
6
|
+
require 'paymob/accept_api'
|
7
|
+
require 'paymob/hmac'
|
8
|
+
require 'paymob/base'
|
9
|
+
require 'paymob/payment_types/onetime'
|
10
|
+
require 'paymob/payment_types/wallet'
|
11
|
+
require 'paymob/payment_types/installment'
|
12
|
+
|
13
|
+
module Paymob
|
14
|
+
module Engine
|
15
|
+
end
|
16
|
+
mattr_accessor :base_url,
|
17
|
+
:api_key,
|
18
|
+
:installment_ifream_number,
|
19
|
+
:hmac_secret,
|
20
|
+
:onetime_integration_id,
|
21
|
+
:wallet_integration_id,
|
22
|
+
:ifream_link,
|
23
|
+
:onetime_ifream_number,
|
24
|
+
:installment_integration_id
|
25
|
+
|
26
|
+
# The base url of paymob api
|
27
|
+
self.base_url = 'https://accept.paymobsolutions.com/api'
|
28
|
+
self.api_key = 'api_key'
|
29
|
+
# HMAC secret key, you can get it from account settings
|
30
|
+
self.hmac_secret = ''
|
31
|
+
|
32
|
+
self.onetime_integration_id = ''
|
33
|
+
self.wallet_integration_id = ''
|
34
|
+
self.installment_integration_id = ''
|
35
|
+
|
36
|
+
# The link of iframes base url, note that you must put `/` at the end of this link
|
37
|
+
self.ifream_link = 'https://accept.paymobsolutions.com/api/acceptance/iframes/'
|
38
|
+
|
39
|
+
# The Ifream number for visa payments
|
40
|
+
self.onetime_ifream_number = ''
|
41
|
+
|
42
|
+
# The Ifream number for installment payments
|
43
|
+
self.installment_ifream_number = ''
|
44
|
+
|
45
|
+
def self.setup
|
46
|
+
yield self
|
47
|
+
end
|
48
|
+
end
|
data/lib/paymob/hmac.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paymob
|
4
|
+
class Hmac
|
5
|
+
def self.calculate(hash)
|
6
|
+
concatenated_params = flatten(hash.to_h).sort.to_h.values.join
|
7
|
+
OpenSSL::HMAC.hexdigest('SHA512', hmac_key, concatenated_params)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.matches_original?(hash, original_hmac)
|
11
|
+
calculate(hash) == original_hmac
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.flatten(hash)
|
15
|
+
new_hash = {}
|
16
|
+
hash.each do |key, value|
|
17
|
+
if value.is_a?(Hash)
|
18
|
+
new_hash.merge!(value.transform_keys { |k| "#{key}.#{k}" })
|
19
|
+
else
|
20
|
+
new_hash[key] = value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
new_hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.hmac_key
|
27
|
+
Paymob.hmac_secret
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paymob
|
4
|
+
module PaymentTypes
|
5
|
+
class Installment < Paymob::Base
|
6
|
+
def payment_link
|
7
|
+
return if @accept_api.payment_key.blank?
|
8
|
+
|
9
|
+
"#{Paymob.ifream_link}#{Paymob.installment_ifream_number}?payment_token=#{@accept_api.payment_key}"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def integration_id
|
15
|
+
Paymob.installment_integration_id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paymob
|
4
|
+
module PaymentTypes
|
5
|
+
class Onetime < Paymob::Base
|
6
|
+
def payment_link
|
7
|
+
return if @accept_api.payment_key.blank?
|
8
|
+
|
9
|
+
"#{Paymob.ifream_link}#{Paymob.onetime_ifream_number}?payment_token=#{@accept_api.payment_key}"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def integration_id
|
15
|
+
Paymob.onetime_integration_id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Paymob
|
4
|
+
module PaymentTypes
|
5
|
+
class Wallet < Paymob::Base
|
6
|
+
def payment_link(mobile_number:)
|
7
|
+
raise PaymentArgumentsMissing, 'Mobile number is required' if mobile_number.blank?
|
8
|
+
|
9
|
+
@accept_api.wallet_payment(mobile_number)
|
10
|
+
@accept_api.wallet_redirect_url
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def integration_id
|
16
|
+
Paymob.wallet_integration_id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paymob-engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- khaledmustafa91
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-http
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 6.1.4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 6.1.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 6.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 6.1.0
|
69
|
+
description: Gem provide you helpers to integrate with paymob service
|
70
|
+
email:
|
71
|
+
- khaled.mustafa1297@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- MIT-LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- app/controllers/paymob/engine/application_controller.rb
|
80
|
+
- app/jobs/paymob/engine/application_job.rb
|
81
|
+
- app/mailers/paymob/engine/application_mailer.rb
|
82
|
+
- app/models/paymob/engine/application_record.rb
|
83
|
+
- config/routes.rb
|
84
|
+
- lib/generators/paymob/controller_generator.rb
|
85
|
+
- lib/generators/paymob/install_generator.rb
|
86
|
+
- lib/generators/paymob/templates/paymob.rb
|
87
|
+
- lib/generators/paymob/templates/paymob_controller.rb
|
88
|
+
- lib/paymob/accept_api.rb
|
89
|
+
- lib/paymob/base.rb
|
90
|
+
- lib/paymob/engine.rb
|
91
|
+
- lib/paymob/engine/engine.rb
|
92
|
+
- lib/paymob/engine/version.rb
|
93
|
+
- lib/paymob/errors.rb
|
94
|
+
- lib/paymob/hmac.rb
|
95
|
+
- lib/paymob/payment_types/installment.rb
|
96
|
+
- lib/paymob/payment_types/onetime.rb
|
97
|
+
- lib/paymob/payment_types/wallet.rb
|
98
|
+
- lib/tasks/paymob/engine_tasks.rake
|
99
|
+
homepage: https://github.com/swiftx-io/paymob-rails
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata:
|
103
|
+
homepage_uri: https://github.com/swiftx-io/paymob-rails
|
104
|
+
source_code_uri: https://github.com/swiftx-io/paymob-rails
|
105
|
+
changelog_uri: https://github.com/swiftx-io/paymob-rails
|
106
|
+
rubygems_mfa_required: 'true'
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 2.6.0
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubygems_version: 3.4.1
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Integration with paymob service
|
126
|
+
test_files: []
|