IEnumerator waitForRequest(WWW www) { yield return(www); if (www.error == null) { string resultJSON = www.text; JSONNode json = JSON.Parse(resultJSON); if (json["developerPayload"].Value.ToString() == currentPurchase.payload) { validateResult result = new validateResult(); result.isConsumed = json["consumptionState"].AsInt == 0; result.isRefund = json["purchaseState"].AsInt == 1; result.kind = json["kind"].Value.ToString(); result.payload = json["developerPayload"].Value.ToString(); result.time = json["purchaseTime"].Value.ToString(); callback(true, "purchase is valid", result); } else { callback(false, "error validating purchase. payload is not valid.", null); } } else { callback(false, "error validating purchase. " + www.error, null); } }
public static async void getSchooolName(string tenant_id) { try { var client2 = new HttpClient(); client2.BaseAddress = new Uri("http://cloudschool.management"); var values2 = new Dictionary <string, string>(); values2.Add("data", "{\"table\":\"company_information\",\"field\":\"company_name\"}"); values2.Add("extra", "{\"tenant_id\":\"" + tenant_id.ToString() + "\"}"); values2.Add("tenant_id", tenant_id.ToString()); var content2 = new FormUrlEncodedContent(values2); HttpResponseMessage response2 = await client2.PostAsync("/itcrm/getElementVal/", content2); var result3 = await response2.Content.ReadAsStringAsync(); validateResult chk_status = JsonConvert.DeserializeObject <validateResult>(result3); if (chk_status.status) { try { string school_name = chk_status.result; App.school_name = school_name; } catch { } } else { // await DisplayAlert("Error!", "Task not added", "ok"); } } catch { } }
private void onPurchaseValidated(bool success, string message, validateResult result) { if (success) { if (!result.isRefund) { // you can check consumptionState // if (result.isConsumed) // you can give user the product switch (selectedProductIndex) { case 0: // 500 coin saveCoin(500); break; case 1: // enable double coin doubleCoin = true; PlayerPrefs.SetInt("doubleCoin", 1); btnDoubleCoin.interactable = false; break; default: throw new UnassignedReferenceException("you forgot to give user the product after purchase. product: " + currentPurchase.orderId); } txtSuccessDialog.text = "Thanks for purchasing."; successDialog.SetActive(true); } else { Debug.Log("the purchase is refund"); txtErrorDialog.text = "the purchase is refund."; errorDialog.SetActive(true); } } else { // error in validating, or purchase is not valid // you can let user retry validating the purchase Debug.Log(message); retryDialog.SetActive(true); } loadingDialog.SetActive(false); txtResult.text = "validate result: " + success + ", " + message + "\n" + txtResult.text; }