【问题标题】:How to: get the end of a subscription after it has been canceled with Paymill如何:在使用 Paymill 取消订阅后结束订阅
【发布时间】:2015-09-04 06:58:59
【问题描述】:

我已设置没有有效期的月度订阅。如果有人取消他的订阅,它会在后台调用以下函数

$subscription->setId('sub_dea86e5c65b2087202e3');
             ->setRemove(false);

我没有得到有关当前预订期间的信息。如果有人在 9 月 1 日订阅并在 9 月 2 日取消,我无法确定他的订阅是否仍然有效。

【问题讨论】:

    标签: php laravel paymill


    【解决方案1】:

    由于没有查询 Paymill-API 的内置方法,因此我执行了以下操作:

    $subscription = $this->getClientSubscriptions(); //Get subscriptions for the client
    
    if ($subscription)
    {
        if ( ! $subscription['is_canceled'])
        {
            $this->client->end_of_period = date('Y-m-d H:i:s', $subscription['next_capture_at']);
            /* Set end of period within the database if
               subscription is not canceled */
        } elseif ($this->client->end_of_period < date('Y-m-d H:i:s'))
        {
            /* If the subscription has been canceled we can
               compare the end of period to the current date
               and set the subscription to false since it expired */
            $this->client->end_of_period = null;
            $subscription = false;
        }
    
        $this->client->save();
        $this->cache->put($subscription_cache, $subscription, 1440);
        /* Save and put it to cache to prevent excessive calls to the paymill-api */
    }
    

    如果对此解决方案有任何疑问,我很乐意回答。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-06
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 1970-01-01
      • 2022-01-19
      • 2012-03-14
      • 2015-08-24
      相关资源
      最近更新 更多