Module: Paysto

Defined in:
lib/paysto/base.rb,
lib/paysto-rails.rb,
lib/paysto/version.rb,
lib/paysto/controller.rb,
lib/generators/paysto/models_generator.rb,
lib/generators/paysto/install_generator.rb

Defined Under Namespace

Modules: Controller Classes: InstallGenerator, ModelsGenerator

Constant Summary collapse

RXP =
Regexp.new('[^a-zA-Z0-9$&%;:?!\.,\s}(\[){\]"\'`\\/|^_~*+=<>@-]+')
VERSION =
'1.0.6'

Class Method Summary collapse

Class Method Details

.balanceObject

Your current balance in Paysto.



47
48
49
# File 'lib/paysto/base.rb', line 47

def balance
  https_request_to @@urls[:balance], base_params
end

.currenciesObject

List of available pay methods according to your tariff plan.



42
43
44
# File 'lib/paysto/base.rb', line 42

def currencies
  https_request_to @@urls[:currencies], base_params
end

.get_payment_type(invoice_id, time = Time.zone.now) ⇒ Object

Returns payment type or ‘common’ by default. invoice_id – invoice ID of payment. time – estimated payment execution time.



67
68
69
70
71
72
73
74
# File 'lib/paysto/base.rb', line 67

def get_payment_type(invoice_id, time = Time.zone.now)
  _payments = get_payments(time.utc - 30.minutes, time.utc + 5.minutes)
  if _payments.present?
    p = _payments.select{ |_p| _p[2].eql?(invoice_id.to_s) }.first
    _type = p[7] if p
  end
  _type || 'common'
end

.get_payments(from, to) ⇒ Object

Returns array of payments with details between dates. from – from date. to – to date.



54
55
56
57
58
59
60
61
62
# File 'lib/paysto/base.rb', line 54

def get_payments(from, to)
  p = { 'PAYSTO_SHOP_ID' => @@id,
        'FROM'           => from.strftime('%Y%m%d%H%M'),
        'TO'             => to.strftime('%Y%m%d%H%M') }
  p.merge!('PAYSTO_MD5'  => generate_md5(p))

  res = https_request_to(@@urls[:payments_list], p)
  CSV.parse(res)
end

.invoice_classObject

Invoice class.



32
33
34
# File 'lib/paysto/base.rb', line 32

def invoice_class
  @@invoice_class_name.constantize
end

.invoice_notification_classObject

InvoiceNotification class.



37
38
39
# File 'lib/paysto/base.rb', line 37

def invoice_notification_class
  @@invoice_notification_class_name.constantize
end

.invoice_valid?(invoice) ⇒ Boolean

Check whether the invoice is valid.

Returns:

  • (Boolean)


77
78
79
# File 'lib/paysto/base.rb', line 77

def invoice_valid?(invoice)
  invoice && invoice.send("#{@@payment_class_name.underscore}_id").blank? && invoice.paid_at.blank?
end

.ip_valid?(ip) ⇒ Boolean

Check whether the IP is permitted.

Returns:

  • (Boolean)


82
83
84
# File 'lib/paysto/base.rb', line 82

def ip_valid?(ip)
  @@ips.include?(ip)
end

.md5_valid?(p) ⇒ Boolean

Check whether the MD5 sign is valid.

Returns:

  • (Boolean)


87
88
89
90
# File 'lib/paysto/base.rb', line 87

def md5_valid?(p)
  hash = p.except('action', 'controller', 'PAYSTO_MD5')
  generate_md5(hash) == p['PAYSTO_MD5']
end

.pay_tillObject

Timestamp string in Paysto format for payments expiration.



93
94
95
# File 'lib/paysto/base.rb', line 93

def pay_till
  (Time.zone.now + @@expiration).utc.strftime('%Y%m%d%H%M')
end

.payment_classObject

Payment class.



27
28
29
# File 'lib/paysto/base.rb', line 27

def payment_class
  @@payment_class_name.constantize
end

.real_amount(str) ⇒ Object

Real income value without Paysto tax for any amount which you want to calculate. str – amount string or numeric, does not matter.



99
100
101
102
103
104
# File 'lib/paysto/base.rb', line 99

def real_amount(str)
  amount = str.to_f
  _tax = amount * @@tax
  _tax = @@min_tax if _tax < @@min_tax
  amount - _tax
end

.setup {|_self| ... } ⇒ Object

Configuring module.

Yields:

  • (_self)

Yield Parameters:

  • _self (Paysto)

    the object that the method was called on



22
23
24
# File 'lib/paysto/base.rb', line 22

def setup
  yield self
end