//Update Customer on BrainTree with Payment Method Request public string UpdateCustomerWithNewCardDuplicateCheck(UserCreditCards model) { bool DuplicateBool = false; bool.TryParse(ConfigService.DuplicatePaymentMethod, out DuplicateBool); bool VerifyBool = false; bool.TryParse(ConfigService.VerifyCard, out VerifyBool); PaymentMethodRequest request = new PaymentMethodRequest { CustomerId = model.UserId, PaymentMethodNonce = model.ExternalCardIdNonce, Options = new PaymentMethodOptionsRequest { FailOnDuplicatePaymentMethod = DuplicateBool, VerifyCard = VerifyBool }, }; Result <PaymentMethod> result = _Gateway.PaymentMethod.Create(request); bool isSuccessful = result.IsSuccess(); if (isSuccessful == false) { throw new System.ArgumentException(result.Message); } return(result.Target.Token); }
//BrainTree Customer Creation for maybe if GUEST wants to become member before Checkout. public bool CreateCustomerTransaction(CustomerPaymentRequest model) { //get user id with currentuserId string gotUserId = UserService.GetCurrentUserId(); model.UserId = gotUserId; //Grab email from UserProfileService UserProfile userObject = _UserProfileService.GetUserById(model.UserId); string userEmail = userObject.Email; //Add the new card nonce & info into credit cards table UserCreditCards CardModel = new UserCreditCards(); CardModel.UserId = model.UserId; CardModel.ExternalCardIdNonce = model.ExternalCardIdNonce; CardModel.Last4DigitsCC = model.Last4DigitsCC; CardModel.CardType = model.CardType; CreditCardService NewCardService = new CreditCardService(); NewCardService.creditCardInsertModel(CardModel); int currentTransactionId = 0; //Post first Transaction log before result currentTransactionId = _TransactionLogService.BillingTransactionInsert(model); bool DuplicateBool = false; bool.TryParse(ConfigService.DuplicatePaymentMethod, out DuplicateBool); bool VerifyBool = false; bool.TryParse(ConfigService.VerifyCard, out VerifyBool); //create transaction and create customer in braintree system //***NEED TO ADD THE JOB_ID AS WELL LATER*** TransactionRequest request = new TransactionRequest { Amount = model.ItemCost, PaymentMethodNonce = model.ExternalCardIdNonce, Customer = new CustomerRequest { Id = model.UserId, FirstName = model.FirstName, LastName = model.LastName, Email = userEmail, CreditCard = new CreditCardRequest { Options = new CreditCardOptionsRequest { FailOnDuplicatePaymentMethod = DuplicateBool, VerifyCard = VerifyBool } } }, Options = new TransactionOptionsRequest { SubmitForSettlement = true, StoreInVaultOnSuccess = true, } }; Result <Transaction> result = _Gateway.Transaction.Sale(request); //serialize the whole result object for backup purposes var transactionJson = new JavaScriptSerializer().Serialize(result); //Instantiate values into Transaction Log Model BillingTransactionLog LogModel = new BillingTransactionLog(); LogModel.Id = currentTransactionId; LogModel.RawResponse = transactionJson; //if else for whether the payment was successful or not if (result.Message == null && result.Errors == null) { //Instatiate Success Values LogModel.AmountConfirmed = result.Target.Amount; LogModel.TransactionId = result.Target.Id; LogModel.CardExpirationDate = result.Target.CreditCard.ExpirationDate; LogModel.CardLastFour = result.Target.CreditCard.LastFour; ActivityLogRequest Activity = new ActivityLogRequest(); Activity.ActivityType = ActivityTypeId.MadePayment; _ActivityLogService.InsertActivityToLog(model.UserId, Activity); return(_TransactionLogService.TransactionLogUpdateSuccess(LogModel)); } else { //Instatiate Error Values LogModel.ErrorCode = result.Message; bool response = _TransactionLogService.TransactionLogUpdateError(LogModel); throw new System.ArgumentException(result.Message, "CreditCard"); } }