inter_api 1.0.1 → 1.0.3
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 +4 -4
 - data/README.md +58 -5
 - data/lib/inter_api/client.rb +3 -3
 - data/lib/inter_api/version.rb +1 -1
 - metadata +8 -8
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 851ced5270a63cb3feea8a1d570c23918548e0fa8fd0ad4175ffd7faf9a87333
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: afb5f7ae4dc0455e34d2c584ffd832246015ef24495fd41df79d44a2829c662d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 7ef44ff9c60803a68fa10212ec3062af971c31f9cd891ae7e46d7e7811a901a3856e09fcfaacc103625c5b9f805662ec4ef18e7132c1f210332d3aff254350d5
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 1aef7ac40411244ff0226ca03daee9a14b6af5c93ae0b1f238327889ed08f9d259c13fbdb5b40796b6de85cde1ce4329b95e72297ad57d1de369ded5f23d8c66
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,19 +1,72 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # InterApi
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            Wrapper de integração com a API v2 do Banco Inter.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
            ### Funcionalidades:
         
     | 
| 
      
 6 
     | 
    
         
            +
            - Autenticação
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Pagamento Pix: get, create, update, refund
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            ## Instalação
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            Adicionar inter_api no Gemfile:
         
     | 
| 
       6 
12 
     | 
    
         | 
| 
       7 
13 
     | 
    
         
             
            ```ruby
         
     | 
| 
       8 
14 
     | 
    
         
             
            gem 'inter_api'
         
     | 
| 
       9 
15 
     | 
    
         
             
            ```
         
     | 
| 
      
 16 
     | 
    
         
            +
            ou
         
     | 
| 
      
 17 
     | 
    
         
            +
            ```shell
         
     | 
| 
      
 18 
     | 
    
         
            +
            bundle add inter_api
         
     | 
| 
      
 19 
     | 
    
         
            +
            ```
         
     | 
| 
       10 
20 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
            Instalar a gem:
         
     | 
| 
       12 
22 
     | 
    
         | 
| 
       13 
23 
     | 
    
         
             
            ```shell
         
     | 
| 
       14 
24 
     | 
    
         
             
            bin/rails generate inter_api:install
         
     | 
| 
       15 
25 
     | 
    
         
             
            ```
         
     | 
| 
       16 
26 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
            ##  
     | 
| 
      
 27 
     | 
    
         
            +
            ## Uso
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            ### Exemplo
         
     | 
| 
      
 30 
     | 
    
         
            +
            #### Criar Pagamento PIX
         
     | 
| 
      
 31 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 32 
     | 
    
         
            +
            # Instanciar o API client
         
     | 
| 
      
 33 
     | 
    
         
            +
            api_client = InterApi::Client.new(crt: "./certificado_api_inter.crt", key: "./chave_api_inter.key", client_id: "123456", client_secret: "abcde", chave_pix: "1011121314", conta_corrente: "9876", scopes: "cobv.write cobv.read cob.write cob.read pix.write pix.read")
         
     | 
| 
      
 34 
     | 
    
         
            +
            # Ao instanciar o objeto, cria um access_token e/ou valida a partir da data de expiração
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            # Criar um pagamento 
         
     | 
| 
      
 37 
     | 
    
         
            +
            payment = api_client.create_payment(amount: 50.00, payer_tax_id: "123.123.123-01", payer_name: "João da Silva", expiration: 3600, solicitacao_pagador: "Compra de produto", info_adicionais: [ nome: "Produto", valor: "Produto 1"])
         
     | 
| 
      
 38 
     | 
    
         
            +
            # retorna um objeto <InterApi::Payment>
         
     | 
| 
      
 39 
     | 
    
         
            +
            puts payment.txid # "123123"
         
     | 
| 
      
 40 
     | 
    
         
            +
            puts payment.status # "ATIVA"
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            # Obter um pagamento a partir do id
         
     | 
| 
      
 43 
     | 
    
         
            +
            payment = api_client.get_payment(payment.txid)
         
     | 
| 
      
 44 
     | 
    
         
            +
            # retorna um objeto <InterApi::Payment>
         
     | 
| 
      
 45 
     | 
    
         
            +
            puts payment.txid # "123123"
         
     | 
| 
      
 46 
     | 
    
         
            +
            puts payment.status # "ATIVA"
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            # Atualizar um pagamento
         
     | 
| 
      
 49 
     | 
    
         
            +
            body = { status: "REMOVIDA_PELO_USUARIO_RECEBEDOR" }
         
     | 
| 
      
 50 
     | 
    
         
            +
            api_client.update(payment.txid, body)
         
     | 
| 
      
 51 
     | 
    
         
            +
            # retorna o objeto <InterApi::Payment> atualizado
         
     | 
| 
      
 52 
     | 
    
         
            +
            puts payment.status # "REMOVIDA_PELO_USUARIO_RECEBEDOR"
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            ```
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            #### Métodos do Pagamento
         
     | 
| 
      
 57 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 58 
     | 
    
         
            +
            payment.valid? # true ou false
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            payment.paid? # true ou false
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            payment.qr_code # retorna o source do SVG
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            payment.reload! # retorna payment atualizado
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            payment.invalidate! # invalida e retorna o payment atualizado
         
     | 
| 
       18 
67 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 68 
     | 
    
         
            +
            # Reebolso de pagamento
         
     | 
| 
      
 69 
     | 
    
         
            +
            reembolso = payment.refund(amount: 50.00, refund_nature: "ORIGINAL", description: "Reembolso")
         
     | 
| 
      
 70 
     | 
    
         
            +
            # retorna o JSON da resposta
         
     | 
| 
      
 71 
     | 
    
         
            +
            reembolso["status"] # "EM_PROCESSAMENTO"
         
     | 
| 
      
 72 
     | 
    
         
            +
            ```
         
     | 
    
        data/lib/inter_api/client.rb
    CHANGED
    
    | 
         @@ -84,12 +84,12 @@ module InterApi 
     | 
|
| 
       84 
84 
     | 
    
         
             
                end
         
     | 
| 
       85 
85 
     | 
    
         | 
| 
       86 
86 
     | 
    
         
             
                def update_payment(payment_id, body)
         
     | 
| 
       87 
     | 
    
         
            -
                  response =  
     | 
| 
      
 87 
     | 
    
         
            +
                  response = patch("/pix/v2/cob/#{payment_id}", headers: build_headers, sslcert: @crt, sslkey: @key, body: JSON.dump(body)) { |response| validate_response(response, "txid") }
         
     | 
| 
       88 
88 
     | 
    
         
             
                  InterApi::Payment.new(response.json, self)
         
     | 
| 
       89 
89 
     | 
    
         
             
                end
         
     | 
| 
       90 
90 
     | 
    
         | 
| 
       91 
91 
     | 
    
         
             
                def get_refund(end_to_end_id, id)
         
     | 
| 
       92 
     | 
    
         
            -
                  response = get("/pix/v2/pix/#{end_to_end_id}/devolucao/#{id}", headers: build_headers, sslcert: @crt, sslkey: @key)
         
     | 
| 
      
 92 
     | 
    
         
            +
                  response = get("/pix/v2/pix/#{end_to_end_id}/devolucao/#{id}", headers: build_headers, sslcert: @crt, sslkey: @key) { |response| validate_response(response, "id") }
         
     | 
| 
       93 
93 
     | 
    
         
             
                  response.json
         
     | 
| 
       94 
94 
     | 
    
         
             
                end
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
         @@ -100,7 +100,7 @@ module InterApi 
     | 
|
| 
       100 
100 
     | 
    
         
             
                    natureza: refund_nature,
         
     | 
| 
       101 
101 
     | 
    
         
             
                    descricao: description
         
     | 
| 
       102 
102 
     | 
    
         
             
                  }
         
     | 
| 
       103 
     | 
    
         
            -
                  response = put("/pix/v2/pix/#{end_to_end_id}/devolucao/#{id}", headers: build_headers, sslcert: @crt, sslkey: @key, body: JSON.dump(body))
         
     | 
| 
      
 103 
     | 
    
         
            +
                  response = put("/pix/v2/pix/#{end_to_end_id}/devolucao/#{id}", headers: build_headers, sslcert: @crt, sslkey: @key, body: JSON.dump(body)) { |response| validate_response(response, "id") }
         
     | 
| 
       104 
104 
     | 
    
         
             
                  response.json
         
     | 
| 
       105 
105 
     | 
    
         
             
                end
         
     | 
| 
       106 
106 
     | 
    
         | 
    
        data/lib/inter_api/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: inter_api
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.3
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
     | 
    
         
            -
            -  
     | 
| 
      
 7 
     | 
    
         
            +
            - Todas Essas Coisas
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024-06- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-06-11 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: ac
         
     | 
| 
         @@ -85,13 +85,13 @@ files: 
     | 
|
| 
       85 
85 
     | 
    
         
             
            - lib/inter_api/payment_error.rb
         
     | 
| 
       86 
86 
     | 
    
         
             
            - lib/inter_api/version.rb
         
     | 
| 
       87 
87 
     | 
    
         
             
            - sig/inter_api.rbs
         
     | 
| 
       88 
     | 
    
         
            -
            homepage: https://github.com/ 
     | 
| 
      
 88 
     | 
    
         
            +
            homepage: https://github.com/todasessascoisas/inter_api
         
     | 
| 
       89 
89 
     | 
    
         
             
            licenses:
         
     | 
| 
       90 
90 
     | 
    
         
             
            - MIT
         
     | 
| 
       91 
91 
     | 
    
         
             
            metadata:
         
     | 
| 
       92 
     | 
    
         
            -
              homepage_uri: https://github.com/ 
     | 
| 
       93 
     | 
    
         
            -
              source_code_uri: https://github.com/ 
     | 
| 
       94 
     | 
    
         
            -
              changelog_uri: https://github.com/ 
     | 
| 
      
 92 
     | 
    
         
            +
              homepage_uri: https://github.com/todasessascoisas/inter_api
         
     | 
| 
      
 93 
     | 
    
         
            +
              source_code_uri: https://github.com/todasessascoisas/inter_api
         
     | 
| 
      
 94 
     | 
    
         
            +
              changelog_uri: https://github.com/todasessascoisas/inter_api
         
     | 
| 
       95 
95 
     | 
    
         
             
            post_install_message: 
         
     | 
| 
       96 
96 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       97 
97 
     | 
    
         
             
            require_paths:
         
     | 
| 
         @@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       107 
107 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       108 
108 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       109 
109 
     | 
    
         
             
            requirements: []
         
     | 
| 
       110 
     | 
    
         
            -
            rubygems_version: 3.5. 
     | 
| 
      
 110 
     | 
    
         
            +
            rubygems_version: 3.5.9
         
     | 
| 
       111 
111 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       112 
112 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       113 
113 
     | 
    
         
             
            summary: ''
         
     |