Try Samurai Gateway Right Now sinatra demo – FeeFighters

Try Samurai Gateway Right Now sinatra demo

Try Samurai Gateway Right Now

30 seconds, 19 lines of code

We made this cool Ruby demo to show you how easy it is to get started with Samurai. But don’t worry, we’ve got support for your language too.

1 Download and install the required gems by running the following command

Shell Command

gem install bundler && curl -s -o Gemfile https://raw.github.com/FeeFighters/samurai-example-sinatra/master/Gemfile && bundle install

2 Run bundle exec ruby, paste the following script, and press Enter

Ruby

require ‘rubygems’; require ‘bundler’; Bundler.require; require ‘open-uri’Samurai.options = { :merchant_key=>’e84803ad9cf61cb21405ab79′, :merchant_password=>’a368e3adcd41a4ed29e7bc3c’, :processor_token=>’0c7eeeb8cc23a79f381bc886′ }get ‘/’ do erb(:index); endlayout :index do <<-__HTML__ <!doctype html><html><head> <link href=”http://feefighters.github.com/samurai-example-sinatra/css/application.css” media=”screen” rel=”stylesheet” type=”text/css”/> <script src=”https://samurai.feefighters.com/assets/api/samurai.js”></script> <script>Samurai.init({merchant_key: ‘<%= Samurai.options[:merchant_key] %>’})</script> </head><body><div><h1>Samurai Demo</h1><hr> <section data-samurai-payment-form></section> <section> <h3>Shopping Cart</h3> <p>(1) Katana Sword: $111.11</p><hr><h3>Accepted Card Types:</h3> <table><tr><th>Valid:</strong></th><td><code style=”border:none;”>4111111111111111</code></td></tr><tr><th>Denied:</strong></th><td><code style=”border:none;”>4242424242424242</code></td></tr><tr><td colspan=’2′><em>All other card numbers will return an error.</em></td></tr></table> </section> <script> Samurai.ready(function(){ var $ = Samurai.jQuery; Samurai.on(‘form’, ‘payment’, function(event, data) { // Attach an event handler to process the transaction $.post(‘/create-transaction’, data.payment_method, function(data) { // Send the payment_method via AJAX to the server var transaction = $.parseJSON(data).transaction; if(transaction.success) { // Update the page to display the results $(‘form’).children(‘.results’).html(‘<h3>Your purchase is complete!</h3><h4>’+transaction.payment_method.payment_method.first_name+’ ‘+transaction.payment_method.payment_method.last_name+’: $’+transaction.amount+’ – ‘+transaction.descriptor+'</h4>’); Samurai.trigger(‘form’, ‘completed’); } else { Samurai.PaymentErrorHandler.forForm($(‘form’)[0]).handleErrorsFromResponse(transaction); } }); }); }); </script> </div></body></html> __HTML__endpost ‘/create-transaction’ do @transaction = Samurai::Processor.the_processor.purchase params[:payment_method_token], 111.11, :description=>’Katana Sword’ @transaction.to_jsonend__END__

  1. Initialize the Samurai ruby gem with your merchant credentials.

  2. Add the Samurai.js script to the page to use our JavaScript API. It gives you nice-looking, secure payment forms for free.

  3. Observe the payment event, and perform the ajax POST to /create-transaction. On complete, display the results and inform Samurai.

  4. Use an AJAX action on the server to process the transaction, via the_processor.purchaseThis action only uses tokenized credit card data, which keeps your server safe & PCI-compliant.

That’s it! Your local server is running!

Try your local demo orTest it on our site

We’ve got all the gems, libraries & documentation you need to get Samurai working with your code.

Just pick your language

Learn more in our developers portal

Convinced?

Start Using Samurai

Talk With Us

© 2019 –  FeeFighters, LLC  – Call Us – (646) 448-8804

PO Box 1459 , Mountainside, NJ 07092