Ejemplo n.º 1
0
func (c *MainController) ApiDepositAmountPost() {
	glog.Infof("%#+v", c.Ctx.Request)
	upath := c.Ctx.Request.URL.Path
	buyIcc := false
	if strings.Contains(upath, "buyicc") {
		buyIcc = true
	}

	currency := "USD"
	if !buyIcc {
		s := c.GetString("currency")
		if s == "" {
			glog.Errorln("currency is nil")
			return
		}
		currency = getCurrencyID(s)
	}

	gba, err := getGba(currency)
	if err != nil {
		glog.Errorln(err)
		return
	}

	amount, err := c.GetFloat("amount")
	if err != nil {
		glog.Errorln(err)
		return
	}

	if buyIcc {
		amount *= models.Gconf.UsdRate
	}

	fees := models.Gconf.Fees

	min, max := fees.FeeMap[currency][0], fees.FeeMap[currency][1]
	fee := amount * fees.Rate
	if fee < min {
		fee = min
	}
	if fee > max {
		fee = max
	}

	amt := &AmountInfo{
		BankName: gba.BankName,
		BankId:   gba.BankId,
		Currency: currency,
		Amount:   amount,
		Fees:     fee,
		Total:    amount + fee,
	}
	c.SetSession("Amt", amt)
	currencys := models.Gconf.Currencies
	c.Data["Currencies"] = currencys
	c.Data["Amt"] = amt
	c.Data["BuyIcc"] = buyIcc
	c.TplNames = "deposit.html"
}
Ejemplo n.º 2
0
func (c *MainController) getReqs(role *models.Role, tname string, status int, st, et *time.Time, t int) []HtmlReq {
	var reqs []*models.Request
	qs := models.Gorm.QueryTable(tname).Filter("Type", t).Filter("CTime__gte", st).Filter("CTime__lte", et).RelatedSel()
	if status != -1 {
		qs.Filter("R__Status", status).All(&reqs)
	} else {
		qs.All(&reqs)
	}
	hreqs := make([]HtmlReq, len(reqs))
	for i, r := range reqs {
		glog.Infof("%+v", r.R)
		hreqs[i] = HtmlReq{
			Request: r,
			Rec:     r.R,
			Role:    role,
			Status:  models.RStatusMap[r.R.Status],
		}
	}
	return hreqs
}
Ejemplo n.º 3
0
// secret is sender's secret
func payment(ws *websockets.Remote, secret, sender, issuer, recipient, currency, invoiceID string, amount float64) error {
	glog.Info("payment:", secret, sender, recipient, currency, amount, issuer, invoiceID)
	sam := ""
	if currency == "ICC" {
		sam = fmt.Sprintf("%d/ICC", uint64(amount))
	} else {
		sam = fmt.Sprintf("%f/%s/%s", amount, currency, issuer)
	}
	a, err := data.NewAmount(sam)
	if err != nil {
		err = errors.New("NewAmount error: " + sam + err.Error())
		glog.Error(err)
		return err
	}

	ptx := &websockets.PaymentTx{
		TransactionType: "Payment",
		Account:         sender,
		Destination:     recipient,
		Amount:          a,
		InvoiceID:       invoiceID,
	}

	// glog.Infof("payment: %+v", ptx)

	r, err := ws.SubmitWithSign(ptx, secret)
	if err != nil {
		glog.Error(err)
		return err
	}
	glog.Infof("pament result: %+v", r)
	if !r.EngineResult.Success() {
		return errors.New(r.EngineResultMessage)
	}
	return nil
}
Ejemplo n.º 4
0
func (c *MainController) addReq(t int) error {
	amt, ok := c.GetSession("Amt").(*AmountInfo)
	if !ok {
		c.Ctx.Request.ParseMultipartForm(1024 * 1024 * 10)
		glog.Infof("%#+v", c.Ctx.Request)
		gbankId := c.GetString("gbankId")
		currency := c.GetString("currency")
		fee, err := c.GetFloat("fees")
		if err != nil {
			glog.Errorln(err)
			return err
		}
		a, err := c.GetFloat("amount")
		if err != nil {
			glog.Errorln(err)
			return err
		}
		amt = &AmountInfo{
			BankId:   gbankId,
			Currency: currency,
			Amount:   a,
			Fees:     fee,
		}
	}
	uname := c.GetString("name")
	uwallet := c.GetString("iccWallet")
	ubankName := c.GetString("bankName")
	ubankId := c.GetString("bankId")
	ucontact := c.GetString("contact")

	rf, header, err := c.Ctx.Request.FormFile("certificate")
	if err != nil {
		glog.Error(err)
		return err
	}
	defer rf.Close()

	filePath := "./certificates/" + RandToken() + "-" + header.Filename

	wf, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
	if err != nil {
		glog.Error(err)
		return err
	}
	io.Copy(wf, rf)
	wf.Close()

	u := &models.User{
		UName:        uname,
		UWallet:      uwallet,
		UBankName:    ubankName,
		UBankId:      ubankId,
		UContact:     ucontact,
		UCertificate: filePath[1:],
	}

	_, err = models.AddReq(amt.BankId, "", t, u, amt.Currency, amt.Amount, amt.Fees)
	if err != nil {
		glog.Errorln(err)
		return err
	}
	return nil
}