public static string updateSubscription(string id, string buyerID, string planID, string cardID, double? amount, string coupon, long? trialEnd, Dictionary<string, string> optional)
{
long timestamp = BCUtil.GetTimeStamp(DateTime.Now);
JsonData data = new JsonData();
data["app_id"] = BCCache.Instance.appId;
data["app_sign"] = BCPrivateUtil.getAppSignature(BCCache.Instance.appId, BCCache.Instance.appSecret, timestamp.ToString());
data["timestamp"] = timestamp;
if (buyerID != null)
{
data["buyer_id"] = buyerID;
}
if (cardID != null)
{
data["card_id"] = cardID;
}
if (planID != null)
{
data["plan_id"] = planID;
}
if (coupon != null)
{
data["coupon"] = coupon;
}
if (amount.HasValue)
{
data["amount"] = amount.Value;
}
if (trialEnd.HasValue)
{
data["trial_end"] = trialEnd.Value;
}
if (optional != null && optional.Count > 0)
{
data["optional"] = new JsonData();
foreach (string key in optional.Keys)
{
data["optional"][key] = optional[key];
}
}
string paraString = data.ToJson();
string subscriptionURL = BCPrivateUtil.getHost() + BCConstants.version + BCConstants.bcsubscriptionURL + "/" + id;
try
{
HttpWebResponse response = BCPrivateUtil.CreatePutHttpResponse(subscriptionURL, paraString, BCCache.Instance.networkTimeout);
string respString = BCPrivateUtil.GetResponseString(response);
JsonData responseData = JsonMapper.ToObject(respString);
if (responseData["result_code"].ToString() == "0")
{
return responseData["id"].ToString();
}
else
{
var ex = new BCException(responseData["err_detail"].ToString());
throw ex;
}
}
catch (Exception e)
{
var ex = new BCException(e.Message);
throw ex;
}
}