dongleibeng5602 2013-08-20 15:22
浏览 155
已采纳

如何在使用Stripe创建订阅后获取费用?

I am using Stripe as a payment gateway. Now there's a big problem bothers me.

I used code below to create a subscription:

<?php
require_once('lib/Stripe.php');

Stripe::setApiKey(API_KEY);

$token = $_POST['stripeToken'];

$customer = Stripe_Customer::create(array(
    "card"  => $token,
    "plan"  => $_POST['plan'],
    "email" => "fakeuser@gmail.com",
));

This works fine, but I can not get Charge ID from $customer, and I found out there's no way in Stripe API to get it.

How to get it when creating a subscription? I really need Charge ID.

  • 写回答

6条回答 默认 最新

  • dragon19720808 2013-09-07 22:00
    关注

    This is exactly what Stripe's webhooks are for. After creating a customer with an initial subscription, you'll get six webhook notifications:

    1. customer.created, with the customer data (which you already have if you're saving what the API returns)
    2. charge.succeeded (or charge.failed), which contains the initial charge data you're looking for
    3. invoice.created, which is the associated invoice
    4. invoice.payment_succeeded (or invoice.payment_failed), also telling you the status of the charge
    5. customer.card.created, with the details of the new card
    6. customer.subscription.created, with the details of the customer's subscription.

    Stripe's API, like many APIs and many payment solutions, is built to be used with webhooks. If you're not taking advantage of webhooks, you're going to be missing functionality, and you're probably working too hard for what can be done without webhooks.

    Stripe works to deliver the data to you. If you're writing code to poll Stripe, you're working way, way too hard.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 利用pthon计算薄膜结构的光导纳
  • ¥15 海康hlss视频流怎么播放
  • ¥15 Paddleocr:out of memory error on GPU
  • ¥30 51单片机C语言数码管驱动单片机为AT89C52