diff --git a/app/controllers/webhooks/stripe_controller.rb b/app/controllers/webhooks/stripe_controller.rb index 90072891..3214dd72 100644 --- a/app/controllers/webhooks/stripe_controller.rb +++ b/app/controllers/webhooks/stripe_controller.rb @@ -1,6 +1,7 @@ class Webhooks::StripeController < ApplicationController skip_before_action :verify_authenticity_token + skip_before_action :check_subscription_status def create endpoint_secret = Rails.application.credentials.stripe_signing_secret diff --git a/app/sidekiq/sync_customer_subscription_job.rb b/app/sidekiq/sync_customer_subscription_job.rb index 44660339..a09ffbc8 100644 --- a/app/sidekiq/sync_customer_subscription_job.rb +++ b/app/sidekiq/sync_customer_subscription_job.rb @@ -11,7 +11,8 @@ def perform(id) company.subscription.stripe_id, { items: [ {id: company.subscription.item_id, quantity: subscription_count } - ]} + ]}, + proration_date: Date.today.iso8601 ) end end diff --git a/spec/cassettes/SyncCustomerSubscriptionJob/perform/informs_Stripe_of_the_new_quantity.yml b/spec/cassettes/SyncCustomerSubscriptionJob/perform/informs_Stripe_of_the_new_quantity.yml index a5c3d7fd..3dda8621 100644 --- a/spec/cassettes/SyncCustomerSubscriptionJob/perform/informs_Stripe_of_the_new_quantity.yml +++ b/spec/cassettes/SyncCustomerSubscriptionJob/perform/informs_Stripe_of_the_new_quantity.yml @@ -5,7 +5,7 @@ http_interactions: uri: https://api.stripe.com/v1/customers body: encoding: UTF-8 - string: name=Hermann%2C+Smitham+and+Yost+18+%7C+Samual+Huels+17&email=something%40static.com + string: name=Streich%2C+Murphy+and+Torphy+1+%7C+Lacey+Hammes+1&email=something%40static.com headers: User-Agent: - Stripe/v1 RubyBindings/10.10.0 @@ -13,8 +13,6 @@ http_interactions: - Bearer Content-Type: - application/x-www-form-urlencoded - X-Stripe-Client-Telemetry: - - '{"last_request_metrics":{"request_id":"req_s1GfqNoa9aqb8w","request_duration_ms":215}}' Stripe-Version: - '2023-10-16' X-Stripe-Client-User-Agent: @@ -33,11 +31,11 @@ http_interactions: Server: - nginx Date: - - Mon, 26 Feb 2024 00:42:19 GMT + - Fri, 01 Mar 2024 00:46:28 GMT Content-Type: - application/json Content-Length: - - '676' + - '675' Connection: - keep-alive Access-Control-Allow-Credentials: @@ -58,11 +56,11 @@ http_interactions: default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; style-src 'self' Idempotency-Key: - - 6033beff-a105-424a-92da-b59af7264d61 + - bf9d2307-06a4-4ae7-8194-09e57fc7894a Original-Request: - - req_495GPpOjchGWEe + - req_3M9ndpqJxMWBvu Request-Id: - - req_495GPpOjchGWEe + - req_3M9ndpqJxMWBvu Stripe-Should-Retry: - 'false' Stripe-Version: @@ -77,18 +75,18 @@ http_interactions: encoding: UTF-8 string: |- { - "id": "cus_Pd8X6J8xPPlpL5", + "id": "cus_PedWT4uA3p04bM", "object": "customer", "address": null, "balance": 0, - "created": 1708908139, + "created": 1709253988, "currency": null, "default_source": null, "delinquent": false, "description": null, "discount": null, "email": "something@static.com", - "invoice_prefix": "9E81ABB7", + "invoice_prefix": "43C33E99", "invoice_settings": { "custom_fields": null, "default_payment_method": null, @@ -97,7 +95,7 @@ http_interactions: }, "livemode": false, "metadata": {}, - "name": "Hermann, Smitham and Yost 18 | Samual Huels 17", + "name": "Streich, Murphy and Torphy 1 | Lacey Hammes 1", "next_invoice_sequence": 1, "phone": null, "preferred_locales": [], @@ -105,13 +103,13 @@ http_interactions: "tax_exempt": "none", "test_clock": null } - recorded_at: Mon, 26 Feb 2024 00:42:19 GMT + recorded_at: Fri, 01 Mar 2024 00:46:28 GMT - request: method: post uri: https://api.stripe.com/v1/subscriptions body: encoding: UTF-8 - string: customer=cus_Pd8X6J8xPPlpL5&items[0][price]=price_1OdkCHBLjyMcgacQoXsoA2v0&items[0][quantity]=1&trial_period_days=30&trial_settings[end_behavior][missing_payment_method]=cancel&payment_settings[save_default_payment_method]=on_subscription + string: customer=cus_PedWT4uA3p04bM&items[0][price]=price_1Oo7tQBLjyMcgacQSNLewS9y&items[0][quantity]=1&trial_period_days=30&trial_settings[end_behavior][missing_payment_method]=cancel&payment_settings[save_default_payment_method]=on_subscription headers: User-Agent: - Stripe/v1 RubyBindings/10.10.0 @@ -120,7 +118,7 @@ http_interactions: Content-Type: - application/x-www-form-urlencoded X-Stripe-Client-Telemetry: - - '{"last_request_metrics":{"request_id":"req_495GPpOjchGWEe","request_duration_ms":234}}' + - '{"last_request_metrics":{"request_id":"req_3M9ndpqJxMWBvu","request_duration_ms":329}}' Stripe-Version: - '2023-10-16' X-Stripe-Client-User-Agent: @@ -139,7 +137,7 @@ http_interactions: Server: - nginx Date: - - Mon, 26 Feb 2024 00:42:20 GMT + - Fri, 01 Mar 2024 00:46:29 GMT Content-Type: - application/json Content-Length: @@ -164,11 +162,11 @@ http_interactions: default-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'; img-src 'self'; script-src 'self' 'report-sample'; style-src 'self' Idempotency-Key: - - 2923c44c-0f48-4dc3-bc56-a1a977b97bee + - d88f0f3c-fb0c-41de-a2ab-61044d077d64 Original-Request: - - req_54i8SRJe3iF9E1 + - req_HeN68Tvl887vTK Request-Id: - - req_54i8SRJe3iF9E1 + - req_HeN68Tvl887vTK Stripe-Should-Retry: - 'false' Stripe-Version: @@ -183,7 +181,7 @@ http_interactions: encoding: UTF-8 string: |- { - "id": "sub_1OnsGuBLjyMcgacQThbXKjZ0", + "id": "sub_1OpKF6BLjyMcgacQHQn4092y", "object": "subscription", "application": null, "application_fee_percent": null, @@ -191,7 +189,7 @@ http_interactions: "enabled": false, "liability": null }, - "billing_cycle_anchor": 1711500140, + "billing_cycle_anchor": 1711845988, "billing_cycle_anchor_config": null, "billing_thresholds": null, "cancel_at": null, @@ -203,11 +201,11 @@ http_interactions: "reason": null }, "collection_method": "charge_automatically", - "created": 1708908140, + "created": 1709253988, "currency": "usd", - "current_period_end": 1711500140, - "current_period_start": 1708908140, - "customer": "cus_Pd8X6J8xPPlpL5", + "current_period_end": 1711845988, + "current_period_start": 1709253988, + "customer": "cus_PedWT4uA3p04bM", "days_until_due": null, "default_payment_method": null, "default_source": null, @@ -225,45 +223,45 @@ http_interactions: "object": "list", "data": [ { - "id": "si_Pd8YqK1xwuU93Z", + "id": "si_PedWDT3pwuwiZ4", "object": "subscription_item", "billing_thresholds": null, - "created": 1708908140, + "created": 1709253989, "metadata": {}, "plan": { - "id": "price_1OdkCHBLjyMcgacQoXsoA2v0", + "id": "price_1Oo7tQBLjyMcgacQSNLewS9y", "object": "plan", "active": true, "aggregate_usage": null, "amount": 300, "amount_decimal": "300", "billing_scheme": "per_unit", - "created": 1706493821, + "created": 1708968188, "currency": "usd", "interval": "month", "interval_count": 1, "livemode": false, "metadata": {}, "nickname": null, - "product": "prod_PSfXu5KouT6GdC", + "product": "prod_PdOgBPQqj1Ri1R", "tiers_mode": null, "transform_usage": null, "trial_period_days": null, "usage_type": "licensed" }, "price": { - "id": "price_1OdkCHBLjyMcgacQoXsoA2v0", + "id": "price_1Oo7tQBLjyMcgacQSNLewS9y", "object": "price", "active": true, "billing_scheme": "per_unit", - "created": 1706493821, + "created": 1708968188, "currency": "usd", "custom_unit_amount": null, "livemode": false, "lookup_key": null, "metadata": {}, "nickname": null, - "product": "prod_PSfXu5KouT6GdC", + "product": "prod_PdOgBPQqj1Ri1R", "recurring": { "aggregate_usage": null, "interval": "month", @@ -279,15 +277,15 @@ http_interactions: "unit_amount_decimal": "300" }, "quantity": 1, - "subscription": "sub_1OnsGuBLjyMcgacQThbXKjZ0", + "subscription": "sub_1OpKF6BLjyMcgacQHQn4092y", "tax_rates": [] } ], "has_more": false, "total_count": 1, - "url": "/v1/subscription_items?subscription=sub_1OnsGuBLjyMcgacQThbXKjZ0" + "url": "/v1/subscription_items?subscription=sub_1OpKF6BLjyMcgacQHQn4092y" }, - "latest_invoice": "in_1OnsGuBLjyMcgacQMdPCeJMo", + "latest_invoice": "in_1OpKF6BLjyMcgacQ56x0JCCl", "livemode": false, "metadata": {}, "next_pending_invoice_item_invoice": null, @@ -299,24 +297,24 @@ http_interactions: "save_default_payment_method": "on_subscription" }, "pending_invoice_item_interval": null, - "pending_setup_intent": "seti_1OnsGuBLjyMcgacQ5TZ8F2d6", + "pending_setup_intent": "seti_1OpKF7BLjyMcgacQqCgXJPic", "pending_update": null, "plan": { - "id": "price_1OdkCHBLjyMcgacQoXsoA2v0", + "id": "price_1Oo7tQBLjyMcgacQSNLewS9y", "object": "plan", "active": true, "aggregate_usage": null, "amount": 300, "amount_decimal": "300", "billing_scheme": "per_unit", - "created": 1706493821, + "created": 1708968188, "currency": "usd", "interval": "month", "interval_count": 1, "livemode": false, "metadata": {}, "nickname": null, - "product": "prod_PSfXu5KouT6GdC", + "product": "prod_PdOgBPQqj1Ri1R", "tiers_mode": null, "transform_usage": null, "trial_period_days": null, @@ -324,17 +322,17 @@ http_interactions: }, "quantity": 1, "schedule": null, - "start_date": 1708908140, + "start_date": 1709253988, "status": "trialing", "test_clock": null, "transfer_data": null, - "trial_end": 1711500140, + "trial_end": 1711845988, "trial_settings": { "end_behavior": { "missing_payment_method": "cancel" } }, - "trial_start": 1708908140 + "trial_start": 1709253988 } - recorded_at: Mon, 26 Feb 2024 00:42:20 GMT + recorded_at: Fri, 01 Mar 2024 00:46:29 GMT recorded_with: VCR 6.2.0 diff --git a/spec/sidekiq/sync_customer_subscription_job_spec.rb b/spec/sidekiq/sync_customer_subscription_job_spec.rb index 20cebfb5..441a658e 100644 --- a/spec/sidekiq/sync_customer_subscription_job_spec.rb +++ b/spec/sidekiq/sync_customer_subscription_job_spec.rb @@ -26,7 +26,8 @@ company.subscription.stripe_id, { items: [ {id: company.subscription.item_id, quantity: 2 } - ]} + ]}, + {proration_date: Date.today.iso8601} ) SyncCustomerSubscriptionJob.perform_inline(company.id)