コード例 #1
0
 private void OnSuccessConsoleLogin(string newToken, LinkingResultContainer linkingResult)
 {
     SdkLoginLogic.Instance.ValidateToken(
         token: newToken,
         onSuccess: validToken => ApplyNewToken(validToken, linkingResult),
         onError: error => { linkingResult.IsLinked = false; StoreDemoPopup.ShowError(error); });
 }
コード例 #2
0
        private IEnumerator Start()
        {
            string pictureUrl = null;
            bool?  isUserPictureUrlObtained = null;

            var token = Token.Instance;

            SdkLoginLogic.Instance.GetUserInfo(token,
                                               onSuccess: info =>
            {
                pictureUrl = info.picture;
                isUserPictureUrlObtained = true;
            },
                                               onError: error =>
            {
                StoreDemoPopup.ShowError(error);
                isUserPictureUrlObtained = false;
            });

            yield return(new WaitWhile(() => isUserPictureUrlObtained == null));

            if (isUserPictureUrlObtained == true && !string.IsNullOrEmpty(pictureUrl))
            {
                SetState(AvatarState.Set);
            }
            else
            {
                SetState(AvatarState.Unset);
            }
        }
コード例 #3
0
        private void LinkSocialProvider()
        {
            var supported = true;

#if UNITY_EDITOR
            switch (EditorUserBuildSettings.activeBuildTarget)
            {
            case BuildTarget.StandaloneOSX:
            case BuildTarget.StandaloneWindows:
            case BuildTarget.StandaloneWindows64:
            case BuildTarget.StandaloneLinux64:
                //Do nothing
                break;

            default:
                supported = false;
                break;
            }
#elif (!UNITY_STANDALONE)
            supported = false;
#else
#endif
            if (supported)
            {
                Action <SocialProvider> onSuccessLink = _ => RefreshState();
                SdkLoginLogic.Instance.LinkSocialProvider(provider, onSuccess: onSuccessLink, onError: StoreDemoPopup.ShowError);
            }
            else
            {
                StoreDemoPopup.ShowError(new Error(errorMessage: "Social account linking is not supported for this platform"));
            }
        }
コード例 #4
0
        private void DeletePicture()
        {
            bool?isPictureDeleted = null;

            ShowWaiting(() => isPictureDeleted == null);

            var token = Token.Instance;

            SdkLoginLogic.Instance.DeleteUserPicture(token,
                                                     onSuccess: () =>
            {
                SetPictureUrlToInfo(null,
                                    onSuccess: () =>
                {
                    isPictureDeleted = true;
                    RefreshImageLoaders();
                },
                                    onError: () => isPictureDeleted = false);
            },
                                                     onError: error =>
            {
                isPictureDeleted = false;
                StoreDemoPopup.ShowError(error);
            });
        }
コード例 #5
0
        public void ConsumeInventoryItem(InventoryItemModel item, int count = 1, Action <InventoryItemModel> onSuccess = null, Action <Error> onError = null,
                                         bool isConfirmationRequired        = true)
        {
            var onConfirmation = new Action(() =>
            {
                var isFinished = false;
                PopupFactory.Instance.CreateWaiting().SetCloseCondition(() => isFinished);

                SdkInventoryLogic.Instance.ConsumeInventoryItem(item, count,
                                                                onSuccess: consumedItem =>
                {
                    isFinished = true;
                    onSuccess?.Invoke(consumedItem);
                },
                                                                onError: error =>
                {
                    isFinished = true;
                    StoreDemoPopup.ShowError(error);
                    onError?.Invoke(error);
                });
            });

            if (isConfirmationRequired)
            {
                StoreDemoPopup.ShowConsumeConfirmation(item.Name, (uint)count, onConfirmation, () => onError?.Invoke(null));
            }
            else
            {
                onConfirmation?.Invoke();
            }
        }
コード例 #6
0
 private Action <Error> OnInventoryError(Action <Error> onError)
 {
     return(error =>
     {
         StoreDemoPopup.ShowError(error);
         onError?.Invoke(error);
     });
 }
コード例 #7
0
 private void LinkingAccountHandler(LinkingResultContainer linkingResult)
 {
     SdkLoginLogic.Instance.SignInConsoleAccount(
         userId: XsollaSettings.UsernameFromConsolePlatform,
         platform: XsollaSettings.Platform.GetString(),
         successCase: newToken => OnSuccessConsoleLogin(newToken, linkingResult),
         failedCase: error => { linkingResult.IsLinked = false; StoreDemoPopup.ShowError(error); }
         );
 }
コード例 #8
0
 public void RaiseOnError(Error error)
 {
     if (error.ErrorType == ErrorType.InvalidAuthorizationCode)
     {
         StoreDemoPopup.ShowError(error);
     }
     else
     {
         StoreDemoPopup.ShowError(error, CloseWidget);
     }
 }
コード例 #9
0
        private void ShowInvalidValue(UserProfileEntryType entryType, string value)
        {
            if (value.Length > POPUP_VALUE_LIMIT)
            {
                value = $"{value.Substring(0, POPUP_VALUE_LIMIT)}...";
            }

            var errorMessage = $"Incorrect new value for {entryType}: '{value}'";
            var error        = new Error(ErrorType.InvalidData, errorMessage: errorMessage);

            StoreDemoPopup.ShowError(error);
        }
コード例 #10
0
        private void GetAccountLinkButtonEnable()
        {
            accountLinkingButton.gameObject.SetActive(false);
            getAccountLinkButton.gameObject.SetActive(true);

            getAccountLinkButton.onClick += () =>
            {
                SdkLoginLogic.Instance.RequestLinkingCode(
                    code => StoreDemoPopup.ShowSuccess($"YOUR CODE: {code.code}"),
                    StoreDemoPopup.ShowError);
            };
        }
コード例 #11
0
 private void HandleFriendsButton()
 {
     UserFriends.Instance.UpdateFriends(
         onSuccess: () =>
     {
         SetMenuState(MenuState.Friends, () => UserFriends.Instance.IsUpdated);
     },
         onError: error =>
     {
         StoreDemoPopup.ShowError(error);
         DemoController.Instance.SetState(MenuState.Authorization);
     });
 }
コード例 #12
0
        private void Awake()
        {
            UserProfileEntryUI.UserEntryEdited += OnUserEntryEdited;

            _commonErrorCallback = error =>
            {
                _isProfileUpdated = false;
                Debug.LogError(error.errorMessage);
                StoreDemoPopup.ShowError(error);
            };

            _commonWaitCondition = () => _isProfileUpdated == null;
        }
コード例 #13
0
        private void TryUpTheLevel()
        {
            var userCurrency = UserInventory.Instance.Balance?.Find(currency => _targetCurrency.Sku == currency.Sku);

            if (userCurrency == null)
            {
                Debug.Log("UserInventory does not contain required currency");
                return;
            }

            if (userCurrency.Amount >= LevelUpPrice)
            {
                var levelUpPayment = new InventoryItemModel()
                {
                    Name = _targetCurrency.Name,
                    Sku  = _targetCurrency.Sku,
                };

                Action onSuccessConsume = () =>
                {
                    _characterLevel++;
                    SaveLevel(_characterLevelEntry, _characterLevel);
                    ShowLevel(_characterLevel);

                    if (UserInventory.IsExist)
                    {
                        UserInventory.Instance.Refresh(onError: StoreDemoPopup.ShowError);
                    }
                };

                if (DemoMarker.IsInventoryPartAvailable)
                {
                    DemoInventory.Instance.ConsumeInventoryItem(
                        levelUpPayment,
                        (int)LevelUpPrice,
                        onSuccess: _ => onSuccessConsume.Invoke(),
                        onError: _ => Debug.Log("Could not consume virtual currency"));
                }
                else
                {
                    Debug.LogError("Character level up supposed to be hidden in case InventoryDemo was not provided");
                }
            }
            else
            {
                var errorMessage = "Not enough currency amount to up the level";
                Debug.Log(errorMessage);
                StoreDemoPopup.ShowWarning(new Error(errorMessage: errorMessage));
            }
        }
コード例 #14
0
        private void RefreshInventory()
        {
            var isDone = false;

            PopupFactory.Instance.CreateWaiting().SetCloseCondition(() => isDone);

            UserInventory.Instance.Refresh(
                () => isDone = true,
                error =>
            {
                isDone = true;
                StoreDemoPopup.ShowError(error);
            }
                );
        }
コード例 #15
0
        private void SetPictureUrlToInfo(string pictureUrl, Action onSuccess = null, Action onError = null)
        {
            var token = Token.Instance;

            SdkLoginLogic.Instance.GetUserInfo(token,
                                               onSuccess: info =>
            {
                info.picture = pictureUrl;
                onSuccess?.Invoke();
            },
                                               onError: error =>
            {
                StoreDemoPopup.ShowError(error);
                onError?.Invoke();
            });
        }
コード例 #16
0
        partial void UpdateInventory()
        {
            if (!UserInventory.IsExist)
            {
                UserInventory.Instance.Init();
            }

            if (!DemoMarker.IsStorePartAvailable)
            {
                UserCatalog.Instance.Init();
                UserCatalog.Instance.UpdateItems(
                    onSuccess: () => UserInventory.Instance.Refresh(onError: StoreDemoPopup.ShowError),
                    onError: error =>
                {
                    Debug.LogError($"InventorySDK init failure: {error}");
                    StoreDemoPopup.ShowError(error);
                });
            }
        }
コード例 #17
0
        private IEnumerator ResetPassword()
        {
            bool?isInfoObtained = null;

            string email = null;

            var token = Token.Instance;

            SdkLoginLogic.Instance.GetUserInfo(token,
                                               onSuccess: info =>
            {
                email          = info.email;
                isInfoObtained = true;
            },
                                               onError: error =>
            {
                StoreDemoPopup.ShowError(error);
                isInfoObtained = false;
            });

            yield return(new WaitWhile(() => isInfoObtained == null));

            if (isInfoObtained == false)
            {
                yield break;
            }

            Action onSuccessfulPasswordChange = () =>
            {
                Debug.Log("Password reset request success");
                var message = MESSAGE_TEMPLATE.Replace("{[email protected]}", email);
                PopupFactory.Instance.CreateSuccessPasswordReset().SetMessage(message);
            };

            Action <Error> onFailedPasswordChange = error =>
            {
                StoreDemoPopup.ShowError(error);
            };

            SdkLoginLogic.Instance.ResetPassword(email, onSuccessfulPasswordChange, onFailedPasswordChange);
        }
コード例 #18
0
        private void LinkingButtonEnable()
        {
            getAccountLinkButton.gameObject.SetActive(false);
            accountLinkingButton.gameObject.SetActive(true);

            accountLinkingButton.onClick += () =>
            {
                ShowCodeConfirmation(code =>
                {
                    var linkingResult = new LinkingResultContainer();
                    PopupFactory.Instance.CreateWaiting().SetCloseCondition(() => linkingResult.IsLinked != null);

                    SdkLoginLogic.Instance.LinkConsoleAccount(
                        userId: XsollaSettings.UsernameFromConsolePlatform,
                        platform: XsollaSettings.Platform.GetString(),
                        confirmationCode: code,
                        onSuccess: () => LinkingAccountHandler(linkingResult),
                        onError: error => { linkingResult.IsLinked = false; StoreDemoPopup.ShowError(error); });
                });
            };
        }
コード例 #19
0
        private void SetNickname(string newNickname)
        {
            var isNicknameUpdateInProgress = true;

            ShowWaiting(() => isNicknameUpdateInProgress);

            var token      = Token.Instance;
            var updatePack = new UserInfoUpdate()
            {
                nickname = newNickname
            };

            SdkLoginLogic.Instance.UpdateUserInfo(token, updatePack,
                                                  onSuccess: _ => isNicknameUpdateInProgress = false,
                                                  onError: error =>
            {
                Debug.LogError("Could not update user info");
                isNicknameUpdateInProgress = false;
                StoreDemoPopup.ShowError(error);
            });
        }
コード例 #20
0
        private void UploadPicture(Sprite sprite)
        {
            bool?isImageUploaded = null;

            ShowWaiting(() => isImageUploaded == null);

            byte[] data = ConvertToData(sprite, out string boundary);

            var token = Token.Instance;

            SdkLoginLogic.Instance.UploadUserPicture(token, data, boundary,
                                                     onSuccess: imageInfo =>
            {
                var packedInfo = ParseUtils.FromJson <UserImageUpload>(imageInfo);

                if (packedInfo != null)
                {
                    var pictureUrl = packedInfo.picture;
                    SetPictureUrlToInfo(pictureUrl,
                                        onSuccess: () =>
                    {
                        ImageLoader.Instance.AddImage(pictureUrl, sprite);
                        RefreshImageLoaders();
                        isImageUploaded = true;
                    },
                                        onError: () => isImageUploaded = false);
                }
                else
                {
                    Debug.LogError($"Could not parse server response: {imageInfo}");
                }
            },
                                                     onError: error =>
            {
                isImageUploaded = false;
                StoreDemoPopup.ShowError(error);
            });
        }
コード例 #21
0
        public void RedeemCouponCode(string couponCode, Action <List <CouponRedeemedItemModel> > onSuccess, Action <Error> onError)
        {
            var isFinished = false;

            PopupFactory.Instance.CreateWaiting().SetCloseCondition(() => isFinished);

            SdkInventoryLogic.Instance.RedeemCouponCode(couponCode,
                                                        onSuccess: redeemedItems =>
            {
                isFinished = true;
                onSuccess?.Invoke(redeemedItems);
            },
                                                        onError: error =>
            {
                isFinished = true;

                if (error.ErrorType != ErrorType.InvalidCoupon)
                {
                    StoreDemoPopup.ShowError(error);
                }

                onError?.Invoke(error);
            });
        }
コード例 #22
0
 private void OnTimerEnd()
 {
     StoreDemoPopup.ShowWarning(
         error: new Error(errorMessage: "Code expired"),
         buttonCallback: OnResendButton);
 }
コード例 #23
0
        private void ApplyNewToken(string newToken, LinkingResultContainer linkingResult)
        {
            Token.Instance = Token.Create(newToken);

            if (!DemoMarker.IsInventoryPartAvailable)
            {
                FindObjectOfType <UserInfoDrawer>()?.Refresh();
            }
            else
            {
                UserInventory.Instance.Refresh(onSuccess: () => GoToInventory(linkingResult), onError: error => { linkingResult.IsLinked = false; StoreDemoPopup.ShowError(error); });
            }
        }