/// <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); }
/// <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)); }