Skip to content

Commit

Permalink
サブスクリプション作成時に税率を追加するようにした
Browse files Browse the repository at this point in the history
インボイス対応の領収書表示のため。
  • Loading branch information
komagata committed Feb 20, 2024
1 parent 133e15e commit 82bc25e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/models/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def retrieve(id)
def create(customer_id, idempotency_key = SecureRandom.uuid, trial: 3)
options = {
customer: customer_id,
items: [{ plan: Plan.standard_plan.id }]
items: [{
plan: Plan.standard_plan.id,
tax_rates: [Rails.application.secrets[:stripe][:tax_rate_id]]
}]
}
options[:trial_end] = trial.days.since.to_i if trial.positive?

Expand Down
2 changes: 2 additions & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ shared:
public_key: pk_test_Je8A9BUHRC8oqsqx8wtfbKwg
secret_key: sk_test_XLP1Ajz1JvT9jUt5uKGvL0Wd
endpoint_secret: 'whsec_7bed86b552fc378b10af3cc11a371e8f3454c5817ba44ac9fc5092bf50056075'
tax_rate_id: <%= ENV['STRIPE_TAX_RATE_ID'] || 'txr_1Om0YyBpeWcLFd8fovSLFgXX' %>
open_ai:
access_token: <%= ENV['OPEN_AI_ACCESS_TOKEN'] || 'xxxxxxxx' %>

Expand All @@ -36,3 +37,4 @@ production:
public_key: <%= ENV['STRIPE_PUBLIC_KEY'] %>
secret_key: <%= ENV['STRIPE_SECRET_KEY'] %>
endpoint_secret: '<%= ENV['STRIPE_ENDPOINT_SECRET'] %>'
tax_rate_id: <%= ENV['STRIPE_TAX_RATE_ID'] %>
6 changes: 5 additions & 1 deletion test/cassettes/subscription/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ http_interactions:
uri: https://api.stripe.com/v1/subscriptions
body:
encoding: UTF-8
string: customer=cus_12345678&items[0][plan]=price_1J0hhTBpeWcLFd8ffLjm4nKO&trial_end=1672758000
base64_string: |
Y3VzdG9tZXI9Y3VzXzEyMzQ1Njc4Jml0ZW1zWzBdW3BsYW5dPXByaWNlXzFK
cmxPeEJwZVdjTEZkOGZkNXJneDA4YyZpdGVtc1swXVt0YXhfcmF0ZXNdWzBd
PXR4cl8xT20wWXlCcGVXY0xGZDhmb3ZTTEZnWFgmdHJpYWxfZW5kPTE2NzI3
NTgwMDA=
headers:
User-Agent:
- Stripe/v1 RubyBindings/4.5.0
Expand Down
2 changes: 1 addition & 1 deletion test/models/subscription_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SubscriptionTest < ActiveSupport::TestCase

test '#create' do
travel_to Time.zone.parse('2023-01-01 00:00:00') do
VCR.use_cassette 'subscription/create' do
VCR.use_cassette 'subscription/create', record: :once, match_requests_on: %i[method uri] do
subscription = Subscription.new.create('cus_12345678')
assert_equal 'sub_12345678', subscription['id']
end
Expand Down

0 comments on commit 82bc25e

Please sign in to comment.