Class: SolidusPaybright::CallbackValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/solidus_paybright/callback_validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ CallbackValidator

Returns a new instance of CallbackValidator.

Parameters:

  • params (Hash)

    The Paybright callback params



4
5
6
# File 'lib/solidus_paybright/callback_validator.rb', line 4

def initialize(params)
  @params = params
end

Instance Method Details

#callArray

Returns The validation result and the error message.

Returns:

  • (Array)

    The validation result and the error message



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/solidus_paybright/callback_validator.rb', line 9

def call
  payment = Spree::Payment.find_by(id: @params[:x_reference])

  unless payment
    return [false, "Payment #{@params[:x_reference]} not found"]
  end

  if payment.completed?
    return [false, "Payment #{payment.id} is already in completed state"]
  end

  if payment.order.complete?
    return [false, "Order is already in complete state"]
  end

  if !signing_helper(payment).valid_params?(@params.to_hash)
    return [false, "Invalid parameters signature"]
  end

  if @params[:x_result].casecmp("completed") != 0
    return [false, "The contract was not completed (#{@params[:x_result]})"]
  end

  [true, ""]
end