Skip to content

Instantly share code, notes, and snippets.

@chakrit
Created August 9, 2016 17:41
Show Gist options
  • Save chakrit/621e13716a6850512ed9c66460ce609e to your computer and use it in GitHub Desktop.
Save chakrit/621e13716a6850512ed9c66460ce609e to your computer and use it in GitHub Desktop.
{
"object": "charge",
"id": "chrg_test_5086xlsx4lghk9bpb75",
"livemode": false,
"location": "/charges/chrg_test_5086xlsx4lghk9bpb75",
"amount": 100000,
"currency": "thb",
"description": null,
"capture": true,
"authorized": true,
"reversed": false,
"paid": true,
"transaction": "trxn_test_5086xltqqbv4qpmu0ri",
"refunded": 0,
"refunds": {
"object": "list",
"from": "1970-01-01T00:00:00+00:00",
"to": "2015-06-02T05:41:49+00:00",
"offset": 0,
"limit": 20,
"total": 0,
"data": [],
"location": "/charges/chrg_test_5086xlsx4lghk9bpb75/refunds"
},
"failure_code": null,
"failure_message": null,
"card": {
"object": "card",
"id": "card_test_5086xl7amxfysl0ac5l",
"livemode": false,
"location": "/customers/cust_test_5086xleuh9ft4bn0ac2/cards/card_test_5086xl7amxfysl0ac5l",
"country": "us",
"city": "Bangkok",
"postal_code": "10320",
"financing": "",
"last_digits": "4242",
"brand": "Visa",
"expiration_month": 10,
"expiration_year": 2018,
"fingerprint": "mKleiBfwp+PoJWB/ipngANuECUmRKjyxROwFW5IO7TM=",
"name": "Somchai Prasert",
"security_code_check": true,
"created": "2015-06-02T05:41:46Z"
},
"customer": "cust_test_5086xleuh9ft4bn0ac2",
"ip": null,
"dispute": null,
"created": "2015-06-02T05:41:49Z"
}
package main
import "net/http"
import "encoding/json"
func main() {
if e := http.ListenAndServe(":8080", http.HandlerFunc(handler)); e != nil {
panic(e)
}
}
func handler(resp http.ResponseWriter, req *http.Request) {
defer req.Body.Close()
result := map[string]interface{}{}
if e := json.NewDecoder(req.Body).Decode(&result); e != nil {
panic(e)
}
key := req.URL.Path[1:]
if value, ok := result[key]; !ok {
http.NotFound(resp, req)
} else if e := json.NewEncoder(resp).Encode(value); e != nil {
panic(e)
}
}
var http = require('http');
var server = http.createServer(function(req, resp) {
var buffer = '';
var key = req.url.substr(1);
req.on('data', function(part) {
buffer += part.toString();
});
req.on('end', function() {
setImmediate(function() {
resp.end(JSON.parse(buffer)[key]);
});
})
});
server.listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment