Class: SisowIdeal::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/sisow_ideal/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
# File 'lib/sisow_ideal/client.rb', line 6

def initialize(options = {})
  required_options(options, :merchantid, :merchantkey)

  @options = options
end

Instance Method Details

#banklistObject

Get the banklist



13
14
15
16
17
18
19
20
21
# File 'lib/sisow_ideal/client.rb', line 13

def banklist
  response = Hashie::Mash.new(
    self.class.get('/DirectoryRequest',
    :query => @options,
    :format => :xml
  ).parsed_response).directoryresponse.directory.issuer

  response.kind_of?(Array) ? response.map { |b| [b.issuername, b.issuerid] } : [[response.issuername, response.issuerid]]
end

#setup_transaction(options = {}) ⇒ Object

Setup a transaction



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sisow_ideal/client.rb', line 24

def setup_transaction(options = {})
  required_options(options, :issuerid, :amount, :description, :returnurl, :callbackurl, :notifyurl, :purchaseid)

  sha1 = [
    options.fetch(:purchaseid),
    options.fetch(:entrancecode),
    options.fetch(:amount),
    options.fetch(:shopid),
    @options.fetch(:merchantid),
    @options.fetch(:merchantkey)
  ].join

  response = Hashie::Mash.new(
    self.class.get('/TransactionRequest',
    :query  => merge_options(options, sha1),
    :format => :xml
  ).parsed_response)

  begin
    return Hashie::Mash.new(
      :url   => CGI.unescape(response.transactionrequest.transaction.issuerurl),
      :trxid => response.transactionrequest.transaction.trxid
    )
  rescue
    raise SisowIdeal::SisowException.new(response.errorresponse.error.errorcode, CGI.unescape(response.errorresponse.error.errormessage))
  end
end

#status_request(options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sisow_ideal/client.rb', line 52

def status_request(options = {})
  required_options(options, :trxid, :shopid)

  sha1 = [
    options.fetch(:trxid),
    options.fetch(:shopid),
    @options.fetch(:merchantid),
    @options.fetch(:merchantkey)
  ].join

  response = Hashie::Mash.new(
    self.class.get('/StatusRequest',
    :query  => merge_options(options, sha1),
    :format => :xml
  ).parsed_response)

  begin
    return response.statusresponse.transaction
  rescue
    raise SisowIdeal::SisowException.new(response.errorresponse.error.errorcode, CGI.unescape(response.errorresponse.error.errormessage))
  end
end

#valid_response?(params) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sisow_ideal/client.rb', line 75

def valid_response?(params)
  sha1 = [
    params.fetch(:trxid),
    params.fetch(:ec),
    params.fetch(:status),
    @options.fetch(:merchantid),
    @options.fetch(:merchantkey)
  ].join

  Digest::SHA1.hexdigest(sha1) == params[:sha1]
end