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

	response, err := accounts.ProcessAccount([]string{token, "acmt", "1001"})
	Response(response, err, w, r)
	return
}
Exemplo n.º 2
0
func AccountRetrieve(w http.ResponseWriter, r *http.Request) {
	// Set these in the header as they are sensitive
	ID := r.Header.Get("X-IDNumber")
	givenName := r.Header.Get("X-GivenName")
	familyName := r.Header.Get("X-FamilyName")
	email := r.Header.Get("X-EmailAddress")

	response, err := accounts.ProcessAccount([]string{"", "acmt", "1006", ID, givenName, familyName, email})
	Response(response, err, w, r)
	return
}
Exemplo n.º 3
0
// Merchat account search
func MerchantAccountSearch(w http.ResponseWriter, r *http.Request) {
	token, err := getTokenFromHeader(w, r)
	if err != nil {
		Response("", err, w, r)
		return
	}

	searchTerm := r.FormValue("Search")

	response, err := accounts.ProcessAccount([]string{token, "acmt", "1104", searchTerm})
	Response(response, err, w, r)
	return
}
Exemplo n.º 4
0
// Merchant account update
func MerchantAccountUpdate(w http.ResponseWriter, r *http.Request) {
	token, err := getTokenFromHeader(w, r)
	if err != nil {
		Response("", err, w, r)
		return
	}

	merchantID := r.FormValue("MerchantID")
	merchantName := r.FormValue("MerchantName")
	merchantDescription := r.FormValue("MerchantDescription")
	merchantContactGivenName := r.FormValue("MerchantContactGivenName")
	merchantContactFamilyName := r.FormValue("MerchantContactFamilyName")
	merchantAddressLine1 := r.FormValue("MerchantAddressLine1")
	merchantAddressLine2 := r.FormValue("MerchantAddressLine2")
	merchantAddressLine3 := r.FormValue("MerchantAddressLine3")
	merchantCountry := r.FormValue("MerchantCountry")
	merchantPostalCode := r.FormValue("MerchantPostalCode")
	merchantBusinessSector := r.FormValue("MerchantBusinessSector")
	merchantWebsite := r.FormValue("MerchantWebsite")
	merchantContactPhone := r.FormValue("MerchantContactPhone")
	merchantContactFax := r.FormValue("MerchantContactFax")
	merchantContactEmail := r.FormValue("MerchantContactEmail")
	_ = r.FormValue("MerchantLogo")

	req := []string{
		token,
		"acmt",
		"1101",
		merchantName,
		merchantDescription,
		merchantContactGivenName,
		merchantContactFamilyName,
		merchantAddressLine1,
		merchantAddressLine2,
		merchantAddressLine3,
		merchantCountry,
		merchantPostalCode,
		merchantBusinessSector,
		merchantWebsite,
		merchantContactPhone,
		merchantContactFax,
		merchantContactEmail,
		//merchantLogo,
		"", // @FIXME We leave logo out for now, need to parse pictures nicely
		merchantID,
	}

	response, err := accounts.ProcessAccount(req)
	Response(response, err, w, r)
	return
}
Exemplo n.º 5
0
// Merchat account view
func MerchantAccountView(w http.ResponseWriter, r *http.Request) {
	token, err := getTokenFromHeader(w, r)
	if err != nil {
		Response("", err, w, r)
		return
	}

	vars := mux.Vars(r)
	merchantID := vars["merchantID"]

	response, err := accounts.ProcessAccount([]string{token, "acmt", "1102", merchantID})
	Response(response, err, w, r)
	return
}
Exemplo n.º 6
0
// Merchant accounts
// Merchant account create
func MerchantAccountCreate(w http.ResponseWriter, r *http.Request) {
	token, err := getTokenFromHeader(w, r)
	if err != nil {
		Response("", err, w, r)
		return
	}

	merchantName := r.FormValue("MerchantName")
	merchantDescription := r.FormValue("MerchantDescription")
	merchantContactGivenName := r.FormValue("MerchantContactGivenName")
	merchantContactFamilyName := r.FormValue("MerchantContactFamilyName")
	merchantAddressLine1 := r.FormValue("MerchantAddressLine1")
	merchantAddressLine2 := r.FormValue("MerchantAddressLine2")
	merchantAddressLine3 := r.FormValue("MerchantAddressLine3")
	merchantCountry := r.FormValue("MerchantCountry")
	merchantPostalCode := r.FormValue("MerchantPostalCode")
	merchantBusinessSector := r.FormValue("MerchantBusinessSector")
	merchantWebsite := r.FormValue("MerchantWebsite")
	merchantContactPhone := r.FormValue("MerchantContactPhone")
	merchantContactFax := r.FormValue("MerchantContactFax")
	merchantContactEmail := r.FormValue("MerchantContactEmail")
	merchantLogo := r.FormValue("MerchantLogo")
	merchantAccountType := r.FormValue("AccountType")

	req := []string{
		token,
		"acmt",
		"1100",
		merchantName,
		merchantDescription,
		merchantContactGivenName,
		merchantContactFamilyName,
		merchantAddressLine1,
		merchantAddressLine2,
		merchantAddressLine3,
		merchantCountry,
		merchantPostalCode,
		merchantBusinessSector,
		merchantWebsite,
		merchantContactPhone,
		merchantContactFax,
		merchantContactEmail,
		merchantLogo,
		merchantAccountType,
	}

	response, err := accounts.ProcessAccount(req)
	Response(response, err, w, r)
	return
}
Exemplo n.º 7
0
func AccountTokenDelete(w http.ResponseWriter, r *http.Request) {
	token, err := getTokenFromHeader(w, r)
	if err != nil {
		Response("", err, w, r)
		return
	}

	pushToken := r.FormValue("PushToken")
	platform := r.FormValue("Platform")

	response, err := accounts.ProcessAccount([]string{token, "acmt", "1004", pushToken, platform})
	Response(response, err, w, r)
	return
}
Exemplo n.º 8
0
func AccountGet(w http.ResponseWriter, r *http.Request) {
	token, err := getTokenFromHeader(w, r)
	if err != nil {
		Response("", err, w, r)
		return
	}

	vars := mux.Vars(r)
	accountId := vars["accountId"]

	response, err := accounts.ProcessAccount([]string{token, "acmt", "1002", accountId})
	Response(response, err, w, r)
	return
}
Exemplo n.º 9
0
func AccountCreate(w http.ResponseWriter, r *http.Request) {
	// Get values from POST
	accountHolderGivenName := r.FormValue("AccountHolderGivenName")
	accountHolderFamilyName := r.FormValue("AccountHolderFamilyName")
	accountHolderDateOfBirth := r.FormValue("AccountHolderDateOfBirth")
	accountHolderIdentificationNumber := r.FormValue("AccountHolderIdentificationNumber")
	accountHolderContactNumber1 := r.FormValue("AccountHolderContactNumber1")
	accountHolderContactNumber2 := r.FormValue("AccountHolderContactNumber2")
	accountHolderEmailAddress := r.FormValue("AccountHolderEmailAddress")
	accountHolderAddressLine1 := r.FormValue("AccountHolderAddressLine1")
	accountHolderAddressLine2 := r.FormValue("AccountHolderAddressLine2")
	accountHolderAddressLine3 := r.FormValue("AccountHolderAddressLine3")
	accountHolderPostalCode := r.FormValue("AccountHolderPostalCode")
	accountType := r.FormValue("AccountType")

	req := []string{
		"0",
		"acmt",
		"1",
		accountHolderGivenName,
		accountHolderFamilyName,
		accountHolderDateOfBirth,
		accountHolderIdentificationNumber,
		accountHolderContactNumber1,
		accountHolderContactNumber2,
		accountHolderEmailAddress,
		accountHolderAddressLine1,
		accountHolderAddressLine2,
		accountHolderAddressLine3,
		accountHolderPostalCode,
		accountType,
	}

	response, err := accounts.ProcessAccount(req)
	Response(response, err, w, r)
	return
}
Exemplo n.º 10
0
Arquivo: server.go Projeto: 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
}