nexio 0.1.0

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: 6f2411545550be2a2cf60a4ab7f8eb701a230e69a47b2351e00be776d27c6c56
4
+ data.tar.gz: bceb8db2b0a04f7fe44b9d215ba844762eb69c4bae73e8e33c1584971cfc1a03
5
+ SHA512:
6
+ metadata.gz: 346f80c80b6e89bac3aefb1b480334f652f1405321b8de018fb356a881e04cb945b3745aefdb9636f78e5bc7668ddc3f25256175e09c70b6454b7ddb52cb748b
7
+ data.tar.gz: 4b1a95b0f7d72dba3a20cced1f0770949df3681a4e00c37f251824db2cf7232a952376df30ad718bb7769e07d021408464e292224ad54a44218f00724096504a
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
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
+ Style/TrailingCommaInHashLiteral:
13
+ Enabled: true
14
+ EnforcedStyle: consistent_comma
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Layout/LineLength:
20
+ Max: 120
21
+
22
+ Metrics/ClassLength:
23
+ Enabled: false
24
+
25
+ Metrics/MethodLength:
26
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-02-27
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in nexio.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ group :test do
15
+ gem 'vcr'
16
+ gem 'webmock'
17
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 TherapyMate LLC
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # Nexio
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nexio`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ **Configuration**
22
+ ```
23
+ Nexio.configure do |config|
24
+ config.api_key = <YOUR_NEXIO_API_KEY>
25
+ config.environment = "development"
26
+ end
27
+ ```
28
+ Setting `config.environment` to `development` will use sandbox, otherwise it will use live Nexio API.
29
+
30
+ **Creating One Time Token**
31
+ ```
32
+ @nexio_one_time_token = Nexio::PaymentGateway.create_one_time_token(
33
+ {
34
+ "card" => {
35
+ "cardHolderName" => "Abdul Barek"
36
+ },
37
+ "data" => {
38
+ "currency" => "USD",
39
+ "customer" => {
40
+ "customerRef" => 780,
41
+ "billToAddressOne" => "Main Road",
42
+ "billToAddressTwo" => "",
43
+ "billToCity" => "Same City",
44
+ "billToState" => "FL",
45
+ "billToPostal" => "84702",
46
+ }
47
+ }})["token"]
48
+ ```
49
+
50
+ **Update a card**
51
+ ```
52
+ data = {
53
+ "shouldUpdateCard" => true,
54
+ "card" => {
55
+ "expirationYear" => 2036,
56
+ "cardHolderName" => Abdul Barek,
57
+ "expirationMonth" => 3
58
+ },
59
+ "data" => {
60
+ "customer" => {
61
+ "billToAddressOne" => "1234 Anywhere St.",
62
+ "billToAddressTwo" => "",
63
+ "billToPostal" => 84072,
64
+ "billToState" => FL,
65
+ "billToCity" => "",
66
+ }
67
+ },
68
+ }
69
+ Nexio::PaymentGateway.update_card(<CARD_TOKEN>, data)
70
+ ```
71
+
72
+ **Deleting Cards**
73
+
74
+ ```
75
+ Nexio::PaymentGateway.delete_card([card_token1, card_token2])
76
+ ```
77
+
78
+ **Retrieving details of card**
79
+ ```
80
+ Nexio::PaymentGateway.card_token(card_token)
81
+ ```
82
+
83
+ **Saving a credit card**
84
+ ```
85
+ @card = Nexio::PaymentGateway.save_card(
86
+ {
87
+ "card" => {
88
+ "cardHolderName" => "Abdul Barek",
89
+ "expirationMonth" => "10",
90
+ "expirationYear" => "#{Date.today.year + 10}",
91
+ "encryptedNumber" => "JQ2DIwFqQOCypsOE+3n0Mx6W6das1LrFAQVFR1lBD9KySCbVQXvJoweQ7R3wCv34oK6d8QlYQgsAWpmcROiwe4LowQI3pLfADmGRg4arowdaW8UBcR3gm26tT7KUdG13Y+0aiTKSleSJiRUSm3yU/VrNMe1tblYG+SsmtC8c3PEZkQxkJ216RYCzBkFRku2O7TRvx/GtxGd4VQItIF567VanRmZ8tIUaZGg9ZN6PKzUifRfCCt+2XGY7I1+Z7EOEAX1gQZT86+2vzcdk8MiZtMS4KYs+4kngSxR2EhyJa+3wRQBmkApRt03qCoWJEPIbNYxgwdjapy2oWeI/DrZu6A=="
92
+ },
93
+ "data" => {
94
+ "currency" => "USD"
95
+ },
96
+ "shouldUpdateCard" => true,
97
+ "token" => <ONE_TIME_TOKEN>
98
+ }
99
+ )
100
+ ```
101
+
102
+ **Charging a card through it's token**
103
+ ```
104
+ amount_in_usd = 20.25
105
+ Nexio::PaymentGateway.charge(amount_in_usd,card_token)
106
+ ```
107
+
108
+ **Handling error**
109
+ ```
110
+ begin
111
+ Nexio::PaymentGateway.charge(10.60,'invalid_card_token')
112
+ rescue Nexio::NexioError => e
113
+ puts e.to_hash
114
+ end
115
+ ```
116
+
117
+ ## Development
118
+
119
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
120
+
121
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
122
+
123
+ ## Contributing
124
+
125
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nexio.
126
+
127
+ ## License
128
+
129
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nexio
4
+ class Configuration
5
+ DEFAULTS = {
6
+ "sandbox_url" => "https://api.nexiopaysandbox.com",
7
+ "production_url" => "https://api.nexiopay.com",
8
+ }.freeze
9
+
10
+ attr_accessor :api_key, :environment
11
+
12
+ attr_writer :api_server_url
13
+
14
+ def initialize
15
+ @api_server_url = nil
16
+ end
17
+
18
+ def api_key!
19
+ api_key || raise(NexioError, "No api key specified.")
20
+ end
21
+
22
+ def api_server_url
23
+ @api_server_url || (environment == "production" ? DEFAULTS.fetch("production_url") : DEFAULTS.fetch("sandbox_url"))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nexio
4
+ DEFAULT_CONFIG = {
5
+ "data" => {
6
+ "currency" => "USD",
7
+ "card" => {
8
+ "cardHolderName" => ""
9
+ },
10
+ "customer" => {
11
+ "customerRef" => ""
12
+ }
13
+ },
14
+ "processingOptions" => {
15
+ "checkFraud" => true,
16
+ "verboseResponse" => false,
17
+ "verifyAvs" => 0,
18
+ "verifyCvc" => false
19
+ },
20
+ "shouldUpdateCard" => true,
21
+ "uiOptions" => {
22
+ "displaySubmitButton" => false,
23
+ "hideBilling" => {
24
+ "hideAddressOne" => false,
25
+ "hideAddressTwo" => false,
26
+ "hideCity" => false,
27
+ "hideCountry" => false,
28
+ "hidePostal" => false,
29
+ "hidePhone" => true,
30
+ "hideState" => false
31
+ },
32
+ "hideCvc" => false,
33
+ "requireCvc" => true,
34
+ "forceExpirationSelection" => true
35
+ }
36
+ }.freeze
37
+
38
+ class PaymentGateway
39
+ # Creates a card token based on the configuration
40
+ def self.create_one_time_token(config={})
41
+ url = URI("#{Nexio.configuration.api_server_url}/pay/v3/token")
42
+ @request = Net::HTTP::Post.new(url)
43
+ http, request = configure_https_request(url, @request)
44
+ request.body = Nexio::DEFAULT_CONFIG.merge(config).to_json
45
+ response = http.request(@request)
46
+ response_or_raise_error(response)
47
+ end
48
+
49
+ # {
50
+ # "card" => {
51
+ # "cardHolderName" => "Abdul Barek",
52
+ # "expirationMonth" => "10",
53
+ # "expirationYear" => "#{Date.today.year + 10}",
54
+ # "encryptedNumber" => "JQ2DIwFqQOCypsOE+3n0Mx6W6das1LrFAQVFR1lBD9KySCbVQXvJoweQ7R3wCv34oK6d8QlYQgsAWpmcROiwe4LowQI3pLfADmGRg4arowdaW8UBcR3gm26tT7KUdG13Y+0aiTKSleSJiRUSm3yU/VrNMe1tblYG+SsmtC8c3PEZkQxkJ216RYCzBkFRku2O7TRvx/GtxGd4VQItIF567VanRmZ8tIUaZGg9ZN6PKzUifRfCCt+2XGY7I1+Z7EOEAX1gQZT86+2vzcdk8MiZtMS4KYs+4kngSxR2EhyJa+3wRQBmkApRt03qCoWJEPIbNYxgwdjapy2oWeI/DrZu6A=="
55
+ # },
56
+ # "data" => {
57
+ # "currency" => "USD"
58
+ # },
59
+ # "shouldUpdateCard" => true,
60
+ # "token" => @nexio_one_time_token
61
+ # }
62
+ def self.save_card(card={})
63
+ url = URI("#{Nexio.configuration.api_server_url}/pay/v3/saveCard")
64
+ @request = Net::HTTP::Post.new(url)
65
+ http, request = configure_https_request(url, @request)
66
+ request.body = card.to_json
67
+ response = http.request(@request)
68
+ response_or_raise_error(response)
69
+ end
70
+
71
+ # Deletes card tokens, tokens can be an array
72
+ def self.delete_card(card_tokens=[])
73
+ url = URI("#{Nexio.configuration.api_server_url}/pay/v3/deleteToken")
74
+ @request = Net::HTTP::Post.new(url)
75
+ http, request = configure_https_request(url, @request)
76
+ request.body = {
77
+ "tokens" => card_tokens
78
+ }.to_json
79
+ response = http.request(request)
80
+ response_or_raise_error(response)
81
+ end
82
+
83
+ # Returns details of a card accepting a card token
84
+ def self.card_token(token)
85
+ url = URI("#{Nexio.configuration.api_server_url}/pay/v3/vault/card/#{token}")
86
+ @request = Net::HTTP::Get.new(url)
87
+ http, request = configure_https_request(url, @request)
88
+ response = http.request(request)
89
+ response_or_raise_error(response)
90
+ end
91
+
92
+ # Updates cards while accepting card token with new data
93
+ # data = {
94
+ # "shouldUpdateCard" => true,
95
+ # "card" => {
96
+ # "expirationYear" => 2036,
97
+ # "cardHolderName" => "Abdul Barek",
98
+ # "expirationMonth" => 3
99
+ # },
100
+ # "data" => {
101
+ # "customer" => {
102
+ # "billToAddressOne" => "1234 Anywhere St.",
103
+ # "billToAddressTwo" => "",
104
+ # "billToPostal" => 84072,
105
+ # "billToState" => FL,
106
+ # "billToCity" => "",
107
+ # }
108
+ # },
109
+ # }
110
+ def self.update_card(token, data={})
111
+ url = URI("#{Nexio.configuration.api_server_url}/pay/v3/vault/card/#{token}")
112
+ @request = Net::HTTP::Put.new(url)
113
+ http, request = configure_https_request(url, @request)
114
+ request.body = data.to_json
115
+ response = http.request(request)
116
+ response_or_raise_error(response)
117
+ end
118
+
119
+ # Makes a charge of a given card using the associated card token
120
+ def self.charge(amount=0, card_token)
121
+ url = URI("#{Nexio.configuration.api_server_url}/pay/v3/process")
122
+ @request = Net::HTTP::Post.new(url)
123
+ http, request = configure_https_request(url, @request)
124
+ request.body = {
125
+ "data" => {
126
+ "currency" => "USD", "amount" => amount
127
+ },
128
+ "tokenex" => {"token" => card_token},
129
+ "processingOptions" =>
130
+ {
131
+ "retryOnSoftDecline" => false,
132
+ "checkFraud" => true,
133
+ "shouldUseFingerprint" => true,
134
+ "check3ds" => false,
135
+ "verboseResponse" => false
136
+ },
137
+ "shouldUpdateCard" => true,
138
+ "isAuthOnly" => false,
139
+ "paymentMethod" => "card"
140
+ }.to_json
141
+ response = http.request(request)
142
+ response_or_raise_error(response)
143
+ end
144
+
145
+ # https configuration using base64 basic auth code
146
+ def self.configure_https_request(url, request)
147
+ http = Net::HTTP.new(url.host, url.port)
148
+ http.use_ssl = true
149
+ request["accept"] = "application/json"
150
+ request["content-type"] = "application/json"
151
+ request["authorization"] = "Basic #{Nexio.configuration.api_key!}"
152
+ [http, request]
153
+ end
154
+
155
+ def self.response_or_raise_error(response)
156
+ if response.code.to_s == '200'
157
+ JSON.parse(response.read_body)
158
+ else
159
+ request_details = {
160
+ headers: @request.each_header.to_h,
161
+ url: @request.uri.to_s,
162
+ method: @request.method,
163
+ query_string: @request.uri.query,
164
+ body: @request.body
165
+ }
166
+ response_body = JSON.parse(response.read_body) rescue {}
167
+ raise Nexio::NexioError.new(response_body, request_details)
168
+ end
169
+ end
170
+
171
+ end
172
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nexio
4
+ VERSION = "0.1.0"
5
+ end
data/lib/nexio.rb ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "net/http"
5
+
6
+ require "nexio/version"
7
+ require "nexio/configuration"
8
+ require "nexio/payment_gateway"
9
+
10
+ module Nexio
11
+ class NexioError < StandardError
12
+ attr_accessor :errors
13
+ attr_accessor :request_details
14
+ def initialize(msg = nil, request_details)
15
+ @errors = msg || {}
16
+ @request_details = request_details || {}
17
+ end
18
+ def to_hash
19
+ @errors
20
+ end
21
+ def request_details_in_hash
22
+ @request_details
23
+ end
24
+ end
25
+
26
+ def self.configuration
27
+ @configuration ||= Configuration.new
28
+ end
29
+
30
+ def self.configure
31
+ config = configuration
32
+ yield(config)
33
+ end
34
+
35
+ def self.api_server_url
36
+ configuration.api_server_url
37
+ end
38
+ end
data/nexio.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/nexio/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "nexio"
7
+ spec.version = Nexio::VERSION
8
+ spec.authors = ["TherapyMate", "James Carbine", "Abdul Barek"]
9
+ spec.email = ["jamescarbine@gmail.com", "barek2k2@gmail.com"]
10
+
11
+ spec.summary = "Nexio integration with Ruby on Rails"
12
+ spec.homepage = "https://github.com/TherapyMateLLC/nexio-rails"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 3.1.0"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/TherapyMateLLC/nexio-rails"
20
+ spec.metadata["changelog_uri"] = "https://github.com/TherapyMateLLC/nexio-rails/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (File.expand_path(f) == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ #spec.add_dependency "vcr"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
data/sig/nexio.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Nexio
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nexio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - TherapyMate
8
+ - James Carbine
9
+ - Abdul Barek
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2024-03-21 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description:
16
+ email:
17
+ - jamescarbine@gmail.com
18
+ - barek2k2@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".rubocop.yml"
24
+ - CHANGELOG.md
25
+ - Gemfile
26
+ - LICENSE
27
+ - README.md
28
+ - Rakefile
29
+ - lib/nexio.rb
30
+ - lib/nexio/configuration.rb
31
+ - lib/nexio/payment_gateway.rb
32
+ - lib/nexio/version.rb
33
+ - nexio.gemspec
34
+ - sig/nexio.rbs
35
+ homepage: https://github.com/TherapyMateLLC/nexio-rails
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ allowed_push_host: https://rubygems.org/
40
+ homepage_uri: https://github.com/TherapyMateLLC/nexio-rails
41
+ source_code_uri: https://github.com/TherapyMateLLC/nexio-rails
42
+ changelog_uri: https://github.com/TherapyMateLLC/nexio-rails/CHANGELOG.md
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 3.1.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.4.19
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Nexio integration with Ruby on Rails
62
+ test_files: []