mercredi 30 août 2017

Start Stripe payments after customer information saved [RAILS 5]

I'm building an payment feature to my application and i'm stuck.

So i am on the first checkout page (fill in shipping address and billing address which are part of my Customers model/controller). What i want is when i click on 'submit / go to checkout' that the customer information gets saved AND i start the procedure of checking out with iDeal. As described here (Stripe API -- Stripe API reference ) to accept iDeal payments.

Currently i have this in my StripesController but i can also delete this and the functionality to the Customers controller if need be:

class StripesController < ApplicationController

def create_source
  create_stripe_source
end

private

def create_stripe_source
    Stripe.api_key = "pk_test_asdasn123jlkasdlkmcfake"

    Stripe::Source.create(
      type: "ideal",
      amount: 1000,
      currency: 'eur',
      owner: {
        name: 'John Wicked',
      },
      redirect: {
        return_url: root_url
      }
    )
end
end

I have this in my '_form' as used in my Customers#New

= form_for :customer do |f|
  = f.first_name
  = f.submit

Help would save me big time and thus be much much appreciated.

Aucun commentaire:

Enregistrer un commentaire