KISO Docs

Transactions Quickstart

#Transactions QuickStart

  1. Install kiso_stripe_payments
  2. Run the kiso_stripe_payments:install generator
  3. bin/rails g scaffold customer name:string email:string
  4. bin/rails db:migrate
  5. bin/rails g kiso_stripe_payments:install_transactions Customer
  6. bin/rails db:migrate
  7. Set the environment variables for STRIPE_SECRET_KEY, STRIPE_PUBLISHABLE_KEY and STRIPE_WEBHOOK_SIGNING_SECRET
  8. Use the KISO Themes generator kiso_themes:landing_pages home index to generate a basic landing page
  9. Add a root route to routes.rb: root to: 'home#index'
  10. In HomeController's home method add: @body_class = 'd-flex h-100'
  11. Replace the contents of app/views/home/index.html.erb:
    1. <main class="d-flex flex-fill h-100">
       <div class="d-flex flex-fill align-items-center justify-content-center h-100">
           <div class="row">
               <div class="col-12 text-center">
                   <h5>SEND MORE MONEY</h5>
                   <%= render_transaction_button                  price_cents: 9900,
                       merchant_name: "John's Cat Carriers",
                       product_description: "Deluxe Cat Carrier",
                       product_name: "Deluxe Cat Carrier",
                       product_sku: "DELUXE-CAT-CARRIER",
                       brand_image: "https://www.google.ca/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
                       %>
               </div>
           </div>
       </div>
      </main>
      
  12. Add a method to the HomeController called success and a view for it. Add the following code to the success method:
    1. tx = params.permit(:tx)[:tx]
      @stripe_tx = KisoStripePayments::StripeTransaction.find_by(tx_id: tx)
      
  13. Add a route for the success page: get '/success/:tx', to: 'home#success'
  14. Configure KisoStripePaymentsConfig object
  15. Now if you start the Rails server, and hit http://localhost:3000 in your browser, you'll see:
  16. Hitting the Buy Now button will launch the Stripe Checkout modal:
  17. Completing the transaction will send you to the configured success page /success
  18. When the HomeController 's success method is fired, you can look up the transaction ID, and in this way determine if the transaction was successful or not, and chose to either grant access to the bought item, or redirect.