mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-08-18 00:00:52 -04:00
Compare commits
204 Commits
master
...
v9.0.0-bet
Author | SHA1 | Date | |
---|---|---|---|
|
fee9143bb1 | ||
|
bd62fe08d6 | ||
|
658a0b786a | ||
|
84bf38a606 | ||
|
882c2a8c36 | ||
|
f7d4abdb5f | ||
|
8977ca553f | ||
|
e8f09f4001 | ||
|
4430246744 | ||
|
e9b70ffd51 | ||
|
b578ab2eb3 | ||
|
79dee2ae96 | ||
|
e0cfc89447 | ||
|
37b1db8140 | ||
|
ce925ab7a4 | ||
|
d604af0247 | ||
|
078adfcc37 | ||
|
e6ff2138c6 | ||
|
5609c6ce72 | ||
|
2227067f71 | ||
|
4981cc844d | ||
|
7e2a036dc5 | ||
|
900ecf2db9 | ||
|
8d5a5ef183 | ||
|
5bf957f53e | ||
|
0e5e7b8647 | ||
|
a334cb5fb4 | ||
|
801b65759e | ||
|
3d772067d1 | ||
|
6db03363ff | ||
|
1af83889bb | ||
|
e6b3043f66 | ||
|
e74bd2e7f7 | ||
|
bc924840dd | ||
|
456f10ab93 | ||
|
96b7453ee9 | ||
|
c0310bc4a7 | ||
|
a2806aca65 | ||
|
2f7ede30d1 | ||
|
4eae12c528 | ||
|
24801210b9 | ||
|
88ef71cf32 | ||
|
50c64e6c06 | ||
|
91015aa41c | ||
|
17619449ed | ||
|
a22bc332ad | ||
|
a5519a6a57 | ||
|
90a2a55687 | ||
|
6e2e8c757d | ||
|
c7a26629e6 | ||
|
62c0f898c3 | ||
|
cd0e601188 | ||
|
43f6318ebd | ||
|
150be92efc | ||
|
99dbffb9c6 | ||
|
a77bbab966 | ||
|
4d5a2aab6e | ||
|
7356579799 | ||
|
23cbd8fc82 | ||
|
adc0ccf8e7 | ||
|
d9118a7dfe | ||
|
f33553bef2 | ||
|
1d1d8a90f0 | ||
|
943dd4b020 | ||
|
6366593ed5 | ||
|
8cdb85cb36 | ||
|
9990e2b8b1 | ||
|
d600f2e9a1 | ||
|
c3cc36ed12 | ||
|
00077b44d8 | ||
|
2c06e9c83e | ||
|
4b74f4c93f | ||
|
e3f0da227f | ||
|
3ac330785f | ||
|
0075550ff8 | ||
|
890cdae767 | ||
|
732a1467b5 | ||
|
d39dcb4a81 | ||
|
fb655489eb | ||
|
4143d3930d | ||
|
23bc1b1f3b | ||
|
fe73975f07 | ||
|
24f8480c71 | ||
|
9d8ca624e3 | ||
|
105506a7fd | ||
|
75b29c3484 | ||
|
a6614ee701 | ||
|
33544c7c25 | ||
|
8f210e251a | ||
|
3b31fb29a6 | ||
|
4519e8fa19 | ||
|
f471a2c6a4 | ||
|
1e3428e87d | ||
|
7233155b42 | ||
|
cbfe81107a | ||
|
0b6cffde22 | ||
|
1be10ae4fc | ||
|
167daeaf62 | ||
|
080fddce5a | ||
|
466824d0af | ||
|
945e691968 | ||
|
f8a9a287ab | ||
|
92083a8615 | ||
|
705078e2cf | ||
|
29d8261b17 | ||
|
3958d6a9df | ||
|
696be38196 | ||
|
ff853fda95 | ||
|
d10398a825 | ||
|
6f70bd8696 | ||
|
1d21c60802 | ||
|
b9c10b9c2f | ||
|
446ffc7a22 | ||
|
58db6d32ef | ||
|
9a4dfdcb2f | ||
|
50bbc0df17 | ||
|
8226f0ad99 | ||
|
43fa8f5af7 | ||
|
0e61789557 | ||
|
cfe69c131e | ||
|
7bf9cace9e | ||
|
d7eac6010d | ||
|
7d91cb83d9 | ||
|
ce4946f5d8 | ||
|
15415fcbf3 | ||
|
f8acdb5f6a | ||
|
fe794f4868 | ||
|
2b841bc109 | ||
|
1835883848 | ||
|
e11400adc8 | ||
|
5ea85d0867 | ||
|
600b1965f6 | ||
|
5fdd180667 | ||
|
97e24e9e57 | ||
|
9531f57236 | ||
|
094574d2fe | ||
|
cff25d0c8b | ||
|
0795c1d3d0 | ||
|
802a1a7aa6 | ||
|
13b0bca995 | ||
|
51d364c844 | ||
|
f4c6f2b304 | ||
|
b64fe42043 | ||
|
586e685e63 | ||
|
3b5c725539 | ||
|
ea91a6f0b9 | ||
|
21f31edff4 | ||
|
a11f1ffd2a | ||
|
4bd92239d5 | ||
|
c261f6bbb6 | ||
|
f45fc7d703 | ||
|
5cd522c007 | ||
|
e6bda8356d | ||
|
2354633a92 | ||
|
549a73544f | ||
|
25833c1408 | ||
|
a59b57c3d1 | ||
|
63d447df77 | ||
|
5cd6f9f9bc | ||
|
ffa3747bdf | ||
|
ddf79610d9 | ||
|
edad946244 | ||
|
e3785d5893 | ||
|
2062e988eb | ||
|
0bdc688516 | ||
|
82ac9f2720 | ||
|
7381eb02a6 | ||
|
6720fc8d3f | ||
|
35a29332c5 | ||
|
519d68ce10 | ||
|
b95ea4ba27 | ||
|
318e244a76 | ||
|
bb1c995e93 | ||
|
0f12721697 | ||
|
671163245a | ||
|
486bee15a8 | ||
|
fdf5be66f5 | ||
|
c732841fd3 | ||
|
22db70b479 | ||
|
2db4fd9d06 | ||
|
6797f906e1 | ||
|
59f2d4d0fe | ||
|
0d1b570bfa | ||
|
d7d3c1b425 | ||
|
7df619de69 | ||
|
f649ed3824 | ||
|
32a95902cc | ||
|
bdcfe6cc33 | ||
|
5e1c4a2302 | ||
|
54a073783f | ||
|
e6a07ae658 | ||
|
588ed3b5e7 | ||
|
de33cde125 | ||
|
d849ec3b14 | ||
|
8b5f78aa6a | ||
|
7f6ba1c35c | ||
|
e55a2559ae | ||
|
0b00266be1 | ||
|
d0cd4fbaa6 | ||
|
979da6f84b | ||
|
d95c518a3c | ||
|
83c773f61e | ||
|
d9f719ba01 | ||
|
73d10e8557 |
@ -41,6 +41,10 @@ Metrics/MethodLength:
|
||||
Metrics/ModuleLength:
|
||||
Enabled: false
|
||||
|
||||
Metrics/ParameterLists:
|
||||
# There's 2 methods in `StripeClient` that have long parameter lists.
|
||||
Max: 8
|
||||
|
||||
Style/AccessModifierDeclarations:
|
||||
EnforcedStyle: inline
|
||||
|
||||
|
2024
CHANGELOG.md
2024
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
||||
v461
|
||||
v482
|
11
README.md
11
README.md
@ -323,6 +323,17 @@ If your beta feature requires a `Stripe-Version` header to be sent, use the `Str
|
||||
Stripe.api_version += "; feature_beta=v3"
|
||||
```
|
||||
|
||||
### Custom requests
|
||||
|
||||
If you would like to send a request to an undocumented API (for example you are in a private beta), or if you prefer to bypass the method definitions in the library and specify your request details directly, you can use the `raw_request` method on `Stripe`.
|
||||
|
||||
```ruby
|
||||
resp = Stripe.raw_request(:post, "/v1/beta_endpoint", {param: 123}, {stripe_version: "2022-11-15; feature_beta=v3"})
|
||||
|
||||
# (Optional) resp is a StripeResponse. You can use `Stripe.deserialize` to get a StripeObject.
|
||||
deserialized_resp = Stripe.deserialize(resp.http_body)
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
New features and bug fixes are released on the latest major version of the Stripe Ruby library. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.
|
||||
|
@ -13,6 +13,7 @@ require "set"
|
||||
require "socket"
|
||||
require "uri"
|
||||
require "forwardable"
|
||||
require "base64"
|
||||
|
||||
# Version
|
||||
require "stripe/api_version"
|
||||
@ -44,6 +45,7 @@ require "stripe/api_resource_test_helpers"
|
||||
require "stripe/singleton_api_resource"
|
||||
require "stripe/webhook"
|
||||
require "stripe/stripe_configuration"
|
||||
require "stripe/request_signing_authenticator"
|
||||
|
||||
# Named API resources
|
||||
require "stripe/resources"
|
||||
@ -70,6 +72,7 @@ module Stripe
|
||||
|
||||
# User configurable options
|
||||
def_delegators :@config, :api_key, :api_key=
|
||||
def_delegators :@config, :authenticator, :authenticator=
|
||||
def_delegators :@config, :api_version, :api_version=
|
||||
def_delegators :@config, :stripe_account, :stripe_account=
|
||||
def_delegators :@config, :api_base, :api_base=
|
||||
@ -116,6 +119,49 @@ module Stripe
|
||||
version: version,
|
||||
}
|
||||
end
|
||||
|
||||
class Preview
|
||||
def self._get_default_opts(opts)
|
||||
{ api_mode: :preview }.merge(opts)
|
||||
end
|
||||
|
||||
def self.get(url, opts = {})
|
||||
Stripe.raw_request(:get, url, {}, _get_default_opts(opts))
|
||||
end
|
||||
|
||||
def self.post(url, params = {}, opts = {})
|
||||
Stripe.raw_request(:post, url, params, _get_default_opts(opts))
|
||||
end
|
||||
|
||||
def self.delete(url, opts = {})
|
||||
Stripe.raw_request(:delete, url, {}, _get_default_opts(opts))
|
||||
end
|
||||
end
|
||||
|
||||
class RawRequest
|
||||
include Stripe::APIOperations::Request
|
||||
|
||||
def initialize
|
||||
@opts = {}
|
||||
end
|
||||
|
||||
def execute(method, url, params = {}, opts = {})
|
||||
resp, = execute_resource_request(method, url, params, opts)
|
||||
|
||||
resp
|
||||
end
|
||||
end
|
||||
|
||||
# Sends a request to Stripe REST API
|
||||
def self.raw_request(method, url, params = {}, opts = {})
|
||||
req = RawRequest.new
|
||||
req.execute(method, url, params, opts)
|
||||
end
|
||||
|
||||
def self.deserialize(data)
|
||||
data = JSON.parse(data) if data.is_a?(String)
|
||||
Util.convert_to_stripe_object(data, {})
|
||||
end
|
||||
end
|
||||
|
||||
Stripe.log_level = ENV["STRIPE_LOG"] unless ENV["STRIPE_LOG"].nil?
|
||||
|
@ -47,6 +47,7 @@ module Stripe
|
||||
api_key = headers.delete(:api_key)
|
||||
api_base = headers.delete(:api_base)
|
||||
client = headers.delete(:client)
|
||||
api_mode = headers.delete(:api_mode)
|
||||
# Assume all remaining opts must be headers
|
||||
|
||||
resp, opts[:api_key] = client.send(
|
||||
@ -54,6 +55,7 @@ module Stripe
|
||||
method, url,
|
||||
api_base: api_base, api_key: api_key,
|
||||
headers: headers, params: params,
|
||||
api_mode: api_mode,
|
||||
&read_body_chunk_block
|
||||
)
|
||||
|
||||
|
@ -4,5 +4,6 @@
|
||||
module Stripe
|
||||
module ApiVersion
|
||||
CURRENT = "2023-08-16"
|
||||
PREVIEW = "2023-08-11.preview-v2"
|
||||
end
|
||||
end
|
||||
|
@ -14,6 +14,7 @@ module Stripe
|
||||
# business objects
|
||||
Account::OBJECT_NAME => Account,
|
||||
AccountLink::OBJECT_NAME => AccountLink,
|
||||
AccountSession::OBJECT_NAME => AccountSession,
|
||||
ApplePayDomain::OBJECT_NAME => ApplePayDomain,
|
||||
ApplicationFee::OBJECT_NAME => ApplicationFee,
|
||||
ApplicationFeeRefund::OBJECT_NAME => ApplicationFeeRefund,
|
||||
@ -24,6 +25,9 @@ module Stripe
|
||||
BillingPortal::Configuration::OBJECT_NAME => BillingPortal::Configuration,
|
||||
BillingPortal::Session::OBJECT_NAME => BillingPortal::Session,
|
||||
Capability::OBJECT_NAME => Capability,
|
||||
Capital::FinancingOffer::OBJECT_NAME => Capital::FinancingOffer,
|
||||
Capital::FinancingSummary::OBJECT_NAME => Capital::FinancingSummary,
|
||||
Capital::FinancingTransaction::OBJECT_NAME => Capital::FinancingTransaction,
|
||||
Card::OBJECT_NAME => Card,
|
||||
CashBalance::OBJECT_NAME => CashBalance,
|
||||
Charge::OBJECT_NAME => Charge,
|
||||
@ -35,6 +39,7 @@ module Stripe
|
||||
Customer::OBJECT_NAME => Customer,
|
||||
CustomerBalanceTransaction::OBJECT_NAME => CustomerBalanceTransaction,
|
||||
CustomerCashBalanceTransaction::OBJECT_NAME => CustomerCashBalanceTransaction,
|
||||
CustomerSession::OBJECT_NAME => CustomerSession,
|
||||
Discount::OBJECT_NAME => Discount,
|
||||
Dispute::OBJECT_NAME => Dispute,
|
||||
EphemeralKey::OBJECT_NAME => EphemeralKey,
|
||||
@ -47,8 +52,12 @@ module Stripe
|
||||
FinancialConnections::AccountOwner::OBJECT_NAME => FinancialConnections::AccountOwner,
|
||||
FinancialConnections::AccountOwnership::OBJECT_NAME =>
|
||||
FinancialConnections::AccountOwnership,
|
||||
FinancialConnections::InferredBalance::OBJECT_NAME => FinancialConnections::InferredBalance,
|
||||
FinancialConnections::Session::OBJECT_NAME => FinancialConnections::Session,
|
||||
FinancialConnections::Transaction::OBJECT_NAME => FinancialConnections::Transaction,
|
||||
FundingInstructions::OBJECT_NAME => FundingInstructions,
|
||||
GiftCards::Card::OBJECT_NAME => GiftCards::Card,
|
||||
GiftCards::Transaction::OBJECT_NAME => GiftCards::Transaction,
|
||||
Identity::VerificationReport::OBJECT_NAME => Identity::VerificationReport,
|
||||
Identity::VerificationSession::OBJECT_NAME => Identity::VerificationSession,
|
||||
Invoice::OBJECT_NAME => Invoice,
|
||||
@ -56,15 +65,19 @@ module Stripe
|
||||
InvoiceLineItem::OBJECT_NAME => InvoiceLineItem,
|
||||
Issuing::Authorization::OBJECT_NAME => Issuing::Authorization,
|
||||
Issuing::Card::OBJECT_NAME => Issuing::Card,
|
||||
Issuing::CardBundle::OBJECT_NAME => Issuing::CardBundle,
|
||||
Issuing::CardDesign::OBJECT_NAME => Issuing::CardDesign,
|
||||
Issuing::Cardholder::OBJECT_NAME => Issuing::Cardholder,
|
||||
Issuing::Dispute::OBJECT_NAME => Issuing::Dispute,
|
||||
Issuing::Transaction::OBJECT_NAME => Issuing::Transaction,
|
||||
LineItem::OBJECT_NAME => LineItem,
|
||||
LoginLink::OBJECT_NAME => LoginLink,
|
||||
Mandate::OBJECT_NAME => Mandate,
|
||||
Order::OBJECT_NAME => Order,
|
||||
PaymentIntent::OBJECT_NAME => PaymentIntent,
|
||||
PaymentLink::OBJECT_NAME => PaymentLink,
|
||||
PaymentMethod::OBJECT_NAME => PaymentMethod,
|
||||
PaymentMethodConfiguration::OBJECT_NAME => PaymentMethodConfiguration,
|
||||
Payout::OBJECT_NAME => Payout,
|
||||
Person::OBJECT_NAME => Person,
|
||||
Plan::OBJECT_NAME => Plan,
|
||||
@ -72,6 +85,9 @@ module Stripe
|
||||
Product::OBJECT_NAME => Product,
|
||||
PromotionCode::OBJECT_NAME => PromotionCode,
|
||||
Quote::OBJECT_NAME => Quote,
|
||||
QuotePhase::OBJECT_NAME => QuotePhase,
|
||||
QuotePreviewInvoice::OBJECT_NAME => QuotePreviewInvoice,
|
||||
QuotePreviewSchedule::OBJECT_NAME => QuotePreviewSchedule,
|
||||
Radar::EarlyFraudWarning::OBJECT_NAME => Radar::EarlyFraudWarning,
|
||||
Radar::ValueList::OBJECT_NAME => Radar::ValueList,
|
||||
Radar::ValueListItem::OBJECT_NAME => Radar::ValueListItem,
|
||||
@ -91,6 +107,8 @@ module Stripe
|
||||
SubscriptionSchedule::OBJECT_NAME => SubscriptionSchedule,
|
||||
Tax::Calculation::OBJECT_NAME => Tax::Calculation,
|
||||
Tax::CalculationLineItem::OBJECT_NAME => Tax::CalculationLineItem,
|
||||
Tax::Form::OBJECT_NAME => Tax::Form,
|
||||
Tax::Registration::OBJECT_NAME => Tax::Registration,
|
||||
Tax::Settings::OBJECT_NAME => Tax::Settings,
|
||||
Tax::Transaction::OBJECT_NAME => Tax::Transaction,
|
||||
Tax::TransactionLineItem::OBJECT_NAME => Tax::TransactionLineItem,
|
||||
|
83
lib/stripe/request_signing_authenticator.rb
Normal file
83
lib/stripe/request_signing_authenticator.rb
Normal file
@ -0,0 +1,83 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
class RequestSigningAuthenticator
|
||||
AUTHORIZATION_HEADER_NAME = "Authorization"
|
||||
CONTENT_TYPE_HEADER_NAME = "Content-Type"
|
||||
STRIPE_CONTEXT_HEADER_NAME = "Stripe-Context"
|
||||
STRIPE_ACCOUNT_HEADER_NAME = "Stripe-Account"
|
||||
CONTENT_DIGEST_HEADER_NAME = "Content-Digest"
|
||||
SIGNATURE_INPUT_HEADER_NAME = "Signature-Input"
|
||||
SIGNATURE_HEADER_NAME = "Signature"
|
||||
|
||||
attr_reader :auth_token, :sign_lambda
|
||||
|
||||
def initialize(auth_token, sign_lambda)
|
||||
unless auth_token.is_a?(String)
|
||||
raise ArgumentError, "auth_token must be a string"
|
||||
end
|
||||
unless sign_lambda.is_a?(Proc)
|
||||
raise ArgumentError, "sign_lambda must be a lambda"
|
||||
end
|
||||
|
||||
@auth_token = auth_token
|
||||
@sign_lambda = sign_lambda
|
||||
end
|
||||
|
||||
def authenticate(method, headers, body)
|
||||
covered_headers = [CONTENT_TYPE_HEADER_NAME,
|
||||
CONTENT_DIGEST_HEADER_NAME,
|
||||
STRIPE_CONTEXT_HEADER_NAME,
|
||||
STRIPE_ACCOUNT_HEADER_NAME,
|
||||
AUTHORIZATION_HEADER_NAME,]
|
||||
|
||||
headers[AUTHORIZATION_HEADER_NAME] = "STRIPE-V2-SIG #{auth_token}"
|
||||
|
||||
if method == :get
|
||||
covered_headers -= [CONTENT_TYPE_HEADER_NAME,
|
||||
CONTENT_DIGEST_HEADER_NAME,]
|
||||
else
|
||||
content = body || ""
|
||||
headers[CONTENT_DIGEST_HEADER_NAME] =
|
||||
%(sha-256=:#{content_digest(content)}:)
|
||||
end
|
||||
|
||||
covered_headers_formatted = covered_headers
|
||||
.map { |string| %("#{string.downcase}") }
|
||||
.join(" ")
|
||||
|
||||
signature_input = "(#{covered_headers_formatted});created=#{created_time}"
|
||||
|
||||
inputs = covered_headers
|
||||
.map { |header| %("#{header.downcase}": #{headers[header]}) }
|
||||
.join("\n")
|
||||
|
||||
signature_base = %(#{inputs}\n"@signature-params": #{signature_input})
|
||||
.encode(Encoding::UTF_8)
|
||||
|
||||
headers[SIGNATURE_INPUT_HEADER_NAME] = "sig1=#{signature_input}"
|
||||
|
||||
headers[SIGNATURE_HEADER_NAME] =
|
||||
"sig1=:#{encoded_signature(signature_base)}:"
|
||||
end
|
||||
|
||||
private def sign(signature_base)
|
||||
@sign_lambda.call(signature_base)
|
||||
end
|
||||
|
||||
private def encoded_signature(signature_base)
|
||||
Base64.strict_encode64(sign(signature_base))
|
||||
rescue StandardError
|
||||
raise AuthenticationError, "Encountered '#{e.message} (#{e.class})' "\
|
||||
"when calculating request signature."
|
||||
end
|
||||
|
||||
private def content_digest(content)
|
||||
Base64.strict_encode64(OpenSSL::Digest.new("SHA256").digest(content))
|
||||
end
|
||||
|
||||
private def created_time
|
||||
Time.now.to_i
|
||||
end
|
||||
end
|
||||
end
|
@ -3,6 +3,7 @@
|
||||
|
||||
require "stripe/resources/account"
|
||||
require "stripe/resources/account_link"
|
||||
require "stripe/resources/account_session"
|
||||
require "stripe/resources/apple_pay_domain"
|
||||
require "stripe/resources/application_fee"
|
||||
require "stripe/resources/application_fee_refund"
|
||||
@ -13,6 +14,9 @@ require "stripe/resources/bank_account"
|
||||
require "stripe/resources/billing_portal/configuration"
|
||||
require "stripe/resources/billing_portal/session"
|
||||
require "stripe/resources/capability"
|
||||
require "stripe/resources/capital/financing_offer"
|
||||
require "stripe/resources/capital/financing_summary"
|
||||
require "stripe/resources/capital/financing_transaction"
|
||||
require "stripe/resources/card"
|
||||
require "stripe/resources/cash_balance"
|
||||
require "stripe/resources/charge"
|
||||
@ -24,6 +28,7 @@ require "stripe/resources/credit_note_line_item"
|
||||
require "stripe/resources/customer"
|
||||
require "stripe/resources/customer_balance_transaction"
|
||||
require "stripe/resources/customer_cash_balance_transaction"
|
||||
require "stripe/resources/customer_session"
|
||||
require "stripe/resources/discount"
|
||||
require "stripe/resources/dispute"
|
||||
require "stripe/resources/ephemeral_key"
|
||||
@ -34,8 +39,12 @@ require "stripe/resources/file_link"
|
||||
require "stripe/resources/financial_connections/account"
|
||||
require "stripe/resources/financial_connections/account_owner"
|
||||
require "stripe/resources/financial_connections/account_ownership"
|
||||
require "stripe/resources/financial_connections/inferred_balance"
|
||||
require "stripe/resources/financial_connections/session"
|
||||
require "stripe/resources/financial_connections/transaction"
|
||||
require "stripe/resources/funding_instructions"
|
||||
require "stripe/resources/gift_cards/card"
|
||||
require "stripe/resources/gift_cards/transaction"
|
||||
require "stripe/resources/identity/verification_report"
|
||||
require "stripe/resources/identity/verification_session"
|
||||
require "stripe/resources/invoice"
|
||||
@ -43,15 +52,19 @@ require "stripe/resources/invoice_item"
|
||||
require "stripe/resources/invoice_line_item"
|
||||
require "stripe/resources/issuing/authorization"
|
||||
require "stripe/resources/issuing/card"
|
||||
require "stripe/resources/issuing/card_bundle"
|
||||
require "stripe/resources/issuing/card_design"
|
||||
require "stripe/resources/issuing/cardholder"
|
||||
require "stripe/resources/issuing/dispute"
|
||||
require "stripe/resources/issuing/transaction"
|
||||
require "stripe/resources/line_item"
|
||||
require "stripe/resources/login_link"
|
||||
require "stripe/resources/mandate"
|
||||
require "stripe/resources/order"
|
||||
require "stripe/resources/payment_intent"
|
||||
require "stripe/resources/payment_link"
|
||||
require "stripe/resources/payment_method"
|
||||
require "stripe/resources/payment_method_configuration"
|
||||
require "stripe/resources/payout"
|
||||
require "stripe/resources/person"
|
||||
require "stripe/resources/plan"
|
||||
@ -59,6 +72,9 @@ require "stripe/resources/price"
|
||||
require "stripe/resources/product"
|
||||
require "stripe/resources/promotion_code"
|
||||
require "stripe/resources/quote"
|
||||
require "stripe/resources/quote_phase"
|
||||
require "stripe/resources/quote_preview_invoice"
|
||||
require "stripe/resources/quote_preview_schedule"
|
||||
require "stripe/resources/radar/early_fraud_warning"
|
||||
require "stripe/resources/radar/value_list"
|
||||
require "stripe/resources/radar/value_list_item"
|
||||
@ -78,6 +94,8 @@ require "stripe/resources/subscription_item"
|
||||
require "stripe/resources/subscription_schedule"
|
||||
require "stripe/resources/tax/calculation"
|
||||
require "stripe/resources/tax/calculation_line_item"
|
||||
require "stripe/resources/tax/form"
|
||||
require "stripe/resources/tax/registration"
|
||||
require "stripe/resources/tax/settings"
|
||||
require "stripe/resources/tax/transaction"
|
||||
require "stripe/resources/tax/transaction_line_item"
|
||||
|
17
lib/stripe/resources/account_session.rb
Normal file
17
lib/stripe/resources/account_session.rb
Normal file
@ -0,0 +1,17 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
# An AccountSession allows a Connect platform to grant access to a connected account in Connect embedded components.
|
||||
#
|
||||
# We recommend that you create an AccountSession each time you need to display an embedded component
|
||||
# to your user. Do not save AccountSessions to your database as they expire relatively
|
||||
# quickly, and cannot be used more than once.
|
||||
#
|
||||
# Related guide: [Connect embedded components](https://stripe.com/docs/connect/get-started-connect-embedded-components)
|
||||
class AccountSession < APIResource
|
||||
extend Stripe::APIOperations::Create
|
||||
|
||||
OBJECT_NAME = "account_session"
|
||||
end
|
||||
end
|
32
lib/stripe/resources/capital/financing_offer.rb
Normal file
32
lib/stripe/resources/capital/financing_offer.rb
Normal file
@ -0,0 +1,32 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module Capital
|
||||
# This is an object representing an offer of financing from
|
||||
# Stripe Capital to a Connect subaccount.
|
||||
class FinancingOffer < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
|
||||
OBJECT_NAME = "capital.financing_offer"
|
||||
|
||||
def mark_delivered(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/capital/financing_offers/%<financing_offer>s/mark_delivered", { financing_offer: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.mark_delivered(financing_offer, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/capital/financing_offers/%<financing_offer>s/mark_delivered", { financing_offer: CGI.escape(financing_offer) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
12
lib/stripe/resources/capital/financing_summary.rb
Normal file
12
lib/stripe/resources/capital/financing_summary.rb
Normal file
@ -0,0 +1,12 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module Capital
|
||||
# A financing object describes an account's current financing state. Used by Connect
|
||||
# platforms to read the state of Capital offered to their connected accounts.
|
||||
class FinancingSummary < SingletonAPIResource
|
||||
OBJECT_NAME = "capital.financing_summary"
|
||||
end
|
||||
end
|
||||
end
|
13
lib/stripe/resources/capital/financing_transaction.rb
Normal file
13
lib/stripe/resources/capital/financing_transaction.rb
Normal file
@ -0,0 +1,13 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module Capital
|
||||
# This is an object representing the details of a transaction on a Capital financing object.
|
||||
class FinancingTransaction < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
|
||||
OBJECT_NAME = "capital.financing_transaction"
|
||||
end
|
||||
end
|
||||
end
|
12
lib/stripe/resources/customer_session.rb
Normal file
12
lib/stripe/resources/customer_session.rb
Normal file
@ -0,0 +1,12 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
# A customer session allows you to grant client access to Stripe's frontend SDKs (like StripeJs)
|
||||
# control over a customer.
|
||||
class CustomerSession < APIResource
|
||||
extend Stripe::APIOperations::Create
|
||||
|
||||
OBJECT_NAME = "customer_session"
|
||||
end
|
||||
end
|
@ -6,9 +6,12 @@ module Stripe
|
||||
# A Financial Connections Account represents an account that exists outside of Stripe, to which you have been granted some degree of access.
|
||||
class Account < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
extend Stripe::APIOperations::NestedResource
|
||||
|
||||
OBJECT_NAME = "financial_connections.account"
|
||||
|
||||
nested_resource_class_methods :inferred_balance, operations: %i[list]
|
||||
|
||||
def disconnect(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
@ -36,6 +39,24 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
def subscribe(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/financial_connections/accounts/%<account>s/subscribe", { account: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def unsubscribe(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/financial_connections/accounts/%<account>s/unsubscribe", { account: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.disconnect(account, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
@ -62,6 +83,24 @@ module Stripe
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.subscribe(account, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/financial_connections/accounts/%<account>s/subscribe", { account: CGI.escape(account) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.unsubscribe(account, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/financial_connections/accounts/%<account>s/unsubscribe", { account: CGI.escape(account) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,13 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module FinancialConnections
|
||||
# A historical balance for the account on a particular day. It may be sourced from a balance snapshot provided by a financial institution, or inferred using transactions data.
|
||||
class InferredBalance < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
|
||||
OBJECT_NAME = "financial_connections.account_inferred_balance"
|
||||
end
|
||||
end
|
||||
end
|
13
lib/stripe/resources/financial_connections/transaction.rb
Normal file
13
lib/stripe/resources/financial_connections/transaction.rb
Normal file
@ -0,0 +1,13 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module FinancialConnections
|
||||
# A Transaction represents a real transaction that affects a Financial Connections Account balance.
|
||||
class Transaction < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
|
||||
OBJECT_NAME = "financial_connections.transaction"
|
||||
end
|
||||
end
|
||||
end
|
25
lib/stripe/resources/gift_cards/card.rb
Normal file
25
lib/stripe/resources/gift_cards/card.rb
Normal file
@ -0,0 +1,25 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module GiftCards
|
||||
# A gift card represents a single gift card owned by a customer, including the
|
||||
# remaining balance, gift card code, and whether or not it is active.
|
||||
class Card < APIResource
|
||||
extend Stripe::APIOperations::Create
|
||||
extend Stripe::APIOperations::List
|
||||
include Stripe::APIOperations::Save
|
||||
|
||||
OBJECT_NAME = "gift_cards.card"
|
||||
|
||||
def self.validate(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: "/v1/gift_cards/cards/validate",
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
56
lib/stripe/resources/gift_cards/transaction.rb
Normal file
56
lib/stripe/resources/gift_cards/transaction.rb
Normal file
@ -0,0 +1,56 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module GiftCards
|
||||
# A gift card transaction represents a single transaction on a referenced gift card.
|
||||
# A transaction is in one of three states, `confirmed`, `held` or `canceled`. A `confirmed`
|
||||
# transaction is one that has added/deducted funds. A `held` transaction has created a
|
||||
# temporary hold on funds, which can then be cancelled or confirmed. A `held` transaction
|
||||
# can be confirmed into a `confirmed` transaction, or canceled into a `canceled` transaction.
|
||||
# A `canceled` transaction has no effect on a gift card's balance.
|
||||
class Transaction < APIResource
|
||||
extend Stripe::APIOperations::Create
|
||||
extend Stripe::APIOperations::List
|
||||
include Stripe::APIOperations::Save
|
||||
|
||||
OBJECT_NAME = "gift_cards.transaction"
|
||||
|
||||
def cancel(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/gift_cards/transactions/%<id>s/cancel", { id: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def confirm(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/gift_cards/transactions/%<id>s/confirm", { id: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.cancel(id, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/gift_cards/transactions/%<id>s/cancel", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.confirm(id, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/gift_cards/transactions/%<id>s/confirm", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -54,6 +54,15 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
def self.submit_card(card, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/submit", { card: CGI.escape(card) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def deliver_card(params = {}, opts = {})
|
||||
@resource.request_stripe_object(
|
||||
method: :post,
|
||||
@ -89,6 +98,15 @@ module Stripe
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def submit_card(params = {}, opts = {})
|
||||
@resource.request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/issuing/cards/%<card>s/shipping/submit", { card: CGI.escape(@resource["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
13
lib/stripe/resources/issuing/card_bundle.rb
Normal file
13
lib/stripe/resources/issuing/card_bundle.rb
Normal file
@ -0,0 +1,13 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module Issuing
|
||||
# A Card Bundle represents the bundle of physical items - card stock, carrier letter, and envelope - that is shipped to a cardholder when you create a physical card.
|
||||
class CardBundle < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
|
||||
OBJECT_NAME = "issuing.card_bundle"
|
||||
end
|
||||
end
|
||||
end
|
58
lib/stripe/resources/issuing/card_design.rb
Normal file
58
lib/stripe/resources/issuing/card_design.rb
Normal file
@ -0,0 +1,58 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module Issuing
|
||||
# A Card Design is a logical grouping of a Card Bundle, card logo, and carrier text that represents a product line.
|
||||
class CardDesign < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
include Stripe::APIOperations::Save
|
||||
|
||||
OBJECT_NAME = "issuing.card_design"
|
||||
|
||||
def test_helpers
|
||||
TestHelpers.new(self)
|
||||
end
|
||||
|
||||
class TestHelpers < APIResourceTestHelpers
|
||||
RESOURCE_CLASS = CardDesign
|
||||
|
||||
def self.activate_testmode(card_design, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/issuing/card_designs/%<card_design>s/status/activate", { card_design: CGI.escape(card_design) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.deactivate_testmode(card_design, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/issuing/card_designs/%<card_design>s/status/deactivate", { card_design: CGI.escape(card_design) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def activate_testmode(params = {}, opts = {})
|
||||
@resource.request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/issuing/card_designs/%<card_design>s/status/activate", { card_design: CGI.escape(@resource["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def deactivate_testmode(params = {}, opts = {})
|
||||
@resource.request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/test_helpers/issuing/card_designs/%<card_design>s/status/deactivate", { card_design: CGI.escape(@resource["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
89
lib/stripe/resources/order.rb
Normal file
89
lib/stripe/resources/order.rb
Normal file
@ -0,0 +1,89 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
# An Order describes a purchase being made by a customer, including the
|
||||
# products & quantities being purchased, the order status, the payment information,
|
||||
# and the billing/shipping details.
|
||||
#
|
||||
# Related guide: [Orders overview](https://stripe.com/docs/orders)
|
||||
class Order < APIResource
|
||||
extend Stripe::APIOperations::Create
|
||||
extend Stripe::APIOperations::List
|
||||
include Stripe::APIOperations::Save
|
||||
|
||||
OBJECT_NAME = "order"
|
||||
|
||||
def cancel(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/orders/%<id>s/cancel", { id: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def list_line_items(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/orders/%<id>s/line_items", { id: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def reopen(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/orders/%<id>s/reopen", { id: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def submit(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/orders/%<id>s/submit", { id: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.cancel(id, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/orders/%<id>s/cancel", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.list_line_items(id, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/orders/%<id>s/line_items", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.reopen(id, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/orders/%<id>s/reopen", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.submit(id, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/orders/%<id>s/submit", { id: CGI.escape(id) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
13
lib/stripe/resources/payment_method_configuration.rb
Normal file
13
lib/stripe/resources/payment_method_configuration.rb
Normal file
@ -0,0 +1,13 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
# An object detailing payment method configurations.
|
||||
class PaymentMethodConfiguration < APIResource
|
||||
extend Stripe::APIOperations::Create
|
||||
extend Stripe::APIOperations::List
|
||||
include Stripe::APIOperations::Save
|
||||
|
||||
OBJECT_NAME = "payment_method_configuration"
|
||||
end
|
||||
end
|
@ -29,6 +29,15 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
def draft_quote(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/quotes/%<quote>s/mark_draft", { quote: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def finalize_quote(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
@ -56,6 +65,24 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
def list_lines(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quotes/%<quote>s/lines", { quote: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def mark_stale_quote(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/quotes/%<quote>s/mark_stale", { quote: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def pdf(params = {}, opts = {}, &read_body_chunk_block)
|
||||
config = opts[:client]&.config || Stripe.config
|
||||
opts = { api_base: config.uploads_base }.merge(opts)
|
||||
@ -68,6 +95,42 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
def preview_invoice_lines(preview_invoice, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quotes/%<quote>s/preview_invoices/%<preview_invoice>s/lines", { quote: CGI.escape(self["id"]), preview_invoice: CGI.escape(preview_invoice) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def preview_invoices(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quotes/%<quote>s/preview_invoices", { quote: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def preview_subscription_schedules(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quotes/%<quote>s/preview_subscription_schedules", { quote: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def reestimate(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/quotes/%<quote>s/reestimate", { quote: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.accept(quote, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
@ -86,6 +149,15 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
def self.draft_quote(quote, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/quotes/%<quote>s/mark_draft", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.finalize_quote(quote, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
@ -113,6 +185,24 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
def self.list_lines(quote, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quotes/%<quote>s/lines", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.mark_stale_quote(quote, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/quotes/%<quote>s/mark_stale", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.pdf(quote, params = {}, opts = {}, &read_body_chunk_block)
|
||||
config = opts[:client]&.config || Stripe.config
|
||||
opts = { api_base: config.uploads_base }.merge(opts)
|
||||
@ -124,5 +214,46 @@ module Stripe
|
||||
&read_body_chunk_block
|
||||
)
|
||||
end
|
||||
|
||||
def self.preview_invoice_lines(
|
||||
quote,
|
||||
preview_invoice,
|
||||
params = {},
|
||||
opts = {}
|
||||
)
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quotes/%<quote>s/preview_invoices/%<preview_invoice>s/lines", { quote: CGI.escape(quote), preview_invoice: CGI.escape(preview_invoice) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.preview_invoices(quote, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quotes/%<quote>s/preview_invoices", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.preview_subscription_schedules(quote, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quotes/%<quote>s/preview_subscription_schedules", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.reestimate(quote, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/quotes/%<quote>s/reestimate", { quote: CGI.escape(quote) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
29
lib/stripe/resources/quote_phase.rb
Normal file
29
lib/stripe/resources/quote_phase.rb
Normal file
@ -0,0 +1,29 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
# A quote phase describes the line items, coupons, and trialing status of a subscription for a predefined time period.
|
||||
class QuotePhase < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
|
||||
OBJECT_NAME = "quote_phase"
|
||||
|
||||
def list_line_items(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quote_phases/%<quote_phase>s/line_items", { quote_phase: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.list_line_items(quote_phase, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :get,
|
||||
path: format("/v1/quote_phases/%<quote_phase>s/line_items", { quote_phase: CGI.escape(quote_phase) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
40
lib/stripe/resources/quote_preview_invoice.rb
Normal file
40
lib/stripe/resources/quote_preview_invoice.rb
Normal file
@ -0,0 +1,40 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
# Invoices are statements of amounts owed by a customer, and are either
|
||||
# generated one-off, or generated periodically from a subscription.
|
||||
#
|
||||
# They contain [invoice items](https://stripe.com/docs/api#invoiceitems), and proration adjustments
|
||||
# that may be caused by subscription upgrades/downgrades (if necessary).
|
||||
#
|
||||
# If your invoice is configured to be billed through automatic charges,
|
||||
# Stripe automatically finalizes your invoice and attempts payment. Note
|
||||
# that finalizing the invoice,
|
||||
# [when automatic](https://stripe.com/docs/invoicing/integration/automatic-advancement-collection), does
|
||||
# not happen immediately as the invoice is created. Stripe waits
|
||||
# until one hour after the last webhook was successfully sent (or the last
|
||||
# webhook timed out after failing). If you (and the platforms you may have
|
||||
# connected to) have no webhooks configured, Stripe waits one hour after
|
||||
# creation to finalize the invoice.
|
||||
#
|
||||
# If your invoice is configured to be billed by sending an email, then based on your
|
||||
# [email settings](https://dashboard.stripe.com/account/billing/automatic),
|
||||
# Stripe will email the invoice to your customer and await payment. These
|
||||
# emails can contain a link to a hosted page to pay the invoice.
|
||||
#
|
||||
# Stripe applies any customer credit on the account before determining the
|
||||
# amount due for the invoice (i.e., the amount that will be actually
|
||||
# charged). If the amount due for the invoice is less than Stripe's [minimum allowed charge
|
||||
# per currency](https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts), the
|
||||
# invoice is automatically marked paid, and we add the amount due to the
|
||||
# customer's credit balance which is applied to the next invoice.
|
||||
#
|
||||
# More details on the customer's credit balance are
|
||||
# [here](https://stripe.com/docs/billing/customer/balance).
|
||||
#
|
||||
# Related guide: [Send invoices to customers](https://stripe.com/docs/billing/invoices/sending)
|
||||
class QuotePreviewInvoice < APIResource
|
||||
OBJECT_NAME = "quote_preview_invoice"
|
||||
end
|
||||
end
|
8
lib/stripe/resources/quote_preview_schedule.rb
Normal file
8
lib/stripe/resources/quote_preview_schedule.rb
Normal file
@ -0,0 +1,8 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
class QuotePreviewSchedule < APIResource
|
||||
OBJECT_NAME = "quote_preview_schedule"
|
||||
end
|
||||
end
|
@ -12,6 +12,15 @@ module Stripe
|
||||
|
||||
OBJECT_NAME = "subscription_schedule"
|
||||
|
||||
def amend(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/subscription_schedules/%<schedule>s/amend", { schedule: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def cancel(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
@ -30,6 +39,15 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
def self.amend(schedule, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/subscription_schedules/%<schedule>s/amend", { schedule: CGI.escape(schedule) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.cancel(schedule, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
|
39
lib/stripe/resources/tax/form.rb
Normal file
39
lib/stripe/resources/tax/form.rb
Normal file
@ -0,0 +1,39 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module Tax
|
||||
# Tax forms are legal documents which are delivered to one or more tax authorities for information reporting purposes.
|
||||
#
|
||||
# Related guide: [US tax reporting for Connect platforms](https://stripe.com/docs/connect/tax-reporting)
|
||||
class Form < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
|
||||
OBJECT_NAME = "tax.form"
|
||||
|
||||
def pdf(params = {}, opts = {}, &read_body_chunk_block)
|
||||
config = opts[:client]&.config || Stripe.config
|
||||
opts = { api_base: config.uploads_base }.merge(opts)
|
||||
request_stream(
|
||||
method: :get,
|
||||
path: format("/v1/tax/forms/%<id>s/pdf", { id: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts,
|
||||
&read_body_chunk_block
|
||||
)
|
||||
end
|
||||
|
||||
def self.pdf(id, params = {}, opts = {}, &read_body_chunk_block)
|
||||
config = opts[:client]&.config || Stripe.config
|
||||
opts = { api_base: config.uploads_base }.merge(opts)
|
||||
execute_resource_request_stream(
|
||||
:get,
|
||||
format("/v1/tax/forms/%<id>s/pdf", { id: CGI.escape(id) }),
|
||||
params,
|
||||
opts,
|
||||
&read_body_chunk_block
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
lib/stripe/resources/tax/registration.rb
Normal file
19
lib/stripe/resources/tax/registration.rb
Normal file
@ -0,0 +1,19 @@
|
||||
# File generated from our OpenAPI spec
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
module Tax
|
||||
# A Tax `Registration` lets us know that your business is registered to collect tax on payments within a region, enabling you to [automatically collect tax](https://stripe.com/docs/tax).
|
||||
#
|
||||
# Stripe doesn't register on your behalf with the relevant authorities when you create a Tax `Registration` object. For more information on how to register to collect tax, see [our guide](https://stripe.com/docs/tax/registering).
|
||||
#
|
||||
# Related guide: [Using the Registrations API](https://stripe.com/docs/tax/registrations-api)
|
||||
class Registration < APIResource
|
||||
extend Stripe::APIOperations::Create
|
||||
extend Stripe::APIOperations::List
|
||||
include Stripe::APIOperations::Save
|
||||
|
||||
OBJECT_NAME = "tax.registration"
|
||||
end
|
||||
end
|
||||
end
|
@ -23,6 +23,33 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
def collect_inputs(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/terminal/readers/%<reader>s/collect_inputs", { reader: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def collect_payment_method(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/terminal/readers/%<reader>s/collect_payment_method", { reader: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def confirm_payment_intent(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/terminal/readers/%<reader>s/confirm_payment_intent", { reader: CGI.escape(self["id"]) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def process_payment_intent(params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
@ -68,6 +95,33 @@ module Stripe
|
||||
)
|
||||
end
|
||||
|
||||
def self.collect_inputs(reader, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/terminal/readers/%<reader>s/collect_inputs", { reader: CGI.escape(reader) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.collect_payment_method(reader, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/terminal/readers/%<reader>s/collect_payment_method", { reader: CGI.escape(reader) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.confirm_payment_intent(reader, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
path: format("/v1/terminal/readers/%<reader>s/confirm_payment_intent", { reader: CGI.escape(reader) }),
|
||||
params: params,
|
||||
opts: opts
|
||||
)
|
||||
end
|
||||
|
||||
def self.process_payment_intent(reader, params = {}, opts = {})
|
||||
request_stripe_object(
|
||||
method: :post,
|
||||
|
@ -212,9 +212,10 @@ module Stripe
|
||||
end
|
||||
|
||||
def execute_request(method, path,
|
||||
api_base: nil, api_key: nil, headers: {}, params: {})
|
||||
api_base: nil, api_key: nil,
|
||||
headers: {}, params: {}, api_mode: nil)
|
||||
http_resp, api_key = execute_request_internal(
|
||||
method, path, api_base, api_key, headers, params
|
||||
method, path, api_base, api_key, headers, params, api_mode
|
||||
)
|
||||
|
||||
begin
|
||||
@ -245,6 +246,7 @@ module Stripe
|
||||
def execute_request_stream(method, path,
|
||||
api_base: nil, api_key: nil,
|
||||
headers: {}, params: {},
|
||||
api_mode: nil,
|
||||
&read_body_chunk_block)
|
||||
unless block_given?
|
||||
raise ArgumentError,
|
||||
@ -252,7 +254,8 @@ module Stripe
|
||||
end
|
||||
|
||||
http_resp, api_key = execute_request_internal(
|
||||
method, path, api_base, api_key, headers, params, &read_body_chunk_block
|
||||
method, path, api_base, api_key,
|
||||
headers, params, api_mode, &read_body_chunk_block
|
||||
)
|
||||
|
||||
# When the read_body_chunk_block is given, we no longer have access to the
|
||||
@ -432,7 +435,7 @@ module Stripe
|
||||
|
||||
private def execute_request_internal(method, path,
|
||||
api_base, api_key, headers, params,
|
||||
&read_body_chunk_block)
|
||||
api_mode, &read_body_chunk_block)
|
||||
raise ArgumentError, "method should be a symbol" \
|
||||
unless method.is_a?(Symbol)
|
||||
raise ArgumentError, "path should be a string" \
|
||||
@ -440,9 +443,10 @@ module Stripe
|
||||
|
||||
api_base ||= config.api_base
|
||||
api_key ||= config.api_key
|
||||
authenticator ||= config.authenticator
|
||||
params = Util.objects_to_ids(params)
|
||||
|
||||
check_api_key!(api_key)
|
||||
check_keys!(api_key, authenticator)
|
||||
|
||||
body_params = nil
|
||||
query_params = nil
|
||||
@ -455,8 +459,9 @@ module Stripe
|
||||
|
||||
query_params, path = merge_query_params(query_params, path)
|
||||
|
||||
headers = request_headers(api_key, method)
|
||||
headers = request_headers(api_key, method, api_mode)
|
||||
.update(Util.normalize_headers(headers))
|
||||
|
||||
url = api_url(path, api_base)
|
||||
|
||||
# Merge given query parameters with any already encoded in the path.
|
||||
@ -467,13 +472,16 @@ module Stripe
|
||||
# a log-friendly variant of the encoded form. File objects are displayed
|
||||
# as such instead of as their file contents.
|
||||
body, body_log =
|
||||
body_params ? encode_body(body_params, headers) : [nil, nil]
|
||||
body_params ? encode_body(body_params, headers, api_mode) : [nil, nil]
|
||||
|
||||
authenticator.authenticate(method, headers, body) unless api_key
|
||||
|
||||
# stores information on the request we're about to make so that we don't
|
||||
# have to pass as many parameters around for logging.
|
||||
context = RequestLogContext.new
|
||||
context.account = headers["Stripe-Account"]
|
||||
context.api_key = api_key
|
||||
context.authenticator = authenticator
|
||||
context.api_version = headers["Stripe-Version"]
|
||||
context.body = body_log
|
||||
context.idempotency_key = headers["Idempotency-Key"]
|
||||
@ -512,8 +520,16 @@ module Stripe
|
||||
(api_base || config.api_base) + url
|
||||
end
|
||||
|
||||
private def check_api_key!(api_key)
|
||||
unless api_key
|
||||
private def check_keys!(api_key, authenticator)
|
||||
if api_key && authenticator
|
||||
raise AuthenticationError, "Can't specify both API key " \
|
||||
"and authenticator. Either set your API key" \
|
||||
'using "Stripe.api_key = <API-KEY>", or set your authenticator ' \
|
||||
'using "Stripe.authenticator = <AUTHENTICATOR>"' \
|
||||
end
|
||||
|
||||
unless api_key || authenticator
|
||||
# Default to missing API key error message for general users.
|
||||
raise AuthenticationError, "No API key provided. " \
|
||||
'Set your API key using "Stripe.api_key = <API-KEY>". ' \
|
||||
"You can generate API keys from the Stripe web interface. " \
|
||||
@ -532,7 +548,7 @@ module Stripe
|
||||
# Encodes a set of body parameters using multipart if `Content-Type` is set
|
||||
# for that, or standard form-encoding otherwise. Returns the encoded body
|
||||
# and a version of the encoded body that's safe to be logged.
|
||||
private def encode_body(body_params, headers)
|
||||
private def encode_body(body_params, headers, api_mode)
|
||||
body = nil
|
||||
flattened_params = Util.flatten_params(body_params)
|
||||
|
||||
@ -548,15 +564,22 @@ module Stripe
|
||||
flattened_params =
|
||||
flattened_params.map { |k, v| [k, v.is_a?(String) ? v : v.to_s] }.to_h
|
||||
|
||||
elsif api_mode == :preview
|
||||
body = JSON.generate(body_params)
|
||||
headers["Content-Type"] = "application/json"
|
||||
else
|
||||
body = Util.encode_parameters(body_params)
|
||||
end
|
||||
|
||||
# We don't use `Util.encode_parameters` partly as an optimization (to not
|
||||
# redo work we've already done), and partly because the encoded forms of
|
||||
# certain characters introduce a lot of visual noise and it's nice to
|
||||
# have a clearer format for logs.
|
||||
body_log = flattened_params.map { |k, v| "#{k}=#{v}" }.join("&")
|
||||
if api_mode == :preview
|
||||
body_log = body
|
||||
else
|
||||
# We don't use `Util.encode_parameters` partly as an optimization (to
|
||||
# not redo work we've already done), and partly because the encoded
|
||||
# forms of certain characters introduce a lot of visual noise and it's
|
||||
# nice to have a clearer format for logs.
|
||||
body_log = flattened_params.map { |k, v| "#{k}=#{v}" }.join("&")
|
||||
end
|
||||
|
||||
[body, body_log]
|
||||
end
|
||||
@ -745,10 +768,11 @@ module Stripe
|
||||
end
|
||||
|
||||
private def specific_api_error(resp, error_data, context)
|
||||
message = error_data[:message]
|
||||
Util.log_error("Stripe API error",
|
||||
status: resp.http_status,
|
||||
error_code: error_data[:code],
|
||||
error_message: error_data[:message],
|
||||
error_message: message,
|
||||
error_param: error_data[:param],
|
||||
error_type: error_data[:type],
|
||||
idempotency_key: context.idempotency_key,
|
||||
@ -769,26 +793,26 @@ module Stripe
|
||||
when 400, 404
|
||||
case error_data[:type]
|
||||
when "idempotency_error"
|
||||
IdempotencyError.new(error_data[:message], **opts)
|
||||
IdempotencyError.new(message, **opts)
|
||||
else
|
||||
InvalidRequestError.new(
|
||||
error_data[:message], error_data[:param],
|
||||
message, error_data[:param],
|
||||
**opts
|
||||
)
|
||||
end
|
||||
when 401
|
||||
AuthenticationError.new(error_data[:message], **opts)
|
||||
AuthenticationError.new(message, **opts)
|
||||
when 402
|
||||
CardError.new(
|
||||
error_data[:message], error_data[:param],
|
||||
message, error_data[:param],
|
||||
**opts
|
||||
)
|
||||
when 403
|
||||
PermissionError.new(error_data[:message], **opts)
|
||||
PermissionError.new(message, **opts)
|
||||
when 429
|
||||
RateLimitError.new(error_data[:message], **opts)
|
||||
RateLimitError.new(message, **opts)
|
||||
else
|
||||
APIError.new(error_data[:message], **opts)
|
||||
APIError.new(message, **opts)
|
||||
end
|
||||
end
|
||||
|
||||
@ -856,7 +880,7 @@ module Stripe
|
||||
message + "\n\n(Network error: #{error.message})"
|
||||
end
|
||||
|
||||
private def request_headers(api_key, method)
|
||||
private def request_headers(api_key, method, api_mode)
|
||||
user_agent = "Stripe/v1 RubyBindings/#{Stripe::VERSION}"
|
||||
unless Stripe.app_info.nil?
|
||||
user_agent += " " + format_app_info(Stripe.app_info)
|
||||
@ -865,9 +889,13 @@ module Stripe
|
||||
headers = {
|
||||
"User-Agent" => user_agent,
|
||||
"Authorization" => "Bearer #{api_key}",
|
||||
"Content-Type" => "application/x-www-form-urlencoded",
|
||||
}
|
||||
|
||||
if api_mode != :preview
|
||||
# TODO: (major) don't set Content-Type if method is not post
|
||||
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||
end
|
||||
|
||||
if config.enable_telemetry? && !@last_request_metrics.nil?
|
||||
headers["X-Stripe-Client-Telemetry"] = JSON.generate(
|
||||
last_request_metrics: @last_request_metrics.payload
|
||||
@ -880,7 +908,12 @@ module Stripe
|
||||
headers["Idempotency-Key"] ||= SecureRandom.uuid
|
||||
end
|
||||
|
||||
headers["Stripe-Version"] = config.api_version if config.api_version
|
||||
if api_mode == :preview
|
||||
headers["Stripe-Version"] = ApiVersion::PREVIEW
|
||||
elsif config.api_version
|
||||
headers["Stripe-Version"] = config.api_version
|
||||
end
|
||||
|
||||
headers["Stripe-Account"] = config.stripe_account if config.stripe_account
|
||||
|
||||
user_agent = @system_profiler.user_agent
|
||||
@ -966,6 +999,7 @@ module Stripe
|
||||
attr_accessor :body
|
||||
attr_accessor :account
|
||||
attr_accessor :api_key
|
||||
attr_accessor :authenticator
|
||||
attr_accessor :api_version
|
||||
attr_accessor :idempotency_key
|
||||
attr_accessor :method
|
||||
|
@ -27,6 +27,7 @@ module Stripe
|
||||
class StripeConfiguration
|
||||
attr_accessor :api_key
|
||||
attr_accessor :api_version
|
||||
attr_accessor :authenticator
|
||||
attr_accessor :client_id
|
||||
attr_accessor :enable_telemetry
|
||||
attr_accessor :logger
|
||||
@ -64,6 +65,7 @@ module Stripe
|
||||
|
||||
def initialize
|
||||
@api_version = ApiVersion::CURRENT
|
||||
|
||||
@ca_bundle_path = Stripe::DEFAULT_CA_BUNDLE_PATH
|
||||
@enable_telemetry = true
|
||||
@verify_ssl_certs = true
|
||||
|
@ -7,6 +7,7 @@ module Stripe
|
||||
# Options that a user is allowed to specify.
|
||||
OPTS_USER_SPECIFIED = Set[
|
||||
:api_key,
|
||||
:authenticator,
|
||||
:idempotency_key,
|
||||
:stripe_account,
|
||||
:stripe_version
|
||||
@ -281,7 +282,13 @@ module Stripe
|
||||
when String
|
||||
{ api_key: opts }
|
||||
when Hash
|
||||
check_api_key!(opts.fetch(:api_key)) if opts.key?(:api_key)
|
||||
# If the user is using request signing for authentication,
|
||||
# no need to check the api_key per request.
|
||||
if !(opts.key?(:client) &&
|
||||
opts.fetch(:client).config.authenticator) &&
|
||||
opts.key?(:api_key)
|
||||
check_api_key!(opts.fetch(:api_key))
|
||||
end
|
||||
# Explicitly use dup here instead of clone to avoid preserving freeze
|
||||
# state on input params.
|
||||
opts.dup
|
||||
|
@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stripe
|
||||
VERSION = "9.0.0"
|
||||
VERSION = "9.0.0-beta.1"
|
||||
end
|
||||
|
@ -80,6 +80,19 @@ module Stripe
|
||||
|
||||
should "not specifying api credentials should raise an exception" do
|
||||
Stripe.api_key = nil
|
||||
Stripe.authenticator = nil
|
||||
assert_raises Stripe::AuthenticationError do
|
||||
Stripe::Customer.new("cus_123").refresh
|
||||
end
|
||||
end
|
||||
|
||||
should "specifying both api_key and authenticator should raise an exception" do
|
||||
Stripe.api_key = "sk_123"
|
||||
|
||||
def no_op; end
|
||||
|
||||
Stripe.authenticator = method(:no_op)
|
||||
|
||||
assert_raises Stripe::AuthenticationError do
|
||||
Stripe::Customer.new("cus_123").refresh
|
||||
end
|
||||
|
@ -1702,6 +1702,12 @@ module Stripe
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/quotes/qt_xxxxxxxxxxxxx/pdf?"
|
||||
end
|
||||
end
|
||||
context "Quote.preview_invoice_lines" do
|
||||
should "support requests with args: quote, preview_invoice" do
|
||||
Stripe::Quote.preview_invoice_lines("qt_xyz", "in_xyz")
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/quotes/qt_xyz/preview_invoices/in_xyz/lines?"
|
||||
end
|
||||
end
|
||||
context "Quote.retrieve" do
|
||||
should "support requests with args: id" do
|
||||
Stripe::Quote.retrieve("qt_xxxxxxxxxxxxx")
|
||||
@ -2214,6 +2220,13 @@ module Stripe
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/tax/calculations/xxx/line_items?"
|
||||
end
|
||||
end
|
||||
context "Tax.Form.pdf" do
|
||||
should "support requests with args: id" do
|
||||
block_handler = {}
|
||||
Stripe::Tax::Form.pdf("form_xxxxxxxxxxxxx", &block_handler)
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/tax/forms/form_xxxxxxxxxxxxx/pdf?"
|
||||
end
|
||||
end
|
||||
context "Tax.Transaction.create_from_calculation" do
|
||||
should "support requests with args: calculation, reference" do
|
||||
Stripe::Tax::Transaction.create_from_calculation({
|
||||
|
84
test/stripe/preview_test.rb
Normal file
84
test/stripe/preview_test.rb
Normal file
@ -0,0 +1,84 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require ::File.expand_path("../test_helper", __dir__)
|
||||
|
||||
class PreviewTest < Test::Unit::TestCase
|
||||
context "preview raw requests" do
|
||||
should "send preview get request with correct default options" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v2/accounts/acc_123")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe::Preview.get("/v2/accounts/acc_123")
|
||||
|
||||
assert_equal nil, req.headers["Content-Type"]
|
||||
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
|
||||
assert_equal expected_body, resp.http_body
|
||||
end
|
||||
|
||||
should "send preview post request with correct default options" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v2/accounts")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe::Preview.post("/v2/accounts", { p1: 1, p2: "string" })
|
||||
|
||||
assert_equal "application/json", req.headers["Content-Type"]
|
||||
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
|
||||
assert_equal "{\"p1\":1,\"p2\":\"string\"}", req.body
|
||||
assert_equal expected_body, resp.http_body
|
||||
end
|
||||
|
||||
should "send preview delete request with correct default options" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:delete, "#{Stripe.api_base}/v2/accounts/acc_123")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe::Preview.delete("/v2/accounts/acc_123")
|
||||
|
||||
assert_equal nil, req.headers["Content-Type"]
|
||||
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
|
||||
assert_equal expected_body, resp.http_body
|
||||
end
|
||||
|
||||
should "allow overriding default options for preview requests" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
stripe_version_override = "2022-11-15"
|
||||
req = nil
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v2/accounts")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe::Preview.post("/v2/accounts", {}, { stripe_version: stripe_version_override })
|
||||
|
||||
assert_equal "application/json", req.headers["Content-Type"]
|
||||
assert_equal stripe_version_override, req.headers["Stripe-Version"]
|
||||
assert_equal expected_body, resp.http_body
|
||||
end
|
||||
|
||||
should "allow setting stripe_context for preview requests" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
stripe_context = "acc_123"
|
||||
req = nil
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v2/accounts")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
Stripe::Preview.post("/v2/accounts", {}, { stripe_context: stripe_context })
|
||||
|
||||
assert_equal "application/json", req.headers["Content-Type"]
|
||||
assert_equal stripe_context, req.headers["Stripe-Context"]
|
||||
end
|
||||
end
|
||||
end
|
112
test/stripe/raw_request_test.rb
Normal file
112
test/stripe/raw_request_test.rb
Normal file
@ -0,0 +1,112 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require ::File.expand_path("../test_helper", __dir__)
|
||||
|
||||
class RawRequestTest < Test::Unit::TestCase
|
||||
context "raw_request" do
|
||||
should "send get request and return a response" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123")
|
||||
|
||||
assert_equal expected_body, resp.http_body
|
||||
assert_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
|
||||
assert_equal Stripe::ApiVersion::CURRENT, req.headers["Stripe-Version"]
|
||||
end
|
||||
|
||||
should "send post request with body and return a response" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
.with(body: "p1=1&p2=string")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" })
|
||||
|
||||
assert_equal expected_body, resp.http_body
|
||||
assert_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
|
||||
assert_equal Stripe::ApiVersion::CURRENT, req.headers["Stripe-Version"]
|
||||
end
|
||||
|
||||
should "send post request with json body and return a response" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
.with(body: "{\"p1\":1,\"p2\":\"string\"}")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" }, { api_mode: :preview })
|
||||
|
||||
assert_equal expected_body, resp.http_body
|
||||
assert_equal "application/json", req.headers["Content-Type"]
|
||||
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
|
||||
end
|
||||
|
||||
should "send post request with json body and headers and return a response" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
.with(body: "{\"p1\":1,\"p2\":\"string\"}")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe.raw_request(:post, "/v1/accounts/acc_123", { p1: 1, p2: "string" }, { api_mode: :preview, "Stripe-Context": "bar" })
|
||||
|
||||
assert_equal expected_body, resp.http_body
|
||||
assert_equal "application/json", req.headers["Content-Type"]
|
||||
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
|
||||
assert_equal "bar", req.headers["Stripe-Context"]
|
||||
end
|
||||
|
||||
should "send get request with json body and headers and return a response" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
resp = Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { api_mode: :preview, "Stripe-Account": "bar" })
|
||||
|
||||
assert_not_equal "application/x-www-form-urlencoded", req.headers["Content-Type"]
|
||||
assert_equal expected_body, resp.http_body
|
||||
end
|
||||
|
||||
should "set default preview version when api_mode is preview and stripe_version not specified" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { api_mode: :preview })
|
||||
|
||||
assert_equal Stripe::ApiVersion::PREVIEW, req.headers["Stripe-Version"]
|
||||
end
|
||||
|
||||
should "allow overriding stripe version when api_mode is preview" do
|
||||
expected_body = "{\"id\": \"acc_123\"}"
|
||||
req = nil
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acc_123")
|
||||
.with { |request| req = request }
|
||||
.to_return(body: expected_body)
|
||||
|
||||
stripe_version_override = "2023-05-15.preview"
|
||||
Stripe.raw_request(:get, "/v1/accounts/acc_123", {}, { api_mode: :preview, stripe_version: stripe_version_override })
|
||||
|
||||
assert_equal stripe_version_override, req.headers["Stripe-Version"]
|
||||
end
|
||||
end
|
||||
end
|
112
test/stripe/request_signing_authenticator_test.rb
Normal file
112
test/stripe/request_signing_authenticator_test.rb
Normal file
@ -0,0 +1,112 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require ::File.expand_path("../test_helper", __dir__)
|
||||
|
||||
module Stripe
|
||||
class RequestSigningAuthenticatorTest < Test::Unit::TestCase
|
||||
TEST_AUTH_TOKEN = "keyid"
|
||||
TEST_SIGN_LAMBDA = -> {}
|
||||
|
||||
context "initialize" do
|
||||
should "raise error if given non-String auth token" do
|
||||
assert_raises ArgumentError do
|
||||
Stripe::RequestSigningAuthenticator.new(123, TEST_SIGN_LAMBDA)
|
||||
end
|
||||
end
|
||||
|
||||
should "raise error if given non-lambda sign function" do
|
||||
assert_raises ArgumentError do
|
||||
Stripe::RequestSigningAuthenticator.new(TEST_AUTH_TOKEN, nil)
|
||||
end
|
||||
end
|
||||
|
||||
should "create a new authenticator with valid arguments" do
|
||||
authenticator = Stripe::RequestSigningAuthenticator.new(TEST_AUTH_TOKEN, TEST_SIGN_LAMBDA)
|
||||
assert_equal(authenticator.auth_token, TEST_AUTH_TOKEN)
|
||||
assert_equal(authenticator.sign_lambda, TEST_SIGN_LAMBDA)
|
||||
end
|
||||
end
|
||||
|
||||
context ".authenticate" do
|
||||
setup do
|
||||
RequestSigningAuthenticator.any_instance.stubs(:created_time).returns(123_456_789)
|
||||
end
|
||||
|
||||
should "applies signature for POST requests" do
|
||||
signature_bases = []
|
||||
sign = lambda { |signature_base|
|
||||
signature_bases.push(signature_base)
|
||||
return [1, 2, 3, 4, 5].pack("C*")
|
||||
}
|
||||
|
||||
authenticator = RequestSigningAuthenticator.new(TEST_AUTH_TOKEN, sign)
|
||||
headers = { "Content-Type" => "application/json" }
|
||||
authenticator.authenticate(:post, headers, '{"string":"String!"}')
|
||||
|
||||
assert_equal("\"content-type\": application/json\n" \
|
||||
"\"content-digest\": sha-256=:HA3i38j+04ac71IzPtG1JK8o4q9sPK0fYPmJHmci5bg=:\n" \
|
||||
"\"stripe-context\": \n" \
|
||||
"\"stripe-account\": \n" \
|
||||
"\"authorization\": STRIPE-V2-SIG keyid\n" \
|
||||
"\"@signature-params\": (\"content-type\" \"content-digest\" \"stripe-context\" \"stripe-account\" \"authorization\");created=123456789",
|
||||
signature_bases[0].force_encoding(Encoding::UTF_8))
|
||||
|
||||
assert_equal('sig1=("content-type" "content-digest" "stripe-context" "stripe-account" "authorization");' \
|
||||
"created=123456789", headers["Signature-Input"])
|
||||
assert_equal("sha-256=:HA3i38j+04ac71IzPtG1JK8o4q9sPK0fYPmJHmci5bg=:", headers["Content-Digest"])
|
||||
assert_equal("sig1=:AQIDBAU=:", headers["Signature"])
|
||||
assert_equal("STRIPE-V2-SIG keyid", headers["Authorization"])
|
||||
end
|
||||
|
||||
should "applies signature for DELETE requests" do
|
||||
signature_bases = []
|
||||
sign = lambda { |signature_base|
|
||||
signature_bases.push(signature_base)
|
||||
return [1, 2, 3, 4, 5].pack("C*")
|
||||
}
|
||||
|
||||
authenticator = RequestSigningAuthenticator.new(TEST_AUTH_TOKEN, sign)
|
||||
headers = { "Content-Type" => "application/json" }
|
||||
authenticator.authenticate(:delete, headers, nil)
|
||||
|
||||
assert_equal("\"content-type\": application/json\n" \
|
||||
"\"content-digest\": sha-256=:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=:\n" \
|
||||
"\"stripe-context\": \n" \
|
||||
"\"stripe-account\": \n" \
|
||||
"\"authorization\": STRIPE-V2-SIG keyid\n" \
|
||||
"\"@signature-params\": (\"content-type\" \"content-digest\" \"stripe-context\" \"stripe-account\" \"authorization\");created=123456789",
|
||||
signature_bases[0].force_encoding(Encoding::UTF_8))
|
||||
|
||||
assert_equal('sig1=("content-type" "content-digest" "stripe-context" "stripe-account" "authorization");' \
|
||||
"created=123456789", headers["Signature-Input"])
|
||||
assert_equal("sha-256=:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=:", headers["Content-Digest"])
|
||||
assert_equal("sig1=:AQIDBAU=:", headers["Signature"])
|
||||
assert_equal("STRIPE-V2-SIG keyid", headers["Authorization"])
|
||||
end
|
||||
|
||||
should "applies signature for GET requests" do
|
||||
signature_bases = []
|
||||
sign = lambda { |signature_base|
|
||||
signature_bases.push(signature_base)
|
||||
return [1, 2, 3, 4, 5].pack("C*")
|
||||
}
|
||||
|
||||
authenticator = RequestSigningAuthenticator.new(TEST_AUTH_TOKEN, sign)
|
||||
headers = {}
|
||||
authenticator.authenticate(:get, headers, nil)
|
||||
|
||||
assert_equal("\"stripe-context\": \n" \
|
||||
"\"stripe-account\": \n" \
|
||||
"\"authorization\": STRIPE-V2-SIG keyid\n" \
|
||||
"\"@signature-params\": (\"stripe-context\" \"stripe-account\" \"authorization\");created=123456789",
|
||||
signature_bases[0].force_encoding(Encoding::UTF_8))
|
||||
|
||||
assert_equal('sig1=("stripe-context" "stripe-account" "authorization");' \
|
||||
"created=123456789", headers["Signature-Input"])
|
||||
assert_nil(headers["Content-Digest"])
|
||||
assert_equal("sig1=:AQIDBAU=:", headers["Signature"])
|
||||
assert_equal("STRIPE-V2-SIG keyid", headers["Authorization"])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -478,6 +478,55 @@ module Stripe
|
||||
end
|
||||
end
|
||||
|
||||
context "signing headers" do
|
||||
setup do
|
||||
RequestSigningAuthenticator.any_instance.stubs(:content_digest).returns("digest")
|
||||
RequestSigningAuthenticator.any_instance.stubs(:created_time).returns(1_234_567_890)
|
||||
RequestSigningAuthenticator.any_instance.stubs(:encoded_signature).returns("signature")
|
||||
|
||||
Stripe.api_key = nil
|
||||
Stripe.authenticator = RequestSigningAuthenticator.new("keyinfo_test_123", -> {})
|
||||
end
|
||||
|
||||
should "apply valid signing headers for get requests" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_123")
|
||||
.to_return(body: JSON.generate(object: "charge"))
|
||||
|
||||
client = StripeClient.new
|
||||
client.send(request_method, :get, "/v1/charges/ch_123",
|
||||
&@read_body_chunk_block)
|
||||
assert_requested(
|
||||
:get,
|
||||
"#{Stripe.api_base}/v1/charges/ch_123",
|
||||
headers: {
|
||||
"Authorization" => "STRIPE-V2-SIG keyinfo_test_123",
|
||||
"Signature" => "sig1=:signature:",
|
||||
"Signature-Input" => 'sig1=("stripe-context" "stripe-account" "authorization");created=1234567890',
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
should "apply valid signing headers for post requests" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/charges")
|
||||
.to_return(body: JSON.generate(object: "charge"))
|
||||
|
||||
client = StripeClient.new
|
||||
client.send(request_method, :post, "/v1/charges",
|
||||
&@read_body_chunk_block)
|
||||
|
||||
assert_requested(
|
||||
:post,
|
||||
"#{Stripe.api_base}/v1/charges",
|
||||
headers: {
|
||||
"Authorization" => "STRIPE-V2-SIG keyinfo_test_123",
|
||||
"Content-Digest" => "sha-256=:digest:",
|
||||
"Signature" => "sig1=:signature:",
|
||||
"Signature-Input" => 'sig1=("content-type" "content-digest" "stripe-context" "stripe-account" "authorization");created=1234567890',
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "logging" do
|
||||
setup do
|
||||
# Freeze time for the purposes of the `elapsed` parameter that we
|
||||
|
@ -134,4 +134,42 @@ class StripeTest < Test::Unit::TestCase
|
||||
assert_equal "client", Stripe.client_id
|
||||
end
|
||||
end
|
||||
|
||||
context "deserialize" do
|
||||
should "deserializes string into known object" do
|
||||
expected_body = "{\"id\": \"acc_123\", \"object\": \"account\"}"
|
||||
|
||||
obj = Stripe.deserialize(expected_body)
|
||||
|
||||
assert_equal obj.class, Stripe::Account
|
||||
assert_equal obj.id, "acc_123"
|
||||
end
|
||||
|
||||
should "deserializes string into unknown object" do
|
||||
expected_body = "{\"id\": \"acc_123\", \"object\": \"unknown\"}"
|
||||
|
||||
obj = Stripe.deserialize(expected_body)
|
||||
|
||||
assert_equal obj.class, Stripe::StripeObject
|
||||
assert_equal obj.id, "acc_123"
|
||||
end
|
||||
|
||||
should "deserializes hash into known object" do
|
||||
expected_body = { "id" => "acc_123", "object" => "account" }
|
||||
|
||||
obj = Stripe.deserialize(expected_body)
|
||||
|
||||
assert_equal obj.class, Stripe::Account
|
||||
assert_equal obj.id, "acc_123"
|
||||
end
|
||||
|
||||
should "deserializes hash into unknown object" do
|
||||
expected_body = { "id" => "acc_123", "object" => "unknown" }
|
||||
|
||||
obj = Stripe.deserialize(expected_body)
|
||||
|
||||
assert_equal obj.class, Stripe::StripeObject
|
||||
assert_equal obj.id, "acc_123"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -67,6 +67,8 @@ module Test
|
||||
Stripe.api_base = "http://localhost:#{MOCK_PORT}"
|
||||
Stripe.uploads_base = "http://localhost:#{MOCK_PORT}"
|
||||
|
||||
Stripe.authenticator = nil
|
||||
|
||||
stub_connect
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user