function buyTokens(address buyer) public payable {
    
    
    require(openingTime <= block.timestamp);
    require(block.timestamp < closingTime);
    
    
    require(msg.value >= minSpend);
    
    
    
    require(msg.value <= maxSpend);
    
    
    require(tokenSaleTokenBalance() > 0);
    
    
    require(tokenSaleIsPaused == false);
    
    
    uint256 weiAmount = msg.value;
    preValidatePurchase(buyer, weiAmount);

    
    uint256 tokens = getTokenAmount(weiAmount);
    
    
    
    require(tokens <= tokenSaleTokenBalance());

    
    weiRaised = weiRaised.add(weiAmount);

    processPurchase(buyer, tokens);
    emit TokenPurchase(
      msg.sender,
      buyer,
      weiAmount,
      tokens
    );

    updatePurchasingState(buyer, weiAmount);

    forwardFunds();
    postValidatePurchase(buyer, weiAmount);
  }