cpr_create.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. BASE_URL="${BASE_URL:-https://api.tooeasy.mixtech.dev.br}"
  4. JWT_TOKEN="${JWT_TOKEN:-eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjEsImVtYWlsIjoiYWRtaW5AbHVteW9uLnRlY2giLCJpYXQiOjE3NjQ3MDkxNzMsImV4cCI6MTc2NDcxMjc3M30.2ZUmjLPxe3RIQoY7LgzrrwKKjj4FuKKOaQIZoaG8QPo}"
  5. PAYLOAD_FILE="${1:-}"
  6. usage() {
  7. cat <<'USAGE'
  8. Usage: JWT_TOKEN=<token> ./cpr_create.sh <payload.json>
  9. Environment variables:
  10. BASE_URL Base URL of the API (default: https://api.tooeasy.mixtech.dev.br)
  11. JWT_TOKEN Bearer token used for Authorization header (required)
  12. Arguments:
  13. <payload.json> Optional path to the JSON payload body. If omitted, a template is used.
  14. USAGE
  15. }
  16. if [[ -z "$JWT_TOKEN" ]]; then
  17. echo "[error] JWT_TOKEN environment variable must be set" >&2
  18. usage
  19. exit 1
  20. fi
  21. API_ENDPOINT="$BASE_URL/cpr/create"
  22. if [[ -n "$PAYLOAD_FILE" ]]; then
  23. if [[ ! -f "$PAYLOAD_FILE" ]]; then
  24. echo "[error] Payload file '$PAYLOAD_FILE' not found" >&2
  25. exit 1
  26. fi
  27. PAYLOAD_CONTENT=$(<"$PAYLOAD_FILE")
  28. else
  29. read -r -d '' PAYLOAD_CONTENT <<'JSON' || true
  30. {
  31. "cpr_type_code": "TEMPLATE",
  32. "cpr_otc_register_account_code": "REG-001",
  33. "cpr_otc_payment_agent_account_code": "PAY-001",
  34. "cpr_otc_custodian_account_code": "CUS-001",
  35. "cpr_internal_control_number": "ICN-0001",
  36. "cpr_electronic_emission_indicator": "Y",
  37. "cpr_isin_code": "BR1234567890",
  38. "cpr_issue_date": "2024-01-01",
  39. "cpr_maturity_date": "2025-01-01",
  40. "cpr_issue_quantity": "1000",
  41. "cpr_issue_value": "500000",
  42. "cpr_issue_financial_value": "500000",
  43. "cpr_unit_value": "500",
  44. "cpr_reference_date": "2024-01-01",
  45. "cpr_profitability_start_date": "2024-02-01",
  46. "cpr_automatic_expiration_indicator": "N",
  47. "cpr_collateral_type_code": "COLL",
  48. "cpr_collateral_type_name": "Collateral",
  49. "cpr_constitution_process_indicator": "MANUAL",
  50. "cpr_otc_bondsman_account_code": "BOND-001",
  51. "cpr_collaterals_document_number": "DOC-COLL-123",
  52. "cpr_product_name": "Soy",
  53. "cpr_product_class_name": "Grain",
  54. "cpr_product_harvest": "2024",
  55. "cpr_product_description": "Template product description",
  56. "cpr_product_quantity": "100",
  57. "cpr_measure_unit_name": "TON",
  58. "cpr_packaging_way_name": "Bulk",
  59. "cpr_product_status_code": "READY",
  60. "cpr_production_type_code": "AGR",
  61. "cpr_issuer_name": "Issuer Name",
  62. "cpr_finality_code": "FIN",
  63. "cpr_ipoc_code": "IPO-001",
  64. "cpr_calculation_type_code": "SIMPLE",
  65. "cpr_initial_exchange_value": "10000",
  66. "cpr_fixing_type_code": "FIXED",
  67. "cpr_data_source_type_code": "MANUAL",
  68. "cpr_adjustment_frequency_type_code": "ANNUAL",
  69. "cpr_adjustment_pro_rata_type_code": "DAY",
  70. "cpr_adjustment_type_code": "FIXED",
  71. "cpr_creditor_name": "Creditor",
  72. "cpr_ballast_type_code": "BAL",
  73. "cpr_lot_number": "LOT-001",
  74. "cpr_ballast_quantity": "100",
  75. "cpr_currency_code": "BRL",
  76. "cpr_transaction_identification": "TRX-001",
  77. "cpr_additional_text": "Additional notes",
  78. "cpr_number": "CPR-001",
  79. "cpr_contract_number": "CONT-001",
  80. "cpr_event_type_code": "EVT",
  81. "cpr_event_original_date": "2024-01-01",
  82. "cpr_unit_price_value": "5000",
  83. "cpr_interest_unit_price_value": "100",
  84. "cpr_residual_value": "10000",
  85. "cpr_amortization_percentage": "10",
  86. "cpr_event_quantity": "1",
  87. "cpr_production_place_name": "Farm",
  88. "cpr_property_registration_number": "REG-123",
  89. "cpr_notary_name": "Notary",
  90. "cpr_total_production_area_in_hectares_number": "100",
  91. "cpr_total_area_in_hectares_number": "120",
  92. "cpr_car_code": "CAR-123",
  93. "cpr_latitude_code": "-23.5505",
  94. "cpr_longitude_code": "-46.6333",
  95. "cpr_zip_code": "01000-000",
  96. "cpr_green_cpr_indicator": "N",
  97. "cpr_green_cpr_certificate_name": "Certificate",
  98. "cpr_green_cpr_certificate_cnpj_number": "12.345.678/0001-99",
  99. "cpr_green_cpr_georeferencing_description": "Geo desc",
  100. "cpr_green_cpr_declaration_indicator": "N",
  101. "cpr_document_deadline_days_number": "30",
  102. "cpr_place_name": "São Paulo",
  103. "cpr_guarantee_limit_type_code": "GLT",
  104. "cpr_mother_code": "MOM-001",
  105. "cpr_issuers_person_type_acronym": "PJ",
  106. "cpr_issuers_state_acronym": "SP",
  107. "cpr_issuers_city_name": "São Paulo",
  108. "cpr_issuers_ibge_code": "3550308",
  109. "cpr_issuer_legal_nature_code": "2046",
  110. "cpr_otc_favored_account_code": "FAV-001",
  111. "cpr_issuers_document_number": "12345678000199",
  112. "cpr_deposit_person_type_acronym": "PJ",
  113. "cpr_self_number": "SELF-001",
  114. "cpr_settlement_modality_type_code": "CASH",
  115. "cpr_otc_settlement_bank_account_code": "SET-001",
  116. "cpr_deposit_quantity": "100",
  117. "cpr_deposit_unit_price_value": "5000",
  118. "cpr_payment_method_code": "PIX",
  119. "cpr_index_code": "CDI",
  120. "cpr_index_short_name": "CDI",
  121. "cpr_vcp_indicator_type_code": "VAR",
  122. "cpr_indexador_percentage_value": "10",
  123. "cpr_interest_rate_spread_percentage": "2",
  124. "cpr_interest_rate_criteria_type_code": "SIMPLE",
  125. "cpr_interest_payment_date": "2024-07-01",
  126. "cpr_interest_payment_value": "10000",
  127. "cpr_interest_payment_frequency_code": "ANNUAL",
  128. "cpr_interest_months_quantity": "12",
  129. "cpr_interestPaymentFlow_time_unit_type_code": "MONTH",
  130. "cpr_interestPaymentFlow_deadline_type_code": "FIXED",
  131. "cpr_payment_start_date": "2024-02-01",
  132. "cpr_amortization_type_code": "LINEAR",
  133. "cpr_amortization_months_quantity": "12",
  134. "cpr_amortizationPaymentFlow_time_unit_type_code": "MONTH",
  135. "cpr_amortizationPaymentFlow_deadline_type_code": "FIXED",
  136. "cpr_amortization_start_date": "2024-03-01",
  137. "cpr_scr_type_code": "SCR",
  138. "cpr_scr_customer_detail": "Customer detail",
  139. "cpr_scr_person_type_acronym": "PJ",
  140. "cpr_deposit_document_number": "DEP-123456",
  141. "cpr_scr_document_number": "SCR-123456",
  142. "cpr_creditor_document_number": "CRED-123456",
  143. "cpr_contract_code": "CON-001",
  144. "cpr_operation_modality_type_code": "CRED",
  145. "cpr_bacen_reference_code": "12345",
  146. "cpr_deliveryPlace_state_acronym": "SP",
  147. "cpr_deliveryPlace_city_name": "São Paulo",
  148. "cpr_deliveryPlace_ibge_code": "3550308",
  149. "cpr_children_codes": ["CHD-001", "CHD-002"]
  150. }
  151. JSON
  152. fi
  153. echo "[info] Sending CPR payload '${PAYLOAD_FILE:-template}' to $API_ENDPOINT"
  154. response_body=$(mktemp)
  155. trap 'rm -f "$response_body"' EXIT
  156. http_code=$(curl --show-error --silent \
  157. -o "$response_body" \
  158. -w "%{http_code}" \
  159. -X POST "$API_ENDPOINT" \
  160. -H "Content-Type: application/json" \
  161. -H "Authorization: Bearer $JWT_TOKEN" \
  162. --data "$PAYLOAD_CONTENT")
  163. if [[ "$http_code" =~ ^2 ]]; then
  164. jq . <"$response_body"
  165. else
  166. echo "[error] Request failed with status $http_code" >&2
  167. cat "$response_body" >&2
  168. exit 1
  169. fi