Skip to content

Instantly share code, notes, and snippets.

@gvalmon
Last active December 15, 2015 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gvalmon/104ee698608fee04fae4 to your computer and use it in GitHub Desktop.
Save gvalmon/104ee698608fee04fae4 to your computer and use it in GitHub Desktop.
# initializer
Paysio.api_key = 'test'
Paysio.publishable_key = 'test'
# controller:
class ChargesController < ApplicationController
def new
@form = Paysio::Form.new(amount: 3999)
@form.html_options.merge!(action: charges_path)
end
def create
@form = Paysio::Form.new(amount: 3999)
@form.html_options.merge!(action: charges_path)
if params[:payment_system_id]
@form.values = params
attributes = {
amount: '3999',
currency_id: 'rur',
description: 'Test charge',
payment_system_id: params['payment_system_id'],
success_url: '#SUCCESS_URL#',
failure_url: '#FAILURE_URL#',
return_url: '#RETURN_URL#'
}
if params[:wallet][:account]
attributes[:wallet][:account] = params[:wallet][:account]
end
begin
charge = Paysio::Charge.create(attributes)
@form.add_params(charge_id: charge.id)
rescue Paysio::Errors::BadRequest => e
@form.errors = e.params
end
end
render :new
end
end
# view
= javascript_include_tag "http://code.jquery.com/jquery-latest.min.js"
= javascript_include_tag Paysio.static_url('/paysio.js')
= stylesheet_link_tag Paysio.static_url('/paysio.css')
article
= @form.render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment