# API Tạo Công ty

- Anchor: `bankhub-vi-api-cong-ty-tao-cong-ty`
- URL: https://developer.sepay.vn/vi/bankhub/api/cong-ty/tao-cong-ty.md
- Description: API tạo công ty mới trong hệ thống Bank Hub. Cho phép tạo công ty với tên và trạng thái ban đầu.

#### API Endpoint
**POST** `https://bankhub-api-sandbox.sepay.vn/v1/company/create`

API tạo công ty mới trong hệ thống Bank Hub.

**Authentication:** bearerAuth

#### Request Body

**Request Body:**

- `full_name` (string, **required**): Tên đầy đủ của công ty
- `status` (enum: `Active`, `Pending`, **required**): Trạng thái ban đầu của công ty

> **Lưu ý** (info)
> - API này yêu cầu Bearer Token trong header Authorization
> - Tên công ty phải là duy nhất trong phạm vi merchant
> - Status nên được set là `Active` khi tạo để công ty có thể sử dụng ngay
> - Công ty sau khi tạo sẽ nhận được một `xid` duy nhất (UUID format)

#### Xử lý lỗi

#### API Response
**Response 201:** Tạo công ty thành công

**Response 400:** Validation error

**Response 401:** 

**Response 503:** Lỗi database

#### Code mẫu
**cURL:**
```bash
curl --request POST \
  --url https://bankhub-api-sandbox.sepay.vn/v1/company/create \
  --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
  --header 'content-type: application/json' \
  --data '{"full_name":"string","status":"Active"}'
```

**PHP:**
```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://bankhub-api-sandbox.sepay.vn/v1/company/create",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\"full_name\":\"string\",\"status\":\"Active\"}",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer REPLACE_BEARER_TOKEN",
    "content-type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

**Python:**
```python
import http.client

conn = http.client.HTTPSConnection("bankhub-api-sandbox.sepay.vn")

payload = "{\"full_name\":\"string\",\"status\":\"Active\"}"

headers = {
    'Authorization': "Bearer REPLACE_BEARER_TOKEN",
    'content-type': "application/json"
    }

conn.request("POST", "/v1/company/create", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
```

**NodeJS:**
```javascript
const http = require("https");

const options = {
  "method": "POST",
  "hostname": "bankhub-api-sandbox.sepay.vn",
  "port": null,
  "path": "/v1/company/create",
  "headers": {
    "Authorization": "Bearer REPLACE_BEARER_TOKEN",
    "content-type": "application/json"
  }
};

const req = http.request(options, function (res) {
  const chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    const body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({full_name: 'string', status: 'Active'}));
req.end();
```

**Java:**
```java
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"full_name\":\"string\",\"status\":\"Active\"}");
Request request = new Request.Builder()
  .url("https://bankhub-api-sandbox.sepay.vn/v1/company/create")
  .post(body)
  .addHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN")
  .addHeader("content-type", "application/json")
  .build();

Response response = client.newCall(request).execute();
```

**Ruby:**
```ruby
require 'uri'
require 'net/http'
require 'openssl'

url = URI("https://bankhub-api-sandbox.sepay.vn/v1/company/create")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer REPLACE_BEARER_TOKEN'
request["content-type"] = 'application/json'
request.body = "{\"full_name\":\"string\",\"status\":\"Active\"}"

response = http.request(request)
puts response.read_body
```

**Go:**
```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://bankhub-api-sandbox.sepay.vn/v1/company/create"

	payload := strings.NewReader("{\"full_name\":\"string\",\"status\":\"Active\"}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer REPLACE_BEARER_TOKEN")
	req.Header.Add("content-type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

**.NET:**
```csharp
var client = new HttpClient();
var request = new HttpRequestMessage
{
    Method = HttpMethod.Post,
    RequestUri = new Uri("https://bankhub-api-sandbox.sepay.vn/v1/company/create"),
    Headers =
    {
        { "Authorization", "Bearer REPLACE_BEARER_TOKEN" },
    },
    Content = new StringContent("{\"full_name\":\"string\",\"status\":\"Active\"}")
    {
        Headers =
        {
            ContentType = new MediaTypeHeaderValue("application/json")
        }
    }
};
using (var response = await client.SendAsync(request))
{
    response.EnsureSuccessStatusCode();
    var body = await response.Content.ReadAsStringAsync();
    Console.WriteLine(body);
}
```

**Swift:**
```swift
import Foundation

let headers = [
  "Authorization": "Bearer REPLACE_BEARER_TOKEN",
  "content-type": "application/json"
]
let parameters = [
  "full_name": "string",
  "status": "Active"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://bankhub-api-sandbox.sepay.vn/v1/company/create")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

**Kotlin:**
```kotlin
val client = OkHttpClient()

val mediaType = MediaType.parse("application/json")
val body = RequestBody.create(mediaType, "{\"full_name\":\"string\",\"status\":\"Active\"}")
val request = Request.Builder()
  .url("https://bankhub-api-sandbox.sepay.vn/v1/company/create")
  .post(body)
  .addHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN")
  .addHeader("content-type", "application/json")
  .build()

val response = client.newCall(request).execute()
```

---

### Ví dụ sử dụng

---

> **Lưu ý quan trọng** (warn)
> - **Có thể lưu trữ company ID**: Sau khi tạo, hãy lưu `xid` để sử dụng cho các API khác

---
