如何:在使用 Paymill 取消订阅后结束订阅

How to: get the end of a subscription after it has been canceled with Paymill

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

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

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

由于没有内置的方式来查询 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 */
}

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