예제 #1
0
    // Use this for initialization
    void Start()
    {
        userId    = um.getCurrentUserId();
        userToken = um.getCurrentSessionToken();


        CardColors.Add(Orca);
        CardColors.Add(Favourit);
        CardColors.Add(Love);
        CardColors.Add(Tonight);
        CardColors.Add(Lagoon);
        CardColors.Add(Roseanna);
        setCardColor(new System.Random().Next(0, 5));



        cardHolderError = GameObject.Find("CardHolderPanel").GetComponent <Animator>();
        cardNumberError = GameObject.Find("CardNumberPanel").GetComponent <Animator>();
        DAEError        = GameObject.Find("DAEPanel").GetComponent <Animator>();
        CVVError        = GameObject.Find("CVVPanel").GetComponent <Animator>();
        cardHolder      = GameObject.Find("card holder").GetComponent <InputField>();
        cardNumber      = GameObject.Find("card number").GetComponent <InputField>();
        CVV             = GameObject.Find("CVV").GetComponent <InputField>();
        Years           = GameObject.Find("Years").GetComponent <Dropdown>();
        Month           = GameObject.Find("Months").GetComponent <Dropdown>();
        GameObject.Find("Card/Front/" + paymentCard).GetComponent <Image>().transform.localScale = Vector3.one;
        GameObject.Find("Card/Back/" + paymentCard).GetComponent <Image>().transform.localScale  = Vector3.one;
        //Credit Amount
        Amount = GameObject.Find("Amount").GetComponent <Text>();
        //Toggle
        TermsToggel = GameObject.Find("ToggleTerms").GetComponent <Toggle>();
        //charge
        Credit = GameObject.Find("Credit").GetComponent <Button>();
        Credit.onClick.AddListener(() =>
        {
            confirmCredit();
        });
        try
        {
            Amount.text = WalletScript.LastCredit.ToString("N2").Replace(",", ".") + CurrencyManager.CURRENT_CURRENCY;
            TermsToggel.onValueChanged.AddListener(delegate
            {
                if (TermsToggel.isOn == true)
                {
                    Credit.interactable = true;
                }
                else
                {
                    Credit.interactable = false;
                }
            });
        }
        catch (NullReferenceException)
        {
        }
        cardHolder.onValueChanged.AddListener(delegate
        {
            card_Name.text = cardHolder.text;
            if (cardHolderError.GetBool("wrongcardholder") == true)
            {
                cardHolderError.SetBool("wrongcardholder", false);
            }
        });
        string content = "";

        cardNumber.onValueChanged.AddListener(delegate
        {
            content          = cardNumber.text;
            card_Number.text = separated(content);
            Debug.Log(content);
            card_NumberHint.text = numberhintEditor(content);
            if (cardNumberError.GetBool("wrongcardnumber") == true)
            {
                cardNumberError.SetBool("wrongcardnumber", false);
            }
        });
        CVV.onValueChanged.AddListener(delegate
        {
            card_CVV.text = CVV.text;
            if (CVVError.GetBool("cvverror") == true)
            {
                CVVError.SetBool("cvverror", false);
            }
        });
        Month.onValueChanged.AddListener(delegate
        {
            int _monthIndex    = GameObject.Find("Months").GetComponent <Dropdown>().value;
            string valueMonths = GameObject.Find("Months").GetComponent <Dropdown>().options[_monthIndex].text;
            if (valueMonths != "MM")
            {
                card_ExpireDate_Month.text = valueMonths;
            }
            else
            {
                card_ExpireDate_Month.text = "";
            }
            if (DAEError.GetBool("daeerror") == true)
            {
                DAEError.SetBool("daeerror", false);
            }
        });
        Years.onValueChanged.AddListener(delegate
        {
            int _yearIndex    = GameObject.Find("Years").GetComponent <Dropdown>().value;
            string valueYears = GameObject.Find("Years").GetComponent <Dropdown>().options[_yearIndex].text;
            if (valueYears != "YYYY")
            {
                card_ExpireDate_Year.text = valueYears.Substring(2, 2);
            }
            else
            {
                card_ExpireDate_Year.text = "";
            }
            if (DAEError.GetBool("daeerror") == true)
            {
                DAEError.SetBool("daeerror", false);
            }
        });

        try
        {
            for (int i = DateTime.Today.Year; i < DateTime.Today.Year + 50; i++)
            {
                Years.options.Add(new UnityEngine.UI.Dropdown.OptionData()
                {
                    text = i.ToString()
                });
            }
            for (int i = 1; i <= 12; i++)
            {
                if (i < 10)
                {
                    Month.options.Add(new UnityEngine.UI.Dropdown.OptionData()
                    {
                        text = "0" + i.ToString()
                    });
                }
                else
                {
                    Month.options.Add(new UnityEngine.UI.Dropdown.OptionData()
                    {
                        text = i.ToString()
                    });
                }
            }
        }
        catch (NullReferenceException ex) { }
    }
예제 #2
0
    public void confirmCredit()
    {
        string token  = um.getCurrentSessionToken();
        string userId = um.getCurrentUserId();
        //If the credit is directly accepted
        const string Chargeable = "chargeable";
        //If the credit is directly accepted
        const string Succeeded = "succeeded";
        //IN Case of 3DS Card
        const string Pending = "pending";
        //Debug.Log("confirmCredit");
        bool confirmData = true;

        UnityThreading.ActionThread thread;
        cardHolderError = GameObject.Find("CardHolderPanel").GetComponent <Animator>();
        cardNumberError = GameObject.Find("CardNumberPanel").GetComponent <Animator>();
        DAEError        = GameObject.Find("DAEPanel").GetComponent <Animator>();
        CVVError        = GameObject.Find("CVVPanel").GetComponent <Animator>();
        int    _yearIndex  = GameObject.Find("Years").GetComponent <Dropdown>().value;
        int    _monthIndex = GameObject.Find("Months").GetComponent <Dropdown>().value;
        string valueYears  = GameObject.Find("Years").GetComponent <Dropdown>().options[_yearIndex].text;
        string valueMonths = GameObject.Find("Months").GetComponent <Dropdown>().options[_monthIndex].text;

        if (string.IsNullOrEmpty(cardHolder.text))
        {
            cardHolderError.SetBool("wrongcardholder", true);
            confirmData = false;
        }
        if (cardNumber.text.Length != 16 || string.IsNullOrEmpty(cardNumber.text))
        {
            cardNumberError.SetBool("wrongcardnumber", true);
            confirmData = false;
        }
        if (CVV.text.Length < 3 || string.IsNullOrEmpty(CVV.text))
        {
            CVVError.SetBool("cvverror", true);
            confirmData = false;
        }
        if (valueYears == "YYYY" || valueMonths == "MM" || (valueYears.Equals(DateTime.Today.Year.ToString()) && int.Parse(valueMonths) < DateTime.Today.Month))
        {
            DAEError.SetBool("daeerror", true);
            confirmData = false;
        }
        if (confirmData == true)
        {
            // a changer pour mettre la popup

            SceneManager.LoadScene("Loader", LoadSceneMode.Additive);

            thread = UnityThreadHelper.CreateThread(() =>
            {
                try
                {
                    string _paymentMethodID = charge.createPaymentMethod(cardNumber.text, CVV.text, int.Parse(valueMonths), int.Parse(valueYears));
                    if (!String.IsNullOrEmpty(_paymentMethodID))
                    {
                        JSONNode _paymentIntent = charge.createPaymentIntent(_paymentMethodID, WalletScript.LastCredit, token);
                        _paymentIntentID        = _paymentIntent["data"]["id"].Value;
                        Debug.Log("_paymentIntentID: " + _paymentIntentID);
                        // Response of Seemba API
                        if (_paymentIntent["success"].AsBool)
                        {
                            //check if 3D Secure needed from Stripe
                            if (is3DSecure(_paymentIntent))
                            {
                                confirm3DSecure(_paymentIntent);
                            }
                            else
                            {   // 3D Secure not required, directly check payment intent status
                                if (_paymentIntent["status"].Value == ChargeManager.PAYMENT_STATUS_SUCCEEDED)
                                {
                                    chargeSucceeded();
                                }
                                else
                                {
                                    chargeCanceled();
                                }
                            }
                            //extract URL and open browser
                            UnityThreadHelper.Dispatcher.Dispatch(() =>
                            {
                                isBackAfterPayment = false;
                            });
                        }
                        else
                        {
                            //Charge Refused : not confirmed
                            chargeCanceled();
                        }
                    }
                    else
                    {
                        UnityThreadHelper.Dispatcher.Dispatch(() =>
                        {
                            //turn back to trophy with Ouups popup
                            TurnBackToTrophy();
                        });
                    }
                }
                catch (NullReferenceException e)
                {
                    Debug.Log(e);
                }
            });
        }
    }