Esempio n. 1
0
    private IEnumerator RequestSubscription(string token, string email, string currency, string amount,
                                            string fingerprint, string description, string plan,
                                            string period, string duration)
    {
        WWWForm form    = new WWWForm();
        var     headers = form.headers;

        headers ["X-ApiKey"] = PWBase.GetSecretKey();
        form.AddField("token", token);
        form.AddField("amount", amount.ToString());
        form.AddField("currency", currency);
        form.AddField("email", email);
        form.AddField("fingerprint", fingerprint);
        form.AddField("description", description);
        form.AddField("plan", plan);
        form.AddField("period", period);
        form.AddField("period_duration", duration);

        WWW www = new WWW(PWBase.GetSubscriptionURL(), form.data, headers);

        yield return(www);

        if (www.error == null)
        {
            string   json     = www.text;
            JSONNode response = JSON.Parse(json);
            if (response != null)
            {
                string objMessage = response ["object"];
                if (objMessage.Equals("subscription"))
                {
                    SetSubStatus(true);
                    this.cardToken = response["card"]["token"];
                    this.subId     = response["id"];
                }
                else
                {
                    Debug.Log(json);
                    SetSubStatus(false);
                }
            }
            else
            {
                Debug.Log("Can't react Paymentwall server");
            }
        }
        else
        {
            Debug.Log(www.error);
        }
    }
Esempio n. 2
0
    private IEnumerator RequestCharge(string token, string email, string currency, string amount, string fingerprint, string description)
    {
        WWWForm form = new WWWForm();
        Dictionary <string, string> headers = form.headers;

        headers ["X-ApiKey"] = PWBase.GetSecretKey();
        form.AddField("token", token);
        form.AddField("amount", amount.ToString());
        form.AddField("currency", currency);
        form.AddField("email", email);
        form.AddField("fingerprint", fingerprint);
        form.AddField("description", description);
        WWW www = new WWW(PWBase.GetChargeURL(), form.data, headers);

        yield return(www);

        if (www.error == null)
        {
            string   json     = www.text;
            JSONNode response = JSON.Parse(json);
            if (response != null)
            {
                string objMessage = response ["object"];
                if (objMessage.Equals("charge"))
                {
                    Debug.Log(json);
                    SetChargeStatus(true);
                    this.cardToken = response["card"]["token"];
                    this.receipt   = response["id"];
                }
                else
                {
                    SetChargeStatus(false);
                    this.errorMessage = response ["error"];
                }
            }
            else
            {
                this.errorMessage = "Can't reach payment server";
            }
        }
        else
        {
            Debug.Log(www.error);
            this.errorMessage = www.error;
        }

        isRequestFinished = true;
    }