Esempio n. 1
0
    /// <summary>
    /// Start a zarinpal purchase
    /// </summary>
    /// <param name="amount">your product/service price in toman</param>
    /// <param name="desc">payment description.please note it can not be null or empty</param>
    /// <param name="productID">the id of product you are purchasing</param>
    public static void Purchase(long amount, string desc, string productID = "na")
    {
        if (amount < 100)
        {
            var message = "Purchase is not valid.Amount can not be less than 100 toman.";
            OnPurchaseFailedToStart(message);
            ZarinpalLog.LogError(message);
            return;
        }

        if (string.IsNullOrEmpty(desc))
        {
            var message = "Purchase is not valid.Description can not be null or empty .Please provide a valid description";
            OnPurchaseFailedToStart(message);
            ZarinpalLog.LogError(message);
            return;
        }

        if (_platform == null || !_platform.IsInitialized)
        {
            var message = "Purchase is not valid.Platform is not supported or is not initialized yet.Please Call initialize first";
            OnPurchaseFailedToStart(message);
            ZarinpalLog.LogError(message);
            return;
        }

        if (string.IsNullOrEmpty(productID))
        {
            productID = "unknown product";
        }

        _platform.Purchase(amount, desc, productID);
    }
    public void InitializePurchase()
    {
        zarinpalJavaClass = new AndroidJavaClass("com.kingcodestudio.unityzarinpaliab.ZarinpalUnityFragment");
        zarinpalJavaClass.CallStatic("start", gameObject.name);
        mZarinpalJavaObject = zarinpalJavaClass.GetStatic <AndroidJavaObject>("instance");



        m_text.text = "plugin initialized ";
        ZarinpalLog.Log("plugin initialized");
    }
 private void Log(string log, params object[] args)
 {
     ZarinpalLog.Log(string.Format(log, args));
 }
 private void Log(string log)
 {
     ZarinpalLog.Log(log);
 }
Esempio n. 5
0
    /// <summary>
    /// Initialize Zarinpal . Call this once is start up of your game.
    /// </summary>
    public static void Initialize()
    {
        if (_platform != null)
        {
            if (Initialized)
            {
                var message = "Zarinpal is already initialized.Please make sure you call 'Initialize' once.";
                OnStoreInitializeFailed(message);
                ZarinpalLog.LogWarning(message);
            }
            else
            {
                var message = "Platform has been created but not initialized . There may be an error. Please see logs for more details";
                OnStoreInitializeFailed(message);
                ZarinpalLog.LogError(message);
            }
            return;
        }

#if UNITY_EDITOR
        _platform = new ZarinpalEditor();
#elif UNITY_IOS
        _platform = ZarinpaliOS.CreateInstance();
#elif UNITY_ANDROID
        _platform = ZarinpalAndroid.CreateInstance();
#endif

        //Subscribing events
        _platform.StoreInitialized           += OnStoreInitialized;
        _platform.PurchaseStarted            += OnPurchaseStarted;
        _platform.PurchaseFailedToStart      += OnPurchaseFailedToStart;
        _platform.PurchaseSucceed            += OnPurchaseSucceed;
        _platform.PurchaseFailed             += OnPurchaseFailed;
        _platform.PurchaseCanceled           += OnPurchaseCanceled;
        _platform.PaymentVerificationStarted += OnPaymentVerificationStarted;
        _platform.PaymentVerificationSucceed += OnPaymentVerificationSucceed;
        _platform.PaymentVerificationFailed  += OnPaymentVerificationFailed;


        if (Initialized)
        {
            var message = "Zarinpal is already initialized.Please make sure you call 'Initialize' once.";
            OnStoreInitializeFailed(message);
            ZarinpalLog.LogWarning(message);
            return;
        }

        var setting = Resources.Load <ZarinpalConfig>("ZarinpalSetting");

        if (setting == null)
        {
            var message =
                "Could not find zarinpal config file.Make sure you have setup zarinpal setting in Zarinpal/Setting";
            OnStoreInitializeFailed(message);
            ZarinpalLog.LogWarning(message);
            return;
        }

        if (string.IsNullOrEmpty(setting.MerchantID) || setting.MerchantID == "MY_ZARINPAL_MERCHANT_ID")
        {
            var message = "Invalid MerchantID.Please go to menu : Zarinpal/Setting to set a valid merchant id";
            OnStoreInitializeFailed(message);
            ZarinpalLog.LogWarning(message);
            return;
        }

        var scheme = setting.Scheme;
        var host   = setting.Host;

#if !UNITY_EDITOR && UNITY_ANDROID
        if (string.IsNullOrEmpty(setting.Scheme) || string.IsNullOrEmpty(setting.Host) ||
            setting.Scheme == "MY_SCHEME" || setting.Host == "MY_HOST")
        {
            var message = "Scheme or Host Can not be null or Empty.Please go to menu : Zarinpal/Setting to set a valid Scheme and Host";
            OnStoreInitializeFailed(message);
            ZarinpalLog.LogWarning(message);
            return;
        }
#else
        scheme = string.Empty;
        host   = string.Empty;
#endif

        if (_platform == null)
        {
            var message = "Platform is not supported";
            OnStoreInitializeFailed(message);
            ZarinpalLog.LogError(message);
            return;
        }

        _platform.Initialize(setting.MerchantID, setting.AutoVerifyPurchase, string.Format("{0}://{1}", scheme, host));
    }
 public void OnPaymentVerificationFailed()
 {
     m_text.text = "payment verification failed ";
     ZarinpalLog.Log("payment verification failed");
 }
 public void OnPaymentVerificationSucceed(string refID)
 {
     m_text.text = "payment verification succeed refid :" + refID;
     ZarinpalLog.Log("payment verification succeed refid :" + refID);
 }
 public void OnPaymentProcessStarted()
 {
     m_text.text = "payment process started ";
     ZarinpalLog.Log("payment process started");
 }
 public void OnErrorOnPaymentRequest(string error)
 {
     m_text.text = "an error occured in requesting for payment : " + error;
     ZarinpalLog.Log("an error occured in requesting for payment : " + error);
 }