-
Notifications
You must be signed in to change notification settings - Fork 850
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
Create a Card #363
Comments
@Grafikart You don't need to add anything as it's already supported in the library and covered in the documentation. To create a card right now you have to go through the Customer who owns it. The code looks like this:
|
Feel free to ignore this comment if you don't agree (this is an opinion, i'm not trying to enforce my point of view :)) Your answer does the job but it forces you to do 2 API calls to create a card. Moreover, I think the method "create" you are showing is not as obvious as others (I could guess the other methods reading from the Stripe API). |
@Grafikart Ah okay I see what you're asking now. You want to create a card in one API call as is done in some other libraries like the Node.js one? If so it would definitely be useful to add but not specifically for cards as the path is the same for any A different fix would be to special-case the cc @brandur-stripe @ob-stripe for thoughts? |
Hmm. I think most of our other libraries have a constructor that lets you create an object from an ID without having to fetch it, e.g. customer = Stripe::Customer.new('cus_123abc')
customer.sources.create(blah: blah) |
@evan-stripe Doesn't that feel wrong though? Sounds more like a hack than a reliable solution to rely on the fact that passing an id will set it in the right place. In that case I definitely prefer either adding |
The problem could be also expanded to retrieve sources from a customer $customer = new Customer('cus_123abs');
$customer->createSource(); // Create a new source
$customer->getSources(); // Retrieve the sources for this customer Or to keep consistancy with the rest of the library, keeping everything static : Source::all(['customer' => 'cus_abc']);
Source::create(['customer' => 'cus_abc']); |
@Grafikart The problem is that sources are first-order API resources, while cards & bank accounts are not (i.e. you can retrieve the former with just their ID, while you need to retrieve the latter through the customer object to which they are attached). This is how the API itself is designed and is not something that can be fixed in the client libraries. If you are really dead-set on skipping the customer retrieval request, I'd suggest something similar to what @evan-stripe said. This should let you retrieve an existing card: $card = \Stripe\Card::constructFrom(array(
'id' => 'card_...',
'customer' => 'cus_...'
), array());
$card->refresh(); You can also create a new card like this: $customerId = "cus_...";
$url = "/v1/customers/$customerId/sources";
$sources = \Stripe\Collection::constructFrom(array("url" => $url), array());
$card = $sources->create(array("source" => "tok_visa")); It's definitely a bit hackish and relies on internal methods that might change without warnings though. I suppose we could add some static methods on customer objects so you could do something like this: $card = \Stripe\Customer::retrieveCard("cus_...", "card_..."); or: $card = \Stripe\Customer::createCard("cus_...", array("source" => "tok_visa")); We'd need to add new static methods for every CRUD request for second-order sources. It's definitely doable but given that it's a fairly rare use-case I'm not sure it's worth the trouble. |
+1 for a "built-in" create card method |
========================= |
I'd recommend contacting our support team: https://support.stripe.com/contact |
Hello
Is there a way to create a card from this library ?
I want to translate this call but the Card Class doesn't contain a
create
method.I could do a PR to add these features but the use of static method is a problem, this class would have to overwrite the _create, _list, _update methods from ApiResource (since the URL expects a parameter).
The text was updated successfully, but these errors were encountered: