# 添加折扣 用优惠券和促销码给客户的小计金额打折,降低向客户收取的金额。 # 完整托管页面 > This is a 完整托管页面 for when payment-ui is stripe-hosted. View the full page at https://docs.stripe.com/payments/checkout/discounts?payment-ui=stripe-hosted. 可以使用折扣来减少向客户收取的金额。使用优惠券和促销码,您可以: - 向整个订单小计应用折扣 - 向特定产品应用折扣 - 将总收款额降低一个百分比或固定金额 - 在优惠券的基础上创建供客户使用的促销码,直接分享给客户。 > 要通过优惠券给 Checkout 和 Billing *订阅* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis)打折,请查看[订阅折扣](https://docs.stripe.com/billing/subscriptions/coupons.md)。 ## 创建优惠券 优惠券指定一个固定值折扣。您可以创建供客户使用的促销码,映射到相关的单个优惠券。这意味着代码 `FALLPROMO` 和 `SPRINGPROMO` 两者都可指向一个 25% 折扣券。您可以在[管理平台](https://dashboard.stripe.com/coupons)中货使用 [API](https://docs.stripe.com/api.md#coupons) 创建优惠券: ```curl curl https://api.stripe.com/v1/coupons \ -u "<>:" \ -d percent_off=20 \ -d duration=once ``` ## 使用优惠券 如需创建应用了折扣的会话,需要在[折扣](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-discounts)数组的 `coupon` 参数中传递[优惠券 ID](https://docs.stripe.com/api/coupons/object.md#coupon_object-id)。目前,Checkout Sessions 最多支持使用一张优惠券或促销码。 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price]={{PRICE_ID}}" \ -d "line_items[0][quantity]=1" \ -d "discounts[0][coupon]={{COUPON_ID}}" \ -d mode=payment \ --data-urlencode "success_url=https://example.com/success" ``` ## 配置优惠券 优惠券具有以下参数,您可以用它来: - `currency` - `percent_off` 或 `amount_off` - `max_redemptions` - `redeem_by` 是客户可以应用优惠券的最后日期 - `applies_to`,限制优惠券可应用到哪些产品 > 优惠券对象可向一次性付款和订阅添加折扣。某些优惠券参数,如 `duration`,仅适用于[订阅](https://docs.stripe.com/billing/subscriptions/coupons.md)。 ### 限制兑换方式 `max_redemptions` 和 `redeem_by` 值会应用到每个应用中的优惠券。例如,您可以将某个优惠券限制在前 50 次使用,也可以通过一个特定日期来限制它的有效期。 ### 限制符合条件的产品 可以限制能够使用优惠券折扣的产品,方法是将产品 ID 添加到 Coupon 对象中的 `applies_to` 散列。映射到这个优惠券的任何促销码仅会引用到符合条件的产品列表。 ### 删除优惠券 优惠券可通过管理平台或 API 删除。删除优惠券可避免它被应用到未来的交易或客户。 ## 创建促销码 促销码是在优惠券的基础上创建的供客户使用的代码。还可以指定客户何时可应用该促销码的额外限制。您可以将这些代码分享给客户,他们输入 Checkout 中即可应用折扣。 要创建[促销码](https://docs.stripe.com/api/promotion_codes.md),请指定现有的 `coupon` 以及任何限制条件(例如,限制在特定 [customer](https://docs.stripe.com/api/promotion_codes/object.md#promotion_code_object-customer) 或 [customer_account](https://docs.stripe.com/api/promotion_codes/object.md#promotion_code_object-customer_account) 范围内)。如果您有特定的代码要给客户(例如,`FALL25OFF`),就要设置 `code`。如果您把此字段留空,我们将为您生成一个随机的 `code`。 这个 `code` 不区分大小写,任何客户的所有有效促销码都必须唯一。例如: - 可以用同一 `code` 创建多个有客户限制的促销码,但不能将这个 `code` 复用于任何客户可兑换的促销码。 - 如果您创建的一个促销码任何客户都可兑换,则不能再用同一个 `code` 来创建另一个有效的促销码。 - 可以先用 `code: NEWUSER` 创建一个促销码,传递 `active: false` 让它失效,然后再用 `code: NEWUSER` 创建一个新的促销码。 促销码可在[管理平台](https://dashboard.stripe.com/coupons/create)内的优惠券部分创建,也可通过 [API](https://docs.stripe.com/api.md#promotion_codes) 创建: ```curl curl https://api.stripe.com/v1/promotion_codes \ -u "<>:" \ -d coupon={{COUPON_ID}} \ -d code=VIPCODE ``` ## 使用促销码 在 Checkout Session 中使用 [allow_promotion_codes](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-allow_promotion_codes) 参数启用客户可兑换的促销码。这将启用 Checkout 中的一个字段,允许用户在其中输入促销码。 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d allow_promotion_codes=true \ --data-urlencode "success_url=https://example.com/success" ``` ## 配置促销码 对于每个促销码,您都可以自定义合格客户、兑换及其他限制。 ### 按客户限制 要将促销限定给特定客户,请在创建促销码时指定 [customer](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-customer) 或 [customer_account](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-customer_account)。如果没有指定客户,任何客户都可以兑换代码。 ### 按首次下单限制 您也可以通过 [restrictions.first_time_transaction](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-restrictions-first_time_transaction) 将促销码限制为首笔交易客户。如果未定义 `customer` 或 `customer_account`,或者定义的 `customer` 或 `customer_account` 没有过往支付记录或非作废的 *账单* (Invoices are statements of amounts owed by a customer. They track the status of payments from draft through paid or otherwise finalized. Subscriptions automatically generate invoices, or you can manually create a one-off invoice),则视为首笔交易。 > 未创建客户的 Sessions 会在管理平台中创建一个 [guest customer](https://docs.stripe.com/payments/checkout/guest-customers.md)。这些 Sessions 仍可接受限首笔交易客户的促销码。 ### 设置最低金额 使用促销码,您可以通过配置 [minimum_amount](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-restrictions-minimum_amount) 和 [minimum_amount_currency](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-restrictions-minimum_amount_currency) 来为符合条件的折扣设置最低交易金额。由于促销码的限制是在兑换时来检查的,因此最低交易金额仅适用于订阅的初次付款。 ### 自定义有效期 可以用 [expires_at](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-expires_at) 设置促销码的有效期。如果相关的优惠券已设置了 `redeem_by`,那么促销码的有效期不能晚于优惠券的这个值。如果未指定 `promotion_code[expires_at]`,则优惠券的 `redeem_by` 会自动生成 `expires_at`。 例如,您可能计划一年中都支持某个优惠券,但又想把它针对具体客户的有效时间设置为收到之后的一个星期之内。那么可以将 `coupon[redeem_by]` 设置为一年以后的时间,然后将每个 `promotion_code[expires_at]` 设置为创建之后的一个星期。 ### 限制兑换 可以用 [max_redemptions](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-max_redemptions) 限制兑换次数,其原理与优惠券参数类似。如果相关的优惠券已设置了 `max_redemptions`,那么促销码的 `max_redemptions` 不能大于优惠券的这个值。 例如,您可能想让前 50 位客户兑换季节促销优惠券,但冬季促销只能使用这其中的 20 次。该场景中,您可以设置 `coupon[max_redemptions]: 50` and `promotion_code[max_redemptions]: 20`。 ### 无效促销码 可以使用 [active](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-active) 参数设置促销码目前是否可兑换。但是,如果某个促销码的相关优惠券无效,它的所有促销码都会永久失效。同样,如果某个促销码达到了它的 `max_redemptions` 或 `expires_at`,则也会永久失效。您不能重新激活这些促销码。 ### 删除促销码 您可以在管理平台或 API 中删除促销码。删除促销码可避免它被应用到未来的交易或客户。 # 完整嵌入式页面 > This is a 完整嵌入式页面 for when payment-ui is embedded-page. View the full page at https://docs.stripe.com/payments/checkout/discounts?payment-ui=embedded-page. 可以使用折扣来减少向客户收取的金额。使用优惠券和促销码,您可以: - 向整个订单小计应用折扣 - 向特定产品应用折扣 - 将总收款额降低一个百分比或固定金额 - 在优惠券的基础上创建供客户使用的促销码,直接分享给客户。 > 要通过优惠券给 Checkout 和 Billing *订阅* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis)打折,请查看[订阅折扣](https://docs.stripe.com/billing/subscriptions/coupons.md)。 ## 创建优惠券 优惠券指定一个固定值折扣。您可以创建供客户使用的促销码,映射到相关的单个优惠券。这意味着代码 `FALLPROMO` 和 `SPRINGPROMO` 两者都可指向一个 25% 折扣券。您可以在[管理平台](https://dashboard.stripe.com/coupons)中货使用 [API](https://docs.stripe.com/api.md#coupons) 创建优惠券: ```curl curl https://api.stripe.com/v1/coupons \ -u "<>:" \ -d percent_off=20 \ -d duration=once ``` ## 使用优惠券 如需创建应用了折扣的会话,需要在[折扣](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-discounts)数组的 `coupon` 参数中传递[优惠券 ID](https://docs.stripe.com/api/coupons/object.md#coupon_object-id)。目前,Checkout Sessions 最多支持使用一张优惠券或促销码。 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price]={{PRICE_ID}}" \ -d "line_items[0][quantity]=1" \ -d "discounts[0][coupon]={{COUPON_ID}}" \ -d mode=payment \ -d ui_mode=embedded_page \ --data-urlencode "return_url=https://example.com/checkout/return?session_id={CHECKOUT_SESSION_ID}" ``` ## 配置优惠券 优惠券具有以下参数,您可以用它来: - `currency` - `percent_off` 或 `amount_off` - `max_redemptions` - `redeem_by` 是客户可以应用优惠券的最后日期 - `applies_to`,限制优惠券可应用到哪些产品 > 优惠券对象可向一次性付款和订阅添加折扣。某些优惠券参数,如 `duration`,仅适用于[订阅](https://docs.stripe.com/billing/subscriptions/coupons.md)。 ### 限制兑换方式 `max_redemptions` 和 `redeem_by` 值会应用到每个应用中的优惠券。例如,您可以将某个优惠券限制在前 50 次使用,也可以通过一个特定日期来限制它的有效期。 ### 限制符合条件的产品 可以限制能够使用优惠券折扣的产品,方法是将产品 ID 添加到 Coupon 对象中的 `applies_to` 散列。映射到这个优惠券的任何促销码仅会引用到符合条件的产品列表。 ### 删除优惠券 优惠券可通过管理平台或 API 删除。删除优惠券可避免它被应用到未来的交易或客户。 ## 创建促销码 促销码是在优惠券的基础上创建的供客户使用的代码。还可以指定客户何时可应用该促销码的额外限制。您可以将这些代码分享给客户,他们输入 Checkout 中即可应用折扣。 要创建[促销码](https://docs.stripe.com/api/promotion_codes.md),请指定现有的 `coupon` 以及任何限制条件(例如,限制在特定 [customer](https://docs.stripe.com/api/promotion_codes/object.md#promotion_code_object-customer) 或 [customer_account](https://docs.stripe.com/api/promotion_codes/object.md#promotion_code_object-customer_account) 范围内)。如果您有特定的代码要给客户(例如,`FALL25OFF`),就要设置 `code`。如果您把此字段留空,我们将为您生成一个随机的 `code`。 这个 `code` 不区分大小写,任何客户的所有有效促销码都必须唯一。例如: - 可以用同一 `code` 创建多个有客户限制的促销码,但不能将这个 `code` 复用于任何客户可兑换的促销码。 - 如果您创建的一个促销码任何客户都可兑换,则不能再用同一个 `code` 来创建另一个有效的促销码。 - 可以先用 `code: NEWUSER` 创建一个促销码,传递 `active: false` 让它失效,然后再用 `code: NEWUSER` 创建一个新的促销码。 促销码可在[管理平台](https://dashboard.stripe.com/coupons/create)内的优惠券部分创建,也可通过 [API](https://docs.stripe.com/api.md#promotion_codes) 创建: ```curl curl https://api.stripe.com/v1/promotion_codes \ -u "<>:" \ -d coupon={{COUPON_ID}} \ -d code=VIPCODE ``` ## 使用促销码 在 Checkout Session 中使用 [allow_promotion_codes](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-allow_promotion_codes) 参数启用客户可兑换的促销码。这将启用 Checkout 中的一个字段,允许用户在其中输入促销码。 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d ui_mode=embedded_page \ -d allow_promotion_codes=true \ --data-urlencode "return_url=https://example.com/checkout/return?session_id={CHECKOUT_SESSION_ID}" ``` ## 配置促销码 对于每个促销码,您都可以自定义合格客户、兑换及其他限制。 ### 按客户限制 要将促销限定给特定客户,请在创建促销码时指定 [customer](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-customer) 或 [customer_account](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-customer_account)。如果没有指定客户,任何客户都可以兑换代码。 ### 按首次下单限制 您也可以通过 [restrictions.first_time_transaction](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-restrictions-first_time_transaction) 将促销码限制为首笔交易客户。如果未定义 `customer` 或 `customer_account`,或者定义的 `customer` 或 `customer_account` 没有过往支付记录或非作废的 *账单* (Invoices are statements of amounts owed by a customer. They track the status of payments from draft through paid or otherwise finalized. Subscriptions automatically generate invoices, or you can manually create a one-off invoice),则视为首笔交易。 > 未创建客户的 Sessions 会在管理平台中创建一个 [guest customer](https://docs.stripe.com/payments/checkout/guest-customers.md)。这些 Sessions 仍可接受限首笔交易客户的促销码。 ### 设置最低金额 使用促销码,您可以通过配置 [minimum_amount](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-restrictions-minimum_amount) 和 [minimum_amount_currency](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-restrictions-minimum_amount_currency) 来为符合条件的折扣设置最低交易金额。由于促销码的限制是在兑换时来检查的,因此最低交易金额仅适用于订阅的初次付款。 ### 自定义有效期 可以用 [expires_at](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-expires_at) 设置促销码的有效期。如果相关的优惠券已设置了 `redeem_by`,那么促销码的有效期不能晚于优惠券的这个值。如果未指定 `promotion_code[expires_at]`,则优惠券的 `redeem_by` 会自动生成 `expires_at`。 例如,您可能计划一年中都支持某个优惠券,但又想把它针对具体客户的有效时间设置为收到之后的一个星期之内。那么可以将 `coupon[redeem_by]` 设置为一年以后的时间,然后将每个 `promotion_code[expires_at]` 设置为创建之后的一个星期。 ### 限制兑换 可以用 [max_redemptions](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-max_redemptions) 限制兑换次数,其原理与优惠券参数类似。如果相关的优惠券已设置了 `max_redemptions`,那么促销码的 `max_redemptions` 不能大于优惠券的这个值。 例如,您可能想让前 50 位客户兑换季节促销优惠券,但冬季促销只能使用这其中的 20 次。该场景中,您可以设置 `coupon[max_redemptions]: 50` and `promotion_code[max_redemptions]: 20`。 ### 无效促销码 可以使用 [active](https://docs.stripe.com/api/promotion_codes/create.md#create_promotion_code-active) 参数设置促销码目前是否可兑换。但是,如果某个促销码的相关优惠券无效,它的所有促销码都会永久失效。同样,如果某个促销码达到了它的 `max_redemptions` 或 `expires_at`,则也会永久失效。您不能重新激活这些促销码。 ### 删除促销码 您可以在管理平台或 API 中删除促销码。删除促销码可避免它被应用到未来的交易或客户。