예제 #1
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);
                }
            });
        }
    }