in src/Web/Controllers/ManageController.cs [223:304]
public async Task<IActionResult> ManagePaymentInstrument(ManagePaymentInstrumentViewModel model)
{
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
}
// Set card info
user.DefaultCardType = model.CreditCard.CardType;
user.DefaultCardNumber = model.CreditCard.CardNumber;
user.DefaultCardName = model.CreditCard.CardName;
user.DefaultCVV = model.CreditCard.CVV;
user.DefaultExpirationMonth = model.CreditCard.ExpirationMonth;
user.DefaultExpirationYear = model.CreditCard.ExpirationYear;
// Set billing address info
user.BillingAddress1 = model.BillingAddress.Address1;
user.BillingAddress2 = model.BillingAddress.Address2;
user.BillingCity = model.BillingAddress.City;
user.BillingState = model.BillingAddress.State;
user.BillingZipCode = model.BillingAddress.ZipCode;
user.BillingCountryRegion = model.BillingAddress.CountryRegion;
var updateResult = await _userManager.UpdateAsync(user);
#region Fraud Protection Service
// If storing the user's payment information succeeds, update Fraud Protection.
if (updateResult.Succeeded)
{
var billingAddress = new AddressDetails
{
FirstName = user.FirstName,
LastName = user.LastName,
Street1 = user.BillingAddress1,
Street2 = user.BillingAddress2,
City = user.BillingCity,
State = user.BillingState,
ZipCode = user.BillingZipCode,
Country = user.BillingCountryRegion
};
var userId = user.Email;
var fraudProtectionUser = new User
{
UserId = userId,
PaymentInstrumentList = new List<PaymentInstrument>
{
new PaymentInstrument
{
MerchantPaymentInstrumentId = $"{userId}-CreditCard",
Type = PaymentInstrumentType.CreditCard.ToString(),
CardType = model.CreditCard.CardType,
HolderName = model.CreditCard.CardName,
BIN = model.CreditCard.BIN,
ExpirationDate = model.CreditCard.ExpirationDate,
LastFourDigits = model.CreditCard.LastFourDigits,
BillingAddress = billingAddress,
CreationDate = DateTimeOffset.Now,
State = PaymentInstrumentState.Active.ToString(),
}
},
DeviceContext = new DeviceContext
{
DeviceContextId = _contextAccessor.GetSessionId(),
IPAddress = _contextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(),
Provider = DeviceContextProvider.DFPFingerPrinting.ToString()
}
};
var correlationId = _fraudProtectionService.NewCorrelationId;
var response = await _fraudProtectionService.PostUser(fraudProtectionUser, correlationId);
var fraudProtectionIO = new FraudProtectionIOModel(correlationId, fraudProtectionUser, response, "UpdateAccount");
TempData.Put(FraudProtectionIOModel.TempDataKey, fraudProtectionIO);
}
#endregion
StatusMessage = "Your payment information has been updated";
return RedirectToAction(nameof(ManagePaymentInstrument));
}