Merge pull request #1695 from stripe/jar/merge-ruby-private-preview

Merge to private-preview
This commit is contained in:
jar-stripe 2025-10-01 18:11:15 -07:00 committed by GitHub
commit 94126fc10e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 46 additions and 51 deletions

View File

@ -47,7 +47,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
# following https://docs.stripe.com/sdks/versioning?server=ruby#stripe-sdk-language-version-support-policy
# following https://docs.stripe.com/sdks/versioning?lang=ruby#stripe-sdk-language-version-support-policy
ruby-version: [2.6, 2.7, '3.0', 3.1, 3.2, 3.3, 3.4, jruby-9.4.0.0, truffleruby-head]
steps:
- uses: extractions/setup-just@v2

View File

@ -97,7 +97,7 @@ This release changes the pinned API version to `2025-09-30.clover` and contains
- Add the `StripeContext` class. Previously you could set the stripe_context to only a string value. Now you can use the new class as well
- ⚠️ Change `EventNotification` (formerly known as `ThinEvent`)'s `context` property from `string` to `StripeContext`
* [#1684](https://github.com/stripe/stripe-ruby/pull/1684) ⚠️ Drop support for Ruby < 2.6 & clarify version policy
- Read our new [language version support policy](https://docs.stripe.com/sdks/versioning?server=ruby#stripe-sdk-language-version-support-policy)
- Read our new [language version support policy](https://docs.stripe.com/sdks/versioning?lang=ruby#stripe-sdk-language-version-support-policy)
- ⚠️ In this release, we drop support for Ruby 2.3, 2.4, and 2.5
- Ruby 2.6 support is deprecated and will be removed in the next scheduled major release (March 2026)
* [#1651](https://github.com/stripe/stripe-ruby/pull/1651) ⚠️ Build SDK w/ V2 OpenAPI spec

View File

@ -37,9 +37,9 @@ gem build stripe.gemspec
### Requirements
Per our [Language Version Support Policy](https://docs.stripe.com/sdks/versioning?server=ruby#stripe-sdk-language-version-support-policy), we currently support **Ruby 2.6+**.
Per our [Language Version Support Policy](https://docs.stripe.com/sdks/versioning?lang=ruby#stripe-sdk-language-version-support-policy), we currently support **Ruby 2.6+**.
Support for Ruby 2.6 and 2.7 is deprecated and will be removed in upcoming major versions. Read more and see the full schedule in the docs: https://docs.stripe.com/sdks/versioning?server=ruby#stripe-sdk-language-version-support-policy
Support for Ruby 2.6 and 2.7 is deprecated and will be removed in upcoming major versions. Read more and see the full schedule in the docs: https://docs.stripe.com/sdks/versioning?lang=ruby#stripe-sdk-language-version-support-policy
### Bundler

View File

@ -7,10 +7,12 @@
# In this example, we:
# - create a StripeClient called client
# - use client.parse_event_notification to parse the received event notification webhook body
# - call client.v2.core.events.retrieve to retrieve the full event object
# - call event_notification.fetch_event to retrieve the full event object
# - if it is a V1BillingMeterErrorReportTriggeredEvent event type, call
# event.fetchRelatedObject to retrieve the Billing Meter object associated
# event_notification.fetch_related_object to retrieve the Billing Meter object associated
# with the event.
# - if it is an UnknownEventNotification, check the type property to see if it matches
# a known event type and handle it accordingly
require "stripe"
require "sinatra"
@ -27,9 +29,23 @@ post "/webhook" do
event_notification = client.parse_event_notification(webhook_body, sig_header, webhook_secret)
if event_notification.instance_of?(Stripe::Events::V1BillingMeterErrorReportTriggeredEventNotification)
# there's basic info about the related object in the notification
puts "Received event for meter", event_notification.related_object.id
# but you can also fetch it if you need more info
meter = event_notification.fetch_related_object
meter_id = meter.id
puts "Success!", meter_id
puts "Meter name:", meter.display_name
# there's often more information on the actual event
event = event_notification.fetch_event
puts "Meter had an error", event.data.developer_message_summary
elsif event_notification.instance_of?(Stripe::Events::UnknownEventNotification)
# this is a valid event type, but this SDK predates it
# we'll have to match on type instead
if event_notification.type == "some.new.event"
# your logic goes here
end
end
# Record the failures and alert your team

View File

@ -3843,13 +3843,34 @@ module Stripe
assert_requested :get, "#{Stripe::DEFAULT_API_BASE}/v1/promotion_codes/promo_xxxxxxxxxxxxx"
end
should "Test promotion codes post" do
promotion_code = Stripe::PromotionCode.create({
promotion: {
type: "coupon",
coupon: "Z4OV52SU",
},
})
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes"
end
should "Test promotion codes post (service)" do
stub_request(:post, "#{Stripe::DEFAULT_API_BASE}/v1/promotion_codes").to_return(body: "{}")
client = Stripe::StripeClient.new("sk_test_123")
promotion_code = client.v1.promotion_codes.create({
promotion: {
type: "coupon",
coupon: "Z4OV52SU",
},
})
assert_requested :post, "#{Stripe::DEFAULT_API_BASE}/v1/promotion_codes"
end
should "Test promotion codes post 2" do
promotion_code = Stripe::PromotionCode.update(
"promo_xxxxxxxxxxxxx",
{ metadata: { order_id: "6735" } }
)
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes/promo_xxxxxxxxxxxxx"
end
should "Test promotion codes post (service)" do
should "Test promotion codes post 2 (service)" do
stub_request(
:post,
"#{Stripe::DEFAULT_API_BASE}/v1/promotion_codes/promo_xxxxxxxxxxxxx"

View File

@ -1,42 +0,0 @@
# frozen_string_literal: true
require File.expand_path("../test_helper", __dir__)
module Stripe
class PromotionCodeTest < Test::Unit::TestCase
should "be listable" do
promotion_codes = Stripe::PromotionCode.list
assert_requested :get, "#{Stripe.api_base}/v1/promotion_codes"
assert promotion_codes.data.is_a?(Array)
assert promotion_codes.first.is_a?(Stripe::PromotionCode)
end
should "be retrievable" do
coupon = Stripe::PromotionCode.retrieve("PROMO_123")
assert_requested :get, "#{Stripe.api_base}/v1/promotion_codes/PROMO_123"
assert coupon.is_a?(Stripe::PromotionCode)
end
should "be creatable" do
coupon = Stripe::PromotionCode.create(
coupon: "co_123",
code: "MYCODE"
)
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes"
assert coupon.is_a?(Stripe::PromotionCode)
end
should "be saveable" do
coupon = Stripe::PromotionCode.retrieve("PROMO_123")
coupon.metadata["key"] = "value"
coupon.save
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes/#{coupon.id}"
end
should "be updateable" do
coupon = Stripe::PromotionCode.update("PROMO_123", metadata: { key: "value" })
assert_requested :post, "#{Stripe.api_base}/v1/promotion_codes/PROMO_123"
assert coupon.is_a?(Stripe::PromotionCode)
end
end
end