# 통합 결제 설정

원문: https://commerce.bootpay.ai/api/marketplace/group-aggregate

> 고객 그룹의 구독 통합 결제를 켜고 결제일을 정합니다. 그룹 안의 구독을 월 또는 주 단위로 정한 날에 한꺼번에 결제하고, 보내지 않은 값은 그대로 둡니다.

고객 그룹의 구독 통합 결제(Aggregate Transaction) 설정을 바꿉니다. 그룹 안의 구독을 정해 둔 결제일에 한꺼번에 결제합니다.

## API 엔드포인트

::: endpoint
method: PUT
url: https://api.bootapi.com/v1/user-groups/:id/aggregate-transaction
auth: [Basic Auth](https://commerce.bootpay.ai/api/server/authentication)
scope: manager:aggregate_transaction
:::

이 scope 는 Bootpay-Role 헤더와 상관없이 검사합니다. [v1 회원 그룹 API 상세 명세](https://commerce.bootpay.ai/api/reference/v1/user-groups)에서 인증과 응답 필드를 확인합니다.

## 요청 파라미터

::: parameters

| 파라미터 | 타입 | 필수 | 설명 |
|---------|------|------|------|
| id | String | Y | 그룹 고유 ID (URL 파라미터) |
| use_subscription_aggregate_transaction | Boolean | N | 통합 결제 사용 여부 |
| subscription_month_day | Integer | N | 월 단위 결제일 (1~21 권장) |
| subscription_week_day | Integer | N | 주 단위 결제일. `1`(월)~`5`(금) — [주 단위 결제일](#주-단위-결제일-subscription_week_day) 참고 |

:::

::: tip
보내지 않은 값은 기존 설정을 유지합니다. 서버는 결제일 값의 범위를 검사하지 않으므로 유효한 값을 보냅니다. 월 결제일은 1~21 사이를 권장합니다. 28일 이후는 월마다 일수가 달라 예측이 어렵습니다.
:::

## 코드 예제

::: code-group

```bash [cURL]
curl -X PUT "https://api.bootapi.com/v1/user-groups/67e2052b03d0cb4e4117b0af/aggregate-transaction" \
  -H "Authorization: Basic {base64(client_key:secret_key)}" \
  -H "Bootpay-Role: manager" \
  -H "Content-Type: application/json" \
  -d '{
    "use_subscription_aggregate_transaction": true,
    "subscription_month_day": 15,
    "subscription_week_day": 3
  }'
```

```javascript [Node.js]
import { BootpayCommerce } from '@bootpay/backend-js';

const commerce = new BootpayCommerce({
    client_key: '{client_key}',
    secret_key: '{secret_key}'
});

const userGroupId = '67e2052b03d0cb4e4117b0af';
const response = await commerce.userGroup.aggregateTransaction({
    user_group_id: userGroupId,
    use_subscription_aggregate_transaction: true,
    subscription_month_day: 15,  // 매월 15일
    subscription_week_day: 3     // 매주 수요일
});
console.log(response);
```

```python [Python]
from bootpay_backend.commerce import BootpayCommerce

commerce = BootpayCommerce('{client_key}', '{secret_key}')
user_group_id = '67e2052b03d0cb4e4117b0af'
response = commerce.user_group.aggregate_transaction({
    'user_group_id': user_group_id,
    'use_subscription_aggregate_transaction': True,
    'subscription_month_day': 15,
    'subscription_week_day': 3
})
print(response)
```

```php [PHP]
use Bootpay\ServerPhp\BootpayCommerceApi;

$commerce = new BootpayCommerceApi("{client_key}", "{secret_key}");
$userGroupId = '67e2052b03d0cb4e4117b0af';
$response = $commerce->userGroup->aggregateTransaction([
    'user_group_id' => $userGroupId,
    'use_subscription_aggregate_transaction' => true,
    'subscription_month_day' => 15,
    'subscription_week_day' => 3
]);
print_r($response);
```

```java [Java]
import kr.co.bootpay.store.BootpayStore;
import kr.co.bootpay.store.model.request.TokenPayload;
import kr.co.bootpay.store.model.request.userGroup.UserGroupAggregateTransactionParams;

TokenPayload tokenPayload = new TokenPayload("{client_key}", "{secret_key}");
BootpayStore bootpay = new BootpayStore(tokenPayload).withToken();
UserGroupAggregateTransactionParams params = new UserGroupAggregateTransactionParams();
params.userGroupId = "67e2052b03d0cb4e4117b0af";
params.useSubscriptionAggregateTransaction = true;
params.subscriptionMonthDay = 15;
params.subscriptionWeekDay = 3;

var response = bootpay.userGroup.aggregateTransaction(params);
System.out.println(response.getData());
```

```ruby [Ruby]
require 'bootpay'

commerce = BootpayStore::RestClient.new(client_key: '{client_key}', secret_key: '{secret_key}')
user_group_id = '67e2052b03d0cb4e4117b0af'
response = commerce.user_group_aggregate_transaction(
  user_group_id: user_group_id,
  use_subscription_aggregate_transaction: true,
  subscription_month_day: 15,
  subscription_week_day: 3
)
puts response.data
```

```go [Go]
commerce := bootpay.NewCommerceAPI("{client_key}", "{secret_key}", nil, "production")
userGroupId := "67e2052b03d0cb4e4117b0af"
response, err := commerce.UserGroup.AggregateTransaction(bootpay.UserGroupAggregateTransactionParams{
    UserGroupId:                         userGroupId,
    UseSubscriptionAggregateTransaction: true,
    SubscriptionMonthDay:                15,
    SubscriptionWeekDay:                 3,
})
fmt.Println(response, err)
```

```csharp [.NET]
using Bootpay.Commerce;
using Bootpay.Commerce.Models;

var commerce = new BootpayCommerceApi("{client_key}", "{secret_key}");
var userGroupId = "67e2052b03d0cb4e4117b0af";
var response = await commerce.UserGroupAggregateTransaction(new UserGroupAggregateTransactionParams {
    UserGroupId = userGroupId,
    UseSubscriptionAggregateTransaction = true,
    SubscriptionMonthDay = 15,
    SubscriptionWeekDay = 3
});
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

:::

## 응답

#### 성공 응답

```json
{
  "use_subscription_aggregate_transaction": true,
  "subscription_month_day": 15,
  "subscription_week_day": 3
}
```

## 주 단위 결제일 (`subscription_week_day`)

요일 번호입니다. enum 키가 아니라 **숫자 그대로** 주고받습니다. `0`(일요일)부터 시작하는 체계라
`Date#wday`·JavaScript `getDay()` 와 같은 번호입니다.

| 값 | 요일 | 선택 가능 |
|----|------|:--------:|
| `0` | 일요일 | — |
| `1` | 월요일 | ✅ |
| `2` | 화요일 | ✅ |
| `3` | 수요일 | ✅ |
| `4` | 목요일 | ✅ |
| `5` | 금요일 | ✅ |
| `6` | 토요일 | — |

::: warning 주말(`0`·`6`)은 지원하지 않습니다
관리자 화면이 월~금만 제공해서, 실제로 설정되는 값은 `1`~`5` 입니다.

API 는 이 값을 검사하지 않아서 `0`(일)·`6`(토)을 보내면 오류 없이 그대로 저장됩니다. 하지만 지원 대상이 아니라
동작을 보장하지 않으니 평일 값만 보냅니다.
:::

## 에러 코드

::: info 공통 에러
인증·권한 관련 에러는 [에러 코드표](https://commerce.bootpay.ai/api/reference/codes#커머스-api-인증-에러)를 참고합니다.
:::

::: error-codes

| 코드 | 메시지 | 대처 방법 |
|------|--------|-----------|
| `USER_GROUP_NOT_FOUND` | 회원 그룹 정보를 찾지 못했습니다. 다시 로그인 해주세요. | user_group_id를 확인합니다 |
| `USER_GROUP_NOT_AUTHORIZED` | 그룹 정보를 설정할 권한이 없습니다. | 이 프로젝트의 그룹인지 확인합니다 |

:::
