Exemple #1
0
func merchantAccountCreate(data []string) (result interface{}, err error) {
	tokenUser, err := appauth.GetUserFromToken(data[0])
	if err != nil {
		return "", errors.New("accounts.merchantAccountCreate: " + err.Error())
	}
	data[len(data)-1] = strings.Replace(data[len(data)-1], "\n", "", -1)

	accountHolder, err := getAccountUser(tokenUser)
	if err != nil {
		return "", errors.New("accounts.merchantAccountCreate: Could not retrieve account user from token user.")
	}
	// Create account
	merchantObject, accountDetails, err := setMerchantDetails(data, accountHolder.IdentificationNumber, "create")
	if err != nil {
		return "", errors.New("accounts.merchantAccountCreate: " + err.Error())
	}

	err = createMerchantAccount(&merchantObject, &accountDetails, &accountHolder)
	if err != nil {
		return "", errors.New("accounts.merchantAccountCreate: " + err.Error())
	}

	result = merchantObject.ID
	return
}
Exemple #2
0
func removeAccountPushToken(data []string) (err error) {
	//Format: token~acmt~1003~token~platform
	tokenUser, err := appauth.GetUserFromToken(data[0])
	if err != nil {
		return errors.New("accounts.addAccountPushToken: " + err.Error())
	}

	// Check platform is correctly set
	// @FIXME This feels very heavy handed for "check if value in array"
	platform := data[4]
	platformPass := false
	allowedPlatforms := []string{"ios", "windows", "android", "blackberry", "other"}
	for _, v := range allowedPlatforms {
		if strings.Compare(v, platform) == 0 {
			platformPass = true
		}
	}

	if !platformPass {
		return errors.New("accounts.addAccountPushToken: Platform invalid")
	}
	err = doDeleteAccountPushToken(tokenUser, data[3], platform)
	if err != nil {
		return err
	}
	return nil
}
Exemple #3
0
func merchantAccountView(data []string) (merchant MerchantDetails, err error) {
	_, err = appauth.GetUserFromToken(data[0])
	if err != nil {
		return MerchantDetails{}, errors.New("accounts.merchantAccountUpdate: " + err.Error())
	}
	data[len(data)-1] = strings.Replace(data[len(data)-1], "\n", "", -1)

	merchant, err = getMerchantFromMerchantID(data[3])
	if err != nil {
		return MerchantDetails{}, errors.New("accounts.merchantAccountView: Could not retrieve merchant from given Merchant ID.")
	}
	return
}
Exemple #4
0
func fetchUserAccounts(data []string) (account interface{}, err error) {
	// Fetch user account. Must be user logged in
	tokenUser, err := appauth.GetUserFromToken(data[0])
	if err != nil {
		return "", errors.New("accounts.fetchSingleAccount: " + err.Error())
	}
	account, err = getUserAccountsDetail(tokenUser)
	if err != nil {
		return "", errors.New("accounts.fetchSingleAccount: " + err.Error())
	}

	return
}
Exemple #5
0
func merchantAccountDelete(data []string) (result interface{}, err error) {
	// Currently this deletes an account entirely
	// Deleting is needed but backups of all data should be done
	// The account could be marked as deleted when called through the API
	// @TODO: Find best solution here. One option: log all data in separate place
	// (perhaps in a file) and remove the record
	tokenUser, err := appauth.GetUserFromToken(data[0])
	if err != nil {
		return "", errors.New("accounts.merchantAccountUpdate: " + err.Error())
	}
	data[len(data)-1] = strings.Replace(data[len(data)-1], "\n", "", -1)

	accountHolderDetails, err := getAccountUser(tokenUser)
	if err != nil {
		return "", errors.New("accounts.merchantAccountCreate: Could not retrieve account user from token user.")
	}

	accountDetails, err := getAccountDetails(data[5])
	if err != nil {
		return "", errors.New("accounts.merchantAccountCreate: Could not retrieve account details from account number provided.")
	}

	merchantObject, err := getMerchantFromMerchantID(data[4])
	if err != nil {
		return "", errors.New("accounts.merchantAccountUpdate: Could not retrieve current merchant using given merchant ID. " + err.Error())
	}

	// Get list of accounts linked to merchant
	accountIDs, err := getAllMerchantAccountNumbersByMerchantID(merchantObject.ID)
	if err != nil {
		return "", errors.New("accounts.merchantAccountUpdate: Could not get accountIDs associated to Merchant ID: " + err.Error())
	}

	// Make sure the user has access to all merchant accounts
	for _, aID := range accountIDs {
		err = CheckUserAccountValidFromToken(accountHolderDetails.IdentificationNumber, aID)
		if err != nil {
			return "", errors.New("accounts.merchantAccountUpdate: Account holder not valid for given Merchant ID. " + err.Error())
		}
	}

	err = deleteMerchantAccount(&merchantObject, &accountDetails, &accountHolderDetails)
	if err != nil {
		return "", errors.New("accounts.merchantAccountUpdate: Could not update merchant. " + err.Error())
	}

	return
}
Exemple #6
0
func merchantAccountUpdate(data []string) (result interface{}, err error) {
	tokenUser, err := appauth.GetUserFromToken(data[0])
	if err != nil {
		return "", errors.New("accounts.merchantAccountUpdate: " + err.Error())
	}
	data[len(data)-1] = strings.Replace(data[len(data)-1], "\n", "", -1)

	accountHolder, err := getAccountUser(tokenUser)
	if err != nil {
		return "", errors.New("accounts.merchantAccountCreate: Could not retrieve account user from token user.")
	}

	// Set merchant details
	merchantObject, _, err := setMerchantDetails(data, accountHolder.IdentificationNumber, "update")
	if err != nil {
		return "", errors.New("accounts.merchantAccountUpdate: " + err.Error())
	}

	// Get list of accounts linked to merchant
	accountIDs, err := getAllMerchantAccountNumbersByMerchantID(merchantObject.ID)
	if err != nil {
		return "", errors.New("accounts.merchantAccountUpdate: Could not get accountIDs associated to Merchant ID: " + err.Error())
	}

	// Make sure the user has access to all merchant accounts
	for _, aID := range accountIDs {
		err = CheckUserAccountValidFromToken(accountHolder.IdentificationNumber, aID)
		if err != nil {
			return "", errors.New("accounts.merchantAccountUpdate: Account holder not valid for given Merchant ID. " + err.Error())
		}
	}

	currentMerchantObject, err := getMerchantFromMerchantID(merchantObject.ID)
	if err != nil {
		return "", errors.New("accounts.merchantAccountUpdate: Could not retrieve current merchant using given merchant ID. " + err.Error())
	}

	// Check which values are updated and set in new object
	compareUpdateMerchantWithCurrentMerchant(&merchantObject, &currentMerchantObject)

	err = updateMerchant(&merchantObject)
	if err != nil {
		return "", errors.New("accounts.merchantAccountUpdate: Could not update merchant. " + err.Error())
	}
	return
}
Exemple #7
0
func merchantAccountSearch(data []string) (result interface{}, err error) {
	_, err = appauth.GetUserFromToken(data[0])
	if err != nil {
		return "", errors.New("accounts.merchantAccountSearch: " + err.Error())
	}

	searchString := data[3]
	if len(searchString) < 2 {
		return "", errors.New("accounts.merchantAccountSearch: Please provide a search term of at least 2 characters.")
	}

	result, err = getMerchantAccountFromSearchData(searchString)
	if err != nil {
		return "", errors.New("accounts.merchantAccountSearch: Searching for account error. " + err.Error())
	}

	return
}
Exemple #8
0
// searchAccountData takes a search term and searches on id, first name and last name
// Results are limited to 10
func searchAccount(data []string) (accounts interface{}, err error) {
	//Format: acmt~1005~token~search-string
	_, err = appauth.GetUserFromToken(data[0])
	if err != nil {
		return "", errors.New("accounts.searchAccount: " + err.Error())
	}

	searchString := data[3]
	if len(searchString) < 4 {
		return "", errors.New("accounts.merchantAccountSearch: Please provide a search term of at least 4 characters.")
	}

	accounts, err = getAccountFromSearchData(searchString)
	if err != nil {
		return "", errors.New("accounts.searchAccount: Searching for account error. " + err.Error())
	}

	return
}