Class: Buckaroo::Ideal::Request

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/buckaroo-ideal/request.rb

Overview

A class to help with the generation of payment forms for the Buckaroo Payment Gateway.

A form has a number of required parameters that are retreived from the Buckaroo::Idea::Order:

  • currency – required; but set by default to ‘EUR’

  • invoice_number – required; not set by default

  • amount – required; this is the whole amount, it is automatically converted to cents

  • bank – optional

  • description – optional

It is possible to set the following options for this form:

  • language – required, defaults to ‘NL’

  • return_method – required, defaults to Buckaroo::Ideal::Config.return_method

  • style – required, defaults to Buckaroo::Ideal::Config.style

  • autoclose_popup – required, defaults to Buckaroo::Ideal::Config.autoclose_popup

  • reference – optional

  • success_url – optional according to documentation

  • reject_url – optional

  • error_url – optional

The test_mode, gateway_url and merchant_key are read from Buckaroo::Ideal::Config.

To access the information required to create a form, instantiate a new Buckaroo::Ideal::Request with an Buckaroo::Ideal::Order instance:

order   = Buckaroo::Ideal::Order.new(amount: 100, invoice_number: 'EETNU-123')
request = Buckaroo::Ideal::Request.new(order)

You can then use the information to create a form. An example in Rails:

<%= form_tag request.gateway_url do %>
  <% request.parameters.each do |name, value| %>
    <%= hidden_field_tag name, value %>
  <% end %>
  <%= submit_tag 'Proceed to payment' %>
<% end %>

Constant Summary

Constants included from Util

Util::STRIP_ACCENTS_RE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#compact, #from_cents, #from_numeric_boolean, #to_cents, #to_normalized_string, #to_numeric_boolean

Constructor Details

#initialize(order, settings = {}) ⇒ Buckaroo::Ideal::Request

Initialize a new Buckaroo::Ideal::Request instance for the given order.

Parameters:



121
122
123
124
125
126
127
# File 'lib/buckaroo-ideal/request.rb', line 121

def initialize(order, settings = {})
  @order = order
  settings = self.class.defaults.merge(settings)
  settings.each do |key, value|
    set key, value
  end
end

Instance Attribute Details

#autoclose_popupBoolean

Defaults to the configured Buckaroo::Ideal::Config.autoclose_popup, but can be overwritten in the Order instance.

Returns:

  • (Boolean)

    Autoclose the popup after a transaction



113
114
115
# File 'lib/buckaroo-ideal/request.rb', line 113

def autoclose_popup
  @autoclose_popup
end

#error_urlString

Defaults to the configured Buckaroo::Ideal::Config.error_url, but can be overwritten in the Order instance.

Returns:

  • (String)

    The URL the user will be redirected to after an error occured during the transaction



94
95
96
# File 'lib/buckaroo-ideal/request.rb', line 94

def error_url
  @error_url
end

#languageString

Returns The language in wich Buckaroo’s user interface is presented.

Returns:

  • (String)

    The language in wich Buckaroo’s user interface is presented.



73
74
75
# File 'lib/buckaroo-ideal/request.rb', line 73

def language
  @language
end

#orderBuckaroo::Ideal::Order (readonly)

Returns The order for which the payment request is being made.

Returns:



69
70
71
# File 'lib/buckaroo-ideal/request.rb', line 69

def order
  @order
end

#reject_urlString

Defaults to the configured Buckaroo::Ideal::Config.reject_url, but can be overwritten in the Order instance.

Returns:

  • (String)

    The URL the user will be redirected to after a failed transaction



87
88
89
# File 'lib/buckaroo-ideal/request.rb', line 87

def reject_url
  @reject_url
end

#return_methodString

Defaults to the configured Buckaroo::Ideal::Config.return_method, but can be overwritten in the Order instance.

Returns:

  • (String)

    The HTTP method that will be used to return the user back to the application after a transaction



101
102
103
# File 'lib/buckaroo-ideal/request.rb', line 101

def return_method
  @return_method
end

#styleString

Defaults to the configured Buckaroo::Ideal::Config.style, but can be overwritten in the Order instance.

Returns:

  • (String)

    The style that is being used



107
108
109
# File 'lib/buckaroo-ideal/request.rb', line 107

def style
  @style
end

#success_urlString

Defaults to the configured Buckaroo::Ideal::Config.success_url, but can be overwritten in the Order instance.

Returns:

  • (String)

    The URL the user will be redirected to after a successful transaction



80
81
82
# File 'lib/buckaroo-ideal/request.rb', line 80

def success_url
  @success_url
end

Class Method Details

.defaultsObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/buckaroo-ideal/request.rb', line 46

def self.defaults
  {
    :language        => 'NL',
    :success_url     => Config.success_url,
    :reject_url      => Config.reject_url,
    :error_url       => Config.error_url,
    :return_method   => Config.return_method,
    :style           => Config.style,
    :autoclose_popup => Config.autoclose_popup
  }
end

Instance Method Details

#gateway_urlString

Returns The configured gateway_url in Buckaroo::Ideal::Config.

Returns:

  • (String)

    The configured gateway_url in Buckaroo::Ideal::Config



59
# File 'lib/buckaroo-ideal/request.rb', line 59

delegate :gateway_url,  :to => Config

#merchant_keyString

Returns The configured merchant_key in Buckaroo::Ideal::Config.

Returns:

  • (String)

    The configured merchant_key in Buckaroo::Ideal::Config



65
# File 'lib/buckaroo-ideal/request.rb', line 65

delegate :merchant_key, :to => Config

#parametersObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/buckaroo-ideal/request.rb', line 129

def parameters
  {
    'BPE_Currency'        => order.currency,
    'BPE_Invoice'         => order.invoice_number,
    'BPE_Amount'          => to_cents(order.amount),
    'BPE_Merchant'        => merchant_key,
    'BPE_Language'        => language,
    'BPE_Mode'            => to_numeric_boolean(test_mode),
    'BPE_Return_Method'   => return_method,
    'BPE_Style'           => style,
    'BPE_Autoclose_Popup' => to_numeric_boolean(autoclose_popup),
    'BPE_Signature2'      => signature
  }.merge compact({
    'BPE_Issuer'          => order.bank,
    'BPE_Description'     => order.description,
    'BPE_Reference'       => order.reference,
    'BPE_Return_Success'  => success_url,
    'BPE_Return_Reject'   => reject_url,
    'BPE_Return_Error'    => error_url
  })
end

#test_modeBoolean

Returns The configured test_mode in Buckaroo::Ideal::Config.

Returns:

  • (Boolean)

    The configured test_mode in Buckaroo::Ideal::Config



62
# File 'lib/buckaroo-ideal/request.rb', line 62

delegate :test_mode,    :to => Config