#Transactions QuickStart
- Install
kiso_stripe_payments
- Run the
kiso_stripe_payments:install
generator bin/rails g scaffold customer name:string email:string
bin/rails db:migrate
bin/rails g kiso_stripe_payments:install_transactions Customer
bin/rails db:migrate
- Set the environment variables for
STRIPE_SECRET_KEY
,STRIPE_PUBLISHABLE_KEY
andSTRIPE_WEBHOOK_SIGNING_SECRET
- Use the KISO Themes generator
kiso_themes:landing_pages home index
to generate a basic landing page - Add a root route to routes.rb: root to: 'home#index'
- In
HomeController
'shome
method add:@body_class = 'd-flex h-100'
- Replace the contents of
app/views/home/index.html.erb
:<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>
- Add a method to the
HomeController
calledsuccess
and a view for it. Add the following code to thesuccess
method:tx = params.permit(:tx)[:tx] @stripe_tx = KisoStripePayments::StripeTransaction.find_by(tx_id: tx)
- Add a route for the success page:
get '/success/:tx', to: 'home#success'
- Configure
KisoStripePaymentsConfig
object - Now if you start the Rails server, and hit
http://localhost:3000
in your browser, you'll see: - Hitting the Buy Now button will launch the Stripe Checkout modal:
- Completing the transaction will send you to the configured success page
/success
- When the
HomeController
'ssuccess
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.