Migrate from Stripe Charges API to Stripe Checkout Sessions API#403
Closed
li-xinwei wants to merge 4 commits intosnap-cloud:mainfrom
Closed
Migrate from Stripe Charges API to Stripe Checkout Sessions API#403li-xinwei wants to merge 4 commits intosnap-cloud:mainfrom
li-xinwei wants to merge 4 commits intosnap-cloud:mainfrom
Conversation
add new feature for counting the total sales for each currency
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
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.rbMade with Cursor