class Pagantis::Rails::Helper

Using this helper you can easily create a form of any flavour in Railsy environments. In the example we are using Rails and HAML

Example:

- helper = Pagantis::Helper.new(args ...)
= form_for helper, as: :helper, url: "https://psp.pagantis.com/2/sale", method: "post" do |f|
  = f.hidden_field :operation
  = f.hidden_field :account_id
  = f.hidden_field :signature
  = f.text_field :order_id
  = f.text_field :auth_method
  = f.text_field :amount
  = f.text_field :currency
  = f.text_field :description
  = f.text_field :ok_url
  = f.text_field :nok_url
  = f.text_field :plan_id    # subscription-only
  = f.text_field :user_id    # subscription-only
  = f.text_field :user_name  # subscription-only
  = f.text_field :user_email # subscription-only
  = f.submit 'Pay'

Attributes

account_id[R]
amount[R]
auth_method[R]
currency[R]
description[R]
nok_url[R]
ok_url[R]
operation[R]
order_id[R]
plan_id[R]
signature[R]
user_email[R]
user_id[R]
user_name[R]

Public Class Methods

new(args = {}) click to toggle source
# File lib/pagantis-rails/helper.rb, line 30
def initialize(args = {})
  @operation   = args.fetch(:operation) { nil } # empty operation equals single charge
  @order_id    = args.fetch(:order_id)
  @amount      = args.fetch(:amount)
  @currency    = parse_currency args.fetch(:currency)
  @description = args.fetch(:description) { "" }
  @ok_url      = args.fetch(:ok_url)
  @nok_url     = args.fetch(:nok_url)
  @account_id  = args.fetch(:account_id)
  @secret      = args.fetch(:secret)

  if subscription?
    @plan_id    = args.fetch(:plan_id)
    @user_id    = args.fetch(:user_id)
    @user_email = args.fetch(:user_email) {}
    @user_name  = args.fetch(:user_name) {}
  end
end

Public Instance Methods

gateway_url() click to toggle source
# File lib/pagantis-rails/helper.rb, line 62
def gateway_url
  "https://psp.pagantis.com/2/sale"
end
subscription?() click to toggle source
# File lib/pagantis-rails/helper.rb, line 49
def subscription?
  @operation == "SUBSCRIPTION"
end

Private Instance Methods

parse_currency(currency) click to toggle source
# File lib/pagantis-rails/helper.rb, line 68
def parse_currency(currency)
  if %w(EUR USD GBP).include? currency
    currency
  else
    fail ArgumentError
  end
end