如何获取付款链接的促销代码信息

问题描述 投票:0回答:1

我正在尝试从条纹付款中获取促销代码信息。它可以是发票、订阅或付款链接。对于订阅,我可以从invoice.paid获取。

但是对于付款链接,我在应用促销代码时很难找到它。 checkout.session.completed 事件没有任何信息。 payment_intent.succeeded事件也没有。

付款意向示例

{
  "object": {
    "id": "pi_3PekrdDLL6mQEvFD2z3EYfXH",
    "object": "payment_intent",
    "amount": 990,
    "amount_capturable": 0,
    "amount_details": {
      "tip": {
      }
    },
    "amount_received": 990,
    "application": null,
    "application_fee_amount": null,
    "automatic_payment_methods": null,
    "canceled_at": null,
    "cancellation_reason": null,
    "capture_method": "automatic_async",
    "client_secret": "pi_3PekrdDLL6mQEvFD2z3EYfXH_secret_8jdd9QUARxzFp7ywewyiQRQ9G",
    "confirmation_method": "automatic",
    "created": 1721511049,
    "currency": "usd",
    "customer": null,
    "description": null,
    "invoice": null,
    "last_payment_error": null,
    "latest_charge": "ch_3PekrdDLL6mQEvFD2SyHUWM2",
    "livemode": false,
    "metadata": {
    },
    "next_action": null,
    "on_behalf_of": null,
    "payment_method": "pm_1PekrdDLL6mQEvFDA0vSPPxG",
    "payment_method_configuration_details": null,
    "payment_method_options": {
      "card": {
        "installments": null,
        "mandate_options": null,
        "network": null,
        "request_three_d_secure": "automatic"
      }
    },
    "payment_method_types": [
      "card"
    ],
    "processing": null,
    "receipt_email": null,
    "review": null,
    "setup_future_usage": null,
    "shipping": null,
    "source": null,
    "statement_descriptor": null,
    "statement_descriptor_suffix": null,
    "status": "succeeded",
    "transfer_data": null,
    "transfer_group": null
  }
}

这用于 checkecout.session.completed

{
  "object": {
    "id": "cs_test_b14uJHQgleFfeBD5YsOQdSXdC4WRGqQ2OGYm4q6ai704FjIkOem5rBF22G",
    "object": "checkout.session",
    "after_expiration": null,
    "allow_promotion_codes": true,
    "amount_subtotal": 1100,
    "amount_total": 990,
    "automatic_tax": {
      "enabled": false,
      "liability": null,
      "status": null
    },
    "billing_address_collection": "auto",
    "cancel_url": "https://stripe.com",
    "client_reference_id": "9PVT0AMJ",
    "client_secret": null,
    "consent": null,
    "consent_collection": {
      "payment_method_reuse_agreement": null,
      "promotions": "none",
      "terms_of_service": "none"
    },
    "created": 1721511033,
    "currency": "usd",
    "currency_conversion": null,
    "custom_fields": [
      {
        "key": "referralcode",
        "label": {
          "custom": "Referral Code",
          "type": "custom"
        },
        "optional": true,
        "text": {
          "default_value": null,
          "maximum_length": 255,
          "minimum_length": null,
          "value": null
        },
        "type": "text"
      }
    ],
    "custom_text": {
      "after_submit": null,
      "shipping_address": null,
      "submit": null,
      "terms_of_service_acceptance": null
    },
    "customer": null,
    "customer_creation": "if_required",
    "customer_details": {
      "address": {
        "city": null,
        "country": "US",
        "line1": null,
        "line2": null,
        "postal_code": "07310",
        "state": null
      },
      "email": "[email protected]",
      "name": "123",
      "phone": null,
      "tax_exempt": "none",
      "tax_ids": [
      ]
    },
    "customer_email": null,
    "expires_at": 1721597433,
    "invoice": null,
    "invoice_creation": {
      "enabled": false,
      "invoice_data": {
        "account_tax_ids": null,
        "custom_fields": null,
        "description": null,
        "footer": null,
        "issuer": null,
        "metadata": {
        },
        "rendering_options": null
      }
    },
    "livemode": false,
    "locale": "auto",
    "metadata": {
    },
    "mode": "payment",
    "payment_intent": "pi_3PekrdDLL6mQEvFD2z3EYfXH",
    "payment_link": "plink_1Ov62mDLL6mQEvFDOyqA0DLX",
    "payment_method_collection": "always",
    "payment_method_configuration_details": {
      "id": "pmc_1Ne5fgDLL6mQEvFDhq2LTqTH",
      "parent": null
    },
    "payment_method_options": {
      "card": {
        "request_three_d_secure": "automatic"
      }
    },
    "payment_method_types": [
      "card"
    ],
    "payment_status": "paid",
    "phone_number_collection": {
      "enabled": false
    },
    "recovered_from": null,
    "saved_payment_method_options": null,
    "setup_intent": null,
    "shipping_address_collection": null,
    "shipping_cost": null,
    "shipping_details": null,
    "shipping_options": [
    ],
    "status": "complete",
    "submit_type": "auto",
    "subscription": null,
    "success_url": "https://stripe.com",
    "total_details": {
      "amount_discount": 110,
      "amount_shipping": 0,
      "amount_tax": 0
    },
    "ui_mode": "hosted",
    "url": null
  }
}

创建的唯一事件是 customer.discount.created,它具有促销 ID,但缺少客户电子邮件。

{
  "object": {
    "id": "di_1PekreDLL6mQEvFDshNIz6fe",
    "object": "discount",
    "checkout_session": "cs_test_b14uJHQgleFfeBD5YsOQdSXdC4WRGqQ2OGYm4q6ai704FjIkOem5rBF22G",
    "coupon": {
      "id": "D3muUbBu",
      "object": "coupon",
      "amount_off": null,
      "created": 1710630574,
      "currency": null,
      "duration": "once",
      "duration_in_months": null,
      "livemode": false,
      "max_redemptions": null,
      "metadata": {
      },
      "name": "williamette",
      "percent_off": 10,
      "redeem_by": null,
      "times_redeemed": 17,
      "valid": true
    },
    "customer": null,
    "end": null,
    "invoice": null,
    "invoice_item": null,
    "promotion_code": "promo_1Ov6MmDLL6mQEvFDcPVK9bfM",
    "start": 1721511050,
    "subscription": null,
    "subscription_item": null
  }
}

如何获取付款链接的这些信息?哪个活动最好查看付款是否有促销代码或没有任何付款(订阅、发票、付款链接)

stripe-payments
1个回答
0
投票

折扣详情可在

total_details.breakdown.discounts
属性下找到。但是,它默认不包含在 Checkout Session 对象中,即
checkout.session.completed
事件。需要单独的检索请求来扩展
total_details.breakdown
属性才能获取折扣/促销代码信息。

例如,

curl https://api.stripe.com/v1/checkout/sessions/cs_test_xxx \
  -u "sk_test_xxx:" \
  -d "expand[]"="total_details.breakdown" \
  -G
© www.soinside.com 2019 - 2024. All rights reserved.