Class: OffsitePayments::Integrations::MollieIdeal::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/mollie_ideal.rb

Instance Attribute Summary collapse

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

#add_field, #add_fields, #add_raw_html_field, #billing_address, #form_fields, inherited, mapping, #raw_html_fields, #shipping_address, #test?

Constructor Details

#initialize(order, account, options = {}) ⇒ Helper

Returns a new instance of Helper.

Raises:

  • (ArgumentError)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 72

def initialize(order, , options = {})
  @token = 
  @redirect_parameters = {
    :amount => options[:amount],
    :description => options[:description],
    :issuer => options[:redirect_param],
    :redirectUrl => options[:return_url],
    :method => 'ideal',
    :metadata => { :order => order }
  }

  @redirect_parameters[:webhookUrl] = options[:notify_url] if options[:notify_url]

  super

  raise ArgumentError, "The redirect_param option needs to be set to the bank_id the customer selected." if options[:redirect_param].blank?
  raise ArgumentError, "The return_url option needs to be set." if options[:return_url].blank?
  raise ArgumentError, "The description option needs to be set." if options[:description].blank?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OffsitePayments::Helper

Instance Attribute Details

#redirect_parametersObject (readonly)

Returns the value of attribute redirect_parameters.



70
71
72
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 70

def redirect_parameters
  @redirect_parameters
end

#tokenObject (readonly)

Returns the value of attribute token.



70
71
72
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 70

def token
  @token
end

#transaction_idObject (readonly)

Returns the value of attribute transaction_id.



70
71
72
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 70

def transaction_id
  @transaction_id
end

Instance Method Details

#credential_based_urlObject



92
93
94
95
96
97
98
99
100
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 92

def credential_based_url
  response = request_redirect
  @transaction_id = response['id']

  uri = URI.parse(response['links']['paymentUrl'])
  set_form_fields_for_redirect(uri)
  uri.query = ''
  uri.to_s.sub(/\?\z/, '')
end

#form_methodObject



102
103
104
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 102

def form_method
  "GET"
end

#request_redirectObject



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 116

def request_redirect
  MollieIdeal.create_payment(token, redirect_parameters)
rescue ActiveUtils::ResponseError => e
  case e.response.code
  when '401', '403', '422'
    error = JSON.parse(e.response.body)['error']['message']
    raise ActionViewHelperError, error
  when '503'
    raise ActionViewHelperError, 'Service temporarily unavailable. Please try again.'
  else
    raise
  end
end

#set_form_fields_for_redirect(uri) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 106

def set_form_fields_for_redirect(uri)
  CGI.parse(uri.query).each do |key, value|
    if value.is_a?(Array) && value.length == 1
      add_field(key, value.first)
    else
      add_field(key, value)
    end
  end
end