/// <summary> /// Returns boolean indicating whether payment has been accepted by zarinpal /// </summary> /// <param name="authority">36digit long code</param> /// <param name="status">status code</param> /// <returns>true - accepted; false - not accepted.</returns> public bool VerifyPayment(string authority, string status) { try { var query = from or in _orderRepository.Table where or.AuthorizationTransactionCode == authority select or; _logger.InsertLog(LogLevel.Debug, "in verify1 :" + query.Count()); ZarinPalService.PaymentGatewayImplementationService zps = new ZarinPalService.PaymentGatewayImplementationService(); _logger.InsertLog(LogLevel.Debug, "in verify2 : merch code: " + _zarinPalPaymentSettings.MerchantCode + " %% authority code: " + authority + " %% order total: " + query.FirstOrDefault().OrderTotal); if (zps.PaymentVerification(_zarinPalPaymentSettings.MerchantCode, authority, Convert.ToInt32(query.FirstOrDefault().OrderTotal / 10), out long RefID).Equals(100)) { _logger.InsertLog(LogLevel.Debug, "in verify3"); query.FirstOrDefault().AuthorizationTransactionResult = RefID.ToString(); _logger.InsertLog(LogLevel.Debug, "in verify4"); _orderRepository.Update(query.FirstOrDefault()); _logger.InsertLog(LogLevel.Debug, "in verify5"); return(true); } else { _logger.InsertLog(LogLevel.Debug, "in verify: verification failed"); return(false); } } catch (Exception ex) { _logger.InsertLog(LogLevel.Debug, "in verify: " + ex.Message); return(false); } }
/// <summary> /// Post process payment (used by payment gateways that require redirecting to a third-party URL) /// </summary> /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param> public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest) { try { ZarinPalService.PaymentGatewayImplementationService zps = new ZarinPalService.PaymentGatewayImplementationService(); string ItemsDescription = ""; foreach (OrderItem item in postProcessPaymentRequest.Order.OrderItems) { ItemsDescription += item.Product.ShortDescription + "; "; } int result = zps.PaymentRequest(_zarinPalPaymentSettings.MerchantCode, Convert.ToInt32(postProcessPaymentRequest.Order.OrderTotal / 10), ItemsDescription, "", "", _zarinPalPaymentSettings.CallbackUrl, out string Authority); if (result == 100) // sussessful { if (Authority.Length.Equals(36)) { // ok to proceed // after getting the number check for duplicate in db in case of fraud var query = from or in _orderRepository.Table where or.AuthorizationTransactionCode == Authority select or; if (query.Count() > 0) { // THIS CODE EXISTS, H A L T O P E R A T I O N postProcessPaymentRequest.Order.PaymentStatus = PaymentStatus.Pending; return; } else { // NO PREVIOUS RECORD OF REFNUM, CLEAR TO PROCEED postProcessPaymentRequest.Order.AuthorizationTransactionCode = Authority; _orderRepository.Update(postProcessPaymentRequest.Order); var remotePostHelper = new RemotePost(); remotePostHelper.FormName = "form1"; remotePostHelper.Url = "https://www.zarinpal.com/pg/StartPay/" + Authority; //remotePostHelper.Add("RefId", strRefNum); remotePostHelper.Post(); } } } else { _logger.Error("int returned from initial request is: " + result.ToString()); postProcessPaymentRequest.Order.PaymentStatus = PaymentStatus.Pending; return; } //nothing } catch (Exception ex) { return; } }