Class: ActiveMerchant::Billing::IdealGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant_ideal/ideal.rb

Overview

Response classes

  • IdealResponse

  • IdealTransactionResponse

  • IdealStatusResponse

  • IdealDirectoryResponse

See the IdealResponse base class for more information on errors.

Constant Summary collapse

AUTHENTICATION_TYPE =
'SHA1_RSA'
LANGUAGE =
'nl'
CURRENCY =
'EUR'
API_VERSION =
'1.1.0'
XML_NAMESPACE =
'http://www.idealdesk.com/Message'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ IdealGateway

Initializes a new IdealGateway instance.

You can optionally specify :sub_id. Defaults to 0.



118
119
120
121
# File 'lib/active_merchant_ideal/ideal.rb', line 118

def initialize(options = {})
  @sub_id = options[:sub_id] || 0
  super
end

Instance Attribute Details

#sub_idObject (readonly)

Returns the merchant ‘subID’ being used for this IdealGateway instance. Defaults to 0.



113
114
115
# File 'lib/active_merchant_ideal/ideal.rb', line 113

def sub_id
  @sub_id
end

Class Method Details

.acquirer=(acquirer) ⇒ Object

Set the correct acquirer url based on the specific Bank Currently supported arguments: :ing, :rabobank, :abnamro



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/active_merchant_ideal/ideal.rb', line 98

def self.acquirer=(acquirer)
  acquirer = acquirer.to_s
  if self.acquirers.include?(acquirer)
    if self.acquirers[acquirer]['live'].is_a?(Hash) #Assume acquirer is abnamro
      self.acquirers[acquirer].each{|env, url| url.each{|sort,value| self.send("#{env}_#{sort}_url=",value)}}
      self.whitespace_behaviour = :abnamro
    else
      self.live_url = self.acquirers[acquirer]['live']
      self.test_url = self.acquirers[acquirer]['test']
    end
  end
end

.acquirersObject



26
27
28
29
# File 'lib/active_merchant_ideal/ideal.rb', line 26

def self.acquirers
  config_file = File.dirname(__FILE__) + '/acquirers.yml'
  File.exists?(config_file) ? YAML.load(File.read(config_file)) : {}
end

.ideal_certificateObject

Returns the global merchant ideal_certificate.



85
86
87
# File 'lib/active_merchant_ideal/ideal.rb', line 85

def self.ideal_certificate
  @ideal_certificate
end

.ideal_certificate=(certificate_data) ⇒ Object

Instantiates and assings a OpenSSL::X509::Certificate instance with the provided iDEAL certificate data.



80
81
82
# File 'lib/active_merchant_ideal/ideal.rb', line 80

def self.ideal_certificate=(certificate_data)
  @ideal_certificate = OpenSSL::X509::Certificate.new(certificate_data)
end

.ideal_certificate_file=(certificate_file) ⇒ Object

Loads the global merchant ideal_certificate from disk.



74
75
76
# File 'lib/active_merchant_ideal/ideal.rb', line 74

def self.ideal_certificate_file=(certificate_file)
  self.ideal_certificate = File.read(certificate_file)
end

.private_certificateObject

Returns the global merchant private_certificate.



69
70
71
# File 'lib/active_merchant_ideal/ideal.rb', line 69

def self.private_certificate
  @private_certificate
end

.private_certificate=(certificate_data) ⇒ Object

Instantiates and assings a OpenSSL::X509::Certificate instance with the provided private certificate data.



64
65
66
# File 'lib/active_merchant_ideal/ideal.rb', line 64

def self.private_certificate=(certificate_data)
  @private_certificate = OpenSSL::X509::Certificate.new(certificate_data)
end

.private_certificate_file=(certificate_file) ⇒ Object

Loads the global merchant private_certificate from disk.



58
59
60
# File 'lib/active_merchant_ideal/ideal.rb', line 58

def self.private_certificate_file=(certificate_file)
  self.private_certificate = File.read(certificate_file)
end

.private_keyObject

Returns the global merchant private_certificate.



53
54
55
# File 'lib/active_merchant_ideal/ideal.rb', line 53

def self.private_key
  @private_key
end

.private_key=(pkey_data) ⇒ Object

Instantiates and assings a OpenSSL::PKey::RSA instance with the provided private key data.



48
49
50
# File 'lib/active_merchant_ideal/ideal.rb', line 48

def self.private_key=(pkey_data)
  @private_key = OpenSSL::PKey::RSA.new(pkey_data, passphrase)
end

.private_key_file=(pkey_file) ⇒ Object

Loads the global merchant private_key from disk.



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

def self.private_key_file=(pkey_file)
  self.private_key = File.read(pkey_file)
end

Instance Method Details

#acquirer_url(request_type) ⇒ Object

Returns the url of the acquirer matching the current environment.

When #test? returns true the IdealGateway.test_url is used, otherwise the IdealGateway.live_url is used.



127
128
129
# File 'lib/active_merchant_ideal/ideal.rb', line 127

def acquirer_url(request_type)
  self.class.send("#{test_or_live}#{sort_request(request_type)}_url")
end

#capture(transaction_id) ⇒ Object

Sends a acquirer status request for the specified transaction_id and returns an IdealStatusResponse.

It is your responsibility as the merchant to check if the payment has been made until you receive a response with a finished status like: ‘Success’, ‘Cancelled’, ‘Expired’, everything else equals ‘Open’.

Example

capture_response = gateway.capture(@purchase.transaction_id)
if capture_response.success?
  @purchase.update_attributes!(:paid => true)
  flash[:notice] = "Congratulations, you are now the proud owner of a Dutch windmill!"
end

See the IdealGateway class description for a more elaborate example.



204
205
206
# File 'lib/active_merchant_ideal/ideal.rb', line 204

def capture(transaction_id)
  post_data acquirer_url(:status), build_status_request_body(:transaction_id => transaction_id), IdealStatusResponse
end

#issuersObject

Sends a directory request to the acquirer and returns an IdealDirectoryResponse. Use IdealDirectoryResponse#list to receive the actuall array of available issuers.

gateway.issuers.list # => [{ :id => '1006', :name => 'ABN AMRO Bank' }, …]


136
137
138
# File 'lib/active_merchant_ideal/ideal.rb', line 136

def issuers
  post_data acquirer_url(:directory), build_directory_request_body, IdealDirectoryResponse
end

#setup_purchase(money, options) ⇒ Object

Starts a purchase by sending an acquirer transaction request for the specified money amount in EURO cents.

On success returns an IdealTransactionResponse with the #transaction_id which is needed for the capture step. (See capture for an example.)

The iDEAL specification states that it is not allowed to use another window or frame when redirecting the consumer to the issuer. So the entire merchant’s page has to be replaced by the selected issuer’s page.

Options

Note that all options that have a character limit are also checked for diacritical characters. If it does contain diacritical characters, or exceeds the character limit, an ArgumentError is raised.

Required

  • :issuer_id - The :id of an issuer available at the acquirer to which the transaction should be made.

  • :order_id - The order number. Limited to 12 characters.

  • :description - A description of the transaction. Limited to 32 characters.

  • :return_url - A URL on the merchant’s system to which the consumer is redirected after payment. The acquirer will add the following GET variables:

    • trxid - The :order_id.

    • ec - The :entrance_code if it was specified.

Optional

  • :entrance_code - This code is an abitrary token which can be used to identify the transaction besides the :order_id. Limited to 40 characters.

  • :expiration_period - The period of validity of the payment request measured from the receipt by the issuer. The consumer must approve the payment within this period, otherwise the IdealStatusResponse#status will be set to ‘Expired’. E.g., consider an :expiration_period of ‘P3DT6H10M’:

    • P: relative time designation.

    • 3 days.

    • T: separator.

    • 6 hours.

    • 10 minutes.

Example

transaction_response = gateway.setup_purchase(4321, valid_options)
if transaction_response.success?
  @purchase.update_attributes!(:transaction_id => transaction_response.transaction_id)
  redirect_to transaction_response.service_url
end

See the IdealGateway class description for a more elaborate example.



184
185
186
# File 'lib/active_merchant_ideal/ideal.rb', line 184

def setup_purchase(money, options)
  post_data acquirer_url(:transaction), build_transaction_request_body(money, options), IdealTransactionResponse
end