doujia1904 2018-06-12 10:56
浏览 21

条带未来订阅不起作用

I am working on future subscription, when i run the code, It create 2 subscription 1 is active and another is trial, don't know why is it creating 2 subscription ? For that active subscription it creates payment that is wrong, i have set the trial_end as "2018-06-20" still it started subscription from today, can anyone please help me how can i resolve this issue ? here i have added my code

<?php
require_once('init.php');
if (isset($_POST['stripeToken'])) {
    \Stripe\Stripe::setApiKey("*****************");
    \Stripe\Stripe::setApiVersion("2018-05-21");
    $token = $_POST['stripeToken'];
    try {
        $plan_id = time();
    /************ check if plan exists ***************/
    $plan_created = \Stripe\Plan::create(array(
                "amount" => 1200,
                "interval" => "day",
                "product" => array(
                "name" => "test",
                ),  
                "currency" => "usd",
                "id" => $plan_id,
            )
    );

        //Create Customer:
        $customer = \Stripe\Customer::create(array(
                    'source' => $token,
            'description'=> 'Test Customer',
                    'email' => 'testabc123@gmail.com',
                    'plan' => $plan_id
        ));
        // Charge the order:
    $dateTime = new DateTime('2018-06-20'); 
    $date_timestamp = $dateTime->format('U');

        $charge = \Stripe\Subscription::create(array(
                    'customer' => $customer->id,
                    "items" => array(
                        array(
                            "plan" => $plan_id,
                        ),
                    ),
            "trial_end"=>$date_timestamp,
                )
        );

        echo "<pre>";
        print_r($charge);
    die;

    } catch (Stripe\Error\Card $e) {
        // The card has been declined
    }
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<form action="" method="post">
    <script src="http://checkout.stripe.com/v2/checkout.js" class="stripe-button"
            data-key="pk_test_4Ak5l6azsnSsVrpVJbIepoBu"
    data-amount="5000" data-description="One year's subscription"></script>
</form>

<script>
    $(document).ready(function () {
        $("button").trigger("click");
    });
</script>
  • 写回答

1条回答 默认 最新

  • douzhanjia0773 2018-06-12 14:41
    关注

    The reason you are seeing two subscriptions is that your creates two of them. The first is created when you call Customer::Create and pass the plan:

    'plan' => $plan_id

    This subscription has no trial period because you didn't specify one on the plan and that is all that is used when creating this particular subscription.

    The other, separate subscription was created from your Subscription::create call. This is the correct subscription and it has the correct trial period set.

    To fix this issue, I would just remove the plan from where you create the Customer and keep your existing code for creating the subscription, since that works fine.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看