paymob_accept 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 519375883a2c35dd6406dc2aee7e471f3525905ded1faee4c286d9d4518014aa
4
- data.tar.gz: dbb89c1765419b3114e0366302494097dae654d13fc9d0bdf20794420230b07e
3
+ metadata.gz: 9be4b1690f4a848451740b6b49bed06814dece0eb6cfc8d4bebb8e0445fbd86f
4
+ data.tar.gz: 94ab14e1b12819055f982b23e29e5fb7c8f4a35b87ed18d2f8a122ff5aca2a45
5
5
  SHA512:
6
- metadata.gz: 0e9bb8812b46f509a9ccbb96bfc97a140726fb360e044980eec42bad30828575e457361ba5a61df608324021bdf58424815c7ef828dad7909322b20ffdaae3a4
7
- data.tar.gz: 7d2811bd93ee7c9a43492c984fa8a5c237929b64ad1f3393bb528f24f489d666427fccff34d15d914f55002e8e52cbce7501b7efa1aad9006b03467fafde577d
6
+ metadata.gz: 86ab02b708a4415b8c1cb4a17d96f7e303472a431653b449c7805a0ae884c512930929c8db34045ab83f470f63f819c0f130acb68bef2e7de594aaa913867353
7
+ data.tar.gz: d846e0ccf9ad28d591f923c56193e25d98a073794ec3da2c13dbcd7db6bc2815606a1432422dc4f340119378260571e0785ba706b65c22cb7e619a38efc3917f
data/CODE_OF_CONDUCT.md CHANGED
@@ -2,73 +2,83 @@
2
2
 
3
3
  ## Our Pledge
4
4
 
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
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 creating a positive environment
15
- include:
11
+ Examples of behavior that contributes to a positive environment for our community include:
16
12
 
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
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 by participants include:
19
+ Examples of unacceptable behavior include:
24
20
 
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
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 electronic
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
- ## Our Responsibilities
30
+ ## Enforcement Responsibilities
35
31
 
36
- Project maintainers are responsible for clarifying the standards of acceptable
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
- Project maintainers have the right and responsibility to remove, edit, or
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 both within project spaces and in public spaces
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
- reported by contacting the project team at hesham_magdy97@hotmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
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
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
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 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
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
- [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/
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 paymob.gemspec
5
+ # Specify your gem's dependencies in paymob_accept.gemspec
4
6
  gemspec
5
7
 
6
- gem "rake", "~> 12.0"
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.1.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 (12.3.3)
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 (~> 12.0)
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 application's Gemfile:
7
+ Add this line to your appliciation's Gemfile:
9
8
 
10
9
  ```ruby
11
10
  gem 'paymob_accept'
@@ -23,89 +22,115 @@ Or install it yourself as:
23
22
 
24
23
  ### Configuration
25
24
 
26
- Configure the gem with your `api_key`
25
+ Configure the gem with your configuration
27
26
 
28
27
  ```ruby
29
28
  PaymobAccept.configure do |config|
30
- config.api_key = YOUR_API_KEY
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
- Also you can pass the api_key to the constructor when initializing your payment service
39
+ Optionally, any configuration parameters mentioned above could be passed to the constructor when initializing the payment service.
35
40
 
36
- :raised_back_of_hand: You get your API_KEY from Settings -> Account info -> API Key in your Paymob portal
41
+ :bulb: You can get your API_KEY from Settings -> Account info -> API Key in your Paymob portal.
37
42
 
38
- ### Creating the payment service
43
+ For reference on the internals & specifics of Paymob, please head to their official documentation [here](https://docs.paymob.com/)
39
44
 
40
- When performing a payment we expect to have two hashes (customer, address)
45
+ ## Creating a charge:
41
46
 
42
- - Customer schema
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
- ## Payment service
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
- service = PaymobAccept::Api::Pay.new(api_key: api_key)
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
- - To charge:
53
- ```ruby
54
- customer_data = {name: "test", email: "test@test.com", phone_number: "01000000000"}
55
- address_data = {address_line1: "10 street name", address_line2: "apt x. floor x", region: "region", city: "Cairo", country: "EG"}
56
- service.charge(customer: customer, address: address, integration_id: 'xxxxx', method: :online, iframe_id: 'xxxxx', amount_cents: 1000, amount_currency: 'EGP', order_id: order_id)
57
- ```
58
- If order_id is not provided, an order is created then linked to this payment_intent
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 = service.get_auth_token
76
+ token = service.get_auth_token
66
77
  ```
67
78
 
68
- - Step #2 Create_order
79
+ 2. Create_order
69
80
  ```ruby
70
- service.create_order(auth_token: auth_token, amount_cents: 1000, amount_currency: 'EGP', items: [])
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
- items = [{
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
- </br>
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
- ## Development
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 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
+ ## Dealing with charges
117
+
118
+ - **Initialize your Charge service**
119
+
120
+ ```ruby
121
+ service = PaymobAccept::Api::Charge.new
122
+ ```
100
123
 
101
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
124
+ - Retrieve transaction: `service.charge(transaction_id: transaction_id)`
125
+ - Refund transaction: `service.refund!(transaction_id: transaction_id, amount_cents: amount_cents)`
126
+ - Void a transaction: `service.void!(transaction_id: transaction_id)`
127
+ - Capture an auth transaction: `service.capture!(transaction_id: transaction_id, amount_cents: amount_cents)`
102
128
 
103
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
104
129
 
105
130
  ## Contributing
106
131
 
107
- Bug reports and pull requests are welcome on [GitHub](https://github.com/HeshamMagdy97/paymob).
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/HeshamMagdy97/paymob/blob/master/CODE_OF_CONDUCT.md).
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).
109
134
 
110
135
  ## License
111
136
 
@@ -113,4 +138,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
113
138
 
114
139
  ## Code of Conduct
115
140
 
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/HeshamMagdy97/paymob/blob/master/CODE_OF_CONDUCT.md).
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).
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
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 "paymob"
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 :integration_id, :method, :customer, :address
5
- attr_accessor :api_key, :iframe_id
4
+ attr_reader :api_key, :client
6
5
 
7
- def initialize(api_key: PaymobAccept.configuration.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
- # STEP #!
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 field has the following error: #{e.message}"
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 field has the following error: #{e.message}"
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
- def initialize(api_key: PaymobAccept.configuration.api_key)
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(customer:, address:, amount_cents:, integration_id:, method:, amount_currency: 'EGP', order_id: nil, iframe_id: nil, auth_token: get_auth_token)
11
- raise ArgumentError, "unsupported payment method #{method}" unless %i[online moto kiosk cash auth
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
- send("pay_#{method}".to_sym,
15
- { auth_token: auth_token, customer: customer, address: address, amount_cents: amount_cents, amount_currency: amount_currency,
16
- integration_id: integration_id, iframe_id: iframe_id, order_id: order_id })
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 request_auth(customer:, address:, amount_cents:, amount_currency:, integration_id:, iframe_id:, order_id:, auth_token:)
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: integration_id, iframe_id: iframe_id, order_id: order_id, auth_token: auth_token)
35
+ integration_id: auth_integration_id)
24
36
  end
25
37
 
26
- # Returns iFrame URL. The iframe will be prepoulated if the credit card token is provided
27
- def pay_online(customer:, address:, amount_cents:, amount_currency:, integration_id:, iframe_id:, order_id:, auth_token:)
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: integration_id, iframe_id: iframe_id, order_id: order_id, auth_token: auth_token)
42
+ integration_id: online_integration_id, iframe_id: iframe_id)
30
43
  end
31
44
 
32
- def pay_moto(customer:, address:, amount_cents:, amount_currency:, integration_id:, iframe_id:, order_id:, auth_token:)
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 moto payments'
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: integration_id, iframe_id: iframe_id, order_id: order_id, auth_token: auth_token)
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:, integration_id:, iframe_id:, order_id:, auth_token:)
48
- if customer[:wallet_mobile_number].nil?
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: integration_id, iframe_id: iframe_id, order_id: order_id, auth_token: auth_token)
70
+ integration_id: wallet_integration_id)
55
71
  body = {
56
- "source": { "subtype": 'WALLET', "identifier": wallet_mobile_number },
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:, integration_id:, iframe_id:, order_id:, auth_token:)
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, amount_currency: amount_currency,
71
- integration_id: integration_id, iframe_id: iframe_id, order_id: order_id, auth_token: auth_token)
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:, integration_id:, iframe_id:, order_id:, auth_token:)
80
- bill_reference = generate_payment_intent(customer: customer, address: address, amount_cents: amount_cents, amount_currency: amount_currency,
81
- integration_id: integration_id, iframe_id: iframe_id, order_id: order_id, auth_token: auth_token)
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, :amount_currency
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaymobAccept
2
- VERSION = "0.1.0"
4
+ VERSION = '0.2.0'
3
5
  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 = ['Hesham Magdy']
9
- spec.email = ['hesham_magdy97@hotmail.com']
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 = 'Paymob 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"
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.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Hesham Magdy
7
+ - OneOrder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-18 00:00:00.000000000 Z
11
+ date: 2022-08-21 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: Paymob is a Ruby gem created by OneOrder tech team for integrating Paymob
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
- - hesham_magdy97@hotmail.com
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
- - paymob.gemspec
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:
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.2
6
- before_install: gem install bundler -v 2.1.4