コード例 #1
0
ファイル: upload2.go プロジェクト: mehulsbhatt/tools-old
// This was an attempt, to "catch" the uploaded blob
// and store it by myself into the datastore -
// where I would be able to delete it.
// But this failed - the actual blob data does not even reach the appengine.
// Only the blob-info data.
func dataStoreClone(w http.ResponseWriter, r *http.Request,
	blob0 *BlobInfo, otherFormFields url.Values) {

	return

	wbl := dsu.WrapBlob{}
	wbl.Category = "print"
	wbl.Name = otherFormFields["title"][0] + " - " + otherFormFields["descr"][0]
	wbl.Name += " - " + util.LowerCasedUnderscored(blob0.Filename)
	wbl.Desc = fmt.Sprintf("%v", blob0.BlobKey)
	wbl.S = blob0.ContentType
	if len(otherFormFields["post_field_file"]) > 0 {
		filecontent := otherFormFields["post_field_file"][0]
		wbl.VByte = []byte(filecontent)
	}
	keyX2 := "bl" + time.Now().Format("060102_1504-05")
	_, errDS := dsu.BufPut(w, r, wbl, keyX2)
	util_err.Err_http(w, r, errDS, false)

}
コード例 #2
0
ファイル: coinbase.go プロジェクト: aarzilli/tools
/*

https://developers.coinbase.com/docs/merchants/callbacks


id				Order number used to uniquely identify an order on Coinbase
completed_at	ISO 8601 timestamp when the order completed
status			[completed, mispaid, expired]
event			[completed, mispayment]. If mispayment => check key mispayment_id. Distinction from status ...
total_btc		Total amount of the order in ‘satoshi’ (1 BTC = 100,000,000 Satoshi). Note the use of the word ‘cents’ in the callback really means satoshi in this context. The btc amount will be calculated at the current exchange rate at the time the order is placed (current to within 15 minutes).
total_native	Units of local currency. 1 unit = 100 cents. Equal to the price from creating the button.
total_payout	Units of local currency deposited using instant payout.
custom			Custom parameter from data-custom attribute of button. Usually an Order, User, or Product ID
receive_address	Bitcoin address associated with this order. This is where the payment was sent.
button			Button details. ID matches the data-code parameter in your embedded HTML code.
transaction		Hash and number of confirmations of underlying transaction.
				Number of confirmations typically zero at the time of the first callback.
customer		Customer information from order form. Can include email xor shipping address.
refund_address	Experimental parameter that is subject to change.


*/
func confirmPay(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	lg, b := loghttp.BuffLoggerUniversal(w, r)
	closureOverBuf := func(bUnused *bytes.Buffer) {
		// loghttp.Pf(w, r, b.String())
	}
	defer closureOverBuf(b) // the argument is ignored,
	r.Header.Set("X-Custom-Header-Counter", "nocounter")

	htmlfrag.SetNocacheHeaders(w)

	//____________________________________________________________________

	bts, err := ioutil.ReadAll(r.Body)
	if err != nil {
		lg("cannot read resp body: %v", err)
		return
	}
	defer r.Body.Close()

	// lg("bytes are -%s-", stringspb.ToLen(string(bts), 20))

	if len(bts) < 1 {
		lg("lo empty post body")
		w.WriteHeader(http.StatusOK)
		b = new(bytes.Buffer)
		return
	}

	var mp map[string]interface{}
	err = json.Unmarshal(bts, &mp)
	lg(err)

	mpPayout := submap(mp, "payout", lg)
	if len(mpPayout) > 0 {
		lg("lo " + stringspb.IndentedDump(mpPayout))
	}
	mpAddress := submap(mp, "address", lg)
	if len(mpAddress) > 0 {
		lg("lo " + stringspb.IndentedDump(mpAddress))
	}

	var cents, BTC float64
	var status string

	mpOrder := submap(mp, "order", lg)
	if len(mpOrder) < 1 {
		w.WriteHeader(http.StatusLengthRequired)
		lg("mpOrder not present %v", status)
		return
	} else {
		lg("lo " + stringspb.IndentedDump(mpOrder))

		mpBTC := submap(mpOrder, "total_btc", lg)
		// lg("lo " + stringspb.IndentedDump(mpBTC))

		if icents, ok := mpBTC["cents"]; ok {
			cents, ok = icents.(float64)
			if !ok {
				lg(" mpBTC[cents] is of unexpected type %T ", mpBTC["cents"])
			}
			BTC = cents / (1000 * 1000 * 100)

		} else {
			lg(" mpBTC[cents] not present")
		}
		lg("received %18.2f satoshi, %2.9v BTC ", cents, BTC)

		if _, ok := mpOrder["status"]; ok {
			status, ok = mpOrder["status"].(string)
			if !ok {
				lg(" mpOrder[status] is of unexpected type %T ", mpOrder["status"])
			}
		}

		lg("status    %v  ", status)
		lg("custom   %#v  ", mpOrder["custom"])
		lg("customer %#v - mostly empty", mpOrder["customer"])

		var values url.Values
		if _, ok := mpOrder["custom"]; ok {
			if mpOrder["custom"] == "123456789" {
				lg("test request recognized")
				values = url.Values{}
				values.Add("uID", "testUser123")
				values.Add("productID", "/member/somearticle")
			} else {
				var err error
				values, err = url.ParseQuery(mpOrder["custom"].(string))
				lg(err)
				if err != nil {
					w.WriteHeader(http.StatusLengthRequired)
					lg("unsatisfactory query in custom string %v", mpOrder["custom"])
					return
				}
			}
		} else {
			w.WriteHeader(http.StatusLengthRequired)
			lg("custom string not present")
			return
		}

		//  save
		if status == "completed" {
			lg("status 'completed'")
			blob := dsu.WrapBlob{
				VByte: stringspb.IndentedDumpBytes(mpOrder),
			}
			blob.Name = values.Get("uID")
			blob.Category = "invoice"
			blob.S = values.Get("productID")
			blob.Desc = status
			blob.F = BTC
			blob.I = int(time.Now().Unix())

			// blob.VVByte, _ = conv.String_to_VVByte(string(blob.VByte)) // just to make it readable

			newKey, err := dsu.BufPut(appengine.NewContext(r), blob, blob.Name+blob.S)
			lg("key is %v", newKey)
			lg(err)

			retrieveAgain, err := dsu.BufGet(appengine.NewContext(r), "dsu.WrapBlob__"+blob.Name+blob.S)
			lg(err)
			lg("retrieved %v %v %v", retrieveAgain.Name, retrieveAgain.Desc, retrieveAgain.F)

		} else {
			w.WriteHeader(http.StatusLengthRequired)
			lg("unsatisfactory status %v", status)
			return
		}

	}
	w.WriteHeader(http.StatusOK)
	b = new(bytes.Buffer)

}