Esempio n. 1
0
func TransactionDepositInitiation(w http.ResponseWriter, r *http.Request) {
	token, err := getTokenFromHeader(w, r)
	if err != nil {
		Response("", err, w, r)
		return
	}

	accountDetails := r.FormValue("AccountDetails")
	amount := r.FormValue("Amount")
	lat := r.FormValue("Lat")
	lon := r.FormValue("Lon")
	desc := r.FormValue("Desc")

	response, err := transactions.ProcessPAIN([]string{token, "pain", "1000", accountDetails, amount, lat, lon, desc})
	Response(response, err, w, r)
	return
}
Esempio n. 2
0
func TransactionList(w http.ResponseWriter, r *http.Request) {
	token, err := getTokenFromHeader(w, r)
	if err != nil {
		Response("", err, w, r)
		return
	}
	// Get account number from header
	accountNumber := r.Header.Get("X-Auth-AccountNumber")
	if accountNumber == "" {
		Response("", errors.New("httpApiHandlers.TransactionList: Could not retrieve accountNumber from headers"), w, r)
		return
	}

	vars := mux.Vars(r)
	perPage := vars["perPage"]
	page := vars["page"]
	timestamp := vars["timestamp"]

	response, err := transactions.ProcessPAIN([]string{token, "pain", "1001", accountNumber, page, perPage, timestamp})
	Response(response, err, w, r)
	return
}
Esempio n. 3
0
File: server.go Progetto: BVNK/bank
func processCommand(text string) (result interface{}, err error) {
	// Commands are received split by tilde (~)
	// command~DATA
	cleanText := strings.Replace(text, "\n", "", -1)
	fmt.Printf("### %s ####\n", cleanText)
	command := strings.Split(cleanText, "~")

	// Check if we received a command
	if len(command) == 0 {
		fmt.Println("No command received")
		return
	}

	// Remove null termination from data
	command[len(command)-1] = string(bytes.Trim([]byte(command[len(command)-1]), "\x00"))

	// Check application auth. This is always the first value, if no token a 0 is sent
	isCreateAccount := (command[0] == "0" && command[1] == "acmt" && command[2] == "1")
	isLogIn := (command[0] == "0" && command[1] == "appauth" && command[2] == "2")
	isCreateUserPassword := (command[0] == "0" && command[1] == "appauth" && command[2] == "3")

	if !isCreateAccount || !isLogIn || !isCreateUserPassword {
		err := appauth.CheckToken(command[0])
		if err != nil {
			return "", errors.New("server.processCommand: " + err.Error())
		}
	}

	switch command[1] {
	case "appauth":
		// Check "help"
		if command[2] == "help" {
			return "Format of appauth: appauth~userName~password", nil
		}
		result, err = appauth.ProcessAppAuth(command)
		if err != nil {
			return "", errors.New("server.processCommand: " + err.Error())
		}
		break
	case "pain":
		// Check "help"
		if command[2] == "help" {
			return "Format of PAIN transaction:\npain\npainType~senderAccountNumber@SenderBankNumber\nreceiverAccountNumber@ReceiverBankNumber\ntransactionAmount\n\nBank numbers may be left void if bank is local", nil
		}
		result, err = transactions.ProcessPAIN(command)
		if err != nil {
			return "", errors.New("server.processCommand: " + err.Error())
		}
	case "camt":
	case "acmt":
		// Check "help"
		if command[2] == "help" {
			return "", nil // @TODO Help section
		}
		result, err = accounts.ProcessAccount(command)
	case "remt":
	case "reda":
	case "pacs":
	case "auth":
		break
	default:
		return "No valid command received", nil
	}

	return
}