예제 #1
0
    /// <summary>
    ///<param name="product_id">id of product for payment</param>
    /// setup product
    /// call webview for payment
    /// </summary>
    public void Payment(string product_id)
    {
        PWBase.SetApiType(typePayment);
        PWBase.SetAppKey("8ec04f96a62ec4c7a0f13ceccee638ac");         // available in your Paymentwall merchant area
        PWBase.SetSecretKey("adb7497cc888e5c1547dded7aa9ca0d7");      // available in your Paymentwall merchant area

        List <PWProduct> productList = new List <PWProduct>();

        if (typePayment == Paymentwall_Base.API_GOODS)
        {
            productList = this.CreateProduct(product_id);
        }

        PWWidget widget = new PWWidget(
            "1",             // id of the end-user who's making the payment
            "p1_1",          // widget code, e.g. p1; can be picked inside of your merchant account
            productList,
            new Dictionary <string, string>()
        {
            { "email", "*****@*****.**" }
        }                                                                                      // additional parameters
            );
        PWUnityWidget unity = new PWUnityWidget(widget);

        StartCoroutine(unity.callWidgetWebView(gameObject, canvas));           // call this function to display widget
    }
예제 #2
0
    private IEnumerator CancelSubscription(string subscriptionId)
    {
        WWW www = new WWW(PWBase.GetCancelSubscriptionURL() + subscriptionId);

        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"))
                {
                    Debug.Log(json);
                    SetSubStatus(false);
                    this.cardToken = "";
                    this.subId     = "";
                }
                else
                {
                    Debug.Log(json);
                }
            }
            else
            {
                Debug.Log("Can't react Paymentwall server");
            }
        }
        else
        {
            Debug.Log(www.error);
        }
    }
예제 #3
0
    public void creditPay()
    {
        int pay;

        if (int.TryParse(payment.text, out pay))
        {
            PWBrick brick = new PWBrick(pay + 0.0f, "USD", "Your Awesome Game", "Small pack");
            PWBase.SetAppKey("t_b33d46eda162a2537ee9849040b02b");              // your Project Public key - available in your Paymentwall merchant area
            PWBase.SetSecretKey("t_c99c2918ee0538144fd81d7dbc40ec");
            brick.ShowPaymentForm();
        }
    }
예제 #4
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);
        }
    }
예제 #5
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;
    }
예제 #6
0
    // Use this for initialization
    void Start()
    {
        string   json = ((TextAsset)Resources.Load("Data/widget")).text;
        JSONNode node = JSON.Parse(json);

        int    type      = int.Parse(node["apiType"]);
        string appKey    = node["appKey"];      // available in your Paymentwall merchant area
        string secretKey = node["secretKey"];   // available in your Paymentwall merchant area

        PWBase.SetApiType(type);
        PWBase.SetAppKey(appKey);
        PWBase.SetSecretKey(secretKey);

        List <PWProduct> productList = new List <PWProduct>();
        PWProduct        product     = new PWProduct(
            "product301",                // id of the product in your system
            9.99f,                       // price
            "USD",                       // currency code
            "Gold Membership",           // product name
            PWProduct.TYPE_SUBSCRIPTION, // this is a time-based product; for one-time products, use Paymentwall_Product.TYPE_FIXED and omit the following 3 parameters
            1,                           // time duration
            PWProduct.PERIOD_TYPE_YEAR,  // year
            true                         // recurring
            );

        productList.Add(product);
        PWWidget widget = new PWWidget(
            "user40012",        // id of the end-user who's making the payment
            "p1_1",             // widget code, e.g. p1; can be picked inside of your merchant account
            productList,
            new Dictionary <string, string>()
        {
            { "email", "*****@*****.**" }
        }                                                                                 // additional parameters
            );

        PWUnityWidget unity = new PWUnityWidget(widget);

        StartCoroutine(unity.callWidgetWebView(gameObject, canvas));          // call this function to show Widget
    }
예제 #7
0
    public IEnumerator OnPay()
    {
        flagCreditCard = true;
        flagExpDate    = true;
        flagCVV        = true;
        flagEmail      = true;
        errTextCard.SetActive(false);
        errTextEmail.SetActive(false);

        if (!PWUltils.IsCVVNumberValid(inputCVV.text))
        {
            inputCVV.transform.parent.GetComponent <InputFieldEventHandle> ().OnError();
            flagCVV = false;
            errTextCard.GetComponent <Text>().text = "Please check CVV2 (CVC) code.";
            errTextCard.SetActive(true);
        }
        if (!PWUltils.IsExpireDateValid(inputExpDate.text))
        {
            inputExpDate.transform.parent.GetComponent <InputFieldEventHandle>().OnError();
            flagExpDate = false;
            errTextCard.GetComponent <Text>().text = "Please check card expiry date.";
            errTextCard.SetActive(true);
        }
        if (!PWUltils.IsCreditCardNumberValid(inputCardNumber.text))
        {
            inputCardNumber.transform.parent.GetComponent <InputFieldEventHandle> ().OnError();
            flagCreditCard = false;
            errTextCard.GetComponent <Text>().text = "Please check your credit card number.";
            errTextCard.SetActive(true);
        }

        if (!PWUltils.IsEmailValid(inputEmail.text))
        {
            inputEmail.transform.parent.GetComponent <InputFieldEventHandle> ().OnError();
            flagEmail = false;
            errTextEmail.SetActive(true);
        }

        if (!flagCreditCard || !flagExpDate || !flagCVV || !flagEmail)
        {
            return(false);
        }

        string cardNumber = inputCardNumber.text;
        string cvv        = inputCVV.text;

        string expMonth = inputExpDate.text.Substring(0, 2);
        string expYear  = inputExpDate.text.Substring(3);

        if (FakeAccountController.Instance.IsAccountOnline())
        {
            PWOneTimeToken token = new PWOneTimeToken();
            token.Create(PWBase.GetAppKey(), cardNumber, expMonth, expYear, cvv);
            PWCharge charge = gameObject.AddComponent <PWCharge>();
            yield return(StartCoroutine(charge.Create(token, inputEmail.text, this.currency, this.amount.ToString(), "fingerprint here", "description here")));

            if (charge.IsSuccessful())
            {
                TransactionSuccess(charge.GetReceipt(), charge.GetChargeAmount().ToString());
            }
            else
            {
                TransactionFail(charge.GetErrorMessage());
            }
        }
        else
        {
            TransactionFail("You must login before progess any purchase");
        }
    }
예제 #8
0
 public void UpdateAPIkey(string publicKey, string secretKey)
 {
     PWBase.SetAppKey(publicKey);
     PWBase.SetSecretKey(secretKey);
 }