github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/mock/jpmorgan.go (about) 1 package mock 2 3 import ( 4 "io/ioutil" 5 "strings" 6 "time" 7 8 "github.com/gin-gonic/gin" 9 ) 10 11 const successResponseJp = ` 12 { 13 "resposta":{ 14 "clienteBeneficiario":{ 15 "codBanco":376, 16 "codAgencia":98, 17 "codContaCorrente":6000164, 18 "tpPessoaBenfcrioOr":2, 19 "cnpjCpfBenfcrioOr":"33172537000198", 20 "codCartTit":1, 21 "txtInfCliCed":"TEST PAGARME" 22 }, 23 "titulo":{ 24 "numDocTit":"1001", 25 "dtVencTit":"2021-10-13", 26 "vlrTit":2, 27 "codEspTit":2, 28 "dtEmsTit":"2021-10-08", 29 "vlrAbattTit":0, 30 "tpCodPrott":3, 31 "qtdDiaPrott":0, 32 "codMoedaCnab":9 33 }, 34 "juros":{ 35 "codJurosTit":2, 36 "vlrPercJurosTit":7, 37 "dtJurosTit":"2021-10-14" 38 }, 39 "descontos":{ 40 "codDesctTit":0, 41 "dtDesctTit":null, 42 "vlrPercDesctTit":0 43 }, 44 "sacadoOuPagador":{ 45 "tpPessoaPagdr":1, 46 "cnpjCpfPagdr":"37303489819", 47 "nomRzSocPagdr":"Nome do Comprador Cliente", 48 "logradPagdr":"Logradouro", 49 "bairroPagdr":"Bairro", 50 "cepPagdr":"15050466", 51 "cidPagdr":"Cidade", 52 "ufPagdr":"SP" 53 }, 54 "multa":{ 55 "dtMultaTit":null, 56 "codMultaTit":3, 57 "vlrPercMultaTit":0 58 }, 59 "numCodBarras":"37691877200000002000098000600016400000504858", 60 "linhaDigitavel":"37690098080060001640600005048582187720000000200", 61 "identdNossoNum":"123456789012" 62 } 63 } 64 ` 65 66 const successResponseJpShortOurNumber = ` 67 { 68 "resposta":{ 69 "clienteBeneficiario":{ 70 "codBanco":376, 71 "codAgencia":98, 72 "codContaCorrente":6000164, 73 "tpPessoaBenfcrioOr":2, 74 "cnpjCpfBenfcrioOr":"33172537000198", 75 "codCartTit":1, 76 "txtInfCliCed":"TEST PAGARME" 77 }, 78 "titulo":{ 79 "numDocTit":"1001", 80 "dtVencTit":"2021-10-13", 81 "vlrTit":2, 82 "codEspTit":2, 83 "dtEmsTit":"2021-10-08", 84 "vlrAbattTit":0, 85 "tpCodPrott":3, 86 "qtdDiaPrott":0, 87 "codMoedaCnab":9 88 }, 89 "juros":{ 90 "codJurosTit":2, 91 "vlrPercJurosTit":7, 92 "dtJurosTit":"2021-10-14" 93 }, 94 "descontos":{ 95 "codDesctTit":0, 96 "dtDesctTit":null, 97 "vlrPercDesctTit":0 98 }, 99 "sacadoOuPagador":{ 100 "tpPessoaPagdr":1, 101 "cnpjCpfPagdr":"37303489819", 102 "nomRzSocPagdr":"Nome do Comprador Cliente", 103 "logradPagdr":"Logradouro", 104 "bairroPagdr":"Bairro", 105 "cepPagdr":"15050466", 106 "cidPagdr":"Cidade", 107 "ufPagdr":"SP" 108 }, 109 "multa":{ 110 "dtMultaTit":null, 111 "codMultaTit":3, 112 "vlrPercMultaTit":0 113 }, 114 "numCodBarras":"37691877200000002000098000600016400000504858", 115 "linhaDigitavel":"37690098080060001640600005048582187720000000200", 116 "identdNossoNum":"123456" 117 } 118 } 119 ` 120 121 const successResponseJpWithoutOurNumber = ` 122 { 123 "resposta":{ 124 "clienteBeneficiario":{ 125 "codBanco":376, 126 "codAgencia":98, 127 "codContaCorrente":6000164, 128 "tpPessoaBenfcrioOr":2, 129 "cnpjCpfBenfcrioOr":"33172537000198", 130 "codCartTit":1, 131 "txtInfCliCed":"TEST PAGARME" 132 }, 133 "titulo":{ 134 "numDocTit":"1001", 135 "dtVencTit":"2021-10-13", 136 "vlrTit":2, 137 "codEspTit":2, 138 "dtEmsTit":"2021-10-08", 139 "vlrAbattTit":0, 140 "tpCodPrott":3, 141 "qtdDiaPrott":0, 142 "codMoedaCnab":9 143 }, 144 "juros":{ 145 "codJurosTit":2, 146 "vlrPercJurosTit":7, 147 "dtJurosTit":"2021-10-14" 148 }, 149 "descontos":{ 150 "codDesctTit":0, 151 "dtDesctTit":null, 152 "vlrPercDesctTit":0 153 }, 154 "sacadoOuPagador":{ 155 "tpPessoaPagdr":1, 156 "cnpjCpfPagdr":"37303489819", 157 "nomRzSocPagdr":"Nome do Comprador Cliente", 158 "logradPagdr":"Logradouro", 159 "bairroPagdr":"Bairro", 160 "cepPagdr":"15050466", 161 "cidPagdr":"Cidade", 162 "ufPagdr":"SP" 163 }, 164 "multa":{ 165 "dtMultaTit":null, 166 "codMultaTit":3, 167 "vlrPercMultaTit":0 168 }, 169 "numCodBarras":"37691877200000002000098000600016400000504858", 170 "linhaDigitavel":"37690098080060001640600005048582187720000000200", 171 "identdNossoNum":"" 172 } 173 } 174 ` 175 176 var withoutCert = ` 177 <ServiceMessage> 178 <Status>Error</Status> 179 <Reason>Internal Error - Contact Service Provider</Reason> 180 </ServiceMessage> 181 ` 182 183 const accountNotFound = ` 184 { 185 "errors" : [ 186 { 187 "errorCode" : "GCA-010", 188 "errorMsg" : "The account was not found." 189 } ] 190 } 191 ` 192 193 const missingParameter = ` 194 { 195 "errors": [ 196 { 197 "errorCode": "GCA-111", 198 "errorMsg": "codContaCorrente/codAgencia is required" 199 } 200 ] 201 } 202 ` 203 204 const expirationDateBeforeIssue = ` 205 { 206 "numCodRetorno": "BOL-3", 207 "mensagem": "Não foi possível processar a requisição por inconsistencia nos campos abaixo", 208 "resposta": { 209 "titulo": [ 210 { 211 "nomCampo": "dtVencTit", 212 "numCodRetorno": 108, 213 "valorRecebido": "2021-10-17", 214 "mensgRetorno": "Data de vencimento inválida" 215 }, 216 { 217 "nomCampo": "dtEmsTit", 218 "numCodRetorno": 111, 219 "valorRecebido": "2021-10-18", 220 "mensgRetorno": "Data de emissão inválida" 221 } 222 ] 223 } 224 } 225 ` 226 227 const boletoDuplicated = ` 228 { 229 "numCodRetorno": "BOL-144", 230 "mensagem": "Boleto já Existente. Detalhes abaixo:", 231 "resposta": { 232 "boletoBeneficiaryNumber": "4102374718", 233 "boletoBarCode": "37691878200000002010098000600016400000504893", 234 "boletoPaymentLine": "37690098080060001640600005048939187820000000201" 235 } 236 } 237 ` 238 239 const boletoDuplicatedWithoutDetails = ` 240 { 241 "numCodRetorno": "BOL-144", 242 "mensagem": "Boleto já Existente. Detalhes abaixo:" 243 } 244 ` 245 246 const signatureFailed = ` 247 <ServiceMessage> 248 <Status>Error</Status> 249 <Reason>Signature Verification Failure </Reason> 250 </ServiceMessage> 251 ` 252 253 const authenticationFailed = ` 254 <ServiceMessage> 255 <Status>Error</Status> 256 <Reason>Authentication Failure. </Reason> 257 </ServiceMessage> 258 ` 259 260 func registerJpMorgan(c *gin.Context) { 261 d, _ := ioutil.ReadAll(c.Request.Body) 262 json := string(d) 263 264 if strings.Contains(json, `"vlrTit": 2,`) { 265 c.Data(200, contentApplication, []byte(successResponseJp)) 266 } else if strings.Contains(json, `"vlrTit": 2.05,`) { 267 c.Data(200, "application/xml", []byte(successResponseJpWithoutOurNumber)) 268 } else if strings.Contains(json, `"vlrTit": 2.11,`) { 269 c.Data(200, "application/xml", []byte(successResponseJpShortOurNumber)) 270 } else if strings.Contains(json, `"vlrTit": 2.01,`) { 271 c.Data(500, "application/xml", []byte(withoutCert)) 272 } else if strings.Contains(json, `"vlrTit": 2.02,`) { 273 c.Data(404, "application/json", []byte(accountNotFound)) 274 } else if strings.Contains(json, `"vlrTit": 2.03,`) { 275 c.Data(422, "application/json", []byte(expirationDateBeforeIssue)) 276 } else if strings.Contains(json, `"vlrTit": 2.04,`) { 277 c.Data(409, "application/json", []byte(boletoDuplicated)) 278 } else if strings.Contains(json, `"vlrTit": 2.06,`) { 279 c.Data(400, "application/json", []byte(missingParameter)) 280 } else if strings.Contains(json, `"vlrTit": 2.07,`) { 281 c.Data(401, "application/xml", []byte(signatureFailed)) 282 } else if strings.Contains(json, `"vlrTit": 2.08,`) { 283 c.Data(401, "application/xml", []byte(authenticationFailed)) 284 } else if strings.Contains(json, `"vlrTit": 2.09,`) { 285 c.Data(409, "application/xml", []byte(boletoDuplicatedWithoutDetails)) 286 } else { 287 time.Sleep(35 * time.Second) 288 c.Data(504, contentApplication, []byte("timeout")) 289 } 290 }