Stripe API - 下一个付款日期

时间:2014-03-21 11:54:37

标签: stripe-payments

我正在使用条带API与我的客户签订每月定期结算。

如果下次付款到期,我该怎么办才能显示:

"subscription": {
    "current_period_end": 1306060846,
    "status": "trialing",
    "plan": {
      "interval": "month",
      "amount": 1000,
      "trial_period_days": 0,
      "object": "plan",
      "id": "Basic"
    },
    "current_period_start": 1305974416,
    "start": 1305974416,
    "object": "subscription",
    "trial_start": 1305974416,
    "trial_end": 1306060846,
    "customer": "O8ygDbcWW9aswmxctU9z",
  },
  "id": "O8ygDbcWW9aswmxctU9z"
}

4 个答案:

答案 0 :(得分:9)

$timestamp = "2306060846";
$next_payment_date = date('Y-m-d',$timestamp));

它为您提供Y-m-d格式的时间

答案 1 :(得分:7)

trial_end gives the next_payment_date in timestamp.

您可以使用php中的日期功能将其转换为日期格式。

更新:截至2019年中期,对于目前未在试用的订阅,您会在Subscription对象中找到下一个结算周期的Unix时间戳{{1} }。

答案 2 :(得分:1)

据我所知,这是完全不可能的。 trial_end(如果设置)将是第一个付款日期。 current_period_end将是下一次尝试,但如果有下降,则下一次收费将遵循设置中的时间表(例如,1天后重试,3天后重试,取消) 。您必须使用设置中的规则跟踪拒绝并计算下一个付款日期。

答案 3 :(得分:0)

您可以按如下方式检查订阅状态:

Stripe::Customer.retrieve("cus_7G9REJXtaW05QY")
subscription = customer.subscriptions.retrieve("sub_7HFIqkWIDqEhho")

if subscription.status == 'trialing'
  next_payment_date = Time.at(subscription.trial_end).strftime("%B %d, %Y")
end

路径结束后,您可以查看订阅中的current_period_end属性

next_payment_date = Time.at(subscription.current_period_end).strftime("%B %d, %Y")

此外,如果您只有一个月的试用期,则可以使用current_period_end。这适用于所有情况。

  

PS:对于状态检查,单词为trialing而不是trialling,如果我没有错,Stripe团队会出现拼写错误。 : - )

相关问题