require 'sinatra'require 'stripe'# This is your test secret API key.Stripe.api_key = 'sk_test_51FwXWdCCmg7qIPInp6OszJj5l0QEsjUQyf4Gll8b5EGnmOnoK0wVLORF6aAvJLzMwpimvJGlTO2ETyVZKDSP5kJZ00ShLX6I18'set :static, trueset :port, 4242# Securely calculate the order amountdef calculate_order_amount(_items) # Replace this constant with a calculation of the order's amount # Calculate the order total on the server to prevent # people from directly manipulating the amount on the client 1400end# An endpoint to start the payment processpost '/create-payment-intent' do content_type 'application/json' data = JSON.parse(request.body.read) # Create a PaymentIntent with amount and currency payment_intent = Stripe::PaymentIntent.create( amount: calculate_order_amount(data['items']), currency: 'usd', # In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default. automatic_payment_methods: { enabled: true, }, ) { clientSecret: payment_intent.client_secret, }.to_jsonend