public SDKResult transaction(TransactionConfig config) { Newtonsoft.Json.JsonSerializerSettings jss = new Newtonsoft.Json.JsonSerializerSettings(); Newtonsoft.Json.Serialization.DefaultContractResolver dcr = new Newtonsoft.Json.Serialization.DefaultContractResolver(); dcr.DefaultMembersSearchFlags |= System.Reflection.BindingFlags.NonPublic; jss.ContractResolver = dcr; string configJson = Newtonsoft.Json.JsonConvert.SerializeObject(config, jss); JObject jo = JObject.Parse(configJson); jo.Add("merchant_id", this.merchant_id); string paramsJson = jo.ToString(); try { var cli = new WebClient(); cli.Headers[HttpRequestHeader.ContentType] = "application/json"; String response = cli.UploadString("http://pierup.asuscomm.com:8686/merchant_api/v1/transaction/pay_by_pier", paramsJson); JObject responseJSON = JObject.Parse(response); return new SDKResult( (int)responseJSON.GetValue ("code")==200, (string)responseJSON.GetValue ("message"), (string)responseJSON.GetValue ("code"), responseJSON.GetValue ("result").ToObject<Dictionary<string,string>>() ); } catch (WebException e) { string responseText = null; if (e.Response != null) { var responseStream = e.Response.GetResponseStream(); if (responseStream != null) { var reader = new StreamReader (responseStream); responseText = reader.ReadToEnd(); } } if (responseText != null) { JObject responseJSON = JObject.Parse(responseText); return new SDKResult( (int)responseJSON.GetValue ("code")==200, (string)responseJSON.GetValue ("message"), (string)responseJSON.GetValue ("code"), responseJSON.GetValue ("result").ToObject<Dictionary<string,string>>() ); } else { return new SDKResult(false, e.ToString(), null, null); } } }
private JsonResult pierTransaction(double amount, string auth_token, string currency, string id_in_merchant) { MerchantSDKClient merchant = new MerchantSDKClient("MC0000014895"); TransactionConfig config = new TransactionConfig( amount, "5b52051a-931a-11e4-aad2-0ea81fa3d43c", "mk-test-5b52041f-931a-11e4-aad2-0ea81fa3d43c", auth_token, currency, id_in_merchant, "dummy C# merchant" ); SDKResult result = merchant.transaction(config); return Json( new { status=result.isStatus (), message=result.getMessage (), code=result.getCode (), result=result.getResult () }, JsonRequestBehavior.AllowGet ); }