viva_wallet 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: df88fd51bb67f6281953a1fde24d80512ccce512a28cac820f50ce4b2f4d7e07
4
+ data.tar.gz: 96f85abf2115cd2c87afbd37bff8113ec7a5ce9c737acc1a6a5d203129dbeea1
5
+ SHA512:
6
+ metadata.gz: e5528585913c86f6efb7d4941a673c0af6f10e80c93eff5d8adc51aa83488517385a13ea53929067fcffb681769c62b6b413a03f5d9fc6dc1922ccf7880f208d
7
+ data.tar.gz: f602904f1d2c92db35d1451611548f567217481bb8b4509cd390ed7671ff5307c9a077c9fc9e8a665ff01e29c6eb4c053aa4bf56726b5100e07d1678c1931e8d
@@ -0,0 +1,13 @@
1
+ version: 2.1
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: ruby:2.7.1
6
+ steps:
7
+ - checkout
8
+ - run:
9
+ name: Run the default task
10
+ command: |
11
+ gem install bundler -v 2.2.15
12
+ bundle install
13
+ bundle exec rake
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/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ </profile>
6
+ </component>
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="Remote: ruby-2.4.4-p296" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/viva_wallet.iml" filepath="$PROJECT_DIR$/.idea/viva_wallet.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ </component>
15
+ <component name="RakeTasksCache">
16
+ <option name="myRootTask">
17
+ <RakeTaskImpl id="rake" />
18
+ </option>
19
+ </component>
20
+ </module>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-03-09
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 me@tomdallimore.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,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in viva_wallet.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Tom Dallimore
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,60 @@
1
+ ## Viva Wallet
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/viva_wallet.svg)](https://badge.fury.io/rb/viva_wallet)
4
+
5
+ A Ruby wrapper for the Viva Wallet Smart Checkout API.
6
+
7
+ ## Installation
8
+
9
+ Add module to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'viva_wallet'
13
+ ```
14
+
15
+ Then run bundle to install the Gem:
16
+
17
+ ```sh
18
+ bundle install
19
+ ```
20
+
21
+ Set up an initializer file with your Viva Wallet Smart Checkout client keys:
22
+
23
+ ```ruby
24
+ VivaWallet.client_id = 'viva_client_id'
25
+ VivaWallet.client_secret = 'v1'
26
+ VivaWallet.test_mode = "true or false"
27
+ ```
28
+ e.g. *config/initializers/viva_wallet.rb*
29
+
30
+ ## Usage
31
+
32
+ This gem provides a collection of operations for use within the Viva Wallet Smarket Checkout API.
33
+
34
+ ### Generate API access token
35
+
36
+ Use OAuth to generate new API access for an account
37
+
38
+ ```ruby
39
+ VivaWallet::Authentication.oauth
40
+ ````
41
+
42
+ ### Payments
43
+
44
+ Create a Payment Order
45
+
46
+ ```ruby
47
+ VivaWallet::Payment.create(payment_order_params)
48
+ ````
49
+
50
+ ## How to contribute
51
+
52
+ * Fork the project
53
+ * Create your feature or bug fix
54
+ * Add the requried tests for it.
55
+ * Commit (do not change version or history)
56
+ * Send a pull request against the *development* branch
57
+
58
+ ## Copyright
59
+ Copyright (c) 2022 [Tom Dallimore](http://www.tomdallimore.com/?utm_source=viva_wallet&utm_medium=website&utm_campaign=tomdallimore) ([@tom_dallimore](http://twitter.com/tom_dallimore))
60
+ Licenced under the MIT licence.
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 "viva_wallet"
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,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VivaWallet
4
+ class Authentication
5
+
6
+ class << self
7
+ def oauth
8
+ RestClient::Request.new({
9
+ method: :post,
10
+ url: VivaWallet.account_api_base + 'connect/token?grant_type=client_credentials',
11
+ headers: {
12
+ accept: :json,
13
+ content_type: :json,
14
+ 'Authorization': "Bearer #{VivaWallet.client_base64}"
15
+ }
16
+ }).execute do |response, request, result|
17
+ str_response = response.to_str
18
+ str_response.blank? ? '' : JSON.parse(str_response)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VivaWallet
4
+ class Payment
5
+
6
+ class << self
7
+
8
+ def create(params = {}, access_token = nil)
9
+ response = VivaWallet.request(:post, 'checkout/v2/orders', params, access_token)
10
+
11
+ response
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VivaWallet
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rest-client'
4
+ require 'base64'
5
+
6
+ require_relative "viva_wallet/version"
7
+ require_relative 'viva_wallet/authentication'
8
+ require_relative 'viva_wallet/payment'
9
+
10
+ module VivaWallet
11
+
12
+ class VivaWalletError < StandardError
13
+ end
14
+
15
+ class ConfigurationError < VivaWalletError; end
16
+
17
+ attr_writer :client_id, :client_secret, :test_mode, :api_base, :account_api_base, :client_base64
18
+
19
+ def client_id
20
+ defined? @client_id and @client_id or raise(
21
+ ConfigurationError, "VivaWallet client_id not configured"
22
+ )
23
+ end
24
+
25
+ def client_secret
26
+ defined? @client_secret and @client_secret or raise(
27
+ ConfigurationError, "VivaWallet client_secret not configured"
28
+ )
29
+ end
30
+
31
+ def test_mode
32
+ @test_mode.nil? ? false : @test_mode
33
+ end
34
+
35
+ def api_base
36
+ VivaWallet.test_mode ? "https://demo-api.vivapayments.com/" : "https://api.vivapayments.com/"
37
+ end
38
+
39
+ def account_api_base
40
+ VivaWallet.test_mode ? "https://demo-accounts.vivapayments.com/" : "https://accounts.vivapayments.com/"
41
+ end
42
+
43
+ def client_base64
44
+ Base64.encode("#{VivaWallet.client_id}:#{VivaWallet.client_secret}")
45
+ end
46
+
47
+ def request(method, resource, params = {}, access_token = nil)
48
+ access_token = access_token
49
+
50
+ params.except!(:access_token)
51
+
52
+ defined? method or raise(
53
+ ArgumentError, "Request method has not been specified"
54
+ )
55
+ defined? resource or raise(
56
+ ArgumentError, "Request resource has not been specified"
57
+ )
58
+
59
+ if method == :get
60
+ url = VivaWallet.api_base + resource + '?' + params
61
+ headers = {
62
+ accept: :json,
63
+ content_type: :json,
64
+ 'Authorization': "Bearer #{access_token}"
65
+ }.merge({ params: params })
66
+ payload = nil
67
+ else
68
+ url = VivaWallet.api_base + resource
69
+ headers = {
70
+ accept: :json,
71
+ content_type: :json,
72
+ 'Authorization': "Bearer #{access_token}"
73
+ }
74
+ payload = params
75
+ end
76
+ RestClient::Request.new({
77
+ method: method,
78
+ url: url,
79
+ payload: payload.to_json,
80
+ headers: headers
81
+ }).execute do |response, request, result|
82
+ str_response = response.to_str
83
+ str_response.blank? ? '' : JSON.parse(str_response)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/viva_wallet/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "viva_wallet"
7
+ spec.version = VivaWallet::VERSION
8
+ spec.authors = ["Tom Dallimore"]
9
+ spec.email = ["me@tomdallimore.com"]
10
+
11
+ spec.summary = "A Ruby wrapper for the Viva Wallet Smart Checkout API."
12
+ spec.description = "A Ruby wrapper for the Viva Wallet Smart Checkout API."
13
+ spec.homepage = "https://github.com/Jellyfishboy/viva_wallet"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ spec.metadata["source_code_uri"] = "https://github.com/Jellyfishboy/viva_wallet"
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(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency 'rest-client', '~> 2'
29
+
30
+ # For more information and examples about making a new gem, checkout our
31
+ # guide at: https://bundler.io/guides/creating_gem.html
32
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: viva_wallet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Dallimore
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ description: A Ruby wrapper for the Viva Wallet Smart Checkout API.
28
+ email:
29
+ - me@tomdallimore.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".circleci/config.yml"
35
+ - ".gitignore"
36
+ - ".idea/.gitignore"
37
+ - ".idea/inspectionProfiles/Project_Default.xml"
38
+ - ".idea/misc.xml"
39
+ - ".idea/modules.xml"
40
+ - ".idea/vcs.xml"
41
+ - ".idea/viva_wallet.iml"
42
+ - ".rspec"
43
+ - CHANGELOG.md
44
+ - CODE_OF_CONDUCT.md
45
+ - Gemfile
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - bin/console
50
+ - bin/setup
51
+ - lib/viva_wallet.rb
52
+ - lib/viva_wallet/authentication.rb
53
+ - lib/viva_wallet/payment.rb
54
+ - lib/viva_wallet/version.rb
55
+ - viva_wallet.gemspec
56
+ homepage: https://github.com/Jellyfishboy/viva_wallet
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ source_code_uri: https://github.com/Jellyfishboy/viva_wallet
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 2.4.0
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 3.2.15
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A Ruby wrapper for the Viva Wallet Smart Checkout API.
80
+ test_files: []