Skip to content

Use InvoicePayment type to sync payment intents or charges#1183

Merged
excid3 merged 2 commits intomainfrom
fix-invoice-payment-sync
Jul 29, 2025
Merged

Use InvoicePayment type to sync payment intents or charges#1183
excid3 merged 2 commits intomainfrom
fix-invoice-payment-sync

Conversation

@excid3
Copy link
Collaborator

@excid3 excid3 commented Jul 16, 2025

This should fix the case where an InvoicePayment has a Charge instead of a PaymentIntent. It will determine which to sync based upon the type of the invoice payment.

Closes #1182

@excid3
Copy link
Collaborator Author

excid3 commented Jul 28, 2025

Ping again. Does this fix your issue @marckohlbrugge?

@marckohlbrugge
Copy link
Contributor

I now receive this error:

bundler/gems/pay-7c23db53d04d/app/models/pay/stripe/customer.rb:157:in `Pay::Stripe::Customer#sync_subscriptions': (Status 400) (Request req_Y4ZkaE79Ehvzbu) You can only specify payment[payment_intent] with payment[type]=payment_intent (Pay::Stripe::Error)

@excid3
Copy link
Collaborator Author

excid3 commented Jul 29, 2025

Please post the full stacktrace.

@marckohlbrugge
Copy link
Contributor

bundler/gems/pay-7c23db53d04d/app/models/pay/stripe/customer.rb:157:in `Pay::Stripe::Customer#sync_subscriptions': (Status 400) (Request req_Y4ZkaE79Ehvzbu) You can only specify payment[payment_intent] with payment[type]=payment_intent (Pay::Stripe::Error)
    from app/controllers/application_controller.rb:78:in `ApplicationController#sync_customer_subscriptions'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:361:in `block in ActiveSupport::Callbacks::CallTemplate::MethodCall#make_lambda'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:178:in `block in ActiveSupport::Callbacks::Filters::Before#call'
    from gems/actionpack-8.0.2/lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:179:in `ActiveSupport::Callbacks::Filters::Before#call'
[…]

Caused by: gems/stripe-15.3.0/lib/stripe/api_requestor.rb:755:in `Stripe::APIRequestor#handle_error_response': You can only specify payment[payment_intent] with payment[type]=payment_intent (Stripe::InvalidRequestError)
    from gems/stripe-15.3.0/lib/stripe/api_requestor.rb:620:in `Stripe::APIRequestor#execute_request_with_rescues'
    from gems/stripe-15.3.0/lib/stripe/api_requestor.rb:525:in `Stripe::APIRequestor#execute_request_internal'
    from gems/stripe-15.3.0/lib/stripe/api_requestor.rb:200:in `Stripe::APIRequestor#execute_request'
    from gems/stripe-15.3.0/lib/stripe/api_operations/request.rb:46:in `Stripe::APIOperations::Request::ClassMethods#execute_resource_request_internal'
    from gems/stripe-15.3.0/lib/stripe/api_operations/request.rb:9:in `Stripe::APIOperations::Request::ClassMethods#execute_resource_request'
    from gems/stripe-15.3.0/lib/stripe/api_operations/request.rb:30:in `Stripe::APIOperations::Request::ClassMethods#request_stripe_object'
    from gems/stripe-15.3.0/lib/stripe/resources/invoice_payment.rb:109:in `Stripe::InvoicePayment.list'
    from bundler/gems/pay-7c23db53d04d/app/models/pay/stripe/charge.rb:50:in `Pay::Stripe::Charge.sync'
    from bundler/gems/pay-7c23db53d04d/app/models/pay/stripe/subscription.rb:109:in `block in Pay::Stripe::Subscription.sync'
    from bundler/gems/pay-7c23db53d04d/app/models/pay/stripe/subscription.rb:102:in `Array#each'
    from bundler/gems/pay-7c23db53d04d/app/models/pay/stripe/subscription.rb:102:in `Pay::Stripe::Subscription.sync'
    from bundler/gems/pay-7c23db53d04d/app/models/pay/stripe/customer.rb:154:in `block in Pay::Stripe::Customer#sync_subscriptions'
    from gems/stripe-15.3.0/lib/stripe/list_object.rb:51:in `Array#each'
    from gems/stripe-15.3.0/lib/stripe/list_object.rb:51:in `Stripe::ListObject#each'
    from bundler/gems/pay-7c23db53d04d/app/models/pay/stripe/customer.rb:153:in `Enumerable#map'
    from bundler/gems/pay-7c23db53d04d/app/models/pay/stripe/customer.rb:153:in `Pay::Stripe::Customer#sync_subscriptions'
    from app/controllers/application_controller.rb:78:in `ApplicationController#sync_customer_subscriptions'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:361:in `block in ActiveSupport::Callbacks::CallTemplate::MethodCall#make_lambda'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:178:in `block in ActiveSupport::Callbacks::Filters::Before#call'
    from gems/actionpack-8.0.2/lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:179:in `ActiveSupport::Callbacks::Filters::Before#call'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:559:in `block in ActiveSupport::Callbacks::CallbackSequence#invoke_before'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:559:in `Array#each'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:559:in `ActiveSupport::Callbacks::CallbackSequence#invoke_before'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:118:in `block in ActiveSupport::Callbacks#run_callbacks'
    from gems/turbo-rails-2.0.16/lib/turbo-rails.rb:24:in `Turbo.with_request_id'
    from gems/turbo-rails-2.0.16/app/controllers/concerns/turbo/request_id_tracking.rb:10:in `Turbo::RequestIdTracking#turbo_tracking_request_id'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:129:in `block in ActiveSupport::Callbacks#run_callbacks'
    from gems/actiontext-8.0.2/lib/action_text/rendering.rb:25:in `ActionText::Rendering::ClassMethods#with_renderer'
    from gems/actiontext-8.0.2/lib/action_text/engine.rb:71:in `block (4 levels) in <class:Engine>'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:129:in `BasicObject#instance_exec'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:129:in `block in ActiveSupport::Callbacks#run_callbacks'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:140:in `ActiveSupport::Callbacks#run_callbacks'
    from gems/actionpack-8.0.2/lib/abstract_controller/callbacks.rb:260:in `AbstractController::Callbacks#process_action'
    from gems/actionpack-8.0.2/lib/action_controller/metal/rescue.rb:27:in `ActionController::Rescue#process_action'
    from gems/actionpack-8.0.2/lib/action_controller/metal/instrumentation.rb:76:in `block in ActionController::Instrumentation#process_action'
    from gems/activesupport-8.0.2/lib/active_support/notifications.rb:210:in `block in ActiveSupport::Notifications.instrument'
    from gems/activesupport-8.0.2/lib/active_support/notifications/instrumenter.rb:58:in `ActiveSupport::Notifications::Instrumenter#instrument'
    from gems/activesupport-8.0.2/lib/active_support/notifications.rb:210:in `ActiveSupport::Notifications.instrument'
    from gems/actionpack-8.0.2/lib/action_controller/metal/instrumentation.rb:75:in `ActionController::Instrumentation#process_action'
    from gems/actionpack-8.0.2/lib/action_controller/metal/params_wrapper.rb:259:in `ActionController::ParamsWrapper#process_action'
    from gems/activerecord-8.0.2/lib/active_record/railties/controller_runtime.rb:39:in `ActiveRecord::Railties::ControllerRuntime#process_action'
    from gems/actionpack-8.0.2/lib/abstract_controller/base.rb:163:in `AbstractController::Base#process'
    from gems/actionview-8.0.2/lib/action_view/rendering.rb:40:in `ActionView::Rendering#process'
    from gems/actionpack-8.0.2/lib/action_controller/metal.rb:252:in `ActionController::Metal#dispatch'
    from gems/actionpack-8.0.2/lib/action_controller/metal.rb:335:in `ActionController::Metal.dispatch'
    from gems/actionpack-8.0.2/lib/action_dispatch/routing/route_set.rb:67:in `ActionDispatch::Routing::RouteSet::Dispatcher#dispatch'
    from gems/actionpack-8.0.2/lib/action_dispatch/routing/route_set.rb:50:in `ActionDispatch::Routing::RouteSet::Dispatcher#serve'
    from gems/actionpack-8.0.2/lib/action_dispatch/journey/router.rb:53:in `block in ActionDispatch::Journey::Router#serve'
    from gems/actionpack-8.0.2/lib/action_dispatch/journey/router.rb:133:in `block in ActionDispatch::Journey::Router#find_routes'
    from gems/actionpack-8.0.2/lib/action_dispatch/journey/router.rb:126:in `Array#each'
    from gems/actionpack-8.0.2/lib/action_dispatch/journey/router.rb:126:in `ActionDispatch::Journey::Router#find_routes'
    from gems/actionpack-8.0.2/lib/action_dispatch/journey/router.rb:34:in `ActionDispatch::Journey::Router#serve'
    from gems/actionpack-8.0.2/lib/action_dispatch/routing/route_set.rb:908:in `ActionDispatch::Routing::RouteSet#call'
    from gems/warden-1.2.9/lib/warden/manager.rb:36:in `block in Warden::Manager#call'
    from gems/warden-1.2.9/lib/warden/manager.rb:34:in `Kernel#catch'
    from gems/warden-1.2.9/lib/warden/manager.rb:34:in `Warden::Manager#call'
    from gems/rack-3.1.16/lib/rack/tempfile_reaper.rb:20:in `Rack::TempfileReaper#call'
    from gems/rack-3.1.16/lib/rack/etag.rb:29:in `Rack::ETag#call'
    from gems/rack-3.1.16/lib/rack/conditional_get.rb:43:in `Rack::ConditionalGet#call'
    from gems/rack-3.1.16/lib/rack/head.rb:15:in `Rack::Head#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/http/permissions_policy.rb:38:in `ActionDispatch::PermissionsPolicy::Middleware#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/http/content_security_policy.rb:38:in `ActionDispatch::ContentSecurityPolicy::Middleware#call'
    from gems/rack-session-2.1.1/lib/rack/session/abstract/id.rb:274:in `Rack::Session::Abstract::Persisted#context'
    from gems/rack-session-2.1.1/lib/rack/session/abstract/id.rb:268:in `Rack::Session::Abstract::Persisted#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/cookies.rb:706:in `ActionDispatch::Cookies#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/callbacks.rb:31:in `block in ActionDispatch::Callbacks#call'
    from gems/activesupport-8.0.2/lib/active_support/callbacks.rb:100:in `ActiveSupport::Callbacks#run_callbacks'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/callbacks.rb:30:in `ActionDispatch::Callbacks#call'
    from gems/bugsnag-6.28.0/lib/bugsnag/integrations/rack.rb:51:in `Bugsnag::Rack#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/debug_exceptions.rb:31:in `ActionDispatch::DebugExceptions#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/show_exceptions.rb:32:in `ActionDispatch::ShowExceptions#call'
    from gems/railties-8.0.2/librack/logger.rb:41:in `Rails::Rack::Logger#call_app'
    from gems/railties-8.0.2/librack/logger.rb:29:in `Rails::Rack::Logger#call'
    from gems/railties-8.0.2/librack/silence_request.rb:28:in `Rails::Rack::SilenceRequest#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/remote_ip.rb:96:in `ActionDispatch::RemoteIp#call'
    from gems/request_store-1.7.0/lib/request_store/middleware.rb:19:in `RequestStore::Middleware#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/request_id.rb:34:in `ActionDispatch::RequestId#call'
    from gems/rack-3.1.16/lib/rack/method_override.rb:28:in `Rack::MethodOverride#call'
    from gems/rack-3.1.16/lib/rack/runtime.rb:24:in `Rack::Runtime#call'
    from gems/activesupport-8.0.2/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `ActiveSupport::Cache::Strategy::LocalCache::Middleware#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/executor.rb:16:in `ActionDispatch::Executor#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/static.rb:27:in `ActionDispatch::Static#call'
    from gems/rack-3.1.16/lib/rack/sendfile.rb:114:in `Rack::Sendfile#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/ssl.rb:92:in `ActionDispatch::SSL#call'
    from gems/actionpack-8.0.2/lib/action_dispatch/middleware/assume_ssl.rb:24:in `ActionDispatch::AssumeSSL#call'
    from gems/rack-mini-profiler-4.0.0/lib/mini_profiler.rb:191:in `Rack::MiniProfiler#call'
    from gems/rack-cors-3.0.0/lib/rack/cors.rb:102:in `Rack::Cors#call'
    from gems/railties-8.0.2/libengine.rb:535:in `Rails::Engine#call'
    from gems/puma-6.6.0/lib/puma/configuration.rb:279:in `Puma::Configuration::ConfigMiddleware#call'
    from gems/puma-6.6.0/lib/puma/request.rb:99:in `block in Puma::Request#handle_request'
    from gems/puma-6.6.0/lib/puma/thread_pool.rb:390:in `Puma::ThreadPool#with_force_shutdown'
    from gems/puma-6.6.0/lib/puma/request.rb:98:in `Puma::Request#handle_request'
    from gems/puma-6.6.0/lib/puma/server.rb:472:in `Puma::Server#process_client'
    from gems/puma-6.6.0/lib/puma/server.rb:254:in `block in Puma::Server#run'
    from gems/puma-6.6.0/lib/puma/thread_pool.rb:167:in `block in Puma::ThreadPool#spawn_thread'

@excid3
Copy link
Collaborator Author

excid3 commented Jul 29, 2025

Try that

@marckohlbrugge
Copy link
Contributor

@excid3 That did the trick! ❤️

@excid3 excid3 merged commit 676921c into main Jul 29, 2025
37 checks passed
@excid3 excid3 deleted the fix-invoice-payment-sync branch July 29, 2025 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Undefined method 'payment_intent' error when syncing older Stripe subscriptions

2 participants