1027 Commits

Author SHA1 Message Date
Brandur
aa5ef2f7ff Add comment so the post-verify parse change doesn't regress 2017-08-18 10:13:54 -07:00
Brandur
a19dfed759 Merge pull request #572 from timcraft/webhook
Parse webhook payload after verifying the signature header
2017-08-18 10:11:51 -07:00
Tim Craft
4739ece7b0 Parse webhook payload after verifying the signature header 2017-08-18 11:17:57 +01:00
Brandur
8e897a43b5 Bump version to 3.3.0 v3.3.0 2017-08-11 15:02:09 -07:00
Brandur
92d28b38cd Merge pull request #570 from stripe/brandur-support-logger
Add support for setting a logger
2017-08-11 14:59:13 -07:00
Brandur
1ca67cb954 Correct behavior for error logging
A few changes:

* Add a new `Util.log_error` method which will forward to the equivalent
  of `#error` on a logger.
* Move errors produced by `StripeClient` to use `Util.log_error`.
* Change standard stdout logging behavior to log to stderr in the case
  of `Util.log_error.
* Change `Stripe.log_level` values to be an enum in a similar fashion as
  the standard library's built in `Logger`.
2017-08-11 11:45:43 -07:00
Brandur
cb111a8e74 Add support for setting a logger
Adds support for setting `Stripe.logger` to a logger that's compatible
with `Logger` from Ruby's standard library. In set, the library will no
longer log to stdout, and instead emit straight to the logger and defer
decision on what log level to print to it.

Addresses a request in #566.
2017-08-11 11:22:14 -07:00
Brandur
20ec883e8b Bump version to 3.2.0 v3.2.0 2017-08-03 14:09:33 -07:00
Brandur
c0bccc8c23 Merge pull request #568 from stripe/brandur-log-stripe-account
Log `Stripe-Account` values with `STRIPE_LOG`
2017-08-03 14:08:55 -07:00
Brandur
eb3671b067 Log Stripe-Account values with STRIPE_LOG
Hopefully the last tweak in a while, but a discussion on [1] tipped me
off that this was missing. Here we add a `Stripe-Account` for a request
and response to logging. Follows #566 and #567.

[1] https://github.com/stripe/stripe-node/issues/364
2017-08-03 14:02:06 -07:00
Brandur
8264b5a82c Merge pull request #567 from stripe/brandur-log-num-retries
Log `num_retries` with `STRIPE_LOG`
2017-08-03 14:01:48 -07:00
Brandur
441331bd82 Log num_retries with STRIPE_LOG
This one is minor, but I realized after shipping #566 that it would be
nice if the number of retries was also logged for every request. This
patch follows up #566 by adding that in.

I also renamed `retry_count` to `num_retries` because I subjectively
think this name is a little better.
2017-08-03 13:50:00 -07:00
Brandur
aaf8391f3d Bump version to 3.1.0 v3.1.0 2017-08-03 13:45:35 -07:00
Brandur
e52c3a2aeb Merge pull request #566 from stripe/brandur-stripe-log
Implement `STRIPE_LOG` for stripe-ruby
2017-08-03 13:44:09 -07:00
Brandur
ce69d749e1 Implement STRIPE_LOG for stripe-ruby
Adds logging support for stripe-ruby in a similar way that we did it for
stripe-python [1], with the idea that users you can optionally get some
additional low-cost-to-configure logging for operational visibility or
debugging.

I made a few tweaks from the Python implementation (which I'll try to
contribute back to there):

* Added an elapsed parameter to responses so you can tell how long they
  lasted.
* Mixed in idempotency_key to all lines that users have a way to
  aggregate logs related to a request from start to finish.
* Standardized naming between different log lines as much as possible.
* Detect a TTY and produce output that's colorized and formatted.

[1] https://github.com/stripe/stripe-python/pull/269
2017-08-03 13:39:15 -07:00
Brandur
a24b7bcf77 Merge pull request #565 from stripe/jacqueline-fix-upcoming
Add upcoming invoice subscription items test
2017-08-02 07:39:07 -07:00
Jacqueline Xu
43b78055aa Add upcoming invoice subscription items test 2017-08-01 17:22:29 -07:00
Brandur
2826bc366a Merge pull request #553 from stripe/brandur-stripestub
Power test suite with stripe-mock
2017-07-31 13:31:06 -07:00
Brandur
00180c5f35 Power test suite with stripe-mock
Moves away from Committee and towards stripe-mock, an external
self-contained executable API stub server based on OpenAPI [1]. The
motivation here is that instead of making stripe-ruby a special
snowflake, we can use a single well-tested and feature-rich mock
implementation to drive every API's test suite.

[1] https://github.com/stripe/stripe-mock
2017-07-31 13:25:48 -07:00
Brandur
d326e51b0e Bump version to 3.0.3 v3.0.3 2017-07-28 11:45:12 -07:00
Brandur
bcb5c5325e Merge pull request #564 from stripe/brandur-revert-nil-handling
Allow empty strings in API invocation parameters
2017-07-28 11:41:53 -07:00
Brandur
1417cb5bd1 Allow empty strings in API invocation parameters
Currently, with a normal API resource, you can unset fields by
specifying a `nil` to that field's setter:

``` ruby
c = Charge.retrieve('ch_123')
c.customer = nil
c.save
```

This actually gets serialized as the form `customer=` (i.e. an empty
string), but we had to use the empty string to handle unsets because
form encoding has no concept of a `nil`/`null`.

To try and prevent usage errors, we actually prevent you from setting
fields with an empty string:

``` ruby
c = Charge.retrieve('ch_123')
c.customer = '' # error! use nil instead
```

When specifying parameters though, this doesn't work anywhere nearly as
well because usage patterns like this are very common in Ruby:

``` ruby
charge_opts = {
  params[:amount],
  params[:currency],
  params[:customer],
}
charge = Charge.create(charge_opts)
```

Each one of `params` above may or may not be `nil`, so we've
traditionally filtered those fields out during the invocation of
`Charge.create`.

Recently, I suggested to Slava that we may be able to change this
behavior, and we ended up putting in a patch as part of #557. Users
brought to my attention that this would be far too disruptive of a
change in #560 though, and having thought about it more carefully, I
agree. There's also an argument that filtered `nil` values are just a
better API, especially in Ruby where patterns like the one above are
frequently in effect.

So the best thing I can think of currently is to leave things as they
were before #557, and just require that users use an explicit empty
string when passes in parameter hashes:

``` ruby
Charge.update(customer: '') # will try to unset customer
```

Empty strings will continue to error for `StripeObject` fields like they
always have.

I don't think this is a perfect solution by any means (the different
between values on `StripeObject` versus using parameters is weird), but
it's the least disruptive thing that I can think of right now that gets
us the functionality that we need for endpoints like
`/v1/invoices/upcoming`.

Fixes #560.
2017-07-27 13:47:25 -07:00
Brandur
b0918b9317 Merge pull request #563 from stripe/brandur-improve-oauth-error-safety
Improve error handling safety in the event of unrecognized OAuth error
2017-07-27 11:36:12 -07:00
Brandur
24a1704f05 Improve error handling safety in the event of unrecognized OAuth error
It was brought up in #562 that in case we receive an OAuth error that we
don't know about, `specific_oauth_error` will fall through with a `nil`,
then picked up by `specific_api_error` which will always try to handle
the error as if it were a `Hash` (even if we know it's not!) and thus
lead to typing problems at runtime.

This patch throws a generic `OAuthError` in cases where a code comes
back that we don't recognize. I'm still crazy about the fact that we
don't have a better way of recognizing an OAuth error in particular, but
it should do the trick.
2017-07-27 09:01:53 -07:00
Brandur
713d7f9fa8 Merge pull request #562 from ymendel/handle_invalid_client_oauth_error
handle invalid-client oauth error
2017-07-27 08:53:35 -07:00
Yossef Mendelssohn
21036261fc handle invalid_client error code from deauth
Actually handle the error code and make the right error, instead of
sending it through the `specific_api_error`.
2017-07-26 13:19:50 -04:00
Yossef Mendelssohn
9e1e755ccd add OAuth::InvalidClientError
Taking the explanation from
https://stripe.com/docs/connect/oauth-reference#post-deauthorize-error-codes
and trying to fit it in with the comment style.
2017-07-26 13:19:21 -04:00
Yossef Mendelssohn
83444b60cd test handling of invalid_client error code
An error in OAuth deauthorization could return the error code of
`invalid_client`, but that isn't handled by the code. That leads to a
`TypeError` instead of a clean, understandable error.
2017-07-26 13:14:12 -04:00
Brandur
2394467615 Note that version 3.0.2 was yanked 2017-07-12 17:45:20 -07:00
Brandur
6914178677 Bump version to 3.0.2 v3.0.2 2017-07-12 14:00:48 -07:00
Brandur
5786abcb7a Merge pull request #557 from stripe/slava-1156
Allows removing coupon via passing nil
2017-07-12 13:59:23 -07:00
Slava Akhmechet
3094199fa8 styling 2017-07-12 12:58:20 -07:00
Slava Akhmechet
b4308aaa7e Moving tests closer to the core 2017-07-12 12:54:53 -07:00
Brandur
743de63894 Bump version to 3.0.1 v3.0.1 2017-07-11 17:02:49 -07:00
Brandur
8bae71f246 Merge pull request #559 from stripe/brandur-include-saved-resources
Include IDs of resources set into properties
2017-07-11 17:00:35 -07:00
Brandur
ab3b1c9dfb Remove now uneeded #saved_and_unchanged method 2017-07-11 12:41:03 -07:00
Brandur
3c632d68b7 Refactor #serialize_params_value to make key optional 2017-07-11 12:40:32 -07:00
Brandur
d90c2b8e74 Include IDs of resources set as properties
Tweaks the serialization behavior so that when a resource is explicitly
set to a resource's field and that resource is subsequently saved, then
if it looks like the set resource was persisted we extract its ID and
send it up to the API.

By slight extension we also throw an `ArgumentError` if it looks like
that set resource was _not_ persisted because if the user set it
explicitly then it was probably not their intention to have it silently
ignored by the library in the event of a problem.
2017-07-11 12:37:19 -07:00
Slava Akhmechet
78178f72d0 Following up with Brandur's fix suggestion 2017-07-10 13:59:23 -07:00
Slava Akhmechet
d0c4450e7e Allows removing coupon via passing nil 2017-07-07 11:27:26 -07:00
Brandur
bf8638a06f Bump version to 3.0.0 v3.0.0 2017-06-27 11:37:55 -07:00
Brandur
98855853cf Merge pull request #555 from stripe/ob-pay-invoice-params
Add parameters when calling `pay` on an invoice
2017-06-27 11:35:44 -07:00
Olivier Bellone
78cd1d4f3d Add parameters when calling pay on an invoice 2017-06-27 14:01:08 +02:00
Brandur
94f6f4c809 Merge pull request #552 from stripe/brandur-remove-fixtures
Remove `FIXTURE` definitions for ephemeral keys
2017-06-21 16:06:52 -07:00
Brandur
524526c9b7 Remove FIXTURE definitions for ephemeral keys
Redefining the constant like this produces a warning:

```
$ bundle exec rake
/Users/brandur/stripe/stripe-ruby/test/stripe/ephemeral_key_test.rb:75: warning: already initialized constant Stripe::EphemeralKeyTest::FIXTURE
/Users/brandur/stripe/stripe-ruby/test/stripe/ephemeral_key_test.rb:6: warning: previous definition of FIXTURE was here
Loaded suite /Users/brandur/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rake-11.1.2/lib/rake/rake_test_loader
Started
...
```

They also don't appear to be used, so it should be fine just to strip
them out of the test suite.
2017-06-21 15:39:41 -07:00
Marc Hesse
8139980f27 Bump version to 2.12.0 v2.12.0 2017-06-20 18:31:57 -07:00
Marc Hesse
d69ccfc1dd Add support for ephemeral keys (#549) 2017-06-20 18:30:30 -07:00
Marc Hesse
3f01024974 Update OpenAPI files for ephemeral keys (#551) 2017-06-20 16:23:27 -07:00
Brandur
8a4e68868d Merge pull request #550 from robinbrandt/docs-api-response
Fix documentation for getting a request id
2017-06-12 13:04:37 -07:00
Robin Brandt
d08ec9895d Fix documentation for getting a request id
The last response is returned as a second return value of
Stripe::StripeClient#request.
2017-06-12 15:51:08 -04:00