/// <summary> /// Adds the card in the context for the user in the context to this partner. /// </summary> /// <returns> /// A task that will yield the result code for the operation. /// </returns> public async Task <ResultCode> AddCardAsync() { ResultCode result = ResultCode.None; // Build request AmexCardSyncRequest amexCardSyncRequest = new AmexCardSyncRequest { CardToken1 = Guid.NewGuid().ToString("N"), CardNumber = ((NewCardInfo)Context[Key.NewCardInfo]).Number }; Context.Log.Verbose("Amex AddCardAsync suggested card token: {0}", amexCardSyncRequest.CardToken1); HashSet <ResultCode> terminalCodes = new HashSet <ResultCode> { ResultCode.Created, ResultCode.Success, ResultCode.InvalidCardNumber, ResultCode.CorporateOrPrepaidCardError }; result = await PartnerUtilities.InvokePartner(Context, async() => { Context.Log.Verbose("Invoking Amex add card partner API."); AmexCardResponse response = await AmexInvoker.AddCardAsync(amexCardSyncRequest); Context.Log.Verbose("Amex add card partner API returned.\r\n {0}", JsonConvert.SerializeObject(response)); string code = null; string text = null; if (response != null && response.ResponseCode != null) { code = response.ResponseCode; text = response.ResponseDescription; switch (code) { case AmexCardSyncResponseCode.AddCardSuccess: case AmexCardSyncResponseCode.CardAndTokenPairAlreadyExists: result = ResultCode.Created; PartnerCardInfo partnerCardInfo = GetAmexCardInfo((Card)Context[Key.Card]); partnerCardInfo.PartnerCardId = response.CardToken1; partnerCardInfo.PartnerCardSuffix = "00"; break; case AmexCardSyncResponseCode.CardExistsWithDifferentToken: result = ResultCode.CardDoesNotBelongToUser; break; case AmexCardSyncResponseCode.CorporateOrPrepaidCardError: result = ResultCode.CorporateOrPrepaidCardError; break; case AmexCardSyncResponseCode.InvalidCardNumber: case AmexCardSyncResponseCode.NotAmexCard: result = ResultCode.InvalidCardNumber; break; default: result = ResultCode.UnknownError; break; } } else { result = ResultCode.UnknownError; } // Log a warning if result was not a success. if (result != ResultCode.Created) { Context.Log.Warning("Amex call failed. respCode: {0}. respText: {1}.", (int)DefaultLogEntryEventId.PartnerErrorWarning, code, text); } return(result); }, terminalCodes); return(result); }
/// <summary> /// Removes the card in the context for the user in the context from this partner. /// </summary> /// <returns> /// A task that will yield the result code for the operation. /// </returns> public async Task <ResultCode> RemoveCardAsync() { ResultCode result = ResultCode.None; Card card = (Card)Context[Key.Card]; PartnerCardInfo amexCardInfo = card.PartnerCardInfoList.SingleOrDefault(partnerCardInfo => partnerCardInfo.PartnerId == Partner.Amex); if (amexCardInfo != null) { // Build request AmexCardUnSyncRequest amexCardUnSyncRequest = new AmexCardUnSyncRequest { CardToken1 = amexCardInfo.PartnerCardId }; result = await PartnerUtilities.InvokePartner(Context, async() => { Context.Log.Verbose("Invoking partner RemoveCardAsync API."); AmexCardResponse response = await AmexInvoker.RemoveCardAsync(amexCardUnSyncRequest); Context.Log.Verbose("Partner RemoveCardAsync API returned: {0}: {1}.", response.ResponseCode, response.ResponseDescription); string code = null; string text = null; if (response != null && response.ResponseCode != null) { code = response.ResponseCode; text = response.ResponseDescription; switch (code) { case AmexCardUnSyncResponseCode.RemoveCardSuccess: case AmexCardUnSyncResponseCode.CardDoesNotExist: case AmexCardUnSyncResponseCode.NoLinkedCards: result = ResultCode.Success; break; default: result = ResultCode.UnknownError; break; } } else { result = ResultCode.UnknownError; } // Log a warning if result was not a success. if (result != ResultCode.Success) { Context.Log.Warning("Amex Data call failed. respCode: {0}. respText: {1}.", (int)DefaultLogEntryEventId.PartnerErrorWarning, code, text); } return(result); }); } return(result); }