pay_with_extend 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 51254d861905fb6c6cade7953644a59441cdadd20680b0897a8ec802c5dacaee
4
+ data.tar.gz: 110d6015e6c9bed2bc875325d307c53ee2fd6a252301af021fcf2b66f5c61dae
5
+ SHA512:
6
+ metadata.gz: 0d4d7241d677904dd8374870505a5cbefcc89fbd912fa31a7817a964cd6328f884cac3d838d4d1cf4db2800918b9adb9df7c505a7f09e5c40915bcf6f6da6273
7
+ data.tar.gz: e780c03182280c9a3d3bdc0e1220502a208d9193308db789d4a70cf845b9f7312a2c07025c7b9e0784705ba1c60daaf3c4e9561467e2e0da30dfe0f24c8f2242
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 3.0.0
6
+ before_install: gem install bundler -v 2.4.7
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-03-01
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pay_with_extend.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.12.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pay_with_extend (0.1.0)
5
+ jwt (~> 2.2.2)
6
+ rest-client (>= 2.1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.3)
12
+ diff-lcs (1.5.0)
13
+ domain_name (0.5.20190701)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ http-accept (1.7.0)
16
+ http-cookie (1.0.5)
17
+ domain_name (~> 0.5)
18
+ jwt (2.2.3)
19
+ method_source (1.0.0)
20
+ mime-types (3.4.1)
21
+ mime-types-data (~> 3.2015)
22
+ mime-types-data (3.2023.0218.1)
23
+ netrc (0.11.0)
24
+ pry (0.14.2)
25
+ coderay (~> 1.1)
26
+ method_source (~> 1.0)
27
+ rake (13.0.6)
28
+ rest-client (2.1.0)
29
+ http-accept (>= 1.7.0, < 2.0)
30
+ http-cookie (>= 1.0.2, < 2.0)
31
+ mime-types (>= 1.16, < 4.0)
32
+ netrc (~> 0.8)
33
+ rspec (3.12.0)
34
+ rspec-core (~> 3.12.0)
35
+ rspec-expectations (~> 3.12.0)
36
+ rspec-mocks (~> 3.12.0)
37
+ rspec-core (3.12.1)
38
+ rspec-support (~> 3.12.0)
39
+ rspec-expectations (3.12.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.12.0)
42
+ rspec-mocks (3.12.3)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.12.0)
45
+ rspec-support (3.12.0)
46
+ unf (0.1.4)
47
+ unf_ext
48
+ unf_ext (0.0.8.2)
49
+
50
+ PLATFORMS
51
+ arm64-darwin-20
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ pay_with_extend!
56
+ pry
57
+ rake (~> 13.0)
58
+ rspec (~> 3.12.0)
59
+
60
+ BUNDLED WITH
61
+ 2.4.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Sandeep Bhatti
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,62 @@
1
+ # PayWithExtend
2
+
3
+ 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/pay_with_extend`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pay_with_extend'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pay_with_extend
20
+
21
+ ## Usage
22
+
23
+ Configure Extend in config/initializers/pay_with_extend.rb
24
+
25
+ ```
26
+ PayWithExtend.configure do |config|
27
+ config.environment = "production"
28
+ config.account_email = "account email goes here"
29
+ config.account_password = "account password goes here"
30
+ config.api_version = "application/vnd.paywithextend.v2021-03-12+json"
31
+ end
32
+ ```
33
+
34
+ Create pay_with_extend client in config/initializers/pay_with_extend.rb
35
+
36
+ ```
37
+ $extend_client = PayWithExtend::Client.new
38
+ ```
39
+
40
+ Refresh token if needed
41
+
42
+ ```
43
+ $extend_client.refresh_token
44
+ ```
45
+
46
+ Get Virtual Credit Card
47
+
48
+ ```
49
+ $extend_client.get_virtual_card(
50
+ { "card_id_xxxxxx" }
51
+ )
52
+ ```
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ 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).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/metaware/pay_with_extend.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
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
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "pay_with_extend"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,80 @@
1
+ require "rest-client"
2
+ require "json"
3
+ require "jwt"
4
+
5
+ module PayWithExtend
6
+ class Client
7
+ class ResponseError < StandardError; end
8
+
9
+ attr_accessor :api_token
10
+
11
+ def initialize
12
+ # Singin
13
+ self.refresh_token
14
+ end
15
+
16
+ def refresh_token
17
+ request_body = {
18
+ email: PayWithExtend.configuration.account_email,
19
+ password: PayWithExtend.configuration.account_password,
20
+ }
21
+ post("/signin", request_body)
22
+ end
23
+
24
+ def post(endpoint, body, token = nil)
25
+ endpoint_url = "#{PayWithExtend.configuration.base_url}#{endpoint}"
26
+ headers = {
27
+ "Content-Type" => "application/json",
28
+ "Accept" => PayWithExtend.configuration.api_version,
29
+ }
30
+ headers["Authorization"] = "Bearer #{token}" if !token.nil?
31
+ begin
32
+ response = RestClient::Request.execute(method: :post, url: endpoint_url, payload: body.to_json, headers: headers)
33
+ if endpoint === "/signin"
34
+ result = JSON.parse(response.body)
35
+ @api_token = result["token"] if !result["token"].blank?
36
+ return "Token refreshed"
37
+ else
38
+ JSON.parse(response.body)
39
+ end
40
+ rescue RestClient::ExceptionWithResponse => exception
41
+ JSON.parse(exception.response.body)
42
+ rescue JSON::ParserError => exception
43
+ puts exception.response
44
+ rescue RestClient::Unauthorized, RestClient::Forbidden => exception
45
+ puts exception.response
46
+ end
47
+ end
48
+
49
+ def get(endpoint, token = nil, secured = false)
50
+ endpoint_url = secured ? "#{PayWithExtend.configuration.secure_base_url}#{endpoint}" : "#{PayWithExtend.configuration.base_url}#{endpoint}"
51
+ headers = {
52
+ "Content-Type" => "application/json",
53
+ "Accept" => PayWithExtend.configuration.api_version,
54
+ }
55
+ headers["Authorization"] = "Bearer #{token}" if !token.nil?
56
+ begin
57
+ response = RestClient::Request.execute(method: :get, url: endpoint_url, headers: headers)
58
+ JSON.parse(response.body)
59
+ rescue RestClient::ExceptionWithResponse => exception
60
+ JSON.parse(exception.response.body)
61
+ rescue JSON::ParserError => exception
62
+ puts exception.response
63
+ rescue RestClient::Unauthorized, RestClient::Forbidden => exception
64
+ puts exception.response
65
+ end
66
+ end
67
+
68
+ def get_virtual_card(card_id)
69
+ get("/virtualcards/#{card_id}", @api_token, false)
70
+ end
71
+
72
+ def get_secured_virtual_card(card_id)
73
+ get("/virtualcards/#{card_id}", @api_token, true)
74
+ end
75
+
76
+ def create_virtual_card(params)
77
+ post("/virtualcards", params, @api_token)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,31 @@
1
+ module PayWithExtend
2
+ class Configuration
3
+ class EnvironmentMismatch < StandardError; end
4
+
5
+ attr_accessor :environment, :base_url, :secure_base_url, :api_key, :account_email, :account_password, :api_version
6
+
7
+ ENVIRONMENT_MAP = {
8
+ "production" => "https://api.paywithextend.com",
9
+ "development" => "https://api.paywithextend.com",
10
+ "staging" => "https://api.paywithextend.com",
11
+ }
12
+
13
+ def initialize
14
+ @environment = "production"
15
+ @base_url = ENVIRONMENT_MAP[@environment]
16
+ @secure_base_url = "https://v.paywithextend.com"
17
+ @api_key = ""
18
+ @account_email = ""
19
+ @account_password = ""
20
+ @api_version = ""
21
+ end
22
+
23
+ def environment=(environment)
24
+ raise EnvironmentMismatch, "#{@environment} is an invalid environment value" if ENVIRONMENT_MAP[environment].nil?
25
+
26
+ @environment = environment
27
+ @base_url = ENVIRONMENT_MAP[@environment]
28
+ @secure_base_url = "https://v.paywithextend.com"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module PayWithExtend
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "pay_with_extend/version"
2
+ require "pay_with_extend/configuration"
3
+ require "pay_with_extend/client"
4
+
5
+ module PayWithExtend
6
+ class Error < StandardError; end
7
+
8
+ class << self
9
+ def configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ def configure
14
+ yield(configuration)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "lib/pay_with_extend/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "pay_with_extend"
5
+ spec.version = PayWithExtend::VERSION
6
+ spec.authors = ["Sandeep Bhatti"]
7
+ spec.email = ["sandeep@metawarelabs.com"]
8
+
9
+ spec.summary = %q{Extend is a Ruby gem that provides a simple interface to the Extend API.}
10
+ spec.description = %q{Extend is a Ruby gem that provides a simple interface to the Extend API. It allows you to create virtual credit cards from Extend API.}
11
+ spec.homepage = "https://roam.auto"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.2")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/metaware/pay_with_extend"
17
+ spec.metadata["changelog_uri"] = "https://github.com/metaware/extend/Readme.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency("pry")
29
+
30
+ spec.add_dependency("rest-client", ">= 2.1.0")
31
+ spec.add_dependency("jwt", "~> 2.2.2")
32
+ end
@@ -0,0 +1,4 @@
1
+ module PayWithExtend
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pay_with_extend
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sandeep Bhatti
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: jwt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.2.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.2.2
55
+ description: Extend is a Ruby gem that provides a simple interface to the Extend API.
56
+ It allows you to create virtual credit cards from Extend API.
57
+ email:
58
+ - sandeep@metawarelabs.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - CHANGELOG.md
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/pay_with_extend.rb
74
+ - lib/pay_with_extend/client.rb
75
+ - lib/pay_with_extend/configuration.rb
76
+ - lib/pay_with_extend/version.rb
77
+ - pay_with_extend.gemspec
78
+ - sig/pay_with_extend.rbs
79
+ homepage: https://roam.auto
80
+ licenses:
81
+ - MIT
82
+ metadata:
83
+ homepage_uri: https://roam.auto
84
+ source_code_uri: https://github.com/metaware/pay_with_extend
85
+ changelog_uri: https://github.com/metaware/extend/Readme.md
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.7.2
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.1.6
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Extend is a Ruby gem that provides a simple interface to the Extend API.
105
+ test_files: []