github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/mock/citibank.go (about) 1 package mock 2 3 import ( 4 "io/ioutil" 5 "strings" 6 7 "github.com/gin-gonic/gin" 8 ) 9 10 func registerBoletoCiti(c *gin.Context) { 11 sData := ` 12 <?xml version="1.0" encoding="UTF-8"?> 13 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s1="http://www.citibank.com.br/comercioeletronico/registerboleto"> 14 <soap:Body> 15 <s1:RegisterBoletoResponse> 16 <actionCode>0</actionCode> 17 <reasonMessage>Data received </reasonMessage> 18 <TitlBarCd>74591728800000001033100087772012000000421265</TitlBarCd> 19 <TitlDgtLine>74593100048777201200800004212650172880000000103 </TitlDgtLine> 20 </s1:RegisterBoletoResponse> 21 </soap:Body> 22 </soap:Envelope> 23 ` 24 25 sDataErr := ` 26 <?xml version="1.0" encoding="UTF-8"?> 27 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s1="http://www.citibank.com.br/comercioeletronico/registerboleto"> 28 <soap:Body> 29 <s1:RegisterBoletoResponse> 30 <actionCode>99</actionCode> 31 <reasonMessage>Data not processed </reasonMessage> 32 <TitlBarCd></TitlBarCd> 33 <TitlDgtLine></TitlDgtLine> 34 </s1:RegisterBoletoResponse> 35 </soap:Body> 36 </soap:Envelope> 37 ` 38 sDataWhiteSpaces := ` 39 <?xml version="1.0" encoding="UTF-8"?> 40 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s1="http://www.citibank.com.br/comercioeletronico/registerboleto"> 41 <soap:Body> 42 <s1:RegisterBoletoResponse> 43 <actionCode>0</actionCode> 44 <reasonMessage>Data received </reasonMessage> 45 <TitlBarCd> </TitlBarCd> 46 <TitlDgtLine> </TitlDgtLine> 47 </s1:RegisterBoletoResponse> 48 </soap:Body> 49 </soap:Envelope> 50 ` 51 sDataEmpty := ` 52 <?xml version="1.0" encoding="UTF-8"?> 53 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s1="http://www.citibank.com.br/comercioeletronico/registerboleto"> 54 <soap:Body> 55 <s1:RegisterBoletoResponse> 56 <actionCode>0</actionCode> 57 <reasonMessage>Data received </reasonMessage> 58 <TitlBarCd></TitlBarCd> 59 <TitlDgtLine></TitlDgtLine> 60 </s1:RegisterBoletoResponse> 61 </soap:Body> 62 </soap:Envelope> 63 ` 64 65 sDataNil := ` 66 <?xml version="1.0" encoding="UTF-8"?> 67 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s1="http://www.citibank.com.br/comercioeletronico/registerboleto"> 68 <soap:Body> 69 <s1:RegisterBoletoResponse> 70 <actionCode>0</actionCode> 71 <reasonMessage>Data received </reasonMessage> 72 </s1:RegisterBoletoResponse> 73 </soap:Body> 74 </soap:Envelope> 75 ` 76 d, _ := ioutil.ReadAll(c.Request.Body) 77 xml := string(d) 78 if strings.Contains(xml, "<TitlAmt>200</TitlAmt>") { 79 c.Data(200, "text/xml", []byte(sData)) 80 } else if strings.Contains(xml, "<TitlAmt>100</TitlAmt>") { 81 c.Data(200, "text/xml", []byte(sDataWhiteSpaces)) 82 } else if strings.Contains(xml, "<TitlAmt>101</TitlAmt>") { 83 c.Data(200, "text/xml", []byte(sDataEmpty)) 84 } else if strings.Contains(xml, "<TitlAmt>102</TitlAmt>") { 85 c.Data(200, "text/xml", []byte(sDataNil)) 86 } else { 87 c.Data(200, "text/xml", []byte(sDataErr)) 88 } 89 90 }