class QiwiPay::PaymentOperation

General patment operation

Constants

ATTRIBUTES

Attributes

credentials[RW]

Public Class Methods

description() click to toggle source

Описание операции

# File lib/qiwi-pay/payment_operation.rb, line 14
def self.description
  raise NotImplementedError
end
new(credentials, params = {}) click to toggle source
# File lib/qiwi-pay/payment_operation.rb, line 31
def initialize(credentials, params = {})
  params.each do |k, v|
    send("#{k}=", v) if in_params.include?(k.to_sym)
  end
  @credentials = credentials
end
opcode() click to toggle source

Код операции

# File lib/qiwi-pay/payment_operation.rb, line 9
def self.opcode
  raise NotImplementedError
end

Private Class Methods

in_params() click to toggle source

@return [Array<Symbol>] Operation input parameters

# File lib/qiwi-pay/payment_operation.rb, line 78
def self.in_params
  raise NotImplementedError
end

Public Instance Methods

amount() click to toggle source

Formatted amount @return [String]

# File lib/qiwi-pay/payment_operation.rb, line 48
def amount
  return unless @amount
  format '%.2f', @amount
end
callback_url=(url) click to toggle source
# File lib/qiwi-pay/payment_operation.rb, line 53
def callback_url=(url)
  raise ArgumentError, 'Use https URI as callback_url' unless url.start_with?('https://')
  @callback_url = url
end
description() click to toggle source
# File lib/qiwi-pay/payment_operation.rb, line 42
def description
  self.class.description
end
opcode() click to toggle source
# File lib/qiwi-pay/payment_operation.rb, line 38
def opcode
  self.class.opcode
end
order_expire=(time) click to toggle source

@param time [String;Time] time to expire order at

Must be a string in format {YYYY-MM-DDThh:mm:ss±hh:mm} or
anything responding to {strftime} message

@example

op.order_expire = Time.now + 3600
op.order_expire = 15.minutes.since
# File lib/qiwi-pay/payment_operation.rb, line 64
def order_expire=(time)
  @order_expire =
    if time.respond_to? :strftime
      time.strftime('%FT%T%:z')
    else
      time.to_s
    end
end

Private Instance Methods

cheque() click to toggle source
# File lib/qiwi-pay/payment_operation.rb, line 103
def cheque
  return @cheque.encode if @cheque.is_a? Cheque
  @cheque
end
in_params() click to toggle source
# File lib/qiwi-pay/payment_operation.rb, line 82
def in_params
  self.class.in_params
end
merchant_cheque() click to toggle source
# File lib/qiwi-pay/payment_operation.rb, line 108
def merchant_cheque
  return @merchant_cheque.encode if @merchant_cheque.is_a? Cheque
  @merchant_cheque
end
params_hash() click to toggle source

Builds hash with meaningful params only @return [Hash]

# File lib/qiwi-pay/payment_operation.rb, line 88
def params_hash
  %i[opcode].push(*ATTRIBUTES)
            .map { |a| [a, send(a).to_s] }
            .to_h
            .reject { |_k, v| v.nil? || v.empty? }
end
request_params() click to toggle source

Builds and signs request parameters @return [Hash]

# File lib/qiwi-pay/payment_operation.rb, line 97
def request_params
  params_hash.tap do |params|
    params[:sign] = Signature.new(params, credentials.secret).sign
  end
end