Class: OffsitePayments::Integrations::MollieMistercash::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/mollie_mistercash.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)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/offsite_payments/integrations/mollie_mistercash.rb', line 35

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

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

  super

  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.



33
34
35
# File 'lib/offsite_payments/integrations/mollie_mistercash.rb', line 33

def redirect_parameters
  @redirect_parameters
end

#tokenObject (readonly)

Returns the value of attribute token.



33
34
35
# File 'lib/offsite_payments/integrations/mollie_mistercash.rb', line 33

def token
  @token
end

#transaction_idObject (readonly)

Returns the value of attribute transaction_id.



33
34
35
# File 'lib/offsite_payments/integrations/mollie_mistercash.rb', line 33

def transaction_id
  @transaction_id
end

Instance Method Details

#credential_based_urlObject



53
54
55
56
57
# File 'lib/offsite_payments/integrations/mollie_mistercash.rb', line 53

def credential_based_url
  response = request_redirect
  uri = URI.parse(response['links']['paymentUrl'])
  uri.to_s
end

#form_methodObject



59
60
61
# File 'lib/offsite_payments/integrations/mollie_mistercash.rb', line 59

def form_method
  "GET"
end

#request_redirectObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/offsite_payments/integrations/mollie_mistercash.rb', line 63

def request_redirect
  MollieMistercash.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