Class: Vpago::PaywayReturnOptionsBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/services/vpago/payway_return_options_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params:) ⇒ PaywayReturnOptionsBuilder

Returns a new instance of PaywayReturnOptionsBuilder.



6
7
8
# File 'app/services/vpago/payway_return_options_builder.rb', line 6

def initialize(params:)
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'app/services/vpago/payway_return_options_builder.rb', line 4

def params
  @params
end

Instance Method Details

#html_paramsObject



30
31
32
33
# File 'app/services/vpago/payway_return_options_builder.rb', line 30

def html_params
  payload = JSON.parse(params[:response])
  { tran_id: payload['tran_id'] }
end

#json_paramsObject



26
27
28
# File 'app/services/vpago/payway_return_options_builder.rb', line 26

def json_params
  { tran_id: params[:tran_id] }
end

#merchant_profile_content_typeObject



35
36
37
# File 'app/services/vpago/payway_return_options_builder.rb', line 35

def merchant_profile_content_type
  ENV['PAYWAY_MERCHANT_PROFILE_CONTENT_TYPE'].presence || 'html'
end

#optionsObject



10
11
12
13
14
15
16
# File 'app/services/vpago/payway_return_options_builder.rb', line 10

def options
  if merchant_profile_content_type == 'html'
    html_params
  elsif merchant_profile_content_type == 'json'
    json_params
  end
end

#paymentObject



18
19
20
# File 'app/services/vpago/payway_return_options_builder.rb', line 18

def payment
  @payment ||= Spree::Payment.find_by(number: tran_id)
end

#tran_idObject



22
23
24
# File 'app/services/vpago/payway_return_options_builder.rb', line 22

def tran_id
  @tran_id ||= options[:tran_id]
end