Class: Parsbank::Mellat

Inherits:
Gates
  • Object
show all
Defined in:
lib/parsbank/mellat/mellat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Gates

#default_config, logo, #redirect_loaders

Constructor Details

#initialize(args = {}) ⇒ Mellat



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/parsbank/mellat/mellat.rb', line 6

def initialize(args = {})
  @order_id = args.fetch(:orderId)
  @amount = args.fetch(:amount)
  @local_date = args.fetch(:localDate, Time.now.strftime('%Y%m%d'))
  @local_time = args.fetch(:localTime, Time.now.strftime('%H%M%S'))
  @additional_data = args.fetch(:additionalData, ' ')
  @payer_id = args.fetch(:payerId, 0)
  @callback_url = args.fetch(:callBackUrl, default_config(:callback_url))
  @terminal_id = args.fetch(:terminalId, default_config(:terminal_id))
  @username = args.fetch(:userName, default_config(:username))
  @user_password = args.fetch(:userPassword, default_config(:password))
  @wsdl = create_wsdl_client
rescue KeyError => e
  raise ArgumentError, "Missing required argument: #{e.message}"
end

Instance Attribute Details

#additional_dataObject

Returns the value of attribute additional_data.



3
4
5
# File 'lib/parsbank/mellat/mellat.rb', line 3

def additional_data
  @additional_data
end

#amountObject

Returns the value of attribute amount.



3
4
5
# File 'lib/parsbank/mellat/mellat.rb', line 3

def amount
  @amount
end

#callback_urlObject

Returns the value of attribute callback_url.



3
4
5
# File 'lib/parsbank/mellat/mellat.rb', line 3

def callback_url
  @callback_url
end

#local_dateObject

Returns the value of attribute local_date.



3
4
5
# File 'lib/parsbank/mellat/mellat.rb', line 3

def local_date
  @local_date
end

#local_timeObject

Returns the value of attribute local_time.



3
4
5
# File 'lib/parsbank/mellat/mellat.rb', line 3

def local_time
  @local_time
end

#order_idObject

Returns the value of attribute order_id.



3
4
5
# File 'lib/parsbank/mellat/mellat.rb', line 3

def order_id
  @order_id
end

#payer_idObject

Returns the value of attribute payer_id.



3
4
5
# File 'lib/parsbank/mellat/mellat.rb', line 3

def payer_id
  @payer_id
end

#ref_idObject (readonly)

Returns the value of attribute ref_id.



4
5
6
# File 'lib/parsbank/mellat/mellat.rb', line 4

def ref_id
  @ref_id
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/parsbank/mellat/mellat.rb', line 4

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/parsbank/mellat/mellat.rb', line 4

def status
  @status
end

#status_messageObject (readonly)

Returns the value of attribute status_message.



4
5
6
# File 'lib/parsbank/mellat/mellat.rb', line 4

def status_message
  @status_message
end

Instance Method Details

#callObject



36
37
38
39
40
41
# File 'lib/parsbank/mellat/mellat.rb', line 36

def call
  response = @wsdl.call(:bp_pay_request, message: build_request_message)
  validate(response.body)
rescue Savon::Error => e
  raise "SOAP request failed: #{e.message}"
end

#redirect_formObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/parsbank/mellat/mellat.rb', line 43

def redirect_form
  `
  <script type="text/javascript" charset="utf-8">
function postRefId (refIdValue) {
  var form = document.createElement('form');
  form.setAttribute('method', 'POST');
  form.setAttribute('action', 'https://bpm.shaparak.ir/pgwchannel/startpay.mellat');
  form.setAttribute("target', '_self");
  var hiddenField = document.createElement("input");
  hiddenField.setAttribute('name', 'RefId');
  hiddenField.setAttribute('value', refIdValue);
  form.appendChild(hiddenField);
  document.body.appendChild(form);
  form.submit();
  document.body.removeChild(form);
}


  postRefId('#{ref_id}') %>')
</script>
    `
end

#valid?Boolean



28
29
30
# File 'lib/parsbank/mellat/mellat.rb', line 28

def valid?
  @valid
end

#validate(response = nil) ⇒ Object



22
23
24
25
26
# File 'lib/parsbank/mellat/mellat.rb', line 22

def validate(response = nil)
  @response = response
  perform_validation
  self
end