Class: SolidusPaybright::CallbackValidator
- Inherits:
-
Object
- Object
- SolidusPaybright::CallbackValidator
- Defined in:
- lib/solidus_paybright/callback_validator.rb
Instance Method Summary collapse
-
#call ⇒ Array
The validation result and the error message.
-
#initialize(params) ⇒ CallbackValidator
constructor
A new instance of CallbackValidator.
Constructor Details
#initialize(params) ⇒ CallbackValidator
Returns a new instance of CallbackValidator.
4 5 6 |
# File 'lib/solidus_paybright/callback_validator.rb', line 4 def initialize(params) @params = params end |
Instance Method Details
#call ⇒ Array
Returns 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 |