Class: Mollie::Ideal

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mollie/ideal.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(partner_id, options = {:production => false}) ⇒ Ideal

Create a new Ideal object

Parameters:

  • partner_id (String)

    your Mollie partner id

  • options (Hash) (defaults to: {:production => false})

Options Hash (options):

  • :production (Boolean) — default: false

    whether or not to operate in production-mode



41
42
43
44
# File 'lib/mollie/ideal.rb', line 41

def initialize(partner_id, options={:production => false})
  @partner_id = partner_id
  @production = options[:production]
end

Instance Attribute Details

#partner_idObject (readonly)

Returns the value of attribute partner_id.



33
34
35
# File 'lib/mollie/ideal.rb', line 33

def partner_id
  @partner_id
end

#productionObject (readonly) Also known as: production?

Returns the value of attribute production.



33
34
35
# File 'lib/mollie/ideal.rb', line 33

def production
  @production
end

Class Method Details

.banksArray<Hash{Symbol => String}> Also known as: banklist

All supported banks.

Examples:

Mollie::Ideal.banks
# => [{:id => '0031', :name => 'ABN AMRO'}, ...]

Returns:

  • (Array<Hash{Symbol => String}>)

    the list of banks.



57
58
59
60
61
62
63
64
65
# File 'lib/mollie/ideal.rb', line 57

def self.banks
  resp = get('', :query => {:a => 'banklist'})
  parsed_response = resp.parsed_response
  return error_response(resp) if resp.error?

  parsed_response["bank"].map do |b|
    {:id => b["bank_id"], :name => b["bank_name"]}
  end
end

Instance Method Details

#request_transaction(options = {}) ⇒ Hash

Request a transaction.

Examples:


mi = Mollie::Ideal.new('12345')
mi.request_transaction(:amount => 1465,
                        :bank_id => '0721',
                        :description => "Charlie Brown's Tree",
                        :report_url => 'http://example.org/report',
                        :return_url => 'http://example.org/return')
# => {
#        :transaction_id => '482d599bbcc7795727650330ad65fe9b',
#        :amount => 1465,
#        :currency => 'EUR',
#        :url => 'https://mijn.postbank.nl/...',
#      }

Parameters:

  • opts (Hash)

Returns:

  • (Hash)

    the transaction (see example)



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/mollie/ideal.rb', line 101

def request_transaction(options={})
  query_options = options_to_query_options(options)

  query_options.merge!(:a => 'fetch', :partnerid => self.partner_id)
  query_options.merge!(:testmode => 'true') unless self.production?

  resp = self.class.get('', :query => query_options, :accept => 'text/xml')
  parsed_response = resp.parsed_response
  return error_response(resp) if resp.error?

  order = parsed_response["order"]

  %w(transaction_id amount currency url).map(&:to_sym).inject({}) do |res, k|
    v = order[k.to_s] || order[k.to_s.upcase]
    v = v.to_i if k == :amount

    res[k] = v
    res
  end
end

#verify_transaction(options = {}) ⇒ Hash

Note:

Once a transaction is payed, only the next time you verify the transaction will the value of ‘payed’ be ‘true’. Else it will be ‘false’.

Verify the status of a transaction.

Examples:

mi = Mollie::Ideal.new('12345')
mi.verify_transaction(:transaction_id => '482d599bbcc7795727650330ad65fe9b')
# => {
#        :transaction_id => '482d599bbcc7795727650330ad65fe9b',
#        :amount => 1465,
#        :currency => 'EUR',
#        :payed => true,
#        :consumer => {
#          :name => 'Hr J Janssen',
#          :account => 'P001234567',
#          :city => 'Amsterdam'
#        },
#        :message => 'This iDEAL-order has successfuly been payed for,
#                     and this is the first time you check it.',
#        :status => 'Expired'
#      }
# Example of an error:
# => {
#      :error => {
#        :code => "-10",
#        :message => "This is an unknown order."
#      }
#    }

Parameters:

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

Options Hash (options):

  • :transaction_id (String)

    the transaction to verify.

Returns:

  • (Hash)

    the status of the transaction (see example).



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/mollie/ideal.rb', line 158

def verify_transaction(options={})
  query_options = options_to_query_options(options)
  query_options.merge!(:a => 'check', :partnerid => self.partner_id)
  query_options.merge!(:testmode => 'true') unless self.production?

  resp = self.class.get('', :query => query_options)
  parsed_response = resp.parsed_response
  return error_response(resp) if resp.error?

  order = parsed_response["order"]

  result = %w(transaction_id amount currency payed status message).map(&:to_sym).inject({}) do |res, k|
    v = order[k.to_s] || order[k.to_s.upcase]
    v = v.to_i if k == :amount
    v = (v == 'true') if k == :payed

    res[k] = v
    res
  end

  if consumer = order["consumer"]
    consumer = {'consumerName' => 'name', 'consumerAccount' => 'account', 'consumerCity' => 'city'}.inject({}) do |res, (theirs, ours)|
      res[ours.to_sym] = consumer[theirs]
      res
    end
    result[:consumer] = consumer
  end
  result
end