inter_api 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: c1b557a668eb322c52dae171a4ac52b78b098ef1f9b3a18583f1d67d4e6bf526
4
+ data.tar.gz: 2935946dd4574822ad03916624143a04d773e0c9eeca0c96abb25effedd1fb85
5
+ SHA512:
6
+ metadata.gz: 61449b97f533dfe179d2814b461709a424ca0b2e48fe9595eacb831601170d46ee797e7e4d51a3a915731a797bd816cd5d949b908550e1beda096c72319a7964
7
+ data.tar.gz: f8ecbf9148def1ebab3f402a0e9d6881c6cdd6157f82f4900fe4bf02e2ab1b98c7af3ca61370a3055f3cb3891dc447acd2ec14ecab99704d1fdd006363504411
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-05-20
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 ulyssesh.20@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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 ulysses
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,19 @@
1
+ # InterApi
2
+
3
+ ## Installation
4
+
5
+ Add inter_api to your Gemfile:
6
+
7
+ ```ruby
8
+ gem 'inter_api'
9
+ ```
10
+
11
+ Bundle your dependencies and run the installation generator:
12
+
13
+ ```shell
14
+ bin/rails generate inter_api:install
15
+ ```
16
+
17
+ ## License
18
+
19
+ Copyright (c) 2023 ulysses-bull, released under the New BSD License.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[test standard]
@@ -0,0 +1,82 @@
1
+ module InterApi
2
+ class Client < Ac::Base
3
+ BASE_URL = "https://cdpj.partners.bancointer.com.br/"
4
+
5
+ attr_accessor :crt, :key, :client_id, :client_secret, :chave_pix, :conta_corrente, :token, :token_expires_at
6
+ def initialize crt:, key:, client_id:, client_secret:, chave_pix:, conta_corrente:, token: nil, token_expires_at: nil
7
+ @crt = crt
8
+ @key = key
9
+ @client_id = client_id
10
+ @client_secret = client_secret
11
+ @chave_pix = chave_pix
12
+ @conta_corrente = conta_corrente
13
+ @token = token
14
+ @token_expires_at = token_expires_at
15
+ if @token.nil? || @token_expires_at.nil?
16
+ authenticate!
17
+ end
18
+ end
19
+
20
+ def authenticate!
21
+ headers = {
22
+ "Content-Type" => "application/x-www-form-urlencoded"
23
+ }
24
+ body = {
25
+ client_id: @client_id,
26
+ client_secret: @client_secret,
27
+ grant_type: "client_credentials",
28
+ scope: "cobv.write cob.write cob.read pix.write pagamento-pix.write"
29
+ }
30
+ response = post("/oauth/v2/token", headers: headers, sslcert: @crt, sslkey: @key, body: body)
31
+ @token = response.json["access_token"]
32
+ @token_expires_at = Time.now + response.json["expires_in"]
33
+ end
34
+
35
+ def get_payment(payment_id)
36
+ headers = build_headers
37
+ response = get("/pix/v2/cob/#{payment_id}", headers: headers, sslcert: @crt, sslkey: @key)
38
+ InterApi::Payment.new(response.json)
39
+ end
40
+
41
+ def create_payment_request(**args_body)
42
+ headers = build_headers
43
+ body = {
44
+ calendario: {
45
+ expiracao: args_body[:expiration]
46
+ },
47
+ devedor: build_devedor(args_body[:payer_tax_id], args_body[:payer_name]),
48
+ valor: {
49
+ original: args_body[:amount],
50
+ modalidadeAlteracao: 0
51
+ },
52
+ chave: @chave_pix,
53
+ solicitacaoPagador: args_body[:solicitacao_pagador],
54
+ infoAdicionais: args_body[:info_adicionais]
55
+ }
56
+ post_request("/pix/v2/cob", headers: headers, sslcert: @crt, sslkey: @key, body: JSON.dump(body))
57
+ end
58
+
59
+ def create_payment(amount:, payer_tax_id:, payer_name:, expiration: 3600, solicitacao_pagador: nil, info_adicionais: [])
60
+ response = create_payment_request(amount: amount, payer_tax_id: payer_tax_id, payer_name: payer_name, expiration: expiration, solicitacao_pagador: solicitacao_pagador, info_adicionais: info_adicionais).run
61
+ InterApi::Payment.new(response.json)
62
+ end
63
+
64
+ private
65
+
66
+ def build_devedor payer_tax_id, payer_name
67
+ document_type = (payer_tax_id.gsub(/\D/, "").length == 11) ? "cpf" : "cnpj"
68
+ {
69
+ document_type => payer_tax_id,
70
+ "nome" => payer_name
71
+ }
72
+ end
73
+
74
+ def build_headers
75
+ {
76
+ "x-conta-corrente" => @conta_corrente,
77
+ "Authorization" => "Bearer #{@token}",
78
+ "Content-Type" => "application/json"
79
+ }
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,38 @@
1
+ module InterApi
2
+ class Payment
3
+
4
+ attr_reader :response, :txid, :copia_e_cola, :status, :solicitacao, :info_adicionais, :valor_original, :valor_pago, :criacao, :expiracao, :devedor_nome, :devedor_tax_id
5
+ def initialize response
6
+ @response = response
7
+ @txid = response.dig("txid")
8
+ @copia_e_cola = response.dig("pixCopiaECola")
9
+ @status = response.dig("status")
10
+ @solicitacao = response.dig("solicitacaoPagador")
11
+ @info_adicionais = response.dig("infoAdicionais")
12
+ @valor_original = response.dig("valor", "original")
13
+ @valor_pago = response.dig("pix", 0, "valor")
14
+ @criacao = Time.new(response.dig("calendario", "criacao"))
15
+ @expiracao = Time.new(response.dig("calendario", "criacao")) + response.dig("calendario", "expiracao")
16
+ @devedor_nome = response.dig("devedor", "nome")
17
+ @devedor_tax_id = response.dig("devedor", "cpf") || response.dig("devedor", "cnpj")
18
+ end
19
+
20
+ def paid?
21
+ @valor_original.to_d == @valor_pago.to_d
22
+ end
23
+
24
+ def qr_code module_size: 4
25
+ qr = RQRCode::QRCode.new(@copia_e_cola, size: 10, level: :l)
26
+ qr.as_svg(module_size: module_size)
27
+ end
28
+
29
+ def valid?
30
+ @expiracao > Time.now
31
+ end
32
+
33
+ # def reload!
34
+ # @response = api_inter.find_by_id(id)
35
+ # end
36
+
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InterApi
4
+ VERSION = "0.1.0"
5
+ end
data/lib/inter_api.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bigdecimal/util"
4
+ require "rqrcode"
5
+ require "debug"
6
+ require "ac"
7
+
8
+ require_relative "inter_api/version"
9
+ require "inter_api/client"
10
+ require "inter_api/payment"
11
+
12
+ module InterApi
13
+ class Error < StandardError; end
14
+ # Your code goes here...
15
+ end
data/sig/inter_api.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module InterApi
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inter_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ulysses
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ac
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: rqrcode
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bigdecimal
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ''
56
+ email:
57
+ - ulyssesh.20@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".standard.yml"
63
+ - CHANGELOG.md
64
+ - CODE_OF_CONDUCT.md
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/inter_api.rb
69
+ - lib/inter_api/client.rb
70
+ - lib/inter_api/payment.rb
71
+ - lib/inter_api/version.rb
72
+ - sig/inter_api.rbs
73
+ homepage: https://github.com/ulysses-bull/inter_api
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ homepage_uri: https://github.com/ulysses-bull/inter_api
78
+ source_code_uri: https://github.com/ulysses-bull/inter_api
79
+ changelog_uri: https://github.com/ulysses-bull/inter_api
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 3.0.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.5.10
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: ''
99
+ test_files: []