protected void SaveCardButton_Click(object sender, EventArgs e) { int profileId = AlwaysConvert.ToInt(HiddenProfileId.Value); Label ProfileSuccessMessage = (Label)PageHelper.RecursiveFindControl(Page, "ProfileSuccessMessage"); Label ProfileErrorMessage = (Label)PageHelper.RecursiveFindControl(Page, "ProfileErrorMessage"); if (profileId > 0) { var profile = GatewayPaymentProfileDataSource.Load(profileId); if (profile != null) { int gatewayId = PaymentGatewayDataSource.GetPaymentGatewayIdByClassId(profile.GatewayIdentifier); PaymentGateway gateway = PaymentGatewayDataSource.Load(gatewayId); if (gateway != null) { var provider = gateway.GetInstance(); try { AccountDataDictionary cardDetails = new AccountDataDictionary(); cardDetails["AccountNumber"] = "XXX" + profile.ReferenceNumber.Replace("x", "X"); cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value; cardDetails["ExpirationYear"] = ExpirationYear.SelectedItem.Value; cardDetails["SecurityCode"] = SecurityCode.Text.Trim(); PaymentMethod method = PaymentMethodDataSource.Load(profile.InstrumentTypeId); PaymentInstrumentData instr = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null); var rsp = provider.DoUpdatePaymentProfile(new CommerceBuilder.Payments.Providers.UpdatePaymentProfileRequest(AbleContext.Current.User, instr, profile.CustomerProfileId, profile.PaymentProfileId)); if (rsp.Successful || rsp.ResponseCode == "E00040") { int id = profile.Id; profile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1)); profile.Save(); if (ProfileSuccessMessage != null) { ProfileSuccessMessage.Text = string.Format("Profile '{0} ending in {1}' updated successfully!", profile.InstrumentType, profile.ReferenceNumber); ProfileSuccessMessage.Visible = true; ProfileErrorMessage.Visible = false; } } else { if (ProfileErrorMessage != null) { ProfileErrorMessage.Text = string.Format("Somthing went wrong! Unable to update profile '{0} ending in {1}'", profile.InstrumentType, profile.ReferenceNumber); ProfileSuccessMessage.Visible = false; ProfileErrorMessage.Visible = true; } Logger.Error(rsp.ResponseMessage); } } catch (Exception exp) { Logger.Error(exp.Message); } } } } EditCardInfoPopUp.Hide(); }
void control_OnEditCardInfo(object sender, CardInfoDetailEventArgs e) { GatewayPaymentProfile profile = GatewayPaymentProfileDataSource.Load(e.ProfileId); if (profile != null) { HiddenProfileId.Value = profile.Id.ToString(); NameOnCardLabel.Text = string.Format("{0}", profile.NameOnCard); ReferenceLabel.Text = string.Format("Profile {0} ending in {1}", profile.InstrumentType, profile.ReferenceNumber); string profileExpiry = profile.Expiry.ToString(); string[] dateParts = profileExpiry.Split('/'); string expiryMonth = (dateParts[0].Length == 1) ? "0" + dateParts[0] : dateParts[0]; string expiryDay = dateParts[1]; string expiryYear = dateParts[2].Substring(0, 4); ListItem selectedYear = ExpirationYear.Items.FindByValue(expiryYear); if (selectedYear != null) { ExpirationYear.ClearSelection(); selectedYear.Selected = true; } ListItem selectedMonth = ExpirationMonth.Items.FindByValue(expiryMonth); if (selectedMonth != null) { ExpirationMonth.ClearSelection(); selectedMonth.Selected = true; } EditCardInfoPopUp.Show(); } else { HiddenProfileId.Value = string.Empty; } }