laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 671 forks source link

Support for Storing Credit Card Expiration Date #540

Closed peeyush1234 closed 6 years ago

peeyush1234 commented 6 years ago

As per the documentation https://laravel.com/docs/5.6/billing#introduction, Cashier only lets you store the last 4 digits and card brand in the app. For my team use case, we need to store the expiration month and year.

Are there any plans for adding the support for expiration date?

If I create a pull request to add the expiration date, would it be possible to add it to the cashier? If yes, then I can start working on it.

mrsimonbennett commented 6 years ago

I don't speak for @taylorotwell on these matters, but I feel you could just request and store this data yourself without needing to change cashier.

function whenCardUpdated($billableStripeModel)
{
    $card = $billableStripeModel->cards()->first();
    echo $card->exp_month;
    echo $card->exp_year
    //store
}
peeyush1234 commented 6 years ago

@mrsimonbennett Thanks for your reply. I am able to support my use case. Closing the issue.

parker-codes commented 5 years ago

For anyone else needing a way to save the expiration date for various reasons, here's a slightly altered version of the code from @mrsimonbennett that uses Carbon to save the expiry on the desired model:

public function whenCardUpdated()
{
    $account = account(); // Account is my billable Stripe model
    $card = $account->cards()->first();
    $expiresAt = \Carbon\Carbon::createFromDate($card->exp_year, $card->exp_month)->endOfMonth();
    $account->card_expires_at = $expiresAt;
    $account->save();
}

Be sure to create this new field with whatever name you choose! Laravel Spark and Cashier do not implement this field for you.

rambo666 commented 4 years ago

Where do I implement this? On billable model [ie: App/User] ?

Or using observer?