dimanche 27 août 2017

Create a stripe source object for iDeal

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

So i have a products controller where people can customize their own product and once they get to the show page where they see the result they need to have a checkout button.

I'm using stripe API to accept iDeal payments.

Currently i have this in my StripesController:

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 Routes.rb

match 'checkout' => 'stripes#create_source', via: [:get, :post]

And this in the view of the my products show action:

%a.btn-primary.btn-success.btn-block{href: checkout_path}
  Checkout

Now what i want to know is how do i accomplish checking out from a button in the show page of my products controller using this api. (Stripe API -- Stripe API reference )

Help would be much much appreciated.

Aucun commentaire:

Enregistrer un commentaire