stripe 4.9.0 → 5.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +10 -0
- data/.rubocop.yml +56 -8
- data/.rubocop_todo.yml +8 -25
- data/.travis.yml +4 -8
- data/.vscode/extensions.json +7 -0
- data/.vscode/settings.json +8 -0
- data/CHANGELOG.md +206 -2
- data/CODE_OF_CONDUCT.md +77 -0
- data/Gemfile +10 -13
- data/README.md +178 -58
- data/Rakefile +8 -7
- data/VERSION +1 -1
- data/lib/stripe.rb +41 -195
- data/lib/stripe/api_operations/create.rb +1 -1
- data/lib/stripe/api_operations/delete.rb +28 -2
- data/lib/stripe/api_operations/list.rb +1 -12
- data/lib/stripe/api_operations/nested_resource.rb +38 -28
- data/lib/stripe/api_operations/request.rb +47 -8
- data/lib/stripe/api_operations/save.rb +8 -7
- data/lib/stripe/api_resource.rb +52 -3
- data/lib/stripe/connection_manager.rb +162 -0
- data/lib/stripe/error_object.rb +94 -0
- data/lib/stripe/errors.rb +31 -10
- data/lib/stripe/instrumentation.rb +82 -0
- data/lib/stripe/list_object.rb +41 -7
- data/lib/stripe/multipart_encoder.rb +131 -0
- data/lib/stripe/oauth.rb +4 -3
- data/lib/stripe/object_types.rb +101 -0
- data/lib/stripe/resources.rb +84 -0
- data/lib/stripe/{account.rb → resources/account.rb} +50 -27
- data/lib/stripe/{account_link.rb → resources/account_link.rb} +2 -1
- data/lib/stripe/resources/alipay_account.rb +34 -0
- data/lib/stripe/{apple_pay_domain.rb → resources/apple_pay_domain.rb} +2 -1
- data/lib/stripe/resources/application_fee.rb +14 -0
- data/lib/stripe/resources/application_fee_refund.rb +30 -0
- data/lib/stripe/{balance.rb → resources/balance.rb} +2 -1
- data/lib/stripe/{balance_transaction.rb → resources/balance_transaction.rb} +2 -5
- data/lib/stripe/resources/bank_account.rb +43 -0
- data/lib/stripe/resources/billing_portal/session.rb +12 -0
- data/lib/stripe/{bitcoin_receiver.rb → resources/bitcoin_receiver.rb} +4 -3
- data/lib/stripe/{bitcoin_transaction.rb → resources/bitcoin_transaction.rb} +1 -1
- data/lib/stripe/resources/capability.rb +33 -0
- data/lib/stripe/{card.rb → resources/card.rb} +13 -4
- data/lib/stripe/resources/charge.rb +23 -0
- data/lib/stripe/resources/checkout/session.rb +16 -0
- data/lib/stripe/{country_spec.rb → resources/country_spec.rb} +2 -1
- data/lib/stripe/{coupon.rb → resources/coupon.rb} +3 -2
- data/lib/stripe/resources/credit_note.rb +33 -0
- data/lib/stripe/resources/credit_note_line_item.rb +7 -0
- data/lib/stripe/resources/customer.rb +36 -0
- data/lib/stripe/resources/customer_balance_transaction.rb +30 -0
- data/lib/stripe/resources/discount.rb +7 -0
- data/lib/stripe/resources/dispute.rb +22 -0
- data/lib/stripe/{ephemeral_key.rb → resources/ephemeral_key.rb} +6 -2
- data/lib/stripe/{event.rb → resources/event.rb} +2 -1
- data/lib/stripe/{exchange_rate.rb → resources/exchange_rate.rb} +2 -1
- data/lib/stripe/{file.rb → resources/file.rb} +9 -11
- data/lib/stripe/{file_link.rb → resources/file_link.rb} +3 -2
- data/lib/stripe/resources/invoice.rb +74 -0
- data/lib/stripe/{invoice_item.rb → resources/invoice_item.rb} +3 -2
- data/lib/stripe/{invoice_line_item.rb → resources/invoice_line_item.rb} +1 -1
- data/lib/stripe/resources/issuing/authorization.rb +34 -0
- data/lib/stripe/resources/issuing/card.rb +25 -0
- data/lib/stripe/{issuing → resources/issuing}/card_details.rb +1 -1
- data/lib/stripe/{issuing → resources/issuing}/cardholder.rb +3 -2
- data/lib/stripe/resources/issuing/dispute.rb +25 -0
- data/lib/stripe/{issuing → resources/issuing}/transaction.rb +3 -2
- data/lib/stripe/resources/line_item.rb +7 -0
- data/lib/stripe/resources/login_link.rb +14 -0
- data/lib/stripe/resources/mandate.rb +8 -0
- data/lib/stripe/resources/order.rb +33 -0
- data/lib/stripe/{order_return.rb → resources/order_return.rb} +2 -1
- data/lib/stripe/resources/payment_intent.rb +43 -0
- data/lib/stripe/resources/payment_method.rb +33 -0
- data/lib/stripe/resources/payout.rb +33 -0
- data/lib/stripe/{person.rb → resources/person.rb} +8 -3
- data/lib/stripe/{plan.rb → resources/plan.rb} +2 -1
- data/lib/stripe/resources/price.rb +12 -0
- data/lib/stripe/{product.rb → resources/product.rb} +4 -3
- data/lib/stripe/resources/promotion_code.rb +12 -0
- data/lib/stripe/resources/radar/early_fraud_warning.rb +12 -0
- data/lib/stripe/{radar → resources/radar}/value_list.rb +3 -2
- data/lib/stripe/{radar → resources/radar}/value_list_item.rb +3 -2
- data/lib/stripe/{recipient.rb → resources/recipient.rb} +3 -6
- data/lib/stripe/{recipient_transfer.rb → resources/recipient_transfer.rb} +1 -1
- data/lib/stripe/{refund.rb → resources/refund.rb} +2 -1
- data/lib/stripe/{reporting → resources/reporting}/report_run.rb +3 -2
- data/lib/stripe/{reporting → resources/reporting}/report_type.rb +3 -2
- data/lib/stripe/resources/reversal.rb +29 -0
- data/lib/stripe/resources/review.rb +21 -0
- data/lib/stripe/resources/setup_attempt.rb +10 -0
- data/lib/stripe/resources/setup_intent.rb +33 -0
- data/lib/stripe/{sigma → resources/sigma}/scheduled_query_run.rb +3 -2
- data/lib/stripe/{sku.rb → resources/sku.rb} +4 -3
- data/lib/stripe/resources/source.rb +47 -0
- data/lib/stripe/{source_transaction.rb → resources/source_transaction.rb} +1 -1
- data/lib/stripe/resources/subscription.rb +26 -0
- data/lib/stripe/resources/subscription_item.rb +26 -0
- data/lib/stripe/resources/subscription_schedule.rb +33 -0
- data/lib/stripe/resources/tax_id.rb +26 -0
- data/lib/stripe/resources/tax_rate.rb +12 -0
- data/lib/stripe/resources/terminal/connection_token.rb +12 -0
- data/lib/stripe/{terminal → resources/terminal}/location.rb +4 -2
- data/lib/stripe/{terminal → resources/terminal}/reader.rb +4 -2
- data/lib/stripe/{three_d_secure.rb → resources/three_d_secure.rb} +2 -1
- data/lib/stripe/{token.rb → resources/token.rb} +2 -1
- data/lib/stripe/resources/topup.rb +23 -0
- data/lib/stripe/resources/transfer.rb +27 -0
- data/lib/stripe/resources/usage_record.rb +7 -0
- data/lib/stripe/{usage_record_summary.rb → resources/usage_record_summary.rb} +1 -1
- data/lib/stripe/{webhook_endpoint.rb → resources/webhook_endpoint.rb} +3 -2
- data/lib/stripe/singleton_api_resource.rb +3 -1
- data/lib/stripe/stripe_client.rb +493 -236
- data/lib/stripe/stripe_configuration.rb +178 -0
- data/lib/stripe/stripe_object.rb +75 -61
- data/lib/stripe/stripe_response.rb +53 -21
- data/lib/stripe/util.rb +66 -109
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe/webhook.rb +43 -10
- data/stripe.gemspec +14 -5
- data/test/stripe/account_link_test.rb +4 -4
- data/test/stripe/account_test.rb +193 -32
- data/test/stripe/alipay_account_test.rb +1 -1
- data/test/stripe/api_operations_test.rb +3 -4
- data/test/stripe/api_resource_test.rb +159 -37
- data/test/stripe/apple_pay_domain_test.rb +18 -5
- data/test/stripe/application_fee_refund_test.rb +1 -1
- data/test/stripe/application_fee_test.rb +45 -1
- data/test/stripe/balance_test.rb +1 -1
- data/test/stripe/balance_transaction_test.rb +20 -0
- data/test/stripe/bank_account_test.rb +1 -1
- data/test/stripe/billing_portal/session_test.rb +18 -0
- data/test/stripe/capability_test.rb +45 -0
- data/test/stripe/charge_test.rb +13 -8
- data/test/stripe/checkout/session_test.rb +19 -1
- data/test/stripe/connection_manager_test.rb +167 -0
- data/test/stripe/country_spec_test.rb +1 -1
- data/test/stripe/coupon_test.rb +16 -6
- data/test/stripe/credit_note_test.rb +90 -0
- data/test/stripe/customer_balance_transaction_test.rb +37 -0
- data/test/stripe/customer_card_test.rb +7 -1
- data/test/stripe/customer_test.rb +151 -40
- data/test/stripe/dispute_test.rb +10 -1
- data/test/stripe/ephemeral_key_test.rb +8 -1
- data/test/stripe/errors_test.rb +42 -9
- data/test/stripe/exchange_rate_test.rb +1 -1
- data/test/stripe/file_link_test.rb +1 -1
- data/test/stripe/file_test.rb +19 -5
- data/test/stripe/instrumentation_test.rb +74 -0
- data/test/stripe/invoice_item_test.rb +18 -7
- data/test/stripe/invoice_line_item_test.rb +1 -1
- data/test/stripe/invoice_test.rb +77 -9
- data/test/stripe/issuing/authorization_test.rb +33 -11
- data/test/stripe/issuing/card_test.rb +27 -6
- data/test/stripe/issuing/cardholder_test.rb +1 -1
- data/test/stripe/issuing/dispute_test.rb +23 -14
- data/test/stripe/issuing/transaction_test.rb +1 -1
- data/test/stripe/list_object_test.rb +70 -24
- data/test/stripe/login_link_test.rb +2 -2
- data/test/stripe/mandate_test.rb +14 -0
- data/test/stripe/multipart_encoder_test.rb +130 -0
- data/test/stripe/oauth_test.rb +17 -1
- data/test/stripe/order_return_test.rb +1 -1
- data/test/stripe/order_test.rb +28 -3
- data/test/stripe/payment_intent_test.rb +31 -4
- data/test/stripe/payment_method_test.rb +84 -0
- data/test/stripe/payout_test.rb +23 -1
- data/test/stripe/person_test.rb +1 -1
- data/test/stripe/plan_test.rb +26 -20
- data/test/stripe/price_test.rb +48 -0
- data/test/stripe/product_test.rb +17 -8
- data/test/stripe/promotion_code_test.rb +42 -0
- data/test/stripe/radar/early_fraud_warning_test.rb +22 -0
- data/test/stripe/radar/value_list_item_test.rb +16 -6
- data/test/stripe/radar/value_list_test.rb +16 -6
- data/test/stripe/recipient_test.rb +18 -5
- data/test/stripe/refund_test.rb +1 -1
- data/test/stripe/reporting/report_run_test.rb +1 -1
- data/test/stripe/reporting/report_type_test.rb +1 -1
- data/test/stripe/reversal_test.rb +1 -1
- data/test/stripe/review_test.rb +1 -1
- data/test/stripe/setup_attempt_test.rb +16 -0
- data/test/stripe/setup_intent_test.rb +84 -0
- data/test/stripe/sigma/scheduled_query_run_test.rb +1 -1
- data/test/stripe/sku_test.rb +16 -6
- data/test/stripe/source_test.rb +52 -19
- data/test/stripe/stripe_client_test.rb +546 -78
- data/test/stripe/stripe_configuration_test.rb +131 -0
- data/test/stripe/stripe_object_test.rb +16 -41
- data/test/stripe/stripe_response_test.rb +71 -25
- data/test/stripe/subscription_item_test.rb +38 -7
- data/test/stripe/subscription_schedule_test.rb +19 -1
- data/test/stripe/subscription_test.rb +29 -9
- data/test/stripe/tax_id_test.rb +31 -0
- data/test/stripe/tax_rate_test.rb +43 -0
- data/test/stripe/terminal/connection_token_test.rb +1 -1
- data/test/stripe/terminal/location_test.rb +18 -1
- data/test/stripe/terminal/reader_test.rb +18 -1
- data/test/stripe/three_d_secure_test.rb +1 -1
- data/test/stripe/topup_test.rb +9 -1
- data/test/stripe/transfer_test.rb +46 -1
- data/test/stripe/usage_record_summary_test.rb +15 -5
- data/test/stripe/util_test.rb +1 -1
- data/test/stripe/webhook_endpoint_test.rb +18 -1
- data/test/stripe/webhook_test.rb +48 -9
- data/test/stripe_mock.rb +4 -3
- data/test/stripe_test.rb +102 -33
- data/test/test_helper.rb +16 -12
- metadata +141 -129
- data/lib/stripe/alipay_account.rb +0 -27
- data/lib/stripe/application_fee.rb +0 -23
- data/lib/stripe/application_fee_refund.rb +0 -22
- data/lib/stripe/bank_account.rb +0 -32
- data/lib/stripe/charge.rb +0 -84
- data/lib/stripe/checkout/session.rb +0 -11
- data/lib/stripe/customer.rb +0 -90
- data/lib/stripe/dispute.rb +0 -19
- data/lib/stripe/invoice.rb +0 -48
- data/lib/stripe/issuer_fraud_record.rb +0 -9
- data/lib/stripe/issuing/authorization.rb +0 -22
- data/lib/stripe/issuing/card.rb +0 -18
- data/lib/stripe/issuing/dispute.rb +0 -13
- data/lib/stripe/login_link.rb +0 -11
- data/lib/stripe/order.rb +0 -31
- data/lib/stripe/payment_intent.rb +0 -26
- data/lib/stripe/payout.rb +0 -20
- data/lib/stripe/reversal.rb +0 -22
- data/lib/stripe/review.rb +0 -14
- data/lib/stripe/source.rb +0 -38
- data/lib/stripe/subscription.rb +0 -25
- data/lib/stripe/subscription_item.rb +0 -17
- data/lib/stripe/subscription_schedule.rb +0 -32
- data/lib/stripe/subscription_schedule_revision.rb +0 -25
- data/lib/stripe/terminal/connection_token.rb +0 -11
- data/lib/stripe/topup.rb +0 -16
- data/lib/stripe/transfer.rb +0 -23
- data/lib/stripe/usage_record.rb +0 -14
- data/test/api_stub_helpers.rb +0 -1
- data/test/stripe/account_external_accounts_operations_test.rb +0 -69
- data/test/stripe/account_login_links_operations_test.rb +0 -21
- data/test/stripe/account_persons_operations_test.rb +0 -70
- data/test/stripe/application_fee_refunds_operations_test.rb +0 -56
- data/test/stripe/customer_sources_operations_test.rb +0 -64
- data/test/stripe/file_upload_test.rb +0 -76
- data/test/stripe/issuer_fraud_record_test.rb +0 -20
- data/test/stripe/source_transaction_test.rb +0 -19
- data/test/stripe/subscription_schedule_revision_test.rb +0 -37
- data/test/stripe/subscription_schedule_revisions_operations_test.rb +0 -35
- data/test/stripe/transfer_reversals_operations_test.rb +0 -57
- data/test/stripe/usage_record_test.rb +0 -28
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to make participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
9
|
+
level of experience, education, socio-economic status, nationality, personal
|
10
|
+
appearance, race, religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies within all project spaces, and it also applies when
|
49
|
+
an individual is representing the project or its community in public spaces.
|
50
|
+
Examples of representing a project or community include using an official
|
51
|
+
project e-mail address, posting via an official social media account, or acting
|
52
|
+
as an appointed representative at an online or offline event. Representation of
|
53
|
+
a project may be further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at conduct@stripe.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
72
|
+
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
74
|
+
|
75
|
+
For answers to common questions about this code of conduct, see
|
76
|
+
https://www.contributor-covenant.org/faq
|
77
|
+
|
data/Gemfile
CHANGED
@@ -7,27 +7,24 @@ gemspec
|
|
7
7
|
group :development do
|
8
8
|
gem "coveralls", require: false
|
9
9
|
gem "mocha", "~> 0.13.2"
|
10
|
+
gem "rack", ">= 2.0.6"
|
10
11
|
gem "rake"
|
11
|
-
|
12
|
+
|
13
|
+
# Update to 2.0.0 once it ships.
|
14
|
+
gem "shoulda-context", "2.0.0.rc4"
|
15
|
+
|
12
16
|
gem "test-unit"
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
# Version doesn't matter that much, but this one contains some fixes for Ruby
|
19
|
+
# 2.7 warnings that add noise to the test suite.
|
20
|
+
gem "webmock", ">= 3.8.0"
|
15
21
|
|
16
22
|
# Rubocop changes pretty quickly: new cops get added and old cops change
|
17
23
|
# names or go into new namespaces. This is a library and we don't have
|
18
24
|
# `Gemfile.lock` checked in, so to prevent good builds from suddenly going
|
19
25
|
# bad, pin to a specific version number here. Try to keep this relatively
|
20
26
|
# up-to-date, but it's not the end of the world if it's not.
|
21
|
-
gem "rubocop", "0.
|
22
|
-
|
23
|
-
# Rack 2.0+ requires Ruby >= 2.2.2 which is problematic for the test suite on
|
24
|
-
# older Ruby versions. Check Ruby the version here and put a maximum
|
25
|
-
# constraint on Rack if necessary.
|
26
|
-
if RUBY_VERSION >= "2.2.2"
|
27
|
-
gem "rack", ">= 2.0.6"
|
28
|
-
else
|
29
|
-
gem "rack", ">= 1.6.11", "< 2.0" # rubocop:disable Bundler/DuplicatedGem
|
30
|
-
end
|
27
|
+
gem "rubocop", "0.80"
|
31
28
|
|
32
29
|
platforms :mri do
|
33
30
|
gem "byebug"
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Stripe Ruby Library
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/stripe.svg)](https://badge.fury.io/rb/stripe)
|
3
4
|
[![Build Status](https://travis-ci.org/stripe/stripe-ruby.svg?branch=master)](https://travis-ci.org/stripe/stripe-ruby)
|
4
5
|
[![Coverage Status](https://coveralls.io/repos/github/stripe/stripe-ruby/badge.svg?branch=master)](https://coveralls.io/github/stripe/stripe-ruby?branch=master)
|
5
6
|
|
@@ -11,11 +12,9 @@ API.
|
|
11
12
|
|
12
13
|
The library also provides other features. For example:
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
executed.
|
18
|
-
* Built-in mechanisms for the serialization of parameters according to the
|
15
|
+
- Easy configuration path for fast setup and use.
|
16
|
+
- Helpers for pagination.
|
17
|
+
- Built-in mechanisms for the serialization of parameters according to the
|
19
18
|
expectations of Stripe's API.
|
20
19
|
|
21
20
|
## Documentation
|
@@ -27,15 +26,19 @@ See the [Ruby API docs](https://stripe.com/docs/api/ruby#intro).
|
|
27
26
|
You don't need this source code unless you want to modify the gem. If you just
|
28
27
|
want to use the package, just run:
|
29
28
|
|
30
|
-
|
29
|
+
```sh
|
30
|
+
gem install stripe
|
31
|
+
```
|
31
32
|
|
32
33
|
If you want to build the gem from source:
|
33
34
|
|
34
|
-
|
35
|
+
```sh
|
36
|
+
gem build stripe.gemspec
|
37
|
+
```
|
35
38
|
|
36
39
|
### Requirements
|
37
40
|
|
38
|
-
|
41
|
+
- Ruby 2.3+.
|
39
42
|
|
40
43
|
### Bundler
|
41
44
|
|
@@ -43,7 +46,7 @@ If you are installing via bundler, you should be sure to use the https rubygems
|
|
43
46
|
source in your Gemfile, as any gems fetched over http could potentially be
|
44
47
|
compromised in transit and alter the code of gems fetched securely over https:
|
45
48
|
|
46
|
-
```
|
49
|
+
```ruby
|
47
50
|
source 'https://rubygems.org'
|
48
51
|
|
49
52
|
gem 'rails'
|
@@ -56,17 +59,15 @@ The library needs to be configured with your account's secret key which is
|
|
56
59
|
available in your [Stripe Dashboard][api-keys]. Set `Stripe.api_key` to its
|
57
60
|
value:
|
58
61
|
|
59
|
-
```
|
60
|
-
require
|
61
|
-
Stripe.api_key =
|
62
|
+
```ruby
|
63
|
+
require 'stripe'
|
64
|
+
Stripe.api_key = 'sk_test_...'
|
62
65
|
|
63
|
-
# list
|
64
|
-
Stripe::
|
66
|
+
# list customers
|
67
|
+
Stripe::Customer.list()
|
65
68
|
|
66
|
-
# retrieve single
|
67
|
-
Stripe::
|
68
|
-
"ch_18atAXCdGbJFKhCuBAa4532Z",
|
69
|
-
)
|
69
|
+
# retrieve single customer
|
70
|
+
Stripe::Customer.retrieve('cus_123456789')
|
70
71
|
```
|
71
72
|
|
72
73
|
### Per-request Configuration
|
@@ -75,51 +76,87 @@ For apps that need to use multiple keys during the lifetime of a process, like
|
|
75
76
|
one that uses [Stripe Connect][connect], it's also possible to set a
|
76
77
|
per-request key and/or account:
|
77
78
|
|
78
|
-
```
|
79
|
+
```ruby
|
79
80
|
require "stripe"
|
80
81
|
|
81
|
-
Stripe::
|
82
|
+
Stripe::Customer.list(
|
82
83
|
{},
|
83
84
|
{
|
84
|
-
:
|
85
|
-
:
|
86
|
-
:
|
85
|
+
api_key: 'sk_test_...',
|
86
|
+
stripe_account: 'acct_...',
|
87
|
+
stripe_version: '2018-02-28',
|
88
|
+
}
|
89
|
+
)
|
90
|
+
|
91
|
+
Stripe::Customer.retrieve(
|
92
|
+
'cus_123456789',
|
93
|
+
{
|
94
|
+
api_key: 'sk_test_...',
|
95
|
+
stripe_account: 'acct_...',
|
96
|
+
stripe_version: '2018-02-28',
|
87
97
|
}
|
88
98
|
)
|
89
99
|
|
90
|
-
Stripe::
|
91
|
-
|
100
|
+
Stripe::Customer.retrieve(
|
101
|
+
{
|
102
|
+
id: 'cus_123456789',
|
103
|
+
expand: %w(balance_transaction)
|
104
|
+
},
|
105
|
+
{
|
106
|
+
stripe_version: '2018-02-28',
|
107
|
+
api_key: 'sk_test_...',
|
108
|
+
}
|
109
|
+
)
|
110
|
+
|
111
|
+
Stripe::Customer.capture(
|
112
|
+
'cus_123456789',
|
113
|
+
{},
|
92
114
|
{
|
93
|
-
:
|
94
|
-
:
|
95
|
-
:stripe_version => "2018-02-28"
|
115
|
+
stripe_version: '2018-02-28',
|
116
|
+
api_key: 'sk_test_...',
|
96
117
|
}
|
97
118
|
)
|
98
119
|
```
|
99
120
|
|
100
|
-
|
121
|
+
Keep in mind that there are different method signatures depending on the action:
|
101
122
|
|
102
|
-
|
103
|
-
|
104
|
-
|
123
|
+
- When operating on a collection (e.g. `.list`, `.create`) the method signature is
|
124
|
+
`method(params, opts)`.
|
125
|
+
- When operating on resource (e.g. `.capture`, `.update`) the method signature is
|
126
|
+
`method(id, params, opts)`.
|
127
|
+
- One exception is that `retrieve`, despite being an operation on a resource, has the signature
|
128
|
+
`retrieve(id, opts)`. In addition, it will accept a Hash for the `id` param but will extract the
|
129
|
+
`id` key out and use the others as options.
|
105
130
|
|
106
|
-
|
107
|
-
|
108
|
-
client
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
131
|
+
### Accessing a response object
|
132
|
+
|
133
|
+
Get access to response objects by initializing a client and using its `request`
|
134
|
+
method:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
client = Stripe::StripeClient.new
|
138
|
+
customer, resp = client.request do
|
139
|
+
Stripe::Customer.retrieve('cus_123456789',)
|
113
140
|
end
|
114
141
|
puts resp.request_id
|
115
142
|
```
|
116
143
|
|
144
|
+
### Configuring a proxy
|
145
|
+
|
146
|
+
A proxy can be configured with `Stripe.proxy`:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
Stripe.proxy = 'https://user:pass@example.com:1234'
|
150
|
+
```
|
151
|
+
|
117
152
|
### Configuring an API Version
|
118
153
|
|
119
154
|
By default, the library will use the API version pinned to the account making
|
120
155
|
a request. This can be overridden with this global option:
|
121
156
|
|
122
|
-
|
157
|
+
```ruby
|
158
|
+
Stripe.api_version = '2018-02-28'
|
159
|
+
```
|
123
160
|
|
124
161
|
See [versioning in the API reference][versioning] for more information.
|
125
162
|
|
@@ -128,25 +165,33 @@ See [versioning in the API reference][versioning] for more information.
|
|
128
165
|
By default, the library will use its own internal bundle of known CA
|
129
166
|
certificates, but it's possible to configure your own:
|
130
167
|
|
131
|
-
|
168
|
+
```ruby
|
169
|
+
Stripe.ca_bundle_path = 'path/to/ca/bundle'
|
170
|
+
```
|
132
171
|
|
133
172
|
### Configuring Automatic Retries
|
134
173
|
|
135
|
-
|
136
|
-
|
174
|
+
You can enable automatic retries on requests that fail due to a transient
|
175
|
+
problem by configuring the maximum number of retries:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
Stripe.max_network_retries = 2
|
179
|
+
```
|
137
180
|
|
138
|
-
|
181
|
+
Various errors can trigger a retry, like a connection error or a timeout, and
|
182
|
+
also certain API responses like HTTP status `409 Conflict`.
|
139
183
|
|
140
184
|
[Idempotency keys][idempotency-keys] are added to requests to guarantee that
|
141
185
|
retries are safe.
|
142
186
|
|
143
187
|
### Configuring Timeouts
|
144
188
|
|
145
|
-
Open and
|
189
|
+
Open, read and write timeouts are configurable:
|
146
190
|
|
147
|
-
```
|
148
|
-
Stripe.open_timeout = 30
|
191
|
+
```ruby
|
192
|
+
Stripe.open_timeout = 30 # in seconds
|
149
193
|
Stripe.read_timeout = 80
|
194
|
+
Stripe.write_timeout = 30 # only supported on Ruby 2.6+
|
150
195
|
```
|
151
196
|
|
152
197
|
Please take care to set conservative read timeouts. Some API requests can take
|
@@ -162,53 +207,129 @@ production use, but `debug` is also available for more verbosity.
|
|
162
207
|
There are a few options for enabling it:
|
163
208
|
|
164
209
|
1. Set the environment variable `STRIPE_LOG` to the value `debug` or `info`:
|
165
|
-
|
210
|
+
|
211
|
+
```sh
|
166
212
|
$ export STRIPE_LOG=info
|
167
213
|
```
|
168
214
|
|
169
215
|
2. Set `Stripe.log_level`:
|
170
|
-
|
216
|
+
|
217
|
+
```ruby
|
171
218
|
Stripe.log_level = Stripe::LEVEL_INFO
|
172
219
|
```
|
173
220
|
|
221
|
+
### Instrumentation
|
222
|
+
|
223
|
+
The library has various hooks that user code can tie into by passing a block to
|
224
|
+
`Stripe::Instrumentation.subscribe` to be notified about specific events.
|
225
|
+
|
226
|
+
#### `request_begin`
|
227
|
+
|
228
|
+
Invoked when an HTTP request starts. Receives `RequestBeginEvent` with the
|
229
|
+
following properties:
|
230
|
+
|
231
|
+
- `method`: HTTP method. (`Symbol`)
|
232
|
+
- `path`: Request path. (`String`)
|
233
|
+
- `user_data`: A hash on which users can set arbitrary data, and which will be
|
234
|
+
passed through to `request_end` invocations. This could be used, for example,
|
235
|
+
to assign unique IDs to each request, and it'd work even if many requests are
|
236
|
+
running in parallel. All subscribers share the same object for any particular
|
237
|
+
request, so they must be careful to use unique keys that will not conflict
|
238
|
+
with other subscribers. (`Hash`)
|
239
|
+
|
240
|
+
#### `request_end`
|
241
|
+
|
242
|
+
Invoked when an HTTP request finishes, regardless of whether it terminated with
|
243
|
+
a success or error. Receives `RequestEndEvent` with the following properties:
|
244
|
+
|
245
|
+
- `duration`: Request duration in seconds. (`Float`)
|
246
|
+
- `http_status`: HTTP response code (`Integer`) if available, or `nil` in case
|
247
|
+
of a lower level network error.
|
248
|
+
- `method`: HTTP method. (`Symbol`)
|
249
|
+
- `num_retries`: The number of retries. (`Integer`)
|
250
|
+
- `path`: Request path. (`String`)
|
251
|
+
- `user_data`: A hash on which users may have set arbitrary data in
|
252
|
+
`request_begin`. See above for more information. (`Hash`)
|
253
|
+
|
254
|
+
#### Example
|
255
|
+
|
256
|
+
For example:
|
257
|
+
|
258
|
+
```ruby
|
259
|
+
Stripe::Instrumentation.subscribe(:request_end) do |request_event|
|
260
|
+
tags = {
|
261
|
+
method: request_event.method,
|
262
|
+
resource: request_event.path.split('/')[2],
|
263
|
+
code: request_event.http_status,
|
264
|
+
retries: request_event.num_retries
|
265
|
+
}
|
266
|
+
StatsD.distribution('stripe_request', request_event.duration, tags: tags)
|
267
|
+
end
|
268
|
+
```
|
269
|
+
|
174
270
|
### Writing a Plugin
|
175
271
|
|
176
272
|
If you're writing a plugin that uses the library, we'd appreciate it if you
|
177
273
|
identified using `#set_app_info`:
|
178
274
|
|
179
|
-
|
275
|
+
```ruby
|
276
|
+
Stripe.set_app_info('MyAwesomePlugin', version: '1.2.34', url: 'https://myawesomeplugin.info')
|
277
|
+
```
|
180
278
|
|
181
279
|
This information is passed along when the library makes calls to the Stripe
|
182
280
|
API.
|
183
281
|
|
282
|
+
### Request latency telemetry
|
283
|
+
|
284
|
+
By default, the library sends request latency telemetry to Stripe. These
|
285
|
+
numbers help Stripe improve the overall latency of its API for all users.
|
286
|
+
|
287
|
+
You can disable this behavior if you prefer:
|
288
|
+
|
289
|
+
```ruby
|
290
|
+
Stripe.enable_telemetry = false
|
291
|
+
```
|
292
|
+
|
184
293
|
## Development
|
185
294
|
|
186
295
|
The test suite depends on [stripe-mock], so make sure to fetch and run it from a
|
187
296
|
background terminal ([stripe-mock's README][stripe-mock] also contains
|
188
297
|
instructions for installing via Homebrew and other methods):
|
189
298
|
|
190
|
-
|
191
|
-
|
299
|
+
```sh
|
300
|
+
go get -u github.com/stripe/stripe-mock
|
301
|
+
stripe-mock
|
302
|
+
```
|
192
303
|
|
193
304
|
Run all tests:
|
194
305
|
|
195
|
-
|
306
|
+
```sh
|
307
|
+
bundle exec rake test
|
308
|
+
```
|
196
309
|
|
197
310
|
Run a single test suite:
|
198
311
|
|
199
|
-
|
312
|
+
```sh
|
313
|
+
bundle exec ruby -Ilib/ test/stripe/util_test.rb
|
314
|
+
```
|
200
315
|
|
201
316
|
Run a single test:
|
202
317
|
|
203
|
-
|
318
|
+
```sh
|
319
|
+
bundle exec ruby -Ilib/ test/stripe/util_test.rb -n /should.convert.names.to.symbols/
|
320
|
+
```
|
204
321
|
|
205
322
|
Run the linter:
|
206
323
|
|
207
|
-
|
324
|
+
```sh
|
325
|
+
bundle exec rake rubocop
|
326
|
+
```
|
208
327
|
|
209
328
|
Update bundled CA certificates from the [Mozilla cURL release][curl]:
|
210
329
|
|
211
|
-
|
330
|
+
```sh
|
331
|
+
bundle exec rake update_certs
|
332
|
+
```
|
212
333
|
|
213
334
|
Update the bundled [stripe-mock] by editing the version number found in
|
214
335
|
`.travis.yml`.
|
@@ -216,7 +337,6 @@ Update the bundled [stripe-mock] by editing the version number found in
|
|
216
337
|
[api-keys]: https://dashboard.stripe.com/account/apikeys
|
217
338
|
[connect]: https://stripe.com/connect
|
218
339
|
[curl]: http://curl.haxx.se/docs/caextract.html
|
219
|
-
[faraday]: https://github.com/lostisland/faraday
|
220
340
|
[idempotency-keys]: https://stripe.com/docs/api/ruby#idempotent_requests
|
221
341
|
[stripe-mock]: https://github.com/stripe/stripe-mock
|
222
342
|
[versioning]: https://stripe.com/docs/api/ruby#versioning
|