Пример #1
0
        //--------------------------------------
        //  Private Methods
        //--------------------------------------

        private static void UnlockProducts(ISN_iSKPaymentTransaction transaction)
        {
            //At this point user already paid for content, so we need to provide it
            //Unless, we want to make sure that payment was legit, and nobody trying to hack us
            //In order to do it, we have to use server side verification, you can read more about it here:
            //https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1
            //
            //this step isn't required. Use it only if you want to make sure that payment is 100% legit
            //So far let's just print a Base64 receipt data

            //  Debug.Log("Receipt: " + ISN_SKPaymentQueue.AppStoreReceipt.AsBase64StringString);

            switch (transaction.ProductIdentifier)
            {
            case SMALL_PACK:
                //code for adding small game money amount here
                break;

            case NC_PACK:
                //code for unlocking cool item here
                break;
            }

            //After connect was provided to use we can finally finish the transaction
            ISN_SKPaymentQueue.FinishTransaction(transaction);
        }
Пример #2
0
 /// <summary>
 /// Completes a pending transaction.
 ///
 /// Your application should call this method from a transaction observer
 /// that received a notification from the payment queue.
 /// Calling <see cref="FinishTransaction"/> on a transaction removes it from the queue.
 /// Your application should call <see cref="FinishTransaction"/> only after
 /// it has successfully processed the transaction and unlocked the functionality purchased by the user.
 ///
 /// Calling <see cref="FinishTransaction"/> on a transaction that is in the Purchasing state throws an exception.
 /// </summary>
 /// <param name="transaction">transaction to finish</param>
 public static void FinishTransaction(ISN_iSKPaymentTransaction transaction)
 {
     Init(result =>
     {
         ISN_SKLib.API.FinishTransaction(transaction);
     });
 }
        public UM_IOSTransaction(ISN_iSKPaymentTransaction transaction)
        {
            m_id             = transaction.TransactionIdentifier;
            m_productId      = transaction.ProductIdentifier;
            m_unitxTimestamp = SA_Unix_Time.ToUnixTime(transaction.Date);

            switch (transaction.State)
            {
            case ISN_SKPaymentTransactionState.Deferred:
                m_state = UM_TransactionState.Deferred;
                break;

            case ISN_SKPaymentTransactionState.Failed:
                m_state = UM_TransactionState.Failed;
                break;

            case ISN_SKPaymentTransactionState.Restored:
                m_state = UM_TransactionState.Restored;
                break;

            case ISN_SKPaymentTransactionState.Purchased:
                m_state = UM_TransactionState.Purchased;
                break;
            }

            m_error = transaction.Error;

            m_iosTransaction = transaction;
        }
Пример #4
0
    //--------------------------------------
    //  ISN_TransactionObserver implementation
    //--------------------------------------

    public void OnTransactionUpdated(ISN_iSKPaymentTransaction transaction)
    {
        //Transactions have been updated.
        //Let's act accordingly
        Debug.Log("transaction JSON: " + JsonUtility.ToJson(transaction));

        Debug.Log("OnTransactionComplete: " + transaction.ProductIdentifier);
        Debug.Log("OnTransactionComplete: state: " + transaction.State);

        switch (transaction.State)
        {
        case ISN_SKPaymentTransactionState.Purchasing:
            //No actions is required here, we probably don't even have a ProductIdentifier
            //but we can use this callback to show preloader for example, since we know that user is currently
            //working on this transaction
            break;

        case ISN_SKPaymentTransactionState.Purchased:
        case ISN_SKPaymentTransactionState.Restored:
            //Our product has been successfully purchased or restored
            //So we need to provide content to our user depends on productIdentifier
            UnlockProducts(transaction);

            break;

        case ISN_SKPaymentTransactionState.Deferred:
            //iOS 8 introduces Ask to Buy, which lets parents approve any purchases initiated by children
            //You should update your UI to reflect this deferred state, and expect another Transaction Complete  to be called again with a new transaction state
            //reflecting the parent’s decision or after the transaction times out. Avoid blocking your UI or gameplay while waiting for the transaction to be updated.
            break;

        case ISN_SKPaymentTransactionState.Failed:
            //Our purchase flow is failed.
            //We can unlock interface and report user that the purchase is failed.
            Debug.Log("Transaction failed with error, code: " + transaction.Error.Code);
            Debug.Log("Transaction failed with error, description: " + transaction.Error.Message);

            //at this point we just need to finish the transaction
            ISN_SKPaymentQueue.FinishTransaction(transaction);
            break;
        }

        if (transaction.State == ISN_SKPaymentTransactionState.Failed)
        {
            Debug.Log("Error code: " + transaction.Error.Code + "\n" + "Error description:" + transaction.Error.Message);
        }
        else
        {
            Debug.Log("product " + transaction.ProductIdentifier + " state: " + transaction.State);
        }
    }
Пример #5
0
        //--------------------------------------
        //  ISN_TransactionObserver implementation
        //--------------------------------------

        public void OnTransactionUpdated(ISN_iSKPaymentTransaction transaction)
        {
            var um_transaction = new UM_IOSTransaction(transaction);

            switch (transaction.State)
            {
            case ISN_SKPaymentTransactionState.Purchasing:
                break;

            case ISN_SKPaymentTransactionState.Purchased:
            case ISN_SKPaymentTransactionState.Restored:
                UpdateTransaction(um_transaction);
                break;

            case ISN_SKPaymentTransactionState.Deferred:
                UpdateTransaction(um_transaction);
                break;

            case ISN_SKPaymentTransactionState.Failed:
                UpdateTransaction(um_transaction);
                break;
            }
        }
Пример #6
0
    //--------------------------------------
    //  Private Methods
    //--------------------------------------

    private static void UnlockProducts(ISN_iSKPaymentTransaction transaction)
    {
        //At this point user already paid for content, so we need to provide it
        //Unless, we want to make sure that payment was legit, and nobody trying to hack us
        //In order to do it, we have to use server side verification, you can read more about it here:
        //https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1
        //
        //this step isn't required. Use it only if you want to make sure that payment is 100% legit
        //So far let's just print a Base64 receipt data

        //  Debug.Log("Receipt: " + ISN_SKPaymentQueue.AppStoreReceipt.AsBase64StringString);
        string ProductId = transaction.ProductIdentifier;

        switch (ProductId)
        {
        case ITEM1:
            Main.CoinAdd(1000);
            //Consume(ProductId);
            Main.buy();
            break;

        case ITEM2:
            Main.CoinAdd(2200);
            // Consume(ProductId);
            Main.buy();
            break;

        case ITEM3:
            Main.CoinAdd(3600);
            // Consume(ProductId);
            Main.buy();
            break;

        case ITEM4:
            Main.CoinAdd(5200);
            // Consume(ProductId);
            Main.buy();
            break;

        case ITEM5:
            Main.CoinAdd(7000);
            //Consume(ProductId);
            Main.buy();
            break;

        case PAGE_1:
            PlayerPrefs.SetInt("page_1", 1);
            Application.LoadLevelAsync(1);
            break;

        case PAGE_2:
            PlayerPrefs.SetInt("page_2", 1);
            Application.LoadLevelAsync(1);
            break;

        case PAGE_3:
            PlayerPrefs.SetInt("page_3", 1);
            Application.LoadLevelAsync(1);
            break;

        case PAGE_4:
            PlayerPrefs.SetInt("page_4", 1);
            Application.LoadLevelAsync(1);
            break;

        default:
            Debug.LogError("Unknown product Id: " + ProductId);
            break;
        }

        //After connect was provided to use we can finally finish the transaction
        ISN_SKPaymentQueue.FinishTransaction(transaction);
    }
Пример #7
0
 public void OnTransactionRemoved(ISN_iSKPaymentTransaction result)
 {
     //Your application does not typically need to anything on this event,
     //but it may be used to update user interface to reflect that a transaction has been completed.
 }
Пример #8
0
 public void FinishTransaction(ISN_iSKPaymentTransaction transaction)
 {
                 #if API_ENABLED
     _ISN_FinishTransaction(transaction.TransactionIdentifier);
                 #endif
 }
Пример #9
0
 public void FinishTransaction(ISN_iSKPaymentTransaction transaction)
 {
     SA_Coroutine.WaitForSeconds(DelayTime, () => {
         m_transactionRemoved.Invoke(transaction);
     });
 }
 public void FinishTransaction(ISN_iSKPaymentTransaction transaction)
 {
                 #if ((UNITY_IPHONE || UNITY_TVOS) && STORE_KIT_API_ENABLED)
     _ISN_FinishTransaction(transaction.TransactionIdentifier);
                 #endif
 }