浏览代码

add the fields on backend need dont finished

gdias 3 周之前
父节点
当前提交
307a4e1f7e
共有 1 个文件被更改,包括 35 次插入0 次删除
  1. 35 0
      controllers/B3CprRegisterController.php

+ 35 - 0
controllers/B3CprRegisterController.php

@@ -25,6 +25,35 @@ class B3CprRegisterController
         $this->paymentModel = new PaymentModel();
     }
 
+    private function applyFixedCprDefaults(array $cpr): array
+    {
+        $nowBr = new \DateTimeImmutable('now', new \DateTimeZone('America/Sao_Paulo'));
+        $currentDate = $nowBr->format('Y-m-d');
+
+        $cpr['cpr_type_code'] = 'P';
+        $cpr['cpr_otc_register_account_code'] = '64359.40-5';
+        $cpr['cpr_otc_payment_agent_account_code'] = '64359.40-5';
+        $cpr['cpr_otc_custodian_account_code'] = '64359.00-3';
+        $cpr['cpr_electronic_emission_indicator'] = 'S';
+        $cpr['cpr_automatic_expiration_indicator'] = 'N';
+        $cpr['cpr_issue_date'] = $currentDate;
+        $cpr['cpr_profitability_start_date'] = $currentDate;
+        $cpr['cpr_issue_quantity'] = '1';
+
+        if (!array_key_exists('cpr_issue_value', $cpr)) {
+            throw new \InvalidArgumentException('Missing field: cpr_issue_value');
+        }
+        $issueValue = (string)$cpr['cpr_issue_value'];
+        $cpr['cpr_issue_financial_value'] = $issueValue;
+
+        $cpr['cpr_creditor_name'] = 'TOO EASY TRADING LTDA';
+        $cpr['cpr_creditor_document_number'] = '47.175.222/0001-09';
+        $cpr['cpr_scr_type_code'] = 'N';
+        $cpr['cpr_finality_code'] = '6099';
+
+        return $cpr;
+    }
+
     public function __invoke(ServerRequestInterface $request)
     {
         $body = json_decode((string)$request->getBody(), true);
@@ -61,6 +90,12 @@ class B3CprRegisterController
             return ResponseLib::sendFail('Missing CPR payload (array) in body as cpr', [], 'E_VALIDATE')->withStatus(400);
         }
 
+        try {
+            $cpr = $this->applyFixedCprDefaults($cpr);
+        } catch (\InvalidArgumentException $e) {
+            return ResponseLib::sendFail($e->getMessage(), [], 'E_VALIDATE')->withStatus(400);
+        }
+
         $userId = (int)($request->getAttribute('api_user_id') ?? 0);
         if ($userId <= 0) {
             return ResponseLib::sendFail('Authenticated user not found', [], 'E_VALIDATE')->withStatus(401);