Friday 19 December 2014

Stripe for PAYMENT in Ruby on Rails application



Stripe is a company that provides a way for individuals and businesses to accept payments over the Internet.


Easy to implement a payment gateway by Stripe in Ruby on Rails Application
It's Provide many function for Client like

1.Create , Update ,Delete --> charges 
2.Create , Update ,Delete --> subscription
3.Create , Update ,Delete --> plain
4.Create , Update ,Delete --> coupons , customer,refund, discounts 


Step 1: adding Gem gem in Gemfile

gem 'stripe',  :git => 'https://github.com/stripe/stripe-ruby'

Step 2: Run 'bundle'
Step 3 : rails generate controller subscriptions

app/controller/subscriptions_controller.rb

def create 
  customer = Stripe::Customer.create(
      :card => params[:stripeToken],
      :plan => 'planname',
      :email => params[:stripeEmail],
  )

rescue Stripe::CardError => e flash[:error] = e.message
 redirect_to charges_path
end
step :4
add in config/route.rb
resources :subscriptions
step: 5 

config/initializers/stripe.rb:

Rails.configuration.stripe = {
 :publishable_key => 'PUBLISHABLE_KEY',
 :secret_key => 'SECRET_KEY'
}

Stripe.api_key = Rails.configuration.stripe[:secret_key]




Step :6



Now let’s create new.html.erb under app/views/subscriptions, which is going to be our checkout page, which will display a credit card overlay which includes validation and error handling.
 


<%= form_tag subscriptions_path, :class => 'subscription_form' do %> 



<script src="https://checkout.stripe.com/checkout.js"


class="stripe-button"


data-key="<%= Rails.configuration.stripe[:publishable_key] %>"


data-description="Description about palin" 


data-amount="Plain amount" data-label='Pay' >


</script>



step :7


Finally let’s make a create.html.erb view under app/views/subscriptions that shows users a success message.


<h2>Thanks, you paid <strong>$5.00</strong>!</h2>








No comments:

Salesforce CRM vs. Zoho: A Comparative Analysis

Introduction: Selecting the right customer relationship management (CRM) software is crucial for businesses seeking to streamline their sal...