Exemplo n.º 1
0
		public void MakeRefund(Transfer transferToRefund, Guid duplicateGuid, int actionUsrK, decimal refundAmount)
		{
			// SecPay takes refund amount as positive
			refundAmount = Math.Abs(Math.Round(refundAmount, 2));
			// Copy all details from transferToRefund to the new transfer
			this.transfer = transferToRefund.RefundThisTransfer(refundAmount);
            
			this.transfer.ActionUsrK = actionUsrK;

			this.transfer.Guid = Guid.NewGuid();
			this.transfer.DuplicateGuid = duplicateGuid;

			this.transfer.AddNote("Refund for transfer #" + transferToRefund.K.ToString(), "SecPay");
			this.transfer.DateTimeCreated = DateTime.Now;

			try
			{
				if (!Vars.DevEnv)
				{
					response = secVpnService.refundCardFull(
											userName,
											password,
											transferToRefund.Guid.ToString(),			// DSI created SecPay Transaction Id as GUID
											refundAmount.ToString(MONEY_FORMAT),
											password,
											this.transfer.Guid.ToString());				// DSI created SecPay Transaction Id as GUID

					// Parse thru to see if it was successful
					ResponseParser();
				}
				else
				{
					this.transfer.Status = Transfer.StatusEnum.Success;
				}
				this.transfer.DateTimeComplete = this.transfer.DateTimeCreated;

				this.transfer.Update();

				if (this.transfer.Status.Equals(Transfer.StatusEnum.Success))
				{
					try
					{
						Utilities.EmailTransfer(transfer, true, true);
					}
					catch (Exception ex)
					{
						EmailSecPayException(ex);
					}
				}
			}
			catch (Exception ex)
			{
				EmailSecPayException(ex);

				throw new DsiUserFriendlyException("SecPay Refund failed. See transfer #" + this.transfer.K + " for details");
			}
		}
Exemplo n.º 2
0
		protected void Page_Load(object sender, EventArgs e)
		{
			ContainerPage.SslPage = true;

			try
			{
				if (ViewState["TransferK"] != null && (int)ViewState["TransferK"] > 0)
					TransferK = (int)ViewState["TransferK"];
				else
				{
					if (ContainerPage.Url["K"].IsInt)
					{
						TransferK = Convert.ToInt32(ContainerPage.Url["K"].Value);
						ViewState["TransferK"] = TransferK;
					}
					else if (ContainerPage.Url["InvoiceK"].IsInt)
					{
						Invoice invoice = new Invoice(Convert.ToInt32(ContainerPage.Url["InvoiceK"].Value));
						this.InvoiceK = invoice.K;
						if (!this.IsPostBack)
							LoadScreenFromInvoice(invoice);
					}
					else if (ContainerPage.Url["TransferRefundK"].IsInt)
					{
						Transfer transferToRefund = new Transfer(Convert.ToInt32(ContainerPage.Url["TransferRefundK"].Value));

						decimal refundAmount = 0;
						if (!this.IsPostBack && !ContainerPage.Url["RefundAmount"].IsNull)
						{
							try { refundAmount = Convert.ToDecimal(ContainerPage.Url["RefundAmount"].Value) / 100m; }
							catch (Exception) { }
						}
						else if (this.AmountTextBox.Text.Length > 0 && Utilities.ConvertMoneyStringToDecimal(this.AmountTextBox.Text) != 0)
						{
							refundAmount = Utilities.ConvertMoneyStringToDecimal(this.AmountTextBox.Text);
						}
						currentTransfer = transferToRefund.RefundThisTransfer(refundAmount);
						// Dont set DateTimeCreated until it is saved
						currentTransfer.DateTimeCreated = DateTime.MinValue;
						loadRefundTransfer = true;
					}

					if (ContainerPage.Url["FailedTransferK"].IsInt)
					{
						Transfer failedTransfer = new Transfer(Convert.ToInt32(ContainerPage.Url["FailedTransferK"].Value));
						currentTransfer = failedTransfer.CopyThisTransfer();
						// Since we cant store card numbers and the SecPay transaction failed, then user must re-enter card number
						currentTransfer.Notes = failedTransfer.Notes;
						currentTransfer.CardNumberEnd = "";
						currentTransfer.Status = Transfer.StatusEnum.Pending;
						redoFailedTransfer = true;
					}
				}
				if (TransferK > 0)
				{
					try
					{
						currentTransfer = new Transfer(TransferK);
					}
					catch (Exception)
					{
						// TODO: add popup error message, then redirect
						Response.Redirect(Transfer.UrlAdminNewTransfer());
					}
				}
			}
			catch
			{
				// if no Transfer K, then assume we are creating a new Transfer
				TransferK = 0;
			}

			
			this.DownloadButton.Enabled = TransferK > 0;
			var currentTransferAmountRemaining = currentTransfer.AmountRemaining();
			this.CreateCampaignCreditsButton.Visible = currentTransfer.Method == Transfer.Methods.TicketSales && currentTransferAmountRemaining > 0;
			if (this.CreateCampaignCreditsButton.Visible)
			{
				int numberOfCredits = CampaignCredit.CalculateTotalCreditsForMoney(currentTransferAmountRemaining / (decimal)(1 + Invoice.VATRate(Invoice.VATCodes.T1, DateTime.Now)), 0.5, currentTransfer.Promoter);
				CreateCampaignCreditsButton.InnerHtml = "Buy " + numberOfCredits.ToString("N0") + " campaign credits";
			}
			if (!this.IsPostBack)
			{
				ViewState["DuplicateGuid"] = Guid.NewGuid();

				this.RefundAmountTextBox.Style["text-align"] = "right";

				NotesAddOnlyTextBox.ReadOnlyTextBox.CssClass = "readOnlyNotesTextBox";
				NotesAddOnlyTextBox.AddTextBox.CssClass = "addNotesTextBox";
				NotesAddOnlyTextBox.TimeStampFormat = "dd/MM/yy HH:mm";
				NotesAddOnlyTextBox.AuthorName = Usr.Current.NickName;
				NotesAddOnlyTextBox.InsertOption = AddOnlyTextBox.InsertOptions.AddAtBeginning;
				CreateCampaignCreditsButton.Attributes["onclick"] = "if(confirm('Are you sure you want to use ticket funds to buy campaign credits?')){__doPostBack('" + CreateCampaignCreditsButton.UniqueID + "','');return false;}else{return false;};";
                SetupTypeDropDownList();

                if (currentTransfer != null)
                    this.TypeDropDownList.SelectedValue = Convert.ToInt32(currentTransfer.Type).ToString();
                
                SetupMethodDropDownList();
				SetupCardTypeDropDownList();				

				if (currentTransfer.K > 0 || loadRefundTransfer == true || redoFailedTransfer == true)
				{
					// Setup screen rules for updating transfer only
					LoadScreenFromTransfer();

					//if(loadRefundTransfer == true)
					//    SetupStatusDropDownList();
				}
				else
				{
					SetupStatusDropDownList();
					this.TransferKValueLabel.Visible = false;
					this.TransferKLabel.Visible = false;
					// Setup screen for new transfer data input
					this.CreatedDateTextBox.Text = DateTime.Now.ToShortDateString();
					if (Usr.Current != null)
					{
						this.uiActionUserAutoComplete.Value = Usr.Current.K.ToString();
						this.uiActionUserAutoComplete.Text = Usr.Current.Name;
						this.ActionUserValueLabel.Text = Usr.Current.Link();
					}
				}

				ShowHidePanels();
			}

			SetBankDetailValidators();
		}