# プロモーションコードを適用する

カートにコードを適用します。プロモーションコードを適用すると、カート全体の割引、または選択したアイテムの割引を反映するようにカートの合計金額が再計算されます。ボーナスアイテムもカートに追加される場合があります。割引はチェックアウト時に適用され、ボーナスアイテムは支払いが成功した後に付与されます。支払前にユーザーはプロモーションコードを削除することができ、その場合、割引がキャンセルされ、ボーナスアイテムがカートから削除されます。

Endpoint: POST /v2/project/{project_id}/promocode/redeem
Version: 2.0.0
Security: AuthForCart

## Path parameters:

  - `project_id` (integer, required)
    プロジェクトID。このパラメータは、パブリッシャーアカウントのプロジェクト名の横、またはプロジェクトの作業中にブラウザのアドレスバーで確認できます。URLの形式は以下の通りです：https://publisher.xsolla.com//projects/。
    Example: 44056

## Request fields (application/json):

  - `coupon_code` (string)
    プロモーションコードの一意のコード。文字と数字が含まれています。
    Example: "SUMMER2021"

  - `cart` (object,null)

  - `cart.id` (string, required)
    カートID。

  - `selected_unit_items` (object)
    ユーザーがボーナスとして選択した、プラットフォーム指定のゲームキー。[受け取った](/ja/api/liveops/promotions-coupons/get-coupon-rewards-by-code#promotions-coupons/get-coupon-rewards-by-code/t=response&c=200&path=bonus/item)bonus.item.skuをキーとして渡し、選択されたbonus.item.unit_items.skuを値として渡します。

## Response 200 fields (application/json):

  - `cart_id` (string)
    カートID。
    Example: "cart_id"

  - `price` (object,null)
    カート価格。
    Example: {"amount":"6150.0000000000000000","amount_without_discount":"6150.0000000000000000","currency":"USD"}

  - `price.amount` (string)
    Example: "6150.0000000000000000"

  - `price.amount_without_discount` (string)
    Example: "6150.0000000000000000"

  - `price.currency` (string)
    Example: "USD"

  - `is_free` (boolean)
    アイテムが無料かどうか。

  - `items` (array)
    Example: [{"attributes":[],"description":"Take it, take it all! All of Xsolla's riches in one Mega Booster.","groups":[{"external_id":"powerups","name":"Power Ups"}],"image_url":"https://cdn.xsolla.net/img/misc/images/e9f2f4a634bc96ea03b5d5ceadd7c55f.png","is_free":false,"name":"Xsolla Booster Mega","price":{"amount":"50.0000000000000000","amount_without_discount":"100.0000000000000000","currency":"USD"},"quantity":123,"sku":"com.xsolla.booster_mega_1","type":"virtual_good","virtual_item_type":"consumable","virtual_prices":[],"promotions":[{"name":"Bonus promotion","date_start":"2020-04-15T16:16:00+03:00","date_end":"2026-04-15T16:16:00+03:00","discount":{"percent":"50.00"},"bonus":[{"quantity":1,"name":"Xsolla Minigun","image_url":"https://cdn.xsolla.net/img/misc/images/2fc5c491a47413a8e8000447889093c2.png","sku":"com.xsolla.minigun_1","type":"virtual_good"}]}],"can_be_bought":true,"vp_rewards":[{"item_id":175232,"sku":"com.xsolla.value_point_1","amount":130,"name":"Value point","image_url":"https://cdn3.xsolla.com/img/misc/images/54c0cf9d345817cdacfdde198db178e0.jpg","is_clan":false},{"item_id":186321,"sku":"com.xsolla.clan_value_point_1","amount":50,"name":"Clan Reward VP 1","image_url":"https://cdn3.xsolla.com/img/misc/images/54c0cf9d345817cdacfdde198db178e0.jpg","is_clan":true}],"limits":{"per_user":{"available":3,"recurrent_schedule":{"interval_type":"weekly","reset_next_date":1746057600},"total":5}},"periods":[{"date_from":"2020-08-11T10:00:00+03:00","date_until":"2020-08-11T20:00:00+03:00"}]}]

  - `items.sku` (string)

  - `items.groups` (array)

  - `items.groups.external_id` (string)

  - `items.groups.name` (string)

  - `items.name` (string,null)

  - `items.type` (string)

  - `items.description` (string)

  - `items.image_url` (string)

  - `items.quantity` (integer)

  - `items.is_free` (boolean)
    アイテムが無料かどうか。

  - `items.promotions` (array)
    カート内の特定アイテムに適用されるプロモーション。この配列は、以下のケースで返されます：

* 特定のアイテムに対して、割引キャンペーンが構成されている場合。

* 選択されたアイテムの割引設定を持つプロモーションコードが適用された場合。

アイテムレベルのプロモーションが適用されない場合は、空の配列が返されます。

  - `items.promotions.name` (string)

  - `items.promotions.date_start` (string,null)

  - `items.promotions.date_end` (string,null)

  - `items.promotions.discount` (object,null)

  - `items.promotions.discount.percent` (string,null)

  - `items.promotions.discount.value` (string,null)

  - `items.promotions.bonus` (array)

  - `items.promotions.bonus.sku` (string)

  - `items.promotions.bonus.quantity` (integer)

  - `items.promotions.bonus.type` (string)
    ボーナスアイテムタイプ。
    Enum: "virtual_good", "virtual_currency", "bundle", "physical_good", "game_key", "nft"

  - `items.promotions.bonus.name` (string)
    ボーナスアイテムの名前です。ボーナスアイテムのタイプphysical_goodでは使用できません。

  - `items.promotions.bonus.image_url` (string)
    ボーナスアイテムの画像URLです。ボーナスアイテムのタイプphysical_goodでは使用できません。

  - `items.promotions.bonus.bundle_type` (string)
    ボーナスバンドルアイテムタイプ。ボーナスアイテムタイプbundleのみで利用可能です。
    Enum: "standard", "virtual_currency_package"

  - `items.promotions.limits` (object)

  - `items.promotions.limits.per_user` (object)

  - `items.promotions.limits.per_user.available` (integer)

  - `items.promotions.limits.per_user.total` (integer)

  - `items.can_be_bought` (boolean)
    trueの場合、ユーザーはアイテムを購入することができます。

  - `items.vp_rewards` (array)
    アイテムのバリューポイント報酬のリスト。

  - `items.vp_rewards.item_id` (integer)
    内部の一意のアイテムID。

  - `items.vp_rewards.sku` (string)
    一意のバリューポイントID。

  - `items.vp_rewards.amount` (integer)
    バリューポイントの量。

  - `items.vp_rewards.name` (string)
    バリューポイント名。

  - `items.vp_rewards.image_url` (string)
    画像URL。

  - `items.vp_rewards.is_clan` (boolean)
    バリューポイントがクランリワードチェーンで使用されるかどうか。

  - `items.loyalty_rewards` (array)
    アイテムを購入した際の報酬としてユーザーが付与されるロイヤルティポイント。

  - `items.loyalty_rewards.name` (string)
    ロイヤリティポイント名。

  - `items.loyalty_rewards.sku` (string)
    ロイヤルティポイントのSKUです。ロイヤルティポイントで支払う注文を作成する場合など、他のAPIコールのloyalty_point_skuパラメータにこの値を渡してください。

  - `items.loyalty_rewards.description` (string)
    ロイヤルティポイントの説明。

  - `items.loyalty_rewards.image_url` (string,null)
    画像URL。

  - `items.loyalty_rewards.amount` (integer)
    アイテムを購入した際にユーザーが付与されるロイヤルティポイントの数。

  - `items.limits` (object,null)
    アイテム制限。

  - `items.limits.per_user` (object,null)
    ユーザーのアイテム制限。

  - `items.limits.per_user.total` (integer)
    1ユーザーあたりのユーザーが購入できるアイテムの最大数。
    Example: 5

  - `items.limits.per_user.available` (integer)
    現在のユーザーが購入できるアイテムの残り数。
    Example: 3

  - `items.limits.per_user.recurrent_schedule` (any)

  - `items.limits.per_user.limit_exceeded_visibility` (string)
    購入制限に達してから次回の制限リセットまでの間、カタログ内でのアイテムの表示・非表示を決定します。

これは、recurrent_schedule配列で定期的な制限リセットが設定されているアイテムに適用されます。

購入制限のリセットが設定されていない場合、購入制限に達した後は、limit_exceeded_visibilityの値に関わらず、そのアイテムはカタログに表示されなくなります。

指定可能な値：
- show — 購入制限に達した後も、カタログ取得用のAPIコールに対してアイテム情報が返却されます。クライアント側のカタログ取得APIコールにおいては、制限に達した時点でアイテムにcan_be_bought: falseフラグが付与されて返されます。次回のリセット日時はreset_next_dateに格納されて返却されます。
- hide — 購入制限に達した時点から、制限値がリセットされるまでの間、カタログ取得用のAPIコールにおいてアイテムは返されなくなります。
    Enum: "show", "hide"

  - `items.limits.per_item` (object,null)
    アイテムのアイテム制限。

  - `items.limits.per_item.total` (integer)
    すべてのユーザーが購入できるアイテムの最大数。
    Example: 5

  - `items.limits.per_item.available` (integer)
    すべてのユーザーが購入できるアイテムの残り数。
    Example: 3

  - `items.periods` (array,null)
    アイテム販売期間。

  - `items.periods.date_from` (string)
    指定されたアイテムの販売開始日。
    Example: "2020-08-11T10:00:00+03:00"

  - `items.periods.date_until` (string,null)
    指定されたアイテムが販売できなくなる日付。nullを指定することもできます。
    Example: "2020-08-11T20:00:00+03:00"

  - `rewards` (object)

  - `rewards.bonus` (array)

  - `rewards.bonus.item` (object)

  - `rewards.bonus.item.sku` (string)
    一意のアイテムID。SKUには、小文字と大文字のラテン英数字、ピリオド、ダッシュ、およびアンダースコアのみが含まれます。
    Example: "game_01"

  - `rewards.bonus.item.name` (string)
    アイテム名。
    Example: "Game name"

  - `rewards.bonus.item.type` (string)
    アイテムタイプ。可能な値：virtual_good — 仮想アイテムvirtual_currency — 仮想通貨bundle — バンドルunit — ゲームキーパッケージ
    Example: "unit"

  - `rewards.bonus.item.description` (string)
    アイテムの説明。
    Example: "Game description"

  - `rewards.bonus.item.image_url` (string)
    画像URL。
    Example: "https://cdn.xsolla.net/img/misc/images/b79342cdf24f0f8557b63c87e8326e62.png"

  - `rewards.bonus.item.unit_items` (array)
    プラットフォーム指定のゲームキーの配列。アイテムタイプがunit (bonus.item.type = 'unit')の場合にのみ使用されます。ゲームキーパッケージにプラットフォーム指定のキーが含まれている場合、ユーザーはそのうちの1つをボーナスとして選択できます。

  - `rewards.bonus.item.unit_items.sku` (string)
    プラットフォーム指定のゲームキーパッケージの一意のID。使用可能な文字：a-z、A-Z、0-9、ピリオド（.）、ハイフン（-）、アンダースコア（_）。これはbonus.item.​skuとbonus.item.unit_items.drm_skuの値を組み合わせたものです。例えば、bonus.item.​sku = 'cool_game'とbonus.item.unit_items.drm_sku = 'steam'の場合、値はcool_game_steamになります。
    Example: "cool_game_steam"

  - `rewards.bonus.item.unit_items.is_free` (boolean)

  - `rewards.bonus.item.unit_items.type` (string)
    アイテムがゲームキーであることを示します。
    Enum: "game_key"

  - `rewards.bonus.item.unit_items.name` (string)
    ゲームタイトル。
    Example: "Awesome Game"

  - `rewards.bonus.item.unit_items.drm_name` (string)
    DRM名。
    Example: "Steam"

  - `rewards.bonus.item.unit_items.drm_sku` (string)
    プラットフォーム固有のゲームキーであることを示すサフィックスとして使用される、一意のDRM ID。使用可能な文字：a-z、A-Z、0-9、ピリオド（.）、ハイフン（-）、アンダースコア（_）。
    Example: "steam"

  - `rewards.bonus.quantity` (number)
    アイテム数量。

  - `rewards.discount` (object,null)
    割引率。
カートの価格は、この割引率で計算された値で減少し、小数点以下2桁に四捨五入されます。

  - `rewards.discount.percent` (string)
    Example: "10.00"

  - `rewards.discounted_items` (array,null)
    プロモーションコードによる割引が適用されるアイテムリスト。

  - `rewards.discounted_items.sku` (string, required)
    アイテムSKU。

  - `rewards.discounted_items.discount` (object, required)

  - `rewards.discounted_items.discount.percent` (string, required)
    割引率。

カートアイテムの価格は、この割引率で
計算された値で減少し、
小数点以下2桁に四捨五入されます。

  - `rewards.is_selectable` (boolean)
    trueの場合、ユーザーはプロモーションコードを引き換える前にボーナスを選択する必要があります。

## Response 401 fields (application/json):

  - `statusCode` (integer)
    Example: 401

  - `errorCode` (integer)
    Example: 1501

  - `errorMessage` (string)
    Example: "[0401-1501]: Authorization failed: Provide authorization"

## Response 403 fields (application/json):

  - `statusCode` (integer)
    Example: 403

  - `errorCode` (integer)

  - `errorMessage` (string)
    Example: "Authorization header not sent."

  - `transactionId` (string)
    Example: "x-x-x-x-transactionId-mock-x-x-x"

## Response 404 fields (application/json):

  - `statusCode` (integer)
    Example: 404

  - `errorCode` (integer)
    Example: 4001

  - `errorMessage` (string)
    Example: "[0401-9807]: Enter valid promo code."

## Response 422 fields (application/json):

  - `statusCode` (integer)
    Example: 422

  - `errorCode` (integer)
    Example: 1102

  - `errorMessage` (string)
    Example: "[0401-1102]: Unprocessable Entity. The property `coupon_code` is required"

  - `transactionId` (string)
    Example: "x-x-x-x-transactionId-mock-x-x-x"


