Why my API requests are successful but receiving errors on Stripe

0

I'm using Stripe Elements and testing the input form. My API requests are going through, the customers are being created, but I receive errors.

Here's my controller:

class ChargesController < ApplicationController
  skip_before_action :verify_authenticity_token
  protect_from_forgery prepend: true

  def new
  end

  def create
    # Amount in cents
    @amount = 500
    token = params[:stripeToken]
    payment_form = params[:payment_form]

    customer = Stripe::Customer.create(
      :email => params[:stripeEmail],
      :source  => params[:stripeToken]
    )

    charge = Stripe::Charge.create(
      :customer    => customer.id,
      :amount      => @amount,
      :description => 'Rails Stripe customer',
      :currency    => 'usd',
      :source => token
    )

  rescue Stripe::CardError => e
    flash[:error] = e.message
    redirect_to new_charge_path
  end



end

Here's my view:

http://jsfiddle.net/skx32mbd/

Every request is successful - along with every request receiving errors.

Here's what my Browser Console does:

TypeError: form is null new:88:1
[Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIContentSniffer.getMIMETypeFromContent]"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: resource:///modules/FaviconLoader.jsm :: onStopRequest :: line 181"  data: no]

My CMD when i enter the credit card test credentials:

Started POST "/charges" for 127.0.0.1 at 2018-10-26 14:26:53 -0400
Processing by ChargesController#create as HTML
Can't verify CSRF token authenticity.
Redirected to http://localhost:3000/charges/new
Completed 302 Found in 1320ms (ActiveRecord: 0.0ms)

Anyone have suggestions on what to do?

Everything works perfectly with Stripe Checkout but i can't seem to get Elements operating successfully yet.

ruby-on-rails
stripe-payments
asked on Stack Overflow Oct 26, 2018 by uno

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0