Ejemplo n.º 1
0
func (t *SwiftSampleApi) PostMessage(r *http.Request, req *PostReq, res *PostRes) error {

	c := endpoints.NewContext(r)

	if u, error := endpoints.CurrentUser(c, Scopes, Audiences, ClientIds); error != nil {
		return endpoints.NewUnauthorizedError("Need auth")
	} else {
		req.Email = u.Email
	}

	req.RegisteredAt = time.Now()

	g := goon.NewGoon(r)

	if _, error := g.Put(req); error != nil {
		return error
	}

	res.Email = req.Email
	res.Message = req.Message
	res.Id = req.Id
	res.RegisteredAt = req.RegisteredAt

	return nil
}
Ejemplo n.º 2
0
func successPaypal(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	client, err := newPaypalClient(c)

	if err != nil {
		return // error was logged inside newPaypalClient function
	}

	paymentID := r.URL.Query().Get("paymentId")
	payerID := r.URL.Query().Get("PayerID")
	executePaymentResponse, err := client.ExecutePayment(paymentID, payerID, nil)

	g := goon.NewGoon(r)
	for _, i := range executePaymentResponse.Transactions[0].ItemList.Items {
		item := &Item{Id: i.SKU}
		_ = g.Get(item)

		item.Quantity += i.Quantity

		g.Put(item)
	}

	if err != nil {
		log.Infof(c, "Couldn't execute payment: %+v", err)
		return
	}

	sendEmail(executePaymentResponse.Payer.PayerInfo.Email, c)

	name := url.QueryEscape(executePaymentResponse.Payer.PayerInfo.FirstName)
	amount := url.QueryEscape(executePaymentResponse.Transactions[0].Amount.Total)
	config := NewConfig(c)
	http.Redirect(w, r, config.BaseURL+"/thanks?n="+name+"&v="+amount, 301)
}