Exemplo n.º 1
0
func (this *PaymentC) Create(ctx *web.Context) {
	r, w := ctx.Request, ctx.Response
	qs := r.URL.Query()
	partnerId := this.GetPartnerId(ctx)
	orderNo := qs.Get("order_no")
	paymentOpt := qs.Get("pay_opt")

	if len(orderNo) != 0 {
		ctx.Session().Set("current_payment", orderNo)
		ctx.Session().Save()

		if paymentOpt == "alipay" {
			aliPayObj := this.getAliPayment(ctx)
			domain := getDomain(ctx.Request)
			returnUrl := fmt.Sprintf("%s/pay/return_alipay", domain)
			notifyUrl := fmt.Sprintf("%s/pay/notify/%d_alipay", domain, partnerId)
			gateway := aliPayObj.CreateGateway(orderNo, 0.01, "在线支付订单", "订单号:"+orderNo, notifyUrl, returnUrl)
			html := "<html><head><meta charset=\"utf-8\"/></head><body>" + gateway + "</body></html>"
			w.Write([]byte(html))

			payment.Debug(" [ Submit] - %s - %s", orderNo, notifyUrl)

			return
		}
	}

	w.Write([]byte("订单不存在"))
}
Exemplo n.º 2
0
func (this *PaymentC) Notify_post(ctx *web.Context) {
	path := ctx.Request.URL.Path
	lastSeg := strings.Split(path[strings.LastIndex(path, "/")+1:], "_")
	paymentOpt := lastSeg[1]
	partnerId, _ := strconv.Atoi(lastSeg[0])
	payment.Debug(" [ Notify] - URL - %s - %d -  %s", ctx.Request.RequestURI, partnerId, paymentOpt)

	if paymentOpt == "alipay" {
		aliPayObj := this.getAliPayment(ctx)
		result := aliPayObj.Notify(ctx.Request)
		order := dps.ShoppingService.GetOrderByNo(partnerId, result.OrderNo)
		if result.Status == payment.StatusTradeSuccess {
			this.handleOrder(order, "alipay", &result)
			payment.Debug("payment ok")
			ctx.Response.Write([]byte("success"))
			return
		}
	}
	ctx.Response.Write([]byte("fail"))
}
Exemplo n.º 3
0
func (this *PaymentC) Create(ctx *web.Context) {
	r, w := ctx.Request, ctx.Response
	qs := r.URL.Query()
	partnerId := this.GetPartnerId(ctx)
	orderNo := qs.Get("order_no")
	paymentOpt := qs.Get("pay_opt")

	var order *shopping.ValueOrder
	if len(orderNo) > 0 {
		//	dps.ShoppingService.PayForOrderOnlineTrade(partnerId,orderNo,"alipay","")
		//	ctx.Response.Header().Add("Location", fmt.Sprintf("/buy/payment?order_no=%s", orderNo))
		//	ctx.Response.WriteHeader(302)
		//	return
		order = dps.ShoppingService.GetOrderByNo(partnerId, orderNo)
	}

	if order != nil {
		if order.IsPaid == enum.TRUE {
			ctx.Response.Header().Add("Location", fmt.Sprintf("/buy/payment?order_no=%s", order.OrderNo))
			ctx.Response.WriteHeader(302)
			return
		}
		ctx.Session().Set("current_payment", orderNo)
		ctx.Session().Save()

		//order.PayFee = 0.01

		if paymentOpt == "alipay" || paymentOpt == strconv.Itoa(enum.PaymentOnlinePay) {
			aliPayObj := this.getAliPayment(ctx)
			domain := getDomain(ctx.Request)
			returnUrl := fmt.Sprintf("%s/pay/return_alipay", domain)
			notifyUrl := fmt.Sprintf("%s/pay/notify/%d_alipay", domain, partnerId)
			gateway := aliPayObj.CreateGateway(orderNo, order.PayFee, "在线支付订单", "订单号:"+orderNo, notifyUrl, returnUrl)
			html := "<html><head><meta charset=\"utf-8\"/></head><body>" + gateway + "</body></html>"
			w.Write([]byte(html))

			payment.Debug(" [ Submit] - %s - %s", orderNo, notifyUrl)

			return
		}
	}

	w.Write([]byte("订单不存在"))
}