Class: Jpay::PaymentRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/jpay/payment_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ PaymentRequest

Note:

A hash of parametes should be send to this class

Returns a new instance of PaymentRequest.

Examples:

PaymentRequest.new(amount: 1000, callback_url: 'localhost:3000/verify', order_id: 12, text: 'sample text')

Parameters:

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

    hash of params to send requests

Options Hash (args):

  • :amount (Integer)

    price in Toman

  • :callback_url (String)

    callback_url url for verification redirect

  • :order_id (Integer)

    your order id

  • :text (string)

    payment description



19
20
21
22
23
24
25
26
27
# File 'lib/jpay/payment_request.rb', line 19

def initialize(args = {})
  @api = args[:api] || Jpay.configuration.api
  @amount   = args[:amount]
  @callback_url = args[:callback_url] || Jpay.configuration.callback_url
  @order_id = args[:order_id]
  @text     = args[:text]
  @client ||= Savon.client(wsdl: Jpay.configuration.client, pretty_print_xml: true)
  @response = Response.new
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



6
7
8
# File 'lib/jpay/payment_request.rb', line 6

def amount
  @amount
end

#order_idObject

Returns the value of attribute order_id.



6
7
8
# File 'lib/jpay/payment_request.rb', line 6

def order_id
  @order_id
end

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/jpay/payment_request.rb', line 7

def response
  @response
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/jpay/payment_request.rb', line 6

def text
  @text
end

Instance Method Details

#payObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jpay/payment_request.rb', line 29

def pay
  response = @client.call :requestpayment, message: {
    'api'      => @api,
    'amount'   => @amount,
    'callback' => @callback_url,
    'orderid'  => @order_id,
    'txt'      => @text
  }

  @response.validate(response.body)
end