Class: Ideal::Gateway
- Inherits:
-
Object
- Object
- Ideal::Gateway
- Defined in:
- lib/ideal/gateway.rb
Overview
Response classes
-
Response
-
TransactionResponse
-
StatusResponse
-
DirectoryResponse
See the Response 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'
Class Attribute Summary collapse
-
.acquirer ⇒ Object
Returns the current acquirer used.
-
.environment ⇒ Object
Holds the environment in which the run (default is test).
-
.live_url ⇒ Object
Holds the test and production urls for your iDeal acquirer.
-
.merchant_id ⇒ Object
Holds the global iDEAL merchant id.
-
.passphrase ⇒ Object
Holds the passphrase that should be used for the merchant private_key.
-
.test_url ⇒ Object
Holds the test and production urls for your iDeal acquirer.
Instance Attribute Summary collapse
-
#sub_id ⇒ Object
readonly
Returns the merchant ‘subID’ being used for this Gateway instance.
Class Method Summary collapse
- .acquirers ⇒ Object
-
.ideal_certificate ⇒ Object
Returns the global merchant ideal_certificate.
-
.ideal_certificate=(certificate_data) ⇒ Object
Instantiates and assings a OpenSSL::X509::Certificate instance with the provided iDEAL certificate data.
-
.ideal_certificate_file=(certificate_file) ⇒ Object
Loads the global merchant ideal_certificate from disk.
-
.private_certificate ⇒ Object
Returns the global merchant private_certificate.
-
.private_certificate=(certificate_data) ⇒ Object
Instantiates and assings a OpenSSL::X509::Certificate instance with the provided private certificate data.
-
.private_certificate_file=(certificate_file) ⇒ Object
Loads the global merchant private_certificate from disk.
-
.private_key ⇒ Object
Returns the global merchant private_certificate.
-
.private_key=(pkey_data) ⇒ Object
Instantiates and assings a OpenSSL::PKey::RSA instance with the provided private key data.
-
.private_key_file=(pkey_file) ⇒ Object
Loads the global merchant private_key from disk.
-
.test? ⇒ Boolean
Returns whether we’re in test mode or not.
Instance Method Summary collapse
-
#capture(transaction_id) ⇒ Object
Sends a acquirer status request for the specified
transaction_id
and returns an StatusResponse. -
#initialize(options = {}) ⇒ Gateway
constructor
Initializes a new Gateway instance.
-
#issuers ⇒ Object
Sends a directory request to the acquirer and returns an DirectoryResponse.
-
#request_url ⇒ Object
Returns the endpoint for the request.
-
#setup_purchase(money, options) ⇒ Object
Starts a purchase by sending an acquirer transaction request for the specified
money
amount in EURO cents.
Constructor Details
#initialize(options = {}) ⇒ Gateway
Initializes a new Gateway instance.
You can optionally specify :sub_id
. Defaults to 0.
124 125 126 |
# File 'lib/ideal/gateway.rb', line 124 def initialize( = {}) @sub_id = [:sub_id] || 0 end |
Class Attribute Details
.acquirer ⇒ Object
Returns the current acquirer used
30 31 32 |
# File 'lib/ideal/gateway.rb', line 30 def acquirer @acquirer end |
.environment ⇒ Object
Holds the environment in which the run (default is test)
33 34 35 |
# File 'lib/ideal/gateway.rb', line 33 def environment @environment end |
.live_url ⇒ Object
Holds the test and production urls for your iDeal acquirer.
43 44 45 |
# File 'lib/ideal/gateway.rb', line 43 def live_url @live_url end |
.merchant_id ⇒ Object
Holds the global iDEAL merchant id. Make sure to use a string with leading zeroes if needed.
37 38 39 |
# File 'lib/ideal/gateway.rb', line 37 def merchant_id @merchant_id end |
.passphrase ⇒ Object
Holds the passphrase that should be used for the merchant private_key.
40 41 42 |
# File 'lib/ideal/gateway.rb', line 40 def passphrase @passphrase end |
.test_url ⇒ Object
Holds the test and production urls for your iDeal acquirer.
43 44 45 |
# File 'lib/ideal/gateway.rb', line 43 def test_url @test_url end |
Instance Attribute Details
#sub_id ⇒ Object (readonly)
Returns the merchant ‘subID’ being used for this Gateway instance. Defaults to 0.
119 120 121 |
# File 'lib/ideal/gateway.rb', line 119 def sub_id @sub_id end |
Class Method Details
.acquirers ⇒ Object
24 25 26 |
# File 'lib/ideal/gateway.rb', line 24 def self.acquirers Ideal::ACQUIRERS end |
.ideal_certificate ⇒ Object
Returns the global merchant ideal_certificate.
93 94 95 |
# File 'lib/ideal/gateway.rb', line 93 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.
88 89 90 |
# File 'lib/ideal/gateway.rb', line 88 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.
82 83 84 |
# File 'lib/ideal/gateway.rb', line 82 def self.ideal_certificate_file=(certificate_file) self.ideal_certificate = File.read(certificate_file) end |
.private_certificate ⇒ Object
Returns the global merchant private_certificate.
77 78 79 |
# File 'lib/ideal/gateway.rb', line 77 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.
72 73 74 |
# File 'lib/ideal/gateway.rb', line 72 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.
66 67 68 |
# File 'lib/ideal/gateway.rb', line 66 def self.private_certificate_file=(certificate_file) self.private_certificate = File.read(certificate_file) end |
.private_key ⇒ Object
Returns the global merchant private_certificate.
61 62 63 |
# File 'lib/ideal/gateway.rb', line 61 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.
56 57 58 |
# File 'lib/ideal/gateway.rb', line 56 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.
50 51 52 |
# File 'lib/ideal/gateway.rb', line 50 def self.private_key_file=(pkey_file) self.private_key = File.read(pkey_file) end |
.test? ⇒ Boolean
Returns whether we’re in test mode or not.
98 99 100 |
# File 'lib/ideal/gateway.rb', line 98 def self.test? environment.to_sym == :test end |
Instance Method Details
#capture(transaction_id) ⇒ Object
Sends a acquirer status request for the specified transaction_id
and returns an StatusResponse.
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 Gateway class description for a more elaborate example.
208 209 210 |
# File 'lib/ideal/gateway.rb', line 208 def capture(transaction_id) post_data request_url, build_status_request_body(:transaction_id => transaction_id), StatusResponse end |
#issuers ⇒ Object
Sends a directory request to the acquirer and returns an DirectoryResponse. Use DirectoryResponse#list to receive the actuall array of available issuers.
gateway.issuers.list # => [{ :id => '1006', :name => 'ABN AMRO Bank' }, …]
140 141 142 |
# File 'lib/ideal/gateway.rb', line 140 def issuers post_data request_url, build_directory_request_body, DirectoryResponse end |
#request_url ⇒ Object
Returns the endpoint for the request.
Automatically uses test or live URLs based on the configuration.
131 132 133 |
# File 'lib/ideal/gateway.rb', line 131 def request_url self.class.send("#{self.class.environment}_url") 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 TransactionResponse 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 StatusResponse#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, )
if transaction_response.success?
@purchase.update_attributes!(:transaction_id => transaction_response.transaction_id)
redirect_to transaction_response.service_url
end
See the Gateway class description for a more elaborate example.
188 189 190 |
# File 'lib/ideal/gateway.rb', line 188 def setup_purchase(money, ) post_data request_url, build_transaction_request_body(money, ), TransactionResponse end |