Class: PscbIntegration::CallbackController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/pscb_integration/callback_controller.rb

Instance Method Summary collapse

Instance Method Details

#payment_statusesObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/pscb_integration/callback_controller.rb', line 5

def payment_statuses
  encrypted_body = request.body.read
  log("PSCB payment_statuses encrypted params '#{encrypted_body.unpack('H*').first}'")

  body, is_demo_env = *decrypt(encrypted_body)
  log("PSCB payment_statuses binary params '#{body.unpack('H*').first}' demo_env=#{is_demo_env}")

  json = JSON.parse(body)
  log("PSCB payment_statuses params #{json.inspect}")

  response = json['payments'].map do |payment|
    confirmed = config.confirm_payment_callback.call(payment, is_demo_env)

    {
      orderId: payment['orderId'],
      action: confirmed ? 'CONFIRM' : 'REJECT'
    }
  end

  log("PSCB payment_statuses response #{response.inspect}")

  render json: { payments: response }
end