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(); }
protected void UpdateButton_Click(object sender, EventArgs e) { if (Page.IsValid) { 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"] = _profile.ReferenceNumber.PadLeft(8, 'x').ToUpper(); cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedValue; cardDetails["ExpirationYear"] = ExpirationYear.SelectedValue; cardDetails["SecurityCode"] = SecurityCode.Text; PaymentInstrumentData instr = PaymentInstrumentData.CreateInstance(cardDetails, _profile.InstrumentType, null); var rsp = provider.DoUpdatePaymentProfile(new CommerceBuilder.Payments.Providers.UpdatePaymentProfileRequest(AbleContext.Current.User, instr, _profile.CustomerProfileId, _profile.PaymentProfileId)); if (rsp.Successful || rsp.ResponseCode == "E00040") { _profile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedValue), AlwaysConvert.ToInt(ExpirationMonth.SelectedValue), 1)); _profile.Save(); SuccessMessage.Text = string.Format(SuccessMessage.Text, LocaleHelper.LocalNow); SuccessMessage.Visible = true; } else { ErrorMessage.Visible = true; Logger.Error(rsp.ResponseMessage); } } catch (Exception exp) { Logger.Error(exp.Message); } } } }
protected void SaveCardButton_Click(object sender, EventArgs e) { if (Page.IsValid && CustomValidation()) { AccountDataDictionary cardDetails = new AccountDataDictionary(); cardDetails["AccountName"] = CardName.Text.Trim(); cardDetails["AccountNumber"] = CardNumber.Text.Trim(); cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value; cardDetails["ExpirationYear"] = ExpirationYear.SelectedItem.Value; cardDetails["SecurityCode"] = SecurityCode.Text.Trim(); PaymentMethod method = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue)); PaymentInstrumentData instr = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null); PaymentGateway gateway = method.PaymentGateway; if (gateway != null) { var provider = gateway.GetInstance(); string customerProfileId = string.Empty; var profileResult = _user.PaymentProfiles.Where(p => p.GatewayIdentifier == gateway.ClassId) .GroupBy(p => p.CustomerProfileId) .Take(1) .Select(g => new { CustomerProfileId = g.Key }) .SingleOrDefault(); if (profileResult != null && !string.IsNullOrEmpty(profileResult.CustomerProfileId)) customerProfileId = profileResult.CustomerProfileId; if (string.IsNullOrEmpty(customerProfileId)) { try { var rsp = provider.DoCreateCustomerProfile(new CommerceBuilder.Payments.Providers.CreateCustomerProfileRequest(_user)); if (rsp.Successful) customerProfileId = rsp.CustomerProfileId; else if (rsp.ResponseCode == "E00039") { var match = Regex.Match(rsp.ResponseMessage, @"\d+", RegexOptions.IgnoreCase); if(match.Success) customerProfileId = match.Value; else ErrorMessage.Text = rsp.ResponseMessage; } else ErrorMessage.Text = rsp.ResponseMessage; } catch(Exception exp) { ErrorMessage.Text = exp.Message; } if (string.IsNullOrEmpty(customerProfileId)) return; } try { var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_user, instr, customerProfileId) { ValidateProfile = true }); if (rsp.Successful) { GatewayPaymentProfile gwprofile = new GatewayPaymentProfile(); gwprofile.NameOnCard = CardName.Text.Trim(); ; gwprofile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1)); gwprofile.CustomerProfileId = customerProfileId; gwprofile.PaymentProfileId = rsp.PaymentProfileId; gwprofile.ReferenceNumber = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]); gwprofile.User = _user; gwprofile.InstrumentType = instr.InstrumentType; gwprofile.PaymentMethodName = method.Name; gwprofile.GatewayIdentifier = gateway.ClassId; gwprofile.Save(); if (_user.PaymentProfiles.Count == 0) { _user.Settings.DefaultPaymentProfileId = gwprofile.Id; _user.Settings.Save(); } CardName.Text = string.Empty; CardNumber.Text = string.Empty; ExpirationMonth.SelectedIndex = 0; ExpirationYear.SelectedIndex = 0; BindCards(); } else { ErrorMessage.Text = rsp.ResponseMessage; Logger.Error(rsp.ResponseMessage); } } catch (Exception exp) { ErrorMessage.Text = exp.Message; } } } }
protected void SaveCardButton_Click(Object sender, EventArgs e) { if (Page.IsValid) { GatewayPaymentProfile profile = _Subscription.PaymentProfile; if (profile != null) { AccountDataDictionary cardDetails = new AccountDataDictionary(); cardDetails["AccountName"] = CardName.Text.Trim(); cardDetails["AccountNumber"] = CardNumber.Text.Trim(); cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value; cardDetails["ExpirationYear"] = ExpirationYear.SelectedItem.Value; cardDetails["SecurityCode"] = SecurityCode.Text.Trim(); PaymentMethod method = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue)); PaymentInstrumentData instr = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null); int gatewayId = PaymentGatewayDataSource.GetPaymentGatewayIdByClassId(_Subscription.PaymentProfile.GatewayIdentifier); PaymentGateway gateway = PaymentGatewayDataSource.Load(gatewayId); if (gateway != null) { var provider = gateway.GetInstance(); try { var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_Subscription.User, instr, profile.CustomerProfileId) { ValidateProfile = true }); if (rsp.Successful) { GatewayPaymentProfile gwprofile = new GatewayPaymentProfile(); gwprofile.NameOnCard = CardName.Text.Trim();; gwprofile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1)); gwprofile.CustomerProfileId = profile.CustomerProfileId; gwprofile.PaymentProfileId = rsp.PaymentProfileId; gwprofile.ReferenceNumber = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]); gwprofile.User = _Subscription.User; gwprofile.InstrumentType = instr.InstrumentType; gwprofile.GatewayIdentifier = profile.GatewayIdentifier; gwprofile.Save(); BindPayments(gwprofile.Id); CardName.Text = string.Empty; CardNumber.Text = string.Empty; ExpirationMonth.SelectedIndex = 0; ExpirationYear.SelectedIndex = 0; AddCardPopup.Hide(); } else { ErrorMessage.Text = rsp.ResponseMessage; AddCardPopup.Show(); } } catch (Exception exp) { Logger.Error(exp.Message); ErrorMessage.Text = exp.Message; AddCardPopup.Show(); } } BindPayments(profile.Id); } } else { AddCardPopup.Show(); } }
protected GatewayPaymentProfile CreateProfile(AccountDataDictionary cardDetails) { PaymentMethod method = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue)); PaymentGateway gateway = method.PaymentGateway; PaymentInstrumentData instr = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null); GatewayPaymentProfile profile = null; if (gateway != null) { var provider = gateway.GetInstance(); string customerProfileId = string.Empty; var profileResult = _user.PaymentProfiles.Where(p => p.GatewayIdentifier == gateway.ClassId) .GroupBy(p => p.CustomerProfileId) .Take(1) .Select(g => new { CustomerProfileId = g.Key }) .SingleOrDefault(); if (profileResult != null && !string.IsNullOrEmpty(profileResult.CustomerProfileId)) { customerProfileId = profileResult.CustomerProfileId; } if (string.IsNullOrEmpty(customerProfileId)) { try { var rsp = provider.DoCreateCustomerProfile(new CommerceBuilder.Payments.Providers.CreateCustomerProfileRequest(_user)); if (rsp.Successful) { customerProfileId = rsp.CustomerProfileId; } else if (rsp.ResponseCode == "E00039") { var match = Regex.Match(rsp.ResponseMessage, @"\d+", RegexOptions.CultureInvariant); if (match.Success) { customerProfileId = match.Value; } else { Logger.Error(rsp.ResponseMessage); } } else { Logger.Error(rsp.ResponseMessage); } } catch (Exception exp) { Logger.Error(exp.Message); } } try { var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_user, instr, customerProfileId) { ValidateProfile = true }); if (rsp.Successful) { GatewayPaymentProfile gwprofile = new GatewayPaymentProfile(); gwprofile.NameOnCard = CardName.Text.Trim();; gwprofile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1)); gwprofile.CustomerProfileId = customerProfileId; gwprofile.PaymentProfileId = rsp.PaymentProfileId; gwprofile.ReferenceNumber = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]); gwprofile.User = _user; gwprofile.InstrumentType = instr.InstrumentType; gwprofile.PaymentMethodName = method.Name; gwprofile.GatewayIdentifier = gateway.ClassId; gwprofile.Save(); CardName.Text = string.Empty; CardNumber.Text = string.Empty; ExpirationMonth.SelectedIndex = 0; ExpirationYear.SelectedIndex = 0; profile = gwprofile; } } catch (Exception exp) { Logger.Error(exp.Message); } } return(profile); }
public void OnSuccess(TransactionResult result) { // Get information about the approved transaction TransactionType transType = result.TransactionType; decimal transAmount = result.AuthorizedAmount; decimal cashbackAmount = result.CashbackAmount; decimal tipAmount = result.TipAmount; TransactionId ecrTransId = result.EcrTransactionId; TransactionId terminalTransId = result.TerminalTransactionId; string approvalCode = result.ApprovalCode; PaymentInstrumentData instrumentData = result.PaymentInstrumentData; PaymentInstrumentType?instrumentType = instrumentData?.PaymentInstrumentType; if (instrumentType == PaymentInstrumentType.Card) { CardData cardData = instrumentData.CardData; EntryModeType entryMode = cardData.EntryMode; string paymentBrand = cardData.PaymentBrand; string maskedPan = cardData.MaskedPan; } else if (instrumentType == PaymentInstrumentType.AlternativePayment) { AlternativePaymentData alternativePaymentData = instrumentData.AlternativePaymentData; string alternativePaymentBrand = alternativePaymentData.AlternativePaymentBrand; EntryModeType entryMode = alternativePaymentData.EntryMode; TransactionId providerTransactionId = alternativePaymentData.ProviderTransactionId; } List <Receipt> receipts = result.Receipts; foreach (Receipt receipt in receipts) { DocumentType documentType = receipt.DocumentType; bool? signatureRequired = receipt.SignatureRequired; ReceiptContent receiptContent = receipt.Content; if (receiptContent.Format == ReceiptFormatType.Text) { ContentText contentText = receiptContent.Text; string plainTextReceipt = contentText.PlainText; } } List <Token> tokens = result.Tokens; foreach (Token token in tokens) { TokenType tokenType = token.Type; string tokenValue = token.Value; DateTime? tokenExpiry = token.Expiry; string tokenSchemeId = token.SchemeId; EnrolmentStatusType?enrolmentStatusType = token.EnrolmentStatus; } // TokenResponses give info about the result of token lookups and // provides an alternative way to get the token when the lookup was successful. List <TokenResponse> tokenResponses = result.TokenResponses; foreach (TokenResponse tokenResponse in tokenResponses) { TokenRequest tokenRequest = tokenResponse.TokenRequest; string tokenSchemeId = tokenRequest.SchemeId; if (tokenResponse.Result == TokenResultType.Success) { Token token = tokenResponse.Token; } else { TokenFailureErrorType?tokenErrorType = tokenResponse.Error; string tokenErrorDescription = tokenResponse.AdditionalReason; } } }
protected void CreditCardButton_Click(object sender, EventArgs e) { if (Page.IsValid && CustomValidation()) { // CREATE THE PAYMENT OBJECT Payment payment = GetPayment(); // PROCESS CHECKING OUT EVENT bool checkOut = true; if (CheckingOut != null) { CheckingOutEventArgs c = new CheckingOutEventArgs(payment); CheckingOut(this, c); checkOut = !c.Cancel; } if (checkOut) { // CONTINUE TO PROCESS THE CHECKOUT Basket basket = AbleContext.Current.User.Basket; ICheckoutService checkoutService = AbleContext.Resolve <ICheckoutService>(); CheckoutRequest checkoutRequest = new CheckoutRequest(basket, payment); CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest); if (checkoutResponse.Success) { if (trSaveCard.Visible && SaveCard.Checked) { AccountDataDictionary cardDetails = new AccountDataDictionary(); cardDetails["AccountName"] = CardName.Text.Trim(); cardDetails["AccountNumber"] = CardNumber.Text.Trim(); cardDetails["ExpirationMonth"] = ExpirationMonth.SelectedItem.Value; cardDetails["ExpirationYear"] = ExpirationYear.SelectedItem.Value; cardDetails["SecurityCode"] = SecurityCode.Text.Trim(); PaymentMethod method = PaymentMethodDataSource.Load(AlwaysConvert.ToInt(CardType.SelectedValue)); PaymentGateway gateway = method.PaymentGateway; PaymentInstrumentData instr = PaymentInstrumentData.CreateInstance(cardDetails, method.PaymentInstrumentType, null); if (gateway != null) { var provider = gateway.GetInstance(); string customerProfileId = string.Empty; var profileResult = _user.PaymentProfiles.Where(p => p.GatewayIdentifier == gateway.ClassId) .GroupBy(p => p.CustomerProfileId) .Take(1) .Select(g => new { CustomerProfileId = g.Key }) .SingleOrDefault(); if (profileResult != null && !string.IsNullOrEmpty(profileResult.CustomerProfileId)) { customerProfileId = profileResult.CustomerProfileId; } if (string.IsNullOrEmpty(customerProfileId)) { try { var rsp = provider.DoCreateCustomerProfile(new CommerceBuilder.Payments.Providers.CreateCustomerProfileRequest(_user)); if (rsp.Successful) { customerProfileId = rsp.CustomerProfileId; } else if (rsp.ResponseCode == "E00039") { var match = Regex.Match(rsp.ResponseMessage, @"\d+", RegexOptions.CultureInvariant); if (match.Success) { customerProfileId = match.Value; } else { Logger.Error(rsp.ResponseMessage); } } else { Logger.Error(rsp.ResponseMessage); } } catch (Exception exp) { Logger.Error(exp.Message); } } try { var rsp = provider.DoCreatePaymentProfile(new CommerceBuilder.Payments.Providers.CreatePaymentProfileRequest(_user, instr, customerProfileId) { ValidateProfile = true }); if (rsp.Successful) { GatewayPaymentProfile gwprofile = new GatewayPaymentProfile(); gwprofile.NameOnCard = CardName.Text.Trim();; gwprofile.Expiry = Misc.GetStartOfDate(new DateTime(AlwaysConvert.ToInt(ExpirationYear.SelectedItem.Value), AlwaysConvert.ToInt(ExpirationMonth.SelectedItem.Value), 1)); gwprofile.CustomerProfileId = customerProfileId; gwprofile.PaymentProfileId = rsp.PaymentProfileId; gwprofile.ReferenceNumber = StringHelper.MakeReferenceNumber(cardDetails["AccountNumber"]); gwprofile.User = _user; gwprofile.InstrumentType = instr.InstrumentType; gwprofile.PaymentMethodName = method.Name; gwprofile.GatewayIdentifier = gateway.ClassId; gwprofile.Save(); CardName.Text = string.Empty; CardNumber.Text = string.Empty; ExpirationMonth.SelectedIndex = 0; ExpirationYear.SelectedIndex = 0; } } catch (Exception exp) { Logger.Error(exp.Message); } } } if (CheckedOut != null) { CheckedOut(this, new CheckedOutEventArgs(checkoutResponse)); } Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber)); } else { IList <string> warningMessages = checkoutResponse.WarningMessages; if (warningMessages.Count == 0) { warningMessages.Add("The order could not be submitted at this time. Please try again later or contact us for assistance."); } if (CheckedOut != null) { CheckedOut(this, new CheckedOutEventArgs(checkoutResponse)); } } } } }