27 Commits

Author SHA1 Message Date
Corey Farwell
c4c38d63fc Add string constants for each of the Stripe object names. 2017-04-26 14:20:22 -04:00
Brandur
1886d9a625 Move to an alternative system based on StripeClient 2017-02-14 12:17:37 -08:00
Brandur
843ea88219 Add a StripeResponse to objects created by API calls 2017-02-14 12:17:37 -08:00
Brandur
11a6eec5f5 Don't allow protected fields in Save.update API operation
As described in #481, adding a protected field like `legal_entity` as
part of an update API operation can cause some issues like a custom
encoding scheme not being considered and special handling around empty
values being ignored.

As a an easy fix for this, let's disallow access to protected fields in
the same way that we disallow them from being set directly on an
instance of a given model.

Helps address (but is not a complete fix for) #481.
2016-11-28 11:42:57 -08:00
Brandur
22839df560 Nicen this code up a little bit and add a comment 2016-08-30 13:42:11 -07:00
Brandur
c796958516 Generalize saving nested resources
Since #433, saving API resources nested under other API resources has
not been the default. Instead, any instances where this should occur
have been special cased with specific method implementations that would
set the `#save_with_parent` flag when a field is written.

This ended up causing some problems because as seen in #457, because
places that we need to do this aren't well vetted, some were forgotten.

This makes implementation of new fields that need this behavior simpler
by implementing a `.save_nested_resource` metraprogramming method on the
`APIResource` class. This can be called as necessary by any concrete API
resource implementations.

We replace existing implementatinos and also add one to `Subscription`,
which had previously been suffering from a similar problem where its
`#source` had not received a special case.
2016-08-30 11:52:16 -07:00
Brandur
67b10a52ca Add deprecated #bank_account=
Add deprecated `#bank_account=` to maintain backwards compatibility.
This would have been broken by #433, so this change keeps the
functionality alive in case someone has not upgraded since.
2016-08-29 13:44:46 -07:00
Brandur
d6514ef633 Flag Account#external_account into save_with_parent system
In #433, we built a framework under which subresources are usually not
persisted, but in certain cases they can be. At the time,
`Customer#source` was the only field that I knew about that had to be
flagged into it.

Issue #456 has raised that we also be doing `Account#external_account`.
This patch adds support for that.

Fixes #456.
2016-08-29 10:34:08 -07:00
Kyle Conroy
732a494ac4 Add update class method to API resources (#426)
* Rename the `Update` operation to `Save`
* Add the `update` class method to all saveable resources
* Add tests for update method
* Add tests for plans, invoice items, and application fees
2016-06-29 14:13:42 -07:00
Greg Sabo
2c0f6bc219 Create account.reject method. 2016-03-14 13:43:19 -07:00
Joshua Kovach
e226ef2ea1 Change everything from url to resource_url 2016-03-11 02:53:50 -05:00
Brandur
592bc89688 Refactor special case serialization for clarity 2016-03-07 11:27:45 -08:00
Brandur
f723080220 Refactor serialize_params under StripeObject
This pull does two major things:

1. Refactors `serialize_params` to be more concise and readable while
   still complying to our existing test suite. Unfortunately over time
   this method has become a ball of mud that's very difficult to reason
   about, as recently evidenced by #384.
2. Moves `serialize_params` from class method to instance method (while
   still keeping for old class method for backwards compatibility). This
   is to give it a more sane interface.
2016-03-04 19:04:29 -08:00
Brandur
431ef3b1f2 Special case the serialization of account's additional_owners
We attempt to do a special encoding trick when serializing
`additional_owners` under an account: when updating a value, we actually
send the update parameters up as an integer-indexed hash rather than an
array. So instead of this:

    field[]=item1&field[]=item2&field[]=item3

We send this:

    field[0]=item1&field[1]=item2&field[2]=item3

The trouble is that this had previously been built into the core library
as the default handling for all arrays. Because of this, it was
impossible to resize a non-`additional_owners` array as described in
more detail in #340.

This patch special cases `additional_owners` and brings sane behavior
back to normal arrays along with a test suite so that we try to build
some better guarantees around both the general and non-general cases.
2015-10-27 09:07:41 -07:00
Brandur
1182539ae4 Give code a little breathing room 2015-10-23 16:25:33 -07:00
Brandur
e75fd86ae5 Fix miswording of error message 2015-10-08 07:39:56 -07:00
Brandur
aa7e559115 Extend Stripe::APIOperations::Create instead of including
Lets not be too shy about just using `extend` instead of `include` here
when it's more appropriate to do so. The advantage to this approach is
that the module can be either extended _or_ included with this change,
but couldn't be without it due to the `ClassMethods` meta-magic.

List has already started doing this as of #314, so we don't have to be
afraid of breaking convention here.
2015-10-05 12:24:53 -07:00
Brandur
42ea34b969 Pagination
Usage on a top-level collection:

```
Stripe::Customer.list.auto_paging_each do |customer|
  puts customer
end
```

Usage on a subcollection:

``` ruby
customer.invoices.auto_paging_each do |invoice|
  puts invoice
end
```

We've also renamed `#all` to `#list` to prevent confusion ("all" implies
that all resources are being returned, and in Stripe's paginated API
this was not the case). An alias has been provided for backward API
compatibility.

Fixes #167.

Replaces #211 and #248.
2015-10-05 12:15:09 -07:00
Jieren Chen
387edb5163 PR Fix: rename to protected_fields 2015-10-01 16:26:30 -07:00
Jieren Chen
797478786d Disallow directly overriding legal_entity 2015-10-01 13:39:11 -07:00
Shale Craig
af66e5ea35 Added the ability to delete an account 2015-07-28 16:16:01 -07:00
Bob Long
c269e9bd9b Safer argument parsing (attempt 2) 2015-03-25 15:15:02 +00:00
Brian Krausz
40405669e2 Comment for clarity 2015-02-13 11:40:46 -08:00
Brian Krausz
581e6348cc Support old signature in Account.retrieve 2015-02-12 20:06:03 -08:00
Brian Krausz
4d611c62f7 Support persisted use of Stripe-Account header everywhere
Including implicit use in /v1/accounts/ endpoints
2015-02-09 23:38:34 -08:00
Andrew Narkewicz
8f93cd5fac Added deauthorize method to account for deauthorizing from stripe connect application 2014-12-26 09:10:23 -07:00
Amber Feng
478ff80ac4 Add Account API resource. 2012-08-16 12:25:15 -07:00