payunit 0.2.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f7abefb3e4bd34522019b0620ef27350c731d61aac894c1f6983d6d4c03b1142
4
+ data.tar.gz: 2cbd10c1c3eef73d8ee1cfb54ffa28783088e52f2f1944be6e599bba2938c3af
5
+ SHA512:
6
+ metadata.gz: 8a3549a346e959641ed520d2635b3257689238109417f9c8eb26973eea5e96cf5304d6baab37d80e3a2bdef46a3912ab51eca4ec87589fdf084eab1394e4cae0
7
+ data.tar.gz: 8fa21bed172d1a3ded6120c19c9195dafaaa41ed7b904b0dc20b8ddd299ac53c3b0214864031e1b8b1aff0dabe90ac216f9c5d8dec112d66c3710b91b8d537f7
data/.byebug_history ADDED
@@ -0,0 +1,31 @@
1
+ continue
2
+ response
3
+ next
4
+ continue
5
+ response
6
+ next
7
+ continue
8
+ reload!
9
+ @mode
10
+ environment
11
+ response
12
+ next
13
+ continue
14
+ response
15
+ next
16
+ response
17
+ continue
18
+ exit
19
+ response
20
+ exit
21
+ response
22
+ exit
23
+ next
24
+ q!
25
+ next
26
+ q!
27
+ next
28
+ response
29
+ q!
30
+ response
31
+ response(["data"]["transaction_url"])
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/ParameterLists:
16
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-08-06
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
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.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
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
18
+
19
+ Examples of unacceptable behavior include:
20
+
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
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
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.
33
+
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.
35
+
36
+ ## Scope
37
+
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.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hguruman@gmail.com. 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.
59
+
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.
73
+
74
+ ## Attribution
75
+
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
82
+
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 ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in payunit.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "base64", "~> 0.1.1"
15
+
16
+ gem "faraday", "~> 2.5", ">= 2.5.2"
17
+
18
+ gem "faraday-net_http", "~> 3.0"
19
+
20
+ gem "json_pure", "~> 2.6", ">= 2.6.2"
data/Gemfile.lock ADDED
@@ -0,0 +1,142 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ payunit (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionpack (7.0.3.1)
10
+ actionview (= 7.0.3.1)
11
+ activesupport (= 7.0.3.1)
12
+ rack (~> 2.0, >= 2.2.0)
13
+ rack-test (>= 0.6.3)
14
+ rails-dom-testing (~> 2.0)
15
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
16
+ actionview (7.0.3.1)
17
+ activesupport (= 7.0.3.1)
18
+ builder (~> 3.1)
19
+ erubi (~> 1.4)
20
+ rails-dom-testing (~> 2.0)
21
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
22
+ activesupport (7.0.3.1)
23
+ concurrent-ruby (~> 1.0, >= 1.0.2)
24
+ i18n (>= 1.6, < 2)
25
+ minitest (>= 5.1)
26
+ tzinfo (~> 2.0)
27
+ addressable (2.8.0)
28
+ public_suffix (>= 2.0.2, < 5.0)
29
+ ast (2.4.2)
30
+ base64 (0.1.1)
31
+ builder (3.2.4)
32
+ byebug (11.1.3)
33
+ concurrent-ruby (1.1.10)
34
+ crass (1.0.6)
35
+ diff-lcs (1.5.0)
36
+ dotenv (2.8.1)
37
+ dotenv-rails (2.8.1)
38
+ dotenv (= 2.8.1)
39
+ railties (>= 3.2)
40
+ erubi (1.11.0)
41
+ faraday (2.5.1)
42
+ faraday-net_http (>= 2.0, < 3.1)
43
+ ruby2_keywords (>= 0.0.4)
44
+ faraday-net_http (3.0.0)
45
+ http-2-next (0.5.0)
46
+ httpx (0.20.4)
47
+ http-2-next (>= 0.4.1)
48
+ i18n (1.12.0)
49
+ concurrent-ruby (~> 1.0)
50
+ json (2.6.2)
51
+ json_pure (2.6.2)
52
+ launchy (2.5.0)
53
+ addressable (~> 2.7)
54
+ loofah (2.18.0)
55
+ crass (~> 1.0.2)
56
+ nokogiri (>= 1.5.9)
57
+ method_source (1.0.0)
58
+ minitest (5.16.2)
59
+ net-http (0.2.2)
60
+ uri
61
+ nokogiri (1.13.8-x86_64-linux)
62
+ racc (~> 1.4)
63
+ parallel (1.22.1)
64
+ parser (3.1.2.0)
65
+ ast (~> 2.4.1)
66
+ public_suffix (4.0.7)
67
+ racc (1.6.0)
68
+ rack (2.2.4)
69
+ rack-test (2.0.2)
70
+ rack (>= 1.3)
71
+ rails-dom-testing (2.0.3)
72
+ activesupport (>= 4.2.0)
73
+ nokogiri (>= 1.6)
74
+ rails-html-sanitizer (1.4.3)
75
+ loofah (~> 2.3)
76
+ railties (7.0.3.1)
77
+ actionpack (= 7.0.3.1)
78
+ activesupport (= 7.0.3.1)
79
+ method_source
80
+ rake (>= 12.2)
81
+ thor (~> 1.0)
82
+ zeitwerk (~> 2.5)
83
+ rainbow (3.1.1)
84
+ rake (13.0.6)
85
+ regexp_parser (2.5.0)
86
+ rexml (3.2.5)
87
+ rspec (3.11.0)
88
+ rspec-core (~> 3.11.0)
89
+ rspec-expectations (~> 3.11.0)
90
+ rspec-mocks (~> 3.11.0)
91
+ rspec-core (3.11.0)
92
+ rspec-support (~> 3.11.0)
93
+ rspec-expectations (3.11.0)
94
+ diff-lcs (>= 1.2.0, < 2.0)
95
+ rspec-support (~> 3.11.0)
96
+ rspec-mocks (3.11.1)
97
+ diff-lcs (>= 1.2.0, < 2.0)
98
+ rspec-support (~> 3.11.0)
99
+ rspec-support (3.11.0)
100
+ rubocop (1.33.0)
101
+ json (~> 2.3)
102
+ parallel (~> 1.10)
103
+ parser (>= 3.1.0.0)
104
+ rainbow (>= 2.2.2, < 4.0)
105
+ regexp_parser (>= 1.8, < 3.0)
106
+ rexml (>= 3.2.5, < 4.0)
107
+ rubocop-ast (>= 1.19.1, < 2.0)
108
+ ruby-progressbar (~> 1.7)
109
+ unicode-display_width (>= 1.4.0, < 3.0)
110
+ rubocop-ast (1.19.1)
111
+ parser (>= 3.1.1.0)
112
+ ruby-progressbar (1.11.0)
113
+ ruby2_keywords (0.0.5)
114
+ securerandom (0.2.0)
115
+ thor (1.2.1)
116
+ tzinfo (2.0.5)
117
+ concurrent-ruby (~> 1.0)
118
+ unicode-display_width (2.2.0)
119
+ uri (0.11.0)
120
+ zeitwerk (2.6.0)
121
+
122
+ PLATFORMS
123
+ x86_64-linux
124
+
125
+ DEPENDENCIES
126
+ base64
127
+ byebug
128
+ dotenv-rails
129
+ faraday
130
+ faraday-net_http
131
+ httpx
132
+ json_pure
133
+ launchy
134
+ net-http
135
+ payunit!
136
+ rake (~> 13.0)
137
+ rspec (~> 3.0)
138
+ rubocop (~> 1.21)
139
+ securerandom
140
+
141
+ BUNDLED WITH
142
+ 2.3.14
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 happiguru
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # Payunit
2
+
3
+ This gem was developed to aid Cameroon businesses to make both national and international payments using MTN and Orange Mobile Money, Paypal, Credit Card and Express Union.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add payunit
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install payunit
14
+
15
+ ## Usage
16
+ Follow the instructions below to make payments locally:
17
+ - Create an account on [Payunit](https://app.payunit.net) to obtain your api_key, api_password, api_username
18
+
19
+ ## To Make A Payment
20
+
21
+ - Add the gem directly to your Gemfile using:
22
+ ```gem 'payunit', '~> 0.2.2.1'```
23
+
24
+ - If you plan to use `.env` then add:
25
+ ```gem 'dotenv'```
26
+ to your gemfile in order to save your secret credentials
27
+ ```
28
+ payment = PayUnit.new(
29
+ ENV.fetch('PAY_UNIT_API_KEY', nil),
30
+ ENV.fetch('PAY_UNIT_API_USERNAME', nil),
31
+ ENV.fetch('PAY_UNIT_API_PASSWORD', nil),
32
+ ENV.fetch('PAY_UNIT_RETURN_URL', nil),
33
+ ENV.fetch('PAY_UNIT_NOTIFY_URL', nil),
34
+ ENV.fetch('PAY_UNIT_MODE', nil),
35
+ ENV.fetch('PAY_UNIT_CURRENCY', nil))
36
+
37
+ payunit_url = payment.make_payment(amount.to_i, transaction_id)
38
+ ```
39
+
40
+ - Create a PayUnit Class and call the payment method:
41
+ ```payment = PayUnit.new(api_key, api_username, api_password, return_url, notify_url, mode, currency)```
42
+
43
+ - Next is to call the ```payment.make_payment(amount, transaction_id)``` function.
44
+
45
+ - The ```payment.make_payment()``` have optional parameters such as:
46
+
47
+ ```
48
+ @purchaseRef = purchaseRef
49
+ @description = description
50
+ @name = name
51
+ ```
52
+ - The above parameters are acceptable by payunit but they are optional and needs to be passed as ```payment.make_payment(amount, purchaseRef, description, name)```
53
+
54
+ - The above code will open a payment url that will be used to make the payment
55
+ - Make payments anywhere in your rails app by running the following
56
+ 1. payment = PayUnit.new(ENV(api_key), ENV(api_username), ENV(api_password), return_url,notify_url, mode, currency)
57
+ 2. Get the payment data and url like this
58
+ ```
59
+ payment_url = payment.make_payment(amount)
60
+ ```
61
+ 3. This following function will open the url in the browser
62
+ ```
63
+ redirect_to payment_url["data"]["transaction_url"]
64
+ ```
65
+ ## To Get A Payment Transaction Details
66
+
67
+ - In order to get transaction detail for a transaction recently made, you have to use the following function and pass in the `transaction_id` you had earlier passed in at the time of the payment.
68
+
69
+ ```
70
+ PayUnit.transaction_details(transaction_id)
71
+ ```
72
+ The response you would get looks like this:
73
+
74
+ ```
75
+ {
76
+ "status": "PENDING",
77
+ "statusCode": 200,
78
+ "message": "Transaction may not exist",
79
+ "data": {
80
+ "transaction_id": "757898467",
81
+ "transaction_amount": "500",
82
+ "transaction_currency": "XAF",
83
+ "transaction_gateway": "mtnmomo",
84
+ "transaction_status": "SUCCESS",
85
+ "notify_url": "https://aproplat.com",
86
+ "redirect_url": "https://aproplat.com"
87
+ }
88
+ }
89
+ ```
90
+
91
+ # Note
92
+ - Amount is an integer gotten from the user
93
+ - Notify url is the success url to redirect to when the request is successful
94
+ - Return url is the url to return to when the request fails
95
+ - Mode is the the environment of the payment whether it is test or live
96
+ - Currency the country currency the payment will be made in
97
+
98
+ ### ✒️ Authors
99
+
100
+ 👤 **Stanley Enow Lekunze**
101
+
102
+ - Github: [@happiguru](https://github.com/happiguru)
103
+ - LinkedIn:[LinkedIn](https://www.linkedin.com/in/lekunze-nley)
104
+
105
+ 👤 **CHE NSOH BLANCHARD**
106
+
107
+ - GitHub: [@che30](https://github.com/che30)
108
+ - Twitter: [@BlanchardNsoh](https://twitter.com/che55085128 )
109
+ - LinkedIn: [Che Blanchard](https://www.linkedin.com/in/che-nsoh-9455271b0/)
110
+
111
+ ## Contributing
112
+
113
+ Bug reports and pull requests are welcome on GitHub at [Create New Issue](https://github.com/happiguru/payunit/issues/new). 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/[happiguru]/payunit/blob/main/CODE_OF_CONDUCT.md).
114
+
115
+ ## License
116
+
117
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
118
+
119
+ ## Code of Conduct
120
+
121
+ Everyone interacting in the Payunit project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/payunit/blob/main/CODE_OF_CONDUCT.md).
122
+
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
13
+
14
+ GEM_NAME = "payunit"
15
+ GEM_VERSION = "0.1.0"
16
+
17
+ task default: :build
18
+
19
+ task :build do
20
+ system "gem build #{GEM_NAME}.gemspec"
21
+ end
22
+
23
+ task install: :build do
24
+ system "gem install #{GEM_NAME}-#{GEM_VERSION}.gem"
25
+ end
26
+
27
+ task publish: :build do
28
+ system "gem push #{GEM_NAME}-#{GEM_VERSION}.gem"
29
+ end
30
+
31
+ task :clean do
32
+ system "rm *.gem"
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Payunit
4
+ VERSION = "0.2.2.2"
5
+ end
data/lib/payunit.rb ADDED
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/MethodLength
4
+ # rubocop:disable Metrics/AbcSize
5
+ # rubocop:disable Metrics/ClassLength
6
+ require_relative "payunit/version"
7
+ require "json/pure"
8
+ require "base64"
9
+ require "net/http"
10
+ require "faraday"
11
+ require "faraday/net_http"
12
+ Faraday.default_adapter = :net_http
13
+
14
+ # Payunit payment class
15
+ class PayUnit
16
+ def initialize(api_key, api_username, api_password, return_url, notify_url, mode, currency)
17
+ @api_key = api_key
18
+ @api_username = api_username
19
+ @api_password = api_password
20
+ @return_url = return_url
21
+ @notify_url = notify_url
22
+ @mode = mode
23
+ @currency = currency
24
+
25
+ check_api_key
26
+ check_api_username
27
+ check_api_password
28
+ check_api_mode
29
+ check_currency
30
+ check_return_url
31
+ check_notify_url
32
+ check_api_sdk
33
+ end
34
+
35
+ def make_payment(amount, transaction_id, purchase_ref = nil, description = nil, name = nil)
36
+ return "Invalid transaction amount" if amount <= 0
37
+
38
+ @purchase_ref = purchase_ref
39
+ @description = description
40
+ @name = name
41
+ auth = "#{@api_username}:#{@api_password}"
42
+ environment = to_str(@mode)
43
+ auth_data = Base64.strict_encode64(auth)
44
+ @transaction_id = transaction_id
45
+
46
+ test_url = "https://app.payunit.net/api/gateway/initialize"
47
+
48
+ headers = {
49
+ "x-api-key": to_str(@api_key),
50
+ "content-type": "application/json",
51
+ "Authorization": "Basic #{to_str(auth_data)}",
52
+ "mode": to_str(environment.downcase)
53
+ }
54
+
55
+ test_body = {
56
+ "notify_url": to_str(@notify_url),
57
+ "total_amount": to_str(amount),
58
+ "return_url": to_str(@return_url),
59
+ "purchaseRef": to_str(@purchase_ref),
60
+ "description": to_str(@description),
61
+ "name": to_str(@name),
62
+ "currency": to_str(@currency),
63
+ "transaction_id": to_str(@transaction_id)
64
+ }
65
+
66
+ begin
67
+ conn = Faraday.new(
68
+ url: "https://app.payunit.net/api/gateway/initialize",
69
+ params: { param: "1" },
70
+ headers: headers
71
+ )
72
+ response = conn.post(test_url, test_body.to_json, headers)
73
+ response = JSON.parse(response&.body || "{}")
74
+
75
+ raise response["message"] unless response["statusCode"] == 200
76
+
77
+ response
78
+ rescue StandardError
79
+ abort(response["message"])
80
+ end
81
+ end
82
+
83
+ def self.transaction_details(transaction_id, api_key, api_username, api_password, mode)
84
+ auth = "#{api_username}:#{api_password}"
85
+ environment = mode.to_s
86
+ auth_data = Base64.strict_encode64(auth)
87
+
88
+ headers = {
89
+ "x-api-key": api_key.to_s,
90
+ "content-type": "application/json",
91
+ "Authorization": "Basic #{auth_data}",
92
+ "mode": environment.downcase.to_s
93
+ }
94
+ begin
95
+ conn = Faraday.new(
96
+ url: "https://app.payunit.net/api/gateway/initialize",
97
+ params: { param: "1" },
98
+ headers: headers
99
+ )
100
+
101
+ url = "https://app.payunit.net/api/gateway/transaction/#{transaction_id}"
102
+ response = conn.get(url)
103
+ response = JSON.parse(response&.body || "{}")
104
+ raise response["message"] unless response["statusCode"] == 200
105
+
106
+ response
107
+ rescue StandardError
108
+ abort(response["message"])
109
+ end
110
+ end
111
+
112
+ private
113
+
114
+ def to_str(param)
115
+ param.to_s
116
+ end
117
+
118
+ def check_api_key
119
+ raise "api_key not present" if @api_key.empty?
120
+ end
121
+
122
+ def check_api_username
123
+ raise "apiUsername not present" if @api_username.empty?
124
+ end
125
+
126
+ def check_api_password
127
+ raise "apiPassword not present" if @api_password.empty?
128
+ end
129
+
130
+ def check_return_url
131
+ raise "return url not present" if @return_url.empty?
132
+ end
133
+
134
+ def check_notify_url
135
+ rraise "notification url not present" if @notify_url.empty?
136
+ end
137
+
138
+ def check_currency
139
+ raise "Current not yet set." if @currency.empty?
140
+ end
141
+
142
+ def check_api_mode
143
+ raise "sdk mode not present" if @mode.empty?
144
+ end
145
+
146
+ def check_api_sdk
147
+ raise "Invalid sdk mode" if @mode.downcase != "test" && @mode.downcase != "live"
148
+ end
149
+ end
150
+ # rubocop:enable Metrics/MethodLength
151
+ # rubocop:enable Metrics/AbcSize
152
+ # rubocop:enable Metrics/ClassLength
data/sig/payunit.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Payunit
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payunit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Lekunze Stanley Enow
8
+ - Che Nsoh Blanchard
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2022-08-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: base64
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.1.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.1.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.5'
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: 2.5.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '2.5'
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.5.2
48
+ - !ruby/object:Gem::Dependency
49
+ name: faraday-net_http
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: json_pure
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.6'
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.6.2
72
+ type: :runtime
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: '2.6'
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 2.6.2
82
+ description: |-
83
+ To aid Cameroon businesses to make both national and
84
+ international payments using MTN and Orange Mobile Money, Paypal, Credit Card and Express Union.
85
+ email:
86
+ - hguruman@gmail.com
87
+ - che.blancoo58@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".byebug_history"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - CHANGELOG.md
96
+ - CODE_OF_CONDUCT.md
97
+ - Gemfile
98
+ - Gemfile.lock
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - lib/payunit.rb
103
+ - lib/payunit/version.rb
104
+ - sig/payunit.rbs
105
+ homepage: https://rubygems.org/gems/payunit
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ allowed_push_host: https://rubygems.org/
110
+ homepage_uri: https://rubygems.org/gems/payunit
111
+ source_code_uri: https://github.com/happiguru/payunit
112
+ changelog_uri: https://github.com/happiguru/payunit/issues
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 2.6.0
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.3.7
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Cameroon Payment Gateway.
132
+ test_files: []