Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v10 - Use different API key for different user models #751

Closed
garygreen opened this issue Aug 16, 2019 · 3 comments · Fixed by #754
Closed

v10 - Use different API key for different user models #751

garygreen opened this issue Aug 16, 2019 · 3 comments · Fixed by #754

Comments

@garygreen
Copy link

In the old version of Cashier v9 it allowed you to specify a different API key for each user. In v10, it doesn't seem this is easily possible because everything has switched to using Cashier::stripeOptions() function which always returns the cashier.secret config value and isn't specific to a particular user.

For our application, we actually split our stripe account into two - one for males and a seperate account for females. It doesn't seem easily possible to convert our codebase over to Cashier v10 for this reason.

Was there any design consideration for removing the functionality of having different stripe keys per-user model? https://github.com/laravel/cashier/blob/9.0/src/Billable.php#L624

@driesvints
Copy link
Member

Hmm I see how that can be a concern for you. Multiple Stripe accounts were never really supported in Cashier as the cashier secret on the billable trait was only meant for the only model it should be set on (usually the default user model in your Laravel app). But I can definitely see why you'd use it like this.

Basically what you're asking is support for multiple Stripe accounts. We could provide support for this. I'll take a look at this real soon.

@garygreen
Copy link
Author

Thanks Dries! The old version of Cashier did definitely support multiple different keys for users though, so the way v10 works now is a step backwards and makes it hard to have seperate keys.

This is how we used it in Cashier v9, you just override the getStripeKey method and Cashier will use it for all API calls.

<?php

class Member extends Eloquent {

	/**
	 * Get stripe key to use for the member.
	 * Female and Male accounts use a different Stripe account
	 * This is used by Laravel Cashier.
	 */
	public function getStripeKey()
	{
		return $this->isFemale() ?
		       config('services.stripe-female.secret') :
		       config('services.stripe-male.secret');
	}

}

@driesvints
Copy link
Member

@garygreen that helped! I've sent in a PR here: #754

you can overwrite the stripeOptions method there to do any customization you want. Please do note the concern I had there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants