github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/pefisa/request.go (about)

     1  package pefisa
     2  
     3  const registerPefisa = `
     4  ## Authorization:Bearer {{.Authentication.AuthorizationToken}}
     5  ## Content-Type:application/json
     6  {
     7      "idBeneficiario": {{.Agreement.AgreementNumber}},
     8      "carteira": {{.Agreement.Wallet}},
     9      "nossoNumero": "{{padLeft (toString .Title.OurNumber) "0" 10}}",
    10      "seuNumero": "{{truncate .Title.DocumentNumber 10}}",    
    11      "tipoTitulo": {{ .Title.BoletoTypeCode}},
    12      "valorTitulo": "{{toFloatStr .Title.AmountInCents}}",
    13      "dataDocumento": "{{enDate (today) "-"}}",
    14  	"dataVencimento": "{{.Title.ExpireDate}}",
    15  	"usoEmpresa": "A",
    16      "emitente": {
    17          "nome": "{{onlyOneSpace .Recipient.Name}}",
    18          {{if (eq .Recipient.Document.Type "CNPJ")}}
    19          "tipo": "J",        
    20          {{else}}
    21          "tipo": "F",
    22          {{end}}        
    23          "cnpjCpf": "{{extractNumbers .Recipient.Document.Number}}",
    24          "endereco": "{{truncate .Recipient.Address.Street 40}}",
    25          "cidade": "{{truncate .Recipient.Address.City 60}}",
    26          "cep": "{{truncate .Recipient.Address.ZipCode 8}}",
    27          "uf": "{{truncate .Recipient.Address.StateCode 2}}",
    28          "bairro": "{{truncate .Recipient.Address.District 65}}"
    29      },
    30      "pagador": {
    31          "nome": "{{truncate (onlyOneSpace .Buyer.Name) 40}}",
    32          {{if (eq .Buyer.Document.Type "CNPJ")}}
    33          "tipo": "J",
    34          {{else}}
    35          "tipo": "F",
    36          {{end}}        
    37          "cnpjCpf": "{{extractNumbers .Buyer.Document.Number}}",
    38          "endereco": "{{truncate (onlyOneSpace .Buyer.Address.Street) 40}}",
    39          "cidade": "{{truncate (onlyOneSpace .Buyer.Address.City) 20}}",
    40          "cep": "{{truncate (extractNumbers .Buyer.Address.ZipCode) 8}}",
    41          "uf": "{{truncate (removeAllSpaces .Buyer.Address.StateCode) 2}}",
    42          "bairro": "{{truncate (onlyOneSpace .Buyer.Address.District) 65}}"
    43          
    44      },
    45      "mensagens": [
    46          "{{truncate .Title.Instructions 80}}"
    47      ]
    48  }
    49  `
    50  
    51  const pefisaGetTokenRequest = `
    52  ## Authorization:Basic {{base64 (concat .Authentication.Username ":" .Authentication.Password)}}
    53  ## Content-Type: application/x-www-form-urlencoded
    54  grant_type=client_credentials`
    55  
    56  const tokenResponse = `{	
    57  	"access_token": "{{access_token}}"
    58  }`
    59  
    60  const tokenErrorResponse = `{    
    61  	"error_description": "{{errorMessage}}"
    62  }`
    63  
    64  func getRequestToken() string {
    65  	return pefisaGetTokenRequest
    66  }
    67  
    68  func getTokenResponse() string {
    69  	return tokenResponse
    70  }
    71  
    72  func getTokenErrorResponse() string {
    73  	return tokenErrorResponse
    74  }
    75  
    76  func getRequestPefisa() string {
    77  	return registerPefisa
    78  }