Class: Supreme::API
- Inherits:
-
Object
- Object
- Supreme::API
- Defined in:
- lib/supreme/api.rb
Constant Summary collapse
- ENDPOINT =
::URI.parse("https://secure.mollie.nl/xml/ideal")
Instance Attribute Summary collapse
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#partner_id ⇒ Object
Returns the value of attribute partner_id.
Instance Method Summary collapse
-
#banklist ⇒ Object
Requests a list of available banks.
-
#check(options) ⇒ Object
Requests the status information for a payment.
-
#fetch(options) ⇒ Object
Starts a new payment by sending payment information.
-
#initialize(options = {}) ⇒ API
constructor
Creates a new API instance.
-
#test? ⇒ Boolean
Returns true when we’re in test mode and false otherwise.
Constructor Details
#initialize(options = {}) ⇒ API
Creates a new API instance. Normally you would use Supreme.api
to create an API instance. If you have to interact with multiple accounts in one process you can instantiate the API class youself.
Options
-
:mode
– Holds either :test or :live to signal whether to run in test or live mode. The default value is :test. -
:partner_id
– Your Mollie Partner ID, you can find it under ‘Accountgegevens’ in the settings for your account on mollie.nl.
Example
api = Supreme::API.new(:partner_id => '9834234')
api.test? #=> true
api.banklist
24 25 26 27 |
# File 'lib/supreme/api.rb', line 24 def initialize(={}) self.mode = [:mode] || ['mode'] || :test self.partner_id = [:partner_id] || ['partner_id'] end |
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode.
8 9 10 |
# File 'lib/supreme/api.rb', line 8 def mode @mode end |
#partner_id ⇒ Object
Returns the value of attribute partner_id.
8 9 10 |
# File 'lib/supreme/api.rb', line 8 def partner_id @partner_id end |
Instance Method Details
#banklist ⇒ Object
40 41 42 43 44 |
# File 'lib/supreme/api.rb', line 40 def banklist response = get('banklist') log('Banklist response', response.body) Supreme::Response.for(response.body, Supreme::Banklist) end |
#check(options) ⇒ Object
Requests the status information for a payment. It returns a Supreme::Status response object.
Returns a Supreme::Error when the call fails.
Options
-
:transaction_id
– The transaction ID you received earlier when setting up the transaction.
Example
status = Supreme.api.check(:transaction_id => '482d599bbcc7795727650330ad65fe9b')
if status.paid?
@purchase.paid!
end
See the Supreme::Status class for more information.
113 114 115 116 117 118 119 120 121 |
# File 'lib/supreme/api.rb', line 113 def check() = .dup [:partner_id] ||= partner_id response = get('check', Supreme.translate_hash_keys({ :partner_id => :partnerid, }, )) log('Status response', response.body) Supreme::Response.for(response.body, Supreme::Status) end |
#fetch(options) ⇒ Object
Starts a new payment by sending payment information. It also configures how the iDEAL provider handles payment status information. It returns a Supreme::Transaction response object.
Returns a Supreme::Error when the call fails.
Options
Note that the :description
option has a character limit of 29 characters. Anything after the 29 characters will be silently removed by the API. Note that this description might be handled by ancient bank systems and anything but ASCII characters might be mangled or worse.
Required
-
:bank_id
– The bank selected by the customer from thebanklist
. -
:amount
– The amount you want to charge in cents (EURO) (ie. €12,99 is 1299) -
:description
– Describe what the payment is for (max 29 characters) (ie. ‘Fluffy Bunny (sku 1234)’ ) -
:report_url
– You will receive a GET to this URL with the transaction_id appended in the query (ie. example.com/payments?transaction_id=23ad33) -
:return_url
– The customer is redirected to this URL after the payment is complete. The transaction_id is appended as explained for:report_url
Optional
-
:partner_id
– Your Mollie Partner ID, you can find it under ‘Accountgegevens’ in the settings for your account on mollie.nl. Note that the Partner ID is only optional if you’ve set it either on the API instance or usingSupreme.partner_id
. -
:profile_key
– When your account receives payment from different websites or companies you can set up company profiles. See the Mollie documentation for more information: www.mollie.nl/support/documentatie/betaaldiensten/ideal/.
Example
transaction = Supreme.api.fetch({
:bank_id => '0031',
:amount => 1299,
:description => '20 credits for your account',
:report_url => 'http://example.com/payments/ad74hj23',
:return_url => 'http://example.com/payments/ad74hj23/thanks'
})
@purchase.update_attributes!(:transaction_id => transaction.transaction_id)
See the Supreme::Transaction class for more information.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/supreme/api.rb', line 84 def fetch() = .dup [:partner_id] ||= partner_id response = get('fetch', Supreme.translate_hash_keys({ :partner_id => :partnerid, :return_url => :returnurl, :report_url => :reporturl }, )) log('Fetch response', response.body) Supreme::Response.for(response.body, Supreme::Transaction) end |
#test? ⇒ Boolean
Returns true when we’re in test mode and false otherwise
30 31 32 |
# File 'lib/supreme/api.rb', line 30 def test? self.mode.to_sym == :test end |