Migrate from Stripe Charges API to Stripe Checkout Sessions API#58
Merged
Migrate from Stripe Charges API to Stripe Checkout Sessions API#58
Conversation
|
Can you fix the rubocop errors please |
Replace the legacy Stripe Charges API and embedded Checkout.js with the modern Stripe Checkout Sessions API. This redirects users to Stripe's hosted checkout page for a more secure and flexible payment experience. Key changes: - Payment model: replace Stripe::Charge.create with Stripe::Checkout::Session.create and session verification - Send itemized ticket breakdown as line_items to Stripe instead of only the total cost, improving payment tracking and reconciliation - Add stripe_session_id column to payments table for session tracking - Add success/cancel callback routes for Stripe redirect flow - Update payment views to use standard form submission instead of embedded Stripe Checkout.js - Update tests to use RSpec mocks for Checkout Session API
Move errors.add after save to prevent ActiveRecord from clearing the error messages when the record is successfully saved.
- Fix RSpec/MessageSpies: use argument capture pattern instead of have_received to satisfy both MessageSpies and StubbedMock cops - Add test files to RSpec/VerifiedDoubles exclude list since Stripe API objects use dynamic attributes incompatible with instance_double - Fix pre-existing Style/NumericPredicate in config/puma.rb - Fix pre-existing RSpec/PendingWithoutReason in organization_spec.rb - Fix pre-existing Layout/SpaceInsidePercentLiteralDelimiters in Gemfile
The organization validation and association tests actually pass. Changed from xit/pending to regular test assertions.
- Move Pay button to the right side using flexbox layout - Remove btn-lg from Pay button to match Edit Purchase button size - Wrap buttons in .payment-actions container for consistent spacing
The ticket table was wrapped in .div > .col-md-12 which caused the form buttons to float beside the table instead of appearing below it. - Remove unnecessary .div and .col-md-12 wrapper - Use .table-responsive directly as the table container - Buttons now correctly appear below the table in a flex row Fixes #67
The _form_fields partial uses Devise's resource variable, which is not available when rendered in non-Devise contexts like proposals/new. Add defined?(resource) guard to prevent NameError.
90103d9 to
e3f3ba6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stripe::Charge.create) and embedded Checkout.js to the modern Stripe Checkout Sessions API (Stripe::Checkout::Session.create)line_itemsto Stripe instead of only the total cost, improving payment tracking and reconciliation on both the Stripe Dashboard and customer receiptsstripe_session_idto the payments table for better payment tracking and session-based verificationChanges
Payment Model (
app/models/payment.rb)purchasemethod (which usedStripe::Charge.create) with:create_checkout_session— creates a Stripe Checkout Session with itemized line items and redirects to Stripecomplete_checkout— retrieves the session after redirect, verifies payment status, and records charge detailsbuild_line_itemsprivate method that maps each unpaidTicketPurchaseto a Stripe line item with proper currency conversionunpaid_ticket_purchaseshelper methodPayments Controller (
app/controllers/payments_controller.rb)createaction now creates a Payment record and Stripe Checkout Session, then redirects to Stripe's hosted pagesuccessaction — handles the return from Stripe after successful payment, verifies the session, marks tickets as paid, and handles registrationcancelaction — handles payment cancellation, redirects back to payment pagestripeToken/stripeEmailparams (no longer needed with hosted checkout)Routes (
config/routes.rb)successandcancelcollection routes underpaymentsViews
<script>tag with a standard form submit button that initiates the checkout flowDatabase
stripe_session_id(string, unique index) topaymentstabledb/schema.rbTests
spec/models/payment_spec.rbto testcreate_checkout_sessionandcomplete_checkoutmethods using RSpec mocksspec/features/ticket_purchases_spec.rbto work with the new checkout flowTest plan
bundle exec rspec spec/models/payment_spec.rbbundle exec rspec spec/features/ticket_purchases_spec.rb