<commit_before><?php namespace Cartalyst\Stripe\Card;
/**
 * Part of the Stripe package.
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the Cartalyst PSL License.
 *
 * This source file is subject to the Cartalyst PSL License that is
 * bundled with this package in the license.txt file.
 *
 * @package    Stripe
 * @version    1.0.0
 * @author     Cartalyst LLC
 * @license    Cartalyst PSL
 * @copyright  (c) 2011-2014, Cartalyst LLC
 * @link       http://cartalyst.com
 */

use Cartalyst\Stripe\BillableInterface;
use Cartalyst\Stripe\StripeGateway;

class CardGateway extends StripeGateway {

	/**
	 * The card object.
	 *
	 * @var \Cartalyst\Stripe\Card\IlluminateCard
	 */
	protected $card;

	/**
	 * Flag for wether the credit card should be made
	 * the default credit card.
	 *
	 * @var bool
	 */
	protected $default = false;

	/**
	 * Create a new Stripe Card gateway instance.
	 *
	 * @param  \Cartalyst\Stripe\BillableInterface  $billable
	 * @param  mixed  $card
	 * @return void
	 */
	public function __construct(BillableInterface $billable, $card = null)
	{
		parent::__construct($billable);

		if (is_numeric($card))
		{
			$card = $this->billable->cards->find($card);
		}

		if ($card instanceof IlluminateCard)
		{
			$this->card = $card;
		}
	}

	/**
	 * Returns the Stripe card object.
	 *
	 * @return \Stripe_Card
	 */
	public function get()
	{
		return $this
				->getStripeCustomer()
				->cards
				->retrieve($this->card->stripe_id);
	}

	/**
	 * Creates a new credit card.
	 *
	 * @param  string  $token
	 * @param  array  $attributes
	 * @return \Stripe_Card
	 */
	public function create($token, array $attributes = [])
	{
		if ($id = $this->billable->getStripeId())
		{
			$customer = $this->updateStripeCustomer($id, array_get($attributes, 'customer', []));

			$card = $customer->cards->create(['card' => $token]);

			if ($this->default)
			{
				$customer->default_card = $card->id;
				$customer->save();
			}

			$attributes = array_merge($attributes, [
				'stripe_id' => $card->id,
				'last_four' => $card->last4,
				'exp_month' => $card->exp_month,
				'exp_year'  => $card->exp_year,
			]);

			array_forget($attributes, 'customer');

			$this->billable->cards()->create($attributes);
		}
		else
		{
			$customer = $this->createStripeCustomer($token, array_get($attributes, 'customer', []));
		}

		$this->updateLocalStripeData($this->getStripeCustomer($customer->id));

		return $card;
	}

	/**
	 * Updates the card.
	 *
	 * @param  array  $attributes
	 * @return \Stripe_Card
	 */
	public function update(array $attributes = [])
	{
		$card = $this->get();

		foreach ($attributes as $key => $value)
		{
			$card->{$key} = $value;
		}

		$card->save();

		return $card;<commit_msg>temp fix for the card creation<commit_after><?php namespace Cartalyst\Stripe\Card;
/**
 * Part of the Stripe package.
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the Cartalyst PSL License.
 *
 * This source file is subject to the Cartalyst PSL License that is
 * bundled with this package in the license.txt file.
 *
 * @package    Stripe
 * @version    1.0.0
 * @author     Cartalyst LLC
 * @license    Cartalyst PSL
 * @copyright  (c) 2011-2014, Cartalyst LLC
 * @link       http://cartalyst.com
 */

use Cartalyst\Stripe\BillableInterface;
use Cartalyst\Stripe\StripeGateway;

class CardGateway extends StripeGateway {

	/**
	 * The card object.
	 *
	 * @var \Cartalyst\Stripe\Card\IlluminateCard
	 */
	protected $card;

	/**
	 * Flag for wether the credit card should be made
	 * the default credit card.
	 *
	 * @var bool
	 */
	protected $default = false;

	/**
	 * Create a new Stripe Card gateway instance.
	 *
	 * @param  \Cartalyst\Stripe\BillableInterface  $billable
	 * @param  mixed  $card
	 * @return void
	 */
	public function __construct(BillableInterface $billable, $card = null)
	{
		parent::__construct($billable);

		if (is_numeric($card))
		{
			$card = $this->billable->cards->find($card);
		}

		if ($card instanceof IlluminateCard)
		{
			$this->card = $card;
		}
	}

	/**
	 * Returns the Stripe card object.
	 *
	 * @return \Stripe_Card
	 */
	public function get()
	{
		return $this
				->getStripeCustomer()
				->cards
				->retrieve($this->card->stripe_id);
	}

	/**
	 * Creates a new credit card.
	 *
	 * @param  string  $token
	 * @param  array  $attributes
	 * @return \Stripe_Card
	 */
	public function create($token, array $attributes = [])
	{
		if ($id = $this->billable->getStripeId())
		{
			$customer = $this->updateStripeCustomer($id, array_get($attributes, 'customer', []));

			$card = $customer->cards->create(['card' => $token]);

			if ($this->default)
			{
				$customer->default_card = $card->id;
				$customer->save();
			}

			$attributes = array_merge($attributes, [
				'stripe_id' => $card->id,
				'last_four' => $card->last4,
				'exp_month' => $card->exp_month,
				'exp_year'  => $card->exp_year,
			]);

			array_forget($attributes, 'customer');

			$this->billable->cards()->create($attributes);
		}
		else
		{
			$customer = $this->createStripeCustomer($token, array_get($attributes, 'customer', []));
		}

		$this->updateLocalStripeData($this->getStripeCustomer($customer->id));

		//return $card;
	}

	/**
	 * Updates the card.
	 *
	 * @param  array  $attributes
	 * @return \Stripe_Card
	 */
	public function update(array $attributes = [])
	{
		$card = $this->get();

		foreach ($attributes as $key => $value)
		{
			$card->{$key} = $value;
		}

		$card->save();

		return $card;
{'fraction_non_alphanumeric': 0.15827074555779447, 'fraction_numerical': 0.004396409598827624, 'mean_word_length': 3.1552511415525113, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, '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': '629100', 'n_tokens_mistral': 2129, 'n_tokens_neox': 1859, 'n_words': 428}