paymob_accept 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CODE_OF_CONDUCT.md +57 -47
- data/Gemfile +5 -2
- data/Gemfile.lock +3 -3
- data/README.md +77 -45
- data/Rakefile +3 -1
- data/bin/console +2 -1
- data/lib/paymob_accept/api/base.rb +6 -9
- data/lib/paymob_accept/api/client.rb +1 -2
- data/lib/paymob_accept/api/pay.rb +42 -26
- data/lib/paymob_accept/configuration.rb +2 -8
- data/lib/paymob_accept/version.rb +3 -1
- data/lib/paymob_accept.rb +6 -2
- data/{paymob.gemspec → paymob_accept.gemspec} +7 -8
- metadata +11 -12
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6ebddca8de134c54bbf5d5f8dceecde5ae4f65cc735f403e40c04afa13e3f5e
|
4
|
+
data.tar.gz: f635a17547b178a9ed8428d1fccf8a8157440e1656b6808375d5984b4e26a8e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3925164b5d6519cf7216d719222c79c3882a70e88d56b1227c59a9c6bec93e4c9e499f22a7351620eb66c320550104615dddd2bc99b9da03fc82335c41d0c3b1
|
7
|
+
data.tar.gz: 6009edcbbbc9f9feeaad04f26169cd14b9131102fb651944fee152b4c8c2b2bd62e109a1030b87ee5be5831faea4f0077bff157add1535a0cd87e5d9343616b1
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -2,73 +2,83 @@
|
|
2
2
|
|
3
3
|
## Our Pledge
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
11
8
|
|
12
9
|
## Our Standards
|
13
10
|
|
14
|
-
Examples of behavior that contributes to
|
15
|
-
include:
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
16
12
|
|
17
|
-
*
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
*
|
20
|
-
*
|
21
|
-
*
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
22
18
|
|
23
|
-
Examples of unacceptable behavior
|
19
|
+
Examples of unacceptable behavior include:
|
24
20
|
|
25
|
-
* The use of sexualized language or imagery and
|
26
|
-
advances
|
27
|
-
* Trolling, insulting
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
28
24
|
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or
|
30
|
-
address, without explicit permission
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
31
27
|
* Other conduct which could reasonably be considered inappropriate in a
|
32
28
|
professional setting
|
33
29
|
|
34
|
-
##
|
30
|
+
## Enforcement Responsibilities
|
35
31
|
|
36
|
-
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
39
33
|
|
40
|
-
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
45
35
|
|
46
36
|
## Scope
|
47
37
|
|
48
|
-
This Code of Conduct applies
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
54
39
|
|
55
40
|
## Enforcement
|
56
41
|
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tech@oneorder.net All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
63
59
|
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
67
73
|
|
68
74
|
## Attribution
|
69
75
|
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version
|
71
|
-
available at
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
72
82
|
|
73
|
-
|
74
|
-
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
|
-
# Specify your gem's dependencies in
|
5
|
+
# Specify your gem's dependencies in paymob_accept.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
|
-
gem "rake", "~>
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
7
10
|
gem "rspec", "~> 3.0"
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
paymob_accept (0.
|
4
|
+
paymob_accept (0.2.0)
|
5
5
|
faraday
|
6
6
|
json-schema
|
7
7
|
|
@@ -18,7 +18,7 @@ GEM
|
|
18
18
|
json-schema (3.0.0)
|
19
19
|
addressable (>= 2.8)
|
20
20
|
public_suffix (4.0.7)
|
21
|
-
rake (
|
21
|
+
rake (13.0.6)
|
22
22
|
rspec (3.11.0)
|
23
23
|
rspec-core (~> 3.11.0)
|
24
24
|
rspec-expectations (~> 3.11.0)
|
@@ -39,7 +39,7 @@ PLATFORMS
|
|
39
39
|
|
40
40
|
DEPENDENCIES
|
41
41
|
paymob_accept!
|
42
|
-
rake (~>
|
42
|
+
rake (~> 13.0)
|
43
43
|
rspec (~> 3.0)
|
44
44
|
|
45
45
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
1
|
# PaymobAccept
|
3
2
|
|
4
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.
|
5
4
|
|
6
5
|
## Installation
|
7
6
|
|
8
|
-
Add this line to your
|
7
|
+
Add this line to your appliciation's Gemfile:
|
9
8
|
|
10
9
|
```ruby
|
11
10
|
gem 'paymob_accept'
|
@@ -23,89 +22,122 @@ Or install it yourself as:
|
|
23
22
|
|
24
23
|
### Configuration
|
25
24
|
|
26
|
-
Configure the gem with your
|
25
|
+
Configure the gem with your configuration
|
27
26
|
|
28
27
|
```ruby
|
29
28
|
PaymobAccept.configure do |config|
|
30
|
-
|
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 = "######"
|
31
36
|
end
|
32
37
|
```
|
33
38
|
|
34
|
-
|
39
|
+
Optionally, any configuration parameters mentioned above could be passed to the constructor when initializing the payment service.
|
35
40
|
|
36
|
-
:
|
41
|
+
:bulb: You can get your API_KEY from Settings -> Account info -> API Key in your Paymob portal.
|
37
42
|
|
38
|
-
|
43
|
+
For reference on the internals & specifics of Paymob, please head to their official documentation [here](https://docs.paymob.com/)
|
39
44
|
|
40
|
-
|
45
|
+
## Creating a charge:
|
41
46
|
|
42
|
-
|
47
|
+
1. Initialize your payment service
|
43
48
|
|
49
|
+
```ruby
|
50
|
+
service = PaymobAccept::Api::Pay.new(api_key: api_key, online_integration_id: "12345678")
|
51
|
+
```
|
44
52
|
|
45
|
-
|
53
|
+
2. Prepare your customer data using the following schemas (All fields are required):
|
46
54
|
|
47
|
-
- Initialize your payment service
|
48
55
|
```ruby
|
49
|
-
|
56
|
+
customer_data = {name: "test", email: "test@test.com", phone_number: "01000000000"}
|
57
|
+
billing_address_data = {address_line1: "10 street name", address_line2: "apt x. floor x", region: "region", city: "Cairo", country: "EG"}
|
50
58
|
```
|
59
|
+
3. Create a charge:
|
51
60
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
```ruby
|
62
|
+
service.charge(customer: customer_data, address: billing_address_data, method: :online, iframe_id: 'xxxxx', amount_cents: 1000)
|
63
|
+
```
|
64
|
+
|
65
|
+
Note. All integration id methods are public and could so it could be easily used to set an integration as:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
service.online_integration_id = "123"
|
69
|
+
```
|
70
|
+
|
71
|
+
### Alternatively, you can you create a charge step by step (Not recommended):
|
72
|
+
|
73
|
+
1. Authentication request
|
59
74
|
|
60
|
-
---
|
61
|
-
### Also, You can do it step by step
|
62
|
-
|
63
|
-
- Step #1 Get auth_token
|
64
75
|
```ruby
|
65
|
-
token =
|
76
|
+
token = service.get_auth_token
|
66
77
|
```
|
67
78
|
|
68
|
-
|
79
|
+
2. Create order
|
69
80
|
```ruby
|
70
|
-
service.create_order(auth_token:
|
81
|
+
service.create_order(auth_token: token, amount_cents: 1000, amount_currency: 'EGP', items: [])
|
71
82
|
```
|
72
83
|
|
73
|
-
auth_token is optional if not passed, it will be automatically generated.
|
74
|
-
</br>
|
75
84
|
- Items are optional
|
76
85
|
|
77
86
|
```ruby
|
78
|
-
|
87
|
+
items = [{
|
79
88
|
"name": "xxxxxxx-1",
|
80
89
|
"amount_cents": "5000",
|
81
90
|
"description": "Smart Watch",
|
82
91
|
"quantity": "10"
|
83
|
-
|
92
|
+
}]
|
84
93
|
```
|
85
94
|
|
86
|
-
|
95
|
+
3. Create payment key
|
87
96
|
|
88
|
-
- Step #3 Create payment key
|
89
|
-
|
90
97
|
```ruby
|
91
|
-
generate_payment_intent(customer: customer, address: address, integration_id: "xxxxx", amount_cents: amount_cents, amount_currency: "EGP", iframe_id: "xxxxxx", order_id: "xxxxxx")
|
98
|
+
service.generate_payment_intent(customer: customer, address: address, integration_id: "xxxxx", amount_cents: amount_cents, amount_currency: "EGP", iframe_id: "xxxxxx", order_id: "xxxxxx")
|
92
99
|
```
|
93
|
-
---
|
94
|
-
## Dealing with charges
|
95
|
-
- retrieve transaction `PaymobAccept::Api::Charge.new.charge(transaction_id: transaction_id)`
|
96
|
-
- refund transaction `PaymobAccept::Api::Charge.new.refund!(transaction_id: transaction_id, amount_cents: amount_cents)`
|
97
|
-
- void a transaction using `PaymobAccept::Api::Charge.new.void!(transaction_id: transaction_id)`
|
98
100
|
|
99
|
-
##
|
101
|
+
## Supported payment methods
|
102
|
+
|
103
|
+
The `:method` key in the `charge` method could be one of the following:
|
104
|
+
|
105
|
+
- :online => 3D Secure payments with external redirection
|
106
|
+
- :auth => Auth/Capture payments
|
107
|
+
- :kiosk => Aman/Masary kiosk network
|
108
|
+
- :cash => Cash on delivery
|
109
|
+
- :wallet => Vodafone cash
|
110
|
+
- :moto => Paying with a saved car token
|
111
|
+
|
112
|
+
Please refer to the official Paymob documentation for in-depth explanation about each payment method.
|
113
|
+
|
114
|
+
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
|
+
### Paying with a saved card token
|
117
|
+
|
118
|
+
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.
|
119
|
+
|
120
|
+
## Dealing with charges
|
121
|
+
|
122
|
+
- **Initialize your Charge service**
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
service = PaymobAccept::Api::Charge.new
|
126
|
+
```
|
127
|
+
|
128
|
+
- Retrieve transaction: `service.charge(transaction_id: transaction_id)`
|
129
|
+
- Refund transaction: `service.refund!(transaction_id: transaction_id, amount_cents: amount_cents)`
|
130
|
+
- Void a transaction: `service.void!(transaction_id: transaction_id)`
|
131
|
+
- Capture an auth transaction: `service.capture!(transaction_id: transaction_id, amount_cents: amount_cents)`
|
100
132
|
|
101
|
-
|
133
|
+
## Roadmap
|
102
134
|
|
103
|
-
|
135
|
+
- [ ] HMAC validation
|
104
136
|
|
105
137
|
## Contributing
|
106
138
|
|
107
|
-
Bug reports and pull requests are welcome on [GitHub](https://github.com/
|
108
|
-
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/
|
139
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/oneorder-tech/paymob-accept).
|
140
|
+
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).
|
109
141
|
|
110
142
|
## License
|
111
143
|
|
@@ -113,4 +145,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
113
145
|
|
114
146
|
## Code of Conduct
|
115
147
|
|
116
|
-
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/
|
148
|
+
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).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "bundler/setup"
|
4
|
-
require "
|
5
|
+
require "paymob_accept"
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -1,16 +1,14 @@
|
|
1
1
|
module PaymobAccept
|
2
2
|
module Api
|
3
3
|
class Base
|
4
|
-
attr_reader :
|
5
|
-
attr_accessor :api_key, :iframe_id
|
4
|
+
attr_reader :api_key, :client
|
6
5
|
|
7
|
-
def initialize(api_key:
|
6
|
+
def initialize(api_key:)
|
8
7
|
@client = PaymobAccept::Api::Client.new
|
9
8
|
@api_key = api_key
|
10
|
-
@address = address
|
11
9
|
end
|
12
10
|
|
13
|
-
#
|
11
|
+
# 1. Authentication Request
|
14
12
|
def get_auth_token
|
15
13
|
response = @client.request('/auth/tokens', { api_key: api_key })
|
16
14
|
response['token']
|
@@ -29,6 +27,7 @@ module PaymobAccept
|
|
29
27
|
@client.request('/ecommerce/orders', body)
|
30
28
|
end
|
31
29
|
|
30
|
+
# 3. Payment Key Request
|
32
31
|
def generate_payment_intent(customer:, address:, integration_id:, amount_cents:, amount_currency:, iframe_id: nil, order_id: nil, auth_token: get_auth_token)
|
33
32
|
if order_id.nil?
|
34
33
|
order = create_order(amount_cents: amount_cents, amount_currency: amount_currency)
|
@@ -40,8 +39,6 @@ module PaymobAccept
|
|
40
39
|
format_bill_reference(payment_token, iframe_id)
|
41
40
|
end
|
42
41
|
|
43
|
-
# 3. Payment Key Request
|
44
|
-
|
45
42
|
private
|
46
43
|
|
47
44
|
def generate_payment_key(customer:, address:, amount_cents:, amount_currency:, integration_id:, order_id: nil, auth_token: get_auth_token)
|
@@ -82,13 +79,13 @@ module PaymobAccept
|
|
82
79
|
def customer_validator(customer)
|
83
80
|
JSON::Validator.validate!(customer_schema, customer)
|
84
81
|
rescue JSON::Schema::ValidationError => e
|
85
|
-
raise ArgumentError, "Customer
|
82
|
+
raise ArgumentError, "Customer hash has the following error: #{e.message}"
|
86
83
|
end
|
87
84
|
|
88
85
|
def address_validator(address)
|
89
86
|
JSON::Validator.validate!(address_schema, address)
|
90
87
|
rescue JSON::Schema::ValidationError => e
|
91
|
-
raise ArgumentError, "Address
|
88
|
+
raise ArgumentError, "Address hash has the following error: #{e.message}"
|
92
89
|
end
|
93
90
|
|
94
91
|
def customer_schema
|
@@ -2,6 +2,7 @@ module PaymobAccept
|
|
2
2
|
module Api
|
3
3
|
class Client
|
4
4
|
API_ENDPOINT = 'https://accept.paymobsolutions.com/api'.freeze
|
5
|
+
|
5
6
|
def initialize; end
|
6
7
|
|
7
8
|
def get(endpoint:, params: {}, headers: {})
|
@@ -29,8 +30,6 @@ module PaymobAccept
|
|
29
30
|
end
|
30
31
|
|
31
32
|
unless response.success?
|
32
|
-
# TODO: Instead of setting the status to failed, this payment intent could be destroyed
|
33
|
-
|
34
33
|
message = parsed_body&.dig('message') || response.body || default_error_message
|
35
34
|
raise PaymobAccept::Errors::BadGateway.new(message: "code: #{response.status}, gateway response: #{message}")
|
36
35
|
end
|
@@ -3,63 +3,79 @@
|
|
3
3
|
module PaymobAccept
|
4
4
|
module Api
|
5
5
|
class Pay < Base
|
6
|
-
|
6
|
+
SUPPORTED_PAYMENT_METHODS = %i[online auth kiosk cash wallet moto].freeze
|
7
|
+
|
8
|
+
attr_accessor :api_key, :online_integration_id, :cash_integration_id, :kiosk_integration_id,
|
9
|
+
:auth_integration_id, :wallet_integration_id, :moto_integration_id
|
10
|
+
|
11
|
+
def initialize(api_key: PaymobAccept.configuration.api_key, online_integration_id: PaymobAccept.configuration.online_integration_id, cash_integration_id: PaymobAccept.configuration.cash_integration_id, kiosk_integration_id: PaymobAccept.configuration.kiosk_integration_id,
|
12
|
+
auth_integration_id: PaymobAccept.configuration.auth_integration_id, wallet_integration_id: PaymobAccept.configuration.wallet_integration_id, moto_integration_id: PaymobAccept.configuration.moto_integration_id)
|
7
13
|
super(api_key: api_key)
|
14
|
+
@api_key = api_key
|
15
|
+
@online_integration_id = online_integration_id
|
16
|
+
@cash_integration_id = cash_integration_id
|
17
|
+
@kiosk_integration_id = kiosk_integration_id
|
18
|
+
@auth_integration_id = auth_integration_id
|
19
|
+
@wallet_integration_id = wallet_integration_id
|
20
|
+
@moto_integration_id = moto_integration_id
|
8
21
|
end
|
9
22
|
|
10
|
-
def charge(
|
11
|
-
raise ArgumentError, "unsupported payment method #{method}" unless
|
12
|
-
wallet].include? method
|
23
|
+
def charge(method:, **kwargs)
|
24
|
+
raise ArgumentError, "unsupported payment method #{method}" unless SUPPORTED_PAYMENT_METHODS.include? method
|
13
25
|
|
14
|
-
|
15
|
-
|
16
|
-
|
26
|
+
# Override any currencies, only EGP is currently supported
|
27
|
+
kwargs[:amount_currency] = 'EGP'
|
28
|
+
send("pay_#{method}".to_sym, **kwargs)
|
17
29
|
end
|
18
30
|
|
19
31
|
private
|
20
32
|
|
21
|
-
def
|
33
|
+
def pay_auth(customer:, address:, amount_cents:, amount_currency:)
|
22
34
|
generate_payment_intent(customer: customer, address: address, amount_cents: amount_cents, amount_currency: amount_currency,
|
23
|
-
integration_id:
|
35
|
+
integration_id: auth_integration_id)
|
24
36
|
end
|
25
37
|
|
26
|
-
#
|
27
|
-
|
38
|
+
# Return an iFrame URL if an iframe_id is provided. Otherwise, returns a payment token
|
39
|
+
# The iFrame will be prepoulated with the credit card info if customer[cc_token] is present and is valid stored credit card token on Paymob's server
|
40
|
+
def pay_online(customer:, address:, amount_cents:, amount_currency:, iframe_id: nil)
|
28
41
|
generate_payment_intent(customer: customer, address: address, amount_cents: amount_cents, amount_currency: amount_currency,
|
29
|
-
integration_id:
|
42
|
+
integration_id: online_integration_id, iframe_id: iframe_id)
|
30
43
|
end
|
31
44
|
|
32
|
-
|
45
|
+
# Paying MOTO (ie. with a saved card token)
|
46
|
+
def pay_moto(customer:, address:, amount_cents:, amount_currency:)
|
33
47
|
if customer[:cc_token].nil?
|
34
48
|
raise ArgumentError,
|
35
|
-
'You need to provide a credit card token for
|
49
|
+
'You need to provide a credit card token for MOTO payments'
|
36
50
|
end
|
37
51
|
|
38
52
|
bill_reference = generate_payment_intent(customer: customer, address: address, amount_cents: amount_cents, amount_currency: amount_currency,
|
39
|
-
integration_id:
|
53
|
+
integration_id: auth_integration_id)
|
40
54
|
body = {
|
41
|
-
"source": { "subtype": 'TOKEN', "identifier": cc_token },
|
55
|
+
"source": { "subtype": 'TOKEN', "identifier": customer[:cc_token] },
|
42
56
|
"payment_token": bill_reference
|
43
57
|
}
|
44
58
|
@client.request('/acceptance/payments/pay', body)
|
45
59
|
end
|
46
60
|
|
47
|
-
def pay_wallet(customer:, address:, amount_cents:, amount_currency
|
48
|
-
|
61
|
+
def pay_wallet(customer:, address:, amount_cents:, amount_currency:)
|
62
|
+
wallet_phone_number = customer[:wallet_phone_number] || customer[:phone_number]
|
63
|
+
|
64
|
+
if wallet_phone_number.nil?
|
49
65
|
raise ArgumentError,
|
50
66
|
'You need to provide a mobile number for wallet payments'
|
51
67
|
end
|
52
68
|
|
53
69
|
bill_reference = generate_payment_intent(customer: customer, address: address, amount_cents: amount_cents, amount_currency: amount_currency,
|
54
|
-
integration_id:
|
70
|
+
integration_id: wallet_integration_id)
|
55
71
|
body = {
|
56
|
-
"source": { "subtype": 'WALLET', "identifier":
|
72
|
+
"source": { "subtype": 'WALLET', "identifier": wallet_phone_number },
|
57
73
|
"payment_token": bill_reference
|
58
74
|
}
|
59
75
|
@client.request('/acceptance/payments/pay', body)
|
60
76
|
end
|
61
77
|
|
62
|
-
def pay_cash(customer:, address:, amount_cents:, amount_currency
|
78
|
+
def pay_cash(customer:, address:, amount_cents:, amount_currency:)
|
63
79
|
if address.nil?
|
64
80
|
raise ArgumentError,
|
65
81
|
"Please provide a valid address in options. You must provide those keys: #{address_schema[:required]}"
|
@@ -67,8 +83,8 @@ module PaymobAccept
|
|
67
83
|
|
68
84
|
address_validator(address)
|
69
85
|
|
70
|
-
bill_reference = generate_payment_intent(customer: customer, address: address, amount_cents: amount_cents,
|
71
|
-
|
86
|
+
bill_reference = generate_payment_intent(customer: customer, address: address, amount_cents: amount_cents,
|
87
|
+
amount_currency: amount_currency, integration_id: cash_integration_id)
|
72
88
|
body = {
|
73
89
|
"source": { "subtype": 'CASH', "identifier": 'cash' },
|
74
90
|
"payment_token": bill_reference
|
@@ -76,9 +92,9 @@ module PaymobAccept
|
|
76
92
|
@client.request('/acceptance/payments/pay', body)
|
77
93
|
end
|
78
94
|
|
79
|
-
def pay_kiosk(customer:, address:, amount_cents:, amount_currency
|
80
|
-
bill_reference = generate_payment_intent(customer: customer, address: address, amount_cents: amount_cents,
|
81
|
-
|
95
|
+
def pay_kiosk(customer:, address:, amount_cents:, amount_currency:)
|
96
|
+
bill_reference = generate_payment_intent(customer: customer, address: address, amount_cents: amount_cents,
|
97
|
+
amount_currency: amount_currency, integration_id: kiosk_integration_id)
|
82
98
|
body = {
|
83
99
|
"source": { "subtype": 'AGGREGATOR', "identifier": 'aggregator' },
|
84
100
|
"payment_token": bill_reference
|
@@ -1,13 +1,7 @@
|
|
1
|
-
# require 'erb'
|
2
|
-
# require 'yaml'
|
3
|
-
|
4
1
|
module PaymobAccept
|
5
2
|
class Configuration
|
6
|
-
attr_accessor :api_key, :
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@amount_currency = 'EGP'
|
10
|
-
end
|
3
|
+
attr_accessor :api_key, :online_integration_id, :cash_integration_id, :kiosk_integration_id,
|
4
|
+
:auth_integration_id, :wallet_integration_id, :moto_integration_id
|
11
5
|
end
|
12
6
|
|
13
7
|
class ConfigurationMissingError < StandardError; end
|
data/lib/paymob_accept.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'paymob_accept/version'
|
4
|
+
|
5
|
+
require 'paymob_accept/configuration'
|
1
6
|
require 'paymob_accept'
|
2
7
|
require 'paymob_accept/api/base'
|
3
8
|
require 'paymob_accept/api/pay'
|
4
9
|
require 'paymob_accept/api/client'
|
5
10
|
require 'paymob_accept/api/charge'
|
6
|
-
require 'paymob_accept/configuration'
|
7
11
|
|
8
12
|
require 'json'
|
9
13
|
require 'faraday'
|
10
14
|
require 'faraday/net_http'
|
11
15
|
require 'paymob_accept/errors/bad_gateway'
|
12
16
|
require 'json-schema'
|
13
|
-
|
14
17
|
module PaymobAccept
|
15
18
|
class Error < StandardError; end
|
19
|
+
|
16
20
|
class << self
|
17
21
|
def configure
|
18
22
|
yield configuration
|
@@ -5,20 +5,19 @@ require_relative 'lib/paymob_accept/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'paymob_accept'
|
7
7
|
spec.version = PaymobAccept::VERSION
|
8
|
-
spec.authors = ['
|
9
|
-
spec.email = ['
|
8
|
+
spec.authors = ['OneOrder']
|
9
|
+
spec.email = ['tech@oneorder.net']
|
10
10
|
|
11
11
|
spec.summary = 'Easy integration of Paymob payment gateway'
|
12
|
-
spec.description = '
|
13
|
-
spec.homepage =
|
12
|
+
spec.description = 'PaymobAccept is a Ruby gem created by OneOrder tech team for integrating Paymob payment solutions with your Ruby application.'
|
13
|
+
spec.homepage = 'https://github.com/oneorder-tech/paymob-accept'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
spec.homepage = 'https://github.com/oneorder-tech/paymob'
|
15
|
+
spec.homepage = 'https://github.com/oneorder-tech/paymob-accept'
|
16
16
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
17
17
|
|
18
|
-
|
19
18
|
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
-
spec.metadata['source_code_uri'] = 'https://github.com/oneorder-tech/paymob'
|
21
|
-
spec.metadata['changelog_uri'] = 'https://github.com/oneorder-tech/paymob'
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/oneorder-tech/paymob-accept'
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/oneorder-tech/paymob-accept'
|
22
21
|
|
23
22
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
23
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
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.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- OneOrder
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,17 +38,16 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description:
|
42
|
-
payment solutions with your Ruby application.
|
41
|
+
description: PaymobAccept is a Ruby gem created by OneOrder tech team for integrating
|
42
|
+
Paymob payment solutions with your Ruby application.
|
43
43
|
email:
|
44
|
-
-
|
44
|
+
- tech@oneorder.net
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
50
|
- ".rspec"
|
51
|
-
- ".travis.yml"
|
52
51
|
- CODE_OF_CONDUCT.md
|
53
52
|
- Gemfile
|
54
53
|
- Gemfile.lock
|
@@ -65,14 +64,14 @@ files:
|
|
65
64
|
- lib/paymob_accept/configuration.rb
|
66
65
|
- lib/paymob_accept/errors/bad_gateway.rb
|
67
66
|
- lib/paymob_accept/version.rb
|
68
|
-
-
|
69
|
-
homepage: https://github.com/oneorder-tech/paymob
|
67
|
+
- paymob_accept.gemspec
|
68
|
+
homepage: https://github.com/oneorder-tech/paymob-accept
|
70
69
|
licenses:
|
71
70
|
- MIT
|
72
71
|
metadata:
|
73
|
-
homepage_uri: https://github.com/oneorder-tech/paymob
|
74
|
-
source_code_uri: https://github.com/oneorder-tech/paymob
|
75
|
-
changelog_uri: https://github.com/oneorder-tech/paymob
|
72
|
+
homepage_uri: https://github.com/oneorder-tech/paymob-accept
|
73
|
+
source_code_uri: https://github.com/oneorder-tech/paymob-accept
|
74
|
+
changelog_uri: https://github.com/oneorder-tech/paymob-accept
|
76
75
|
post_install_message:
|
77
76
|
rdoc_options: []
|
78
77
|
require_paths:
|