class Internal::Paya::TransactionsController < Internal::Paya::Controller
  def create
    response = transaction_service

    if response['errors']
      render_error :unprocessable_entity, errors: response['errors']
    else
      render_success :ok, json: response['transaction']
    end
  end

  private
    def transaction_service
      Paya::TransactionService.call(
        current_school,
        :create,
        vault_id: params[:vault_id],
        payment_method: params[:payment_method],
        contact_id: params[:contact_id],
        subtotal: params[:subtotal],
        surcharge: params[:surcharge],
        product_transaction_id: params[:product_transaction_id],
        family_initiated: current_user.role == :family
      )
    end
end
