Class: Rubyplat::Requests::PaymentPermission

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyplat/requests/payment_permission.rb

Constant Summary collapse

InvalidPaytool =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ PaymentPermission

Returns a new instance of PaymentPermission.

Parameters:

  • params (Hash) (defaults to: {})

    arguments to create request

Options Hash (params):

  • :sender (String)

    sender of request

  • :receiver (String)

    request receiver

  • :operator (String)

    operator

  • :date (String)

    request date

  • :session (String)

    session

  • :number (String)

    phone number or payer’s account number(can be blank)

  • :account (String)

    payer’s identifier or payees service identifier. Can be blank.

  • :req_type (Float)

    if 1 – simply check number without payment

  • :amount (Float)

    amount to be payed. example: 1234.12

  • :term_id (String)

    actual sender code(Only for MTS and Beeline)

  • :no_route (Bool)

    auto redirect sign



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubyplat/requests/payment_permission.rb', line 19

def initialize(params = {})
  params = defaults.merge(params)

  @sender = params[:sender]
  @receiver = params[:receiver]
  @operator = params[:operator]
  @date = DateTime.parse((params[:date] || Time.now).to_s).strftime('%Y.%m.%d %H:%M:%S')
  @session = params[:session]
  @number = params[:number]
  @account = params[:account]
  @amount = params[:amount]
  @req_type = params[:req_type]
  @pay_tool = Rubyplat::PAYTOOL.fetch(params[:pay_tool]) { raise InvalidPaytool.new("Paytool может принимать значения #{PAYTOOL.keys}") }
  @term_id = params[:term_id]
  @comment = params[:comment]
  @accept_keys = params[:accept_keys]
  @no_route = params[:no_route]
  @amount_all = params[:amount_all]
end

Instance Method Details

#bodyString

Returns String representation of request.

Examples:

@check_request = Rubyplat::Requests::Check.new(
  sender: 'sender',
  receiver: 'receiver',
  operator: 'operator',
  date: Time.now,
  session: 'sess',
  account: 'account',
  amount: 1234.42,
  req_type: false,
  term_id: '12345',
  comment: 'FooBar',
  accept_keys: '12345',
  pay_tool: :cash,
  no_route: true)

@check_request.body
 #=> "SD=sender\r\nAP=receiver\r\nOP=operator\r\nDATE=2018.04.27 17:08:49\r\nSESSION=sess\r\nACCOUNT=account\r\nAMOUNT=1234.42\r\nREQ_TYPE=0\r\nPAY_TOOL=0\r\nTERM_ID=12345\r\nCOMMENT=FooBar\r\nACCEPT_KEYS=12345\r\nNO_ROUTE=1"

Returns:

  • (String)

    String representation of request



58
59
60
# File 'lib/rubyplat/requests/payment_permission.rb', line 58

def body
  body_parameters.compact.join("\r\n").encode(Encoding::WINDOWS_1251)
end