shipay 0.1.5

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: 6b20219c6a70124d703b3bb89b25b8b0301efe50e69e5fa54944231f8a8efab1
4
+ data.tar.gz: 204c12e08721538169d23e8e63b69daf3c1cd0ffaae61b735434c9434dd71943
5
+ SHA512:
6
+ metadata.gz: f9c812520f9e4cb22fa3f5bb5ae85ed90b5189feaa4f2ee259e6343bbec831174c223094dd6dcea1300eaf183eea3ce781122412fd61866ea6d050d860a642d9
7
+ data.tar.gz: 0e145114ad89201bf70ef36961c8711c1b0e426a59564c6e1b7a8c6b088679f7293332d05ad9c622de437442ba29910e0e33ca28324b090f8ea7cc18c63e6397
data/.byebug_history ADDED
@@ -0,0 +1,125 @@
1
+ c
2
+ s
3
+ n
4
+ RESOURCES
5
+ s
6
+ resource_name
7
+ s
8
+ resource_name
9
+ n
10
+ resource_name
11
+ n
12
+ resource_name
13
+ n
14
+ resource_name
15
+ n
16
+ resource_name
17
+ n
18
+ c
19
+ response
20
+ n
21
+ response
22
+ n
23
+ response
24
+ n
25
+ response
26
+ c
27
+ response
28
+ cresorce_name
29
+ c
30
+ RESSOURCES
31
+ resource_name
32
+ c
33
+ RESOURCES
34
+ RESSOURCES
35
+ resource_name
36
+ resourece_name
37
+ ressourece_name
38
+ c
39
+ n
40
+ s
41
+ n
42
+ c
43
+ n
44
+ s
45
+ n
46
+ path
47
+ query
48
+ n
49
+ c
50
+ s
51
+ c
52
+ n
53
+ DEFAULT_HEADERS.merge(Shipay::Authenticator.headers )
54
+ headers
55
+ full_api_url
56
+ path
57
+ c
58
+ path
59
+ parameters
60
+ c
61
+ n
62
+ c
63
+ n
64
+ c
65
+ n
66
+ args
67
+ n
68
+ c
69
+ n
70
+ c
71
+ n
72
+ exc
73
+ n
74
+ parameters
75
+ n
76
+ params
77
+ c
78
+ parameters
79
+ method
80
+ path
81
+ c
82
+ n
83
+ c
84
+ n
85
+ c
86
+ q
87
+ c
88
+ n
89
+ url
90
+ n
91
+ c
92
+ url
93
+ c
94
+ url
95
+ c
96
+ request_params
97
+ n
98
+ c
99
+ response
100
+ c
101
+ response
102
+ n
103
+ m
104
+ n
105
+ c
106
+ n
107
+ response
108
+ n
109
+ response['object']
110
+ response
111
+ n
112
+ response
113
+ n
114
+ response
115
+ n
116
+ response
117
+ n
118
+ response
119
+ n
120
+ y
121
+ n
122
+ response
123
+ n
124
+ response
125
+ n
data/.editorconfig ADDED
@@ -0,0 +1,30 @@
1
+ root = true
2
+
3
+ [*]
4
+ end_of_line = lf
5
+ indent_size = 2
6
+ indent_style = space
7
+ insert_final_newline = true
8
+ tab_width = 4
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.bat]
12
+ end_of_line = crlf
13
+
14
+ [*.gemspec]
15
+ indent_size = 2
16
+
17
+ [*.rb]
18
+ indent_size = 2
19
+
20
+ [*.yml]
21
+ indent_size = 2
22
+
23
+ [{*[Mm]akefile*,*.mak,*.mk,depend}]
24
+ indent_style = tab
25
+
26
+ [enc/*]
27
+ indent_size = 2
28
+
29
+ [reg*.[ch]]
30
+ indent_size = 2
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
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
data/.solargraph.yml ADDED
@@ -0,0 +1,2 @@
1
+ include:
2
+ - "lib/*.rb"
@@ -0,0 +1,16 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Listen for rdebug-ide",
9
+ "type": "Ruby",
10
+ "request": "attach",
11
+ "remoteHost": "127.0.0.1",
12
+ "remotePort": "1234",
13
+ "remoteWorkspaceRoot": "${workspaceRoot}"
14
+ }
15
+ ]
16
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-05-07
4
+
5
+ - Initial release
6
+
7
+ ## [0.1.2] - 2022-07-05
8
+
9
+ - Adds enviroment checking for production URL switching.
10
+
11
+ ## [0.1.3] - 2022-07-05
12
+
13
+ - Correct production verifivation method
14
+
15
+ ## [0.1.4] - 2022-07-05
16
+
17
+ - Fix production definition for Rails enviroment
18
+
19
+
20
+ ## [0.1.5] - 2023-05-24
21
+
22
+ - Issue #1 - Failed to create Pix - undefined method `map' for nil:NilClass
@@ -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 guilherme.gazzinelli@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,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in shipay.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "readapt"
data/Gemfile.lock ADDED
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shipay (0.1.5)
5
+ jwt
6
+ multi_json
7
+ rest-client
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.2)
13
+ backport (1.2.0)
14
+ diff-lcs (1.5.0)
15
+ domain_name (0.5.20190701)
16
+ unf (>= 0.0.5, < 1.0.0)
17
+ http-accept (1.7.0)
18
+ http-cookie (1.0.5)
19
+ domain_name (~> 0.5)
20
+ jwt (2.7.1)
21
+ mime-types (3.5.1)
22
+ mime-types-data (~> 3.2015)
23
+ mime-types-data (3.2023.1003)
24
+ multi_json (1.15.0)
25
+ netrc (0.11.0)
26
+ parallel (1.22.1)
27
+ parser (3.1.2.0)
28
+ ast (~> 2.4.1)
29
+ rainbow (3.1.1)
30
+ rake (13.0.6)
31
+ readapt (1.4.3)
32
+ backport (~> 1.2)
33
+ thor (~> 1.0)
34
+ regexp_parser (2.3.1)
35
+ rest-client (2.1.0)
36
+ http-accept (>= 1.7.0, < 2.0)
37
+ http-cookie (>= 1.0.2, < 2.0)
38
+ mime-types (>= 1.16, < 4.0)
39
+ netrc (~> 0.8)
40
+ rexml (3.2.5)
41
+ rspec (3.11.0)
42
+ rspec-core (~> 3.11.0)
43
+ rspec-expectations (~> 3.11.0)
44
+ rspec-mocks (~> 3.11.0)
45
+ rspec-core (3.11.0)
46
+ rspec-support (~> 3.11.0)
47
+ rspec-expectations (3.11.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.11.0)
50
+ rspec-mocks (3.11.1)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.11.0)
53
+ rspec-support (3.11.0)
54
+ rubocop (1.29.0)
55
+ parallel (~> 1.10)
56
+ parser (>= 3.1.0.0)
57
+ rainbow (>= 2.2.2, < 4.0)
58
+ regexp_parser (>= 1.8, < 3.0)
59
+ rexml (>= 3.2.5, < 4.0)
60
+ rubocop-ast (>= 1.17.0, < 2.0)
61
+ ruby-progressbar (~> 1.7)
62
+ unicode-display_width (>= 1.4.0, < 3.0)
63
+ rubocop-ast (1.17.0)
64
+ parser (>= 3.1.1.0)
65
+ ruby-progressbar (1.11.0)
66
+ thor (1.2.1)
67
+ unf (0.1.4)
68
+ unf_ext
69
+ unf_ext (0.0.8.2)
70
+ unicode-display_width (2.1.0)
71
+
72
+ PLATFORMS
73
+ x86_64-linux
74
+
75
+ DEPENDENCIES
76
+ rake (~> 13.0)
77
+ readapt
78
+ rspec (~> 3.0)
79
+ rubocop (~> 1.21)
80
+ shipay!
81
+
82
+ BUNDLED WITH
83
+ 2.3.11
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Shipay
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/shipay`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'shipay'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install shipay
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/shipay. 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/[USERNAME]/shipay/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the ShipayRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/shipay/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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]
data/bin/console ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "irb"
5
+ require "irb/completion"
6
+ require "bundler/setup"
7
+ require "shipay"
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ # Config IRB to enable --simple-prompt and auto indent
17
+ IRB.conf[:PROMPT_MODE] = :SIMPLE
18
+ IRB.conf[:AUTO_INDENT] = true
19
+
20
+ def reload!(print = true)
21
+ puts 'Reloading ...' if print
22
+ # Main project directory.
23
+ root_dir = File.expand_path('..', __dir__)
24
+ # Directories within the project that should be reloaded.
25
+ reload_dirs = %w{lib}
26
+ # Loop through and reload every file in all relevant project directories.
27
+ reload_dirs.each do |dir|
28
+ Dir.glob("#{root_dir}/#{dir}/**/*.rb").each { |f| load(f) }
29
+ end
30
+ # Return true when complete.
31
+ true
32
+ end
33
+
34
+ def initialize_shipay
35
+ pp "Initilizing..."
36
+ Shipay.secret_key = ""
37
+ Shipay.access_key = ""
38
+ # Shipay.client_id = ""
39
+
40
+ Shipay.credentials = [ { key: :default, client_id: "" } ]
41
+
42
+ @ch = {
43
+ order_ref: "shipaypag-001",
44
+ wallet: "shipay-pagador",
45
+ total: 0.51,
46
+ items: [
47
+ {
48
+ item_title: "Item 1",
49
+ unit_price: 0.30,
50
+ quantity: 1
51
+ },
52
+ {
53
+ item_title: "Item 2",
54
+ unit_price: 0.20,
55
+ quantity: 1
56
+ },
57
+ {
58
+ item_title: "Item 3",
59
+ unit_price: 0.01,
60
+ quantity: 1
61
+ }
62
+ ],
63
+ buyer: {
64
+ name: "Shipay PDV",
65
+ cpf_cnpj: "121.191.870-02",
66
+ email: "shipay-pagador@shipay.com.br",
67
+ phone: "+55 11 99999-9999"
68
+ }
69
+ }
70
+ end
71
+
72
+ initialize_shipay
73
+ IRB.start
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,114 @@
1
+ require 'jwt'
2
+
3
+
4
+ module Shipay
5
+ CLIENT_TYPES = %i(pdv e_comerce)
6
+
7
+ #
8
+ # Class to hold client authetication data
9
+ #
10
+ class Client
11
+ attr_reader :secret_key, :access_key, :client_id, :key, :type
12
+ attr_accessor :default
13
+
14
+
15
+ #
16
+ # Initialize Client instance
17
+ #
18
+ # @param [Hash] **options Options required
19
+ # @options [String] :secret_key (Defaults to Shipay.secret_key)
20
+ # @options [String] :access_key (Defaults to Shipay.access_key)
21
+ # @options [String] :client_id (Required) The client identifier
22
+ # @options [String] :key (Defaults to Shipay.default_client_key)
23
+ # @options [Boolean] :default (Defaults to true) Param to define if client is the default one ( Not fully used)
24
+ # @options [Symbol] :type (Defaults to :pdv) Param to define if client is an PDV or E-Commerce [:pdv, :e_comerce]. Raises ParamError if not included in these types.
25
+ def initialize(**options)
26
+ begin
27
+ @secret_key = options.fetch(:secret_key, Shipay.secret_key)
28
+ @access_key = options.fetch(:access_key, Shipay.access_key)
29
+ @client_id = options.fetch(:client_id)
30
+ @key = Shipay::Util.to_sym(options.fetch(:key, Shipay.default_client_key ))
31
+ @default = options.fetch(:default, true)
32
+ @type = options.fetch(:type, :pdv)
33
+ raise ParamError.new("Incorrect client type, must be one of #{CLIENT_TYPES}", :type, "Symbol") unless CLIENT_TYPES.include? @type
34
+ rescue KeyError => e
35
+ raise ParamError.new("Missing data for credentials: #{e.key}, (#{e.message})", "Credentials", "Symbol or String") unless CLIENT_TYPES.include? @type
36
+ end
37
+ end
38
+
39
+ #
40
+ # Convert Client instance to hash
41
+ #
42
+ # @return [Hash] Return Client in hash form
43
+ #
44
+ def to_h
45
+ {
46
+ secret_key: @secret_key,
47
+ access_key: @access_key,
48
+ client_id: @client_id,
49
+ key: @key
50
+ }
51
+ end
52
+ end
53
+
54
+ class Authenticator
55
+ attr_reader :key, :client
56
+
57
+ #
58
+ # Initialize Authenticator Class
59
+ #
60
+ # @param [Client] client Receives Client instance to initialize authenticator
61
+ #
62
+ def initialize(client)
63
+ @client = client
64
+ @key = client.key
65
+ authenticate
66
+ end
67
+
68
+ #
69
+ # Return client authentication token
70
+ #
71
+ # @return [String] Returns cleint authentication token
72
+ #
73
+ def token
74
+ refresh_token_if_expired
75
+ @a_token
76
+ end
77
+
78
+ private
79
+
80
+ #
81
+ # Call api to authenticate client, receiving auth and refresh token
82
+ #
83
+ # @return [String] Refresh token
84
+ #
85
+ def authenticate
86
+ set_token_from_request Shipay::Request.auth('/pdvauth', {params: {client_id: @client.client_id, secret_key: @client.secret_key, access_key: @client.access_key, client_key: @key}}).run
87
+ end
88
+
89
+ #
90
+ # Refreshes token to receive a new, not expired, JWT auth_token
91
+ #
92
+ # @return [<Type>] <description>
93
+ #
94
+ def refresh_token
95
+ set_token_from_request Shipay::Request.auth('/refresh-token', {headers: { authorization: 'Bearer ' + @r_token}, client_key: @key}).run
96
+ end
97
+
98
+ def refresh_token_if_expired
99
+ refresh_token if Time.at(JWT.decode(@a_token, nil, false).first.dig('exp')) < Time.now()
100
+ end
101
+
102
+ #
103
+ # Sets tokens based on response of request
104
+ #
105
+ # @param [ShipayObject] response Response from authentication or refresh request
106
+ # @note Must include 'access_token' and 'refresh_token'
107
+ # @return [String] Refresh token
108
+ #
109
+ def set_token_from_request response
110
+ @a_token = response['access_token']
111
+ @r_token = response['refresh_token']
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,9 @@
1
+ class Object
2
+ def blank?
3
+ respond_to?(:empty?) ? !!empty? : !self
4
+ end
5
+
6
+ def present?
7
+ !blank?
8
+ end
9
+ end