Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Updates for beta branch #1182

Merged
merged 9 commits into from
Feb 24, 2023
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 8.3.0 - 2023-02-16
* [#1175](https://github.com/stripe/stripe-ruby/pull/1175) API Updates
* Add support for `refund_payment` method on resource `Terminal.Reader`

## 8.3.0-beta.1 - 2023-02-02
* [#1174](https://github.com/stripe/stripe-ruby/pull/1174) API Updates for beta branch
* Updated stable APIs to the latest version
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v223
v232
10 changes: 6 additions & 4 deletions lib/stripe/resources/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

module Stripe
# This is an object representing a Stripe account. You can retrieve it to see
# properties on the account like its current e-mail address or if the account is
# enabled yet to make live charges.
# properties on the account like its current requirements or if the account is
# enabled to make live charges or receive payouts.
#
# Some properties, marked below, are available only to platforms that want to
# [create and manage Express or Custom accounts](https://stripe.com/docs/connect/accounts).
# For Custom accounts, the properties below are always returned. For other accounts, some properties are returned until that
# account has started to go through Connect Onboarding. Once you create an [Account Link](https://stripe.com/docs/api/account_links)
# for a Standard or Express account, some parameters are no longer returned. These are marked as **Custom Only** or **Custom and Express**
# below. Learn about the differences [between accounts](https://stripe.com/docs/connect/accounts).
class Account < APIResource
extend Gem::Deprecate
extend Stripe::APIOperations::Create
Expand Down
4 changes: 2 additions & 2 deletions lib/stripe/resources/checkout/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module Checkout
# [PaymentIntent](https://stripe.com/docs/api/payment_intents) or an active
# [Subscription](https://stripe.com/docs/api/subscriptions).
#
# You can create a Checkout Session on your server and pass its ID to the
# client to begin Checkout.
# You can create a Checkout Session on your server and redirect to its URL
# to begin Checkout.
#
# Related guide: [Checkout Quickstart](https://stripe.com/docs/checkout/quickstart).
class Session < APIResource
Expand Down
16 changes: 10 additions & 6 deletions lib/stripe/resources/invoice_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
# frozen_string_literal: true

module Stripe
# Sometimes you want to add a charge or credit to a customer, but actually
# charge or credit the customer's card only at the end of a regular billing
# cycle. This is useful for combining several charges (to minimize
# per-transaction fees), or for having Stripe tabulate your usage-based billing
# totals.
# Invoice Items represent the component lines of an [invoice](https://stripe.com/docs/api/invoices). An invoice item is added to an
# invoice by creating or updating it with an `invoice` field, at which point it will be included as
# [an invoice line item](https://stripe.com/docs/api/invoices/line_item) within
# [invoice.lines](https://stripe.com/docs/api/invoices/object#invoice_object-lines).
#
# Related guide: [Subscription Invoices](https://stripe.com/docs/billing/invoices/subscription#adding-upcoming-invoice-items).
# Invoice Items can be created before you are ready to actually send the invoice. This can be particularly useful when combined
# with a [subscription](https://stripe.com/docs/api/subscriptions). Sometimes you want to add a charge or credit to a customer, but actually charge
# or credit the customer's card only at the end of a regular billing cycle. This is useful for combining several charges
# (to minimize per-transaction fees), or for having Stripe tabulate your usage-based billing totals.
#
# Related guides: [Integrate with the Invoicing API](https://stripe.com/docs/invoicing/integration), [Subscription Invoices](https://stripe.com/docs/billing/invoices/subscription#adding-upcoming-invoice-items).
class InvoiceItem < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
Expand Down
3 changes: 2 additions & 1 deletion lib/stripe/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def self.convert_to_stripe_object_with_params(data, params, opts = {})
when Hash
# Try converting to a known object class. If none available, fall back
# to generic StripeObject
obj = object_classes.fetch(data[:object], StripeObject)
object_name = data[:object] || data["object"]
obj = object_classes.fetch(object_name, StripeObject)
.construct_from(data, opts)

# set filters so that we can fetch the same limit, expansions, and
Expand Down
94 changes: 60 additions & 34 deletions test/stripe/generated_examples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class CodegennedExampleTest < Test::Unit::TestCase
Stripe::Apps::Secret.list({ scope: { type: "account" }, limit: 2 })
assert_requested :get, "#{Stripe.api_base}/v1/apps/secrets?scope[type]=account&limit=2"
end
should "support requests with args: scope, limit2" do
Stripe::Apps::Secret.list({ scope: { type: "account" }, limit: 2 })
assert_requested :get, "#{Stripe.api_base}/v1/apps/secrets?scope[type]=account&limit=2"
end
end
context "BalanceTransaction.list" do
should "support requests with args: limit" do
Expand Down Expand Up @@ -273,7 +277,7 @@ class CodegennedExampleTest < Test::Unit::TestCase
amount: 2000,
currency: "usd",
source: "tok_xxxx",
description: "My First Test Charge (created for API docs)",
description: "My First Test Charge (created for API docs at https://www.stripe.com/docs/api)",
}
)
assert_requested :post, "#{Stripe.api_base}/v1/charges"
Expand Down Expand Up @@ -331,11 +335,10 @@ class CodegennedExampleTest < Test::Unit::TestCase
)
assert_requested :post, "#{Stripe.api_base}/v1/checkout/sessions"
end
should "support requests with args: success_url, cancel_url, line_items, mode" do
should "support requests with args: success_url, line_items, mode" do
Stripe::Checkout::Session.create(
{
success_url: "https://example.com/success",
cancel_url: "https://example.com/cancel",
line_items: [{ price: "price_xxxxxxxxxxxxx", quantity: 2 }],
mode: "payment",
}
Expand Down Expand Up @@ -447,7 +450,9 @@ class CodegennedExampleTest < Test::Unit::TestCase
context "Customer.create" do
should "support requests with args: description" do
Stripe::Customer.create(
{ description: "My First Test Customer (created for API docs)" }
{
description: "My First Test Customer (created for API docs at https://www.stripe.com/docs/api)",
}
)
assert_requested :post, "#{Stripe.api_base}/v1/customers"
end
Expand Down Expand Up @@ -646,6 +651,10 @@ class CodegennedExampleTest < Test::Unit::TestCase
Stripe::FinancialConnections::Account.disconnect("fca_xyz")
assert_requested :post, "#{Stripe.api_base}/v1/financial_connections/accounts/fca_xyz/disconnect?"
end
should "support requests with args: id" do
Stripe::FinancialConnections::Account.disconnect("fca_xxxxxxxxxxxxx")
assert_requested :post, "#{Stripe.api_base}/v1/financial_connections/accounts/fca_xxxxxxxxxxxxx/disconnect?"
end
end
context "FinancialConnections.Account.list" do
should "work" do
Expand Down Expand Up @@ -817,6 +826,10 @@ class CodegennedExampleTest < Test::Unit::TestCase
Stripe::Invoice.retrieve("in_xxxxxxxxxxxxx")
assert_requested :get, "#{Stripe.api_base}/v1/invoices/in_xxxxxxxxxxxxx?"
end
should "support requests with args: id, expand" do
Stripe::Invoice.retrieve({ expand: ["customer"], id: "in_xxxxxxxxxxxxx" })
assert_requested :get, "#{Stripe.api_base}/v1/invoices/in_xxxxxxxxxxxxx?expand[0]=customer"
end
end
context "Invoice.search" do
should "support requests with args: query" do
Expand Down Expand Up @@ -1114,9 +1127,13 @@ class CodegennedExampleTest < Test::Unit::TestCase
)
assert_requested :post, "#{Stripe.api_base}/v1/payment_intents"
end
should "support requests with args: amount, currency, payment_method_types" do
should "support requests with args: amount, currency, automatic_payment_methods2" do
Stripe::PaymentIntent.create(
{ amount: 2000, currency: "usd", payment_method_types: ["card"] }
{
amount: 2000,
currency: "usd",
automatic_payment_methods: { enabled: true },
}
)
assert_requested :post, "#{Stripe.api_base}/v1/payment_intents"
end
Expand Down Expand Up @@ -1164,6 +1181,13 @@ class CodegennedExampleTest < Test::Unit::TestCase
Stripe::PaymentIntent.verify_microdeposits("pi_xxxxxxxxxxxxx")
assert_requested :post, "#{Stripe.api_base}/v1/payment_intents/pi_xxxxxxxxxxxxx/verify_microdeposits?"
end
should "support requests with args: amounts, id" do
Stripe::PaymentIntent.verify_microdeposits(
"pi_xxxxxxxxxxxxx",
{ amounts: [32, 45] }
)
assert_requested :post, "#{Stripe.api_base}/v1/payment_intents/pi_xxxxxxxxxxxxx/verify_microdeposits"
end
end
context "PaymentLink.create" do
should "support requests with args: line_items" do
Expand Down Expand Up @@ -1223,8 +1247,8 @@ class CodegennedExampleTest < Test::Unit::TestCase
type: "card",
card: {
number: "4242424242424242",
exp_month: 5,
exp_year: 2023,
exp_month: 8,
exp_year: 2024,
cvc: "314",
},
}
Expand Down Expand Up @@ -1780,6 +1804,13 @@ class CodegennedExampleTest < Test::Unit::TestCase
Stripe::SetupIntent.verify_microdeposits("seti_xxxxxxxxxxxxx")
assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_xxxxxxxxxxxxx/verify_microdeposits?"
end
should "support requests with args: amounts, id" do
Stripe::SetupIntent.verify_microdeposits(
"seti_xxxxxxxxxxxxx",
{ amounts: [32, 45] }
)
assert_requested :post, "#{Stripe.api_base}/v1/setup_intents/seti_xxxxxxxxxxxxx/verify_microdeposits"
end
end
context "ShippingRate.create" do
should "support requests with args: display_name, fixed_amount, type" do
Expand Down Expand Up @@ -1876,15 +1907,6 @@ class CodegennedExampleTest < Test::Unit::TestCase
assert_requested :get, "#{Stripe.api_base}/v1/subscriptions?limit=3"
end
end
context "Subscription.resume" do
should "support requests with args: id, proration_date, proration_behavior" do
Stripe::Subscription.resume(
"sub_xxxxxxxxxxxxx",
{ proration_date: 1_675_400_000, proration_behavior: "always_invoice" }
)
assert_requested :post, "#{Stripe.api_base}/v1/subscriptions/sub_xxxxxxxxxxxxx/resume"
end
end
context "Subscription.retrieve" do
should "support requests with args: id" do
Stripe::Subscription.retrieve("sub_xxxxxxxxxxxxx")
Expand Down Expand Up @@ -1958,7 +1980,7 @@ class CodegennedExampleTest < Test::Unit::TestCase
Stripe::SubscriptionSchedule.create(
{
customer: "cus_xxxxxxxxxxxxx",
start_date: 1_652_909_005,
start_date: 1_676_070_661,
end_behavior: "release",
phases: [
{
Expand Down Expand Up @@ -2135,8 +2157,9 @@ class CodegennedExampleTest < Test::Unit::TestCase
address: {
line1: "1234 Main Street",
city: "San Francisco",
country: "US",
postal_code: "94111",
state: "CA",
country: "US",
},
}
)
Expand Down Expand Up @@ -2209,6 +2232,18 @@ class CodegennedExampleTest < Test::Unit::TestCase
assert_requested :post, "#{Stripe.api_base}/v1/terminal/readers/tmr_xxxxxxxxxxxxx/process_payment_intent"
end
end
context "Terminal.Reader.process_setup_intent" do
should "support requests with args: setup_intent, customer_consent_collected, id" do
Stripe::Terminal::Reader.process_setup_intent(
"tmr_xxxxxxxxxxxxx",
{
setup_intent: "seti_xxxxxxxxxxxxx",
customer_consent_collected: true,
}
)
assert_requested :post, "#{Stripe.api_base}/v1/terminal/readers/tmr_xxxxxxxxxxxxx/process_setup_intent"
end
end
context "Terminal.Reader.retrieve" do
should "support requests with args: id" do
Stripe::Terminal::Reader.retrieve("tmr_xxxxxxxxxxxxx")
Expand All @@ -2232,7 +2267,7 @@ class CodegennedExampleTest < Test::Unit::TestCase
should "support requests with args: frozen_time, id" do
Stripe::TestHelpers::TestClock.advance(
"clock_xxxxxxxxxxxxx",
{ frozen_time: 1_652_390_605 }
{ frozen_time: 1_675_552_261 }
)
assert_requested :post, "#{Stripe.api_base}/v1/test_helpers/test_clocks/clock_xxxxxxxxxxxxx/advance"
end
Expand Down Expand Up @@ -2496,15 +2531,6 @@ class CodegennedExampleTest < Test::Unit::TestCase
assert_requested :post, "#{Stripe.api_base}/v1/treasury/financial_accounts/fa_xxxxxxxxxxxxx"
end
end
context "Treasury.FinancialAccount.update_features" do
should "support requests with args: card_issuing, parent_id" do
Stripe::Treasury::FinancialAccount.update_features(
"fa_xxxxxxxxxxxxx",
{ card_issuing: { requested: false } }
)
assert_requested :post, "#{Stripe.api_base}/v1/treasury/financial_accounts/fa_xxxxxxxxxxxxx/features"
end
end
context "Treasury.InboundTransfer.cancel" do
should "support requests with args: id" do
Stripe::Treasury::InboundTransfer.cancel("ibt_xxxxxxxxxxxxx")
Expand Down Expand Up @@ -2564,8 +2590,8 @@ class CodegennedExampleTest < Test::Unit::TestCase
end
context "Treasury.OutboundPayment.cancel" do
should "support requests with args: id" do
Stripe::Treasury::OutboundPayment.cancel("obp_xxxxxxxxxxxxx")
assert_requested :post, "#{Stripe.api_base}/v1/treasury/outbound_payments/obp_xxxxxxxxxxxxx/cancel?"
Stripe::Treasury::OutboundPayment.cancel("bot_xxxxxxxxxxxxx")
assert_requested :post, "#{Stripe.api_base}/v1/treasury/outbound_payments/bot_xxxxxxxxxxxxx/cancel?"
end
end
context "Treasury.OutboundPayment.create" do
Expand All @@ -2575,7 +2601,7 @@ class CodegennedExampleTest < Test::Unit::TestCase
financial_account: "fa_xxxxxxxxxxxxx",
amount: 10_000,
currency: "usd",
customer: "cu_xxxxxxxxxxxxx",
customer: "cus_xxxxxxxxxxxxx",
destination_payment_method: "pm_xxxxxxxxxxxxx",
description: "OutboundPayment to a 3rd party",
}
Expand All @@ -2593,8 +2619,8 @@ class CodegennedExampleTest < Test::Unit::TestCase
end
context "Treasury.OutboundPayment.retrieve" do
should "support requests with args: id" do
Stripe::Treasury::OutboundPayment.retrieve("obp_xxxxxxxxxxxxx")
assert_requested :get, "#{Stripe.api_base}/v1/treasury/outbound_payments/obp_xxxxxxxxxxxxx?"
Stripe::Treasury::OutboundPayment.retrieve("bot_xxxxxxxxxxxxx")
assert_requested :get, "#{Stripe.api_base}/v1/treasury/outbound_payments/bot_xxxxxxxxxxxxx?"
end
end
context "Treasury.OutboundTransfer.cancel" do
Expand Down
5 changes: 5 additions & 0 deletions test/stripe/util_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ class UtilTest < Test::Unit::TestCase
assert obj.is_a?(ListObject)
end

should "#convert_to_stripe_object should marshal hashes with string keys" do
obj = Util.convert_to_stripe_object({ "object" => "account" }, {})
assert obj.is_a?(Account)
end

should "#convert_to_stripe_object should marshal other classes" do
obj = Util.convert_to_stripe_object({ object: "account" }, {})
assert obj.is_a?(Account)
Expand Down