<commit_before><?php

/**
 * Part of the Stripe package.
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the 3-clause BSD License.
 *
 * This source file is subject to the 3-clause BSD License that is
 * bundled with this package in the LICENSE file.
 *
 * @package    Stripe
 * @version    1.0.0
 * @author     Cartalyst LLC
 * @license    BSD License (3-clause)
 * @copyright  (c) 2011-2015, Cartalyst LLC
 * @link       http://cartalyst.com
 */

namespace Cartalyst\Stripe\Api;

class Subscriptions extends Api
{
    /**
     * Creates a new subscription on the given customer.
     *
     * @param  string  $customerId
     * @param  array  $parameters
     * @return \GuzzleHttp\Message\ResponseInterface
     */
    public function create($customerId, array $parameters = [])
    {
        return $this->_post("customers/{$customerId}/subscriptions", $parameters);
    }

    /**
     * Retrieves an existing subscription from the given customer.
     *
     * @param  string  $customerId
     * @param  string  $subscriptionId
     * @return \GuzzleHttp\Message\ResponseInterface
     */
    public function find($customerId, $subscriptionId)
    {
        return $this->_get("customers/{$customerId}/subscriptions/{$subscriptionId}");
    }

    /**
     * Updates an existing subscription from the given customer.
     *
     * @param  string  $customerId
     * @param  string  $subscriptionId
     * @param  array  $parameters
     * @return \GuzzleHttp\Message\ResponseInterface
     */
    public function update($customerId, $subscriptionId, array $parameters = [])
    {
        return $this->_post("customers/{$customerId}/subscriptions/{$subscriptionId}", $parameters);
    }

    /**
     * Cancels an existing subscription from the given customer.
     *
     * @param  string  $customerId
     * @param  string  $subscriptionId
     * @param  bool  $atPeriodEnd
     * @return \GuzzleHttp\Message\ResponseInterface
     */
    public function cancel($customerId, $subscriptionId, $atPeriodEnd = false)
    {
        return $this->_delete("customers/{$customerId}/subscriptions/{$subscriptionId}", [
            'at_period_end' => (bool) $atPeriodEnd,
        ]);
    }

    /**
     * Reactivates an existing canceled subscription from the given customer.
     *
     * @param  string  $customerId
     * @param  string  $subscriptionId
     * @return \GuzzleHttp\Message\ResponseInterface
     */
    public function reactivate($customerId, $subscriptionId)
    {
        $subscription = $this->find($customerId, $subscriptionId);

        return $this->update($customerId, $subscriptionId, [
            'plan' => $subscription['plan']['id'],
        ]);
    }

    /**
     * Applies the given discount on the given subscription.
     *
     * @param  string  $customerId
     * @param  string  $subscriptionId
     * @param  string  $couponId<commit_msg>Update the reactivate() method on the Subscription request class.<commit_after><?php

/**
 * Part of the Stripe package.
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the 3-clause BSD License.
 *
 * This source file is subject to the 3-clause BSD License that is
 * bundled with this package in the LICENSE file.
 *
 * @package    Stripe
 * @version    1.0.0
 * @author     Cartalyst LLC
 * @license    BSD License (3-clause)
 * @copyright  (c) 2011-2015, Cartalyst LLC
 * @link       http://cartalyst.com
 */

namespace Cartalyst\Stripe\Api;

class Subscriptions extends Api
{
    /**
     * Creates a new subscription on the given customer.
     *
     * @param  string  $customerId
     * @param  array  $parameters
     * @return \GuzzleHttp\Message\ResponseInterface
     */
    public function create($customerId, array $parameters = [])
    {
        return $this->_post("customers/{$customerId}/subscriptions", $parameters);
    }

    /**
     * Retrieves an existing subscription from the given customer.
     *
     * @param  string  $customerId
     * @param  string  $subscriptionId
     * @return \GuzzleHttp\Message\ResponseInterface
     */
    public function find($customerId, $subscriptionId)
    {
        return $this->_get("customers/{$customerId}/subscriptions/{$subscriptionId}");
    }

    /**
     * Updates an existing subscription from the given customer.
     *
     * @param  string  $customerId
     * @param  string  $subscriptionId
     * @param  array  $parameters
     * @return \GuzzleHttp\Message\ResponseInterface
     */
    public function update($customerId, $subscriptionId, array $parameters = [])
    {
        return $this->_post("customers/{$customerId}/subscriptions/{$subscriptionId}", $parameters);
    }

    /**
     * Cancels an existing subscription from the given customer.
     *
     * @param  string  $customerId
     * @param  string  $subscriptionId
     * @param  bool  $atPeriodEnd
     * @return \GuzzleHttp\Message\ResponseInterface
     */
    public function cancel($customerId, $subscriptionId, $atPeriodEnd = false)
    {
        return $this->_delete("customers/{$customerId}/subscriptions/{$subscriptionId}", [
            'at_period_end' => (bool) $atPeriodEnd,
        ]);
    }

    /**
     * Reactivates an existing canceled subscription from the given customer.
     *
     * @param  string  $customerId
     * @param  string  $subscriptionId
     * @param  array  $attributes
     * @return \GuzzleHttp\Message\ResponseInterface
     */
    public function reactivate($customerId, $subscriptionId, array $attributes = [])
    {
        if ( ! isset($attributes['plan'])) {
            $subscription = $this->find($customerId, $subscriptionId);

            $attributes['plan'] = $subscription['plan']['id'];
        }

        return $this->update($customerId, $subscriptionId, $attributes);
    }

    /**
     * Applies the given discount on the given subscription.
     *
     * @param  string  $customerId
     * @param  string  $subscriptionId
     * @param  string  $couponId
{'fraction_non_alphanumeric': 0.11564396493594066, 'fraction_numerical': 0.004720161834120027, 'mean_word_length': 2.664607782581841, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3188300', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1697, 'n_words': 433}