Class: Parsbank::Zibal

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Gates

#default_config, logo, #redirect_loaders

Constructor Details

#initialize(args = {}) ⇒ Zibal

Returns a new instance of Zibal.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/parsbank/zibal/zibal.rb', line 12

def initialize(args = {})
  @amount = args.fetch(:amount)
  @description = args.fetch(:description, nil)
  @email = args.fetch(:email, nil)
  @mobile = args.fetch(:mobile, nil)
  @merchant = args.fetch(:merchant, default_config(:merchant))
  @callbackUrl = args.fetch(:callbackUrl, (default_config(:callback_url) || Parsbank.configuration.callback_url))
  @orderId = args.fetch(:orderId, nil)
  @allowedCards = args.fetch(:allowedCards, nil)
  @ledgerId = args.fetch(:ledgerId, nil)
  @nationalCode = args.fetch(:nationalCode, nil)
  @checkMobileWithCard = args.fetch(:checkMobileWithCard, nil)
rescue KeyError => e
  raise ArgumentError, "Missing required argument: #{e.message}"
end

Instance Attribute Details

#allowedCardsObject

Returns the value of attribute allowedCards.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def allowedCards
  @allowedCards
end

#amountObject

Returns the value of attribute amount.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def amount
  @amount
end

#callbackUrlObject

Returns the value of attribute callbackUrl.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def callbackUrl
  @callbackUrl
end

#checkMobileWithCardObject

Returns the value of attribute checkMobileWithCard.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def checkMobileWithCard
  @checkMobileWithCard
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def description
  @description
end

#emailObject

Returns the value of attribute email.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def email
  @email
end

#ledgerIdObject

Returns the value of attribute ledgerId.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def ledgerId
  @ledgerId
end

#logoObject (readonly)

Returns the value of attribute logo.



10
11
12
# File 'lib/parsbank/zibal/zibal.rb', line 10

def 
  
end

#merchantObject

Returns the value of attribute merchant.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def merchant
  @merchant
end

#mobileObject

Returns the value of attribute mobile.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def mobile
  @mobile
end

#nationalCodeObject

Returns the value of attribute nationalCode.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def nationalCode
  @nationalCode
end

#orderIdObject

Returns the value of attribute orderId.



7
8
9
# File 'lib/parsbank/zibal/zibal.rb', line 7

def orderId
  @orderId
end

#ref_idObject (readonly)

Returns the value of attribute ref_id.



10
11
12
# File 'lib/parsbank/zibal/zibal.rb', line 10

def ref_id
  @ref_id
end

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/parsbank/zibal/zibal.rb', line 10

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/parsbank/zibal/zibal.rb', line 10

def status
  @status
end

#status_messageObject (readonly)

Returns the value of attribute status_message.



10
11
12
# File 'lib/parsbank/zibal/zibal.rb', line 10

def status_message
  @status_message
end

Instance Method Details

#callObject



45
46
47
# File 'lib/parsbank/zibal/zibal.rb', line 45

def call
  create_rest_client
end

#redirect_formObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/parsbank/zibal/zibal.rb', line 49

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://gateway.zibal.ir/start/#{ref_id}');
    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

Returns:

  • (Boolean)


37
38
39
# File 'lib/parsbank/zibal/zibal.rb', line 37

def valid?
  @valid
end

#validate(response = nil) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/parsbank/zibal/zibal.rb', line 28

def validate(response = nil)
  @response = response
  @ref_id = @response['trackId']
  @status = @response['result'].present? ? @response['result'] : 'FAILED'

  perform_validation
  self
end