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