github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/stone/contracts.go (about) 1 package stone 2 3 const templateRequest = ` 4 ## Content-Type:application/json 5 ## Authorization:Bearer {{.Authentication.AuthorizationToken}} 6 { 7 "account_id": "{{.Authentication.AccessKey}}", 8 "amount": {{.Title.AmountInCents}}, 9 "expiration_date": "{{.Title.ExpireDate}}", 10 {{if .Title.HasRules}} 11 "limit_date": "{{enDate (datePlusDays .Title.ExpireDateTime .Title.Rules.MaxDaysToPayPastDue) "-"}}", 12 {{else}} 13 "limit_date": "{{enDate (datePlusDays .Title.ExpireDateTime 1) "-"}}", 14 {{end}} 15 "invoice_type": "{{.Title.BoletoTypeCode}}", 16 "customer": { 17 "document": "{{.Buyer.Document.Number}}", 18 "legal_name": "{{truncateOnly (onlyAlphanumerics (onlyOneSpace .Buyer.Name)) 50}}", 19 {{if eq .Buyer.Document.Type "CNPJ"}} 20 "trade_name": "{{truncateOnly (onlyAlphanumerics (onlyOneSpace .Buyer.Name)) 50}}" 21 {{else}} 22 "trade_name": null 23 {{end}} 24 } 25 {{if .Title.Fees.HasFine}} 26 ,"fine": { 27 "date": "{{enDate (datePlusDays .Title.ExpireDateTime .Title.Fees.Fine.DaysAfterExpirationDate) "-"}}", 28 {{if .Title.Fees.Fine.HasAmountInCents}} 29 "value": "{{float64ToStringTruncate "%.2f" 2 (convertAmountInCentsToPercent .Title.AmountInCents .Title.Fees.Fine.AmountInCents)}}" 30 {{else}} 31 "value": "{{float64ToString "%.2f" .Title.Fees.Fine.PercentageOnTotal}}" 32 {{end}} 33 } 34 {{end}} 35 {{if .Title.Fees.HasInterest}} 36 ,"interest": { 37 "date": "{{enDate (datePlusDays .Title.ExpireDateTime .Title.Fees.Interest.DaysAfterExpirationDate) "-"}}", 38 {{if .Title.Fees.Interest.HasAmountPerDayInCents}} 39 "value": "{{float64ToStringTruncate "%.2f" 2 (convertAmountInCentsToPercentPerDay .Title.AmountInCents .Title.Fees.Interest.AmountPerDayInCents)}}" 40 {{else}} 41 "value": "{{float64ToString "%.2f" .Title.Fees.Interest.PercentagePerMonth}}" 42 {{end}} 43 } 44 {{end}} 45 }` 46 47 const templateResponse = ` 48 { 49 "barcode": "{{barCodeNumber}}", 50 "our_number": "{{ourNumber}}", 51 "writable_line": "{{digitableLine}}" 52 } 53 ` 54 55 const templateError = ` 56 { 57 "reason": "{{messageError}}", 58 "type": "{{errorCode}}" 59 } 60 ` 61 62 const templateAPI = ` 63 { 64 {{if (hasErrorTags . "errorCode") | (hasErrorTags . "messageError")}} 65 "Errors": [ 66 { 67 {{if (hasErrorTags . "errorCode")}} 68 "Code": "{{trim .errorCode}}", 69 {{end}} 70 {{if (eq .messageError "{}")}} 71 "Message": "{{trim .errorCode}}" 72 {{else}} 73 "Message": "{{trim .messageError}}" 74 {{end}} 75 } 76 ] 77 {{else}} 78 "DigitableLine": "{{fmtDigitableLine (trim .digitableLine)}}", 79 "BarCodeNumber": "{{trim .barCodeNumber}}", 80 "OurNumber": "{{.ourNumber}}" 81 {{end}} 82 } 83 `