public static Contracts.BasicTypes.ConfirmationType ApiTypeToContractType( XmlInterfaces.BasicObjects.ConfirmationType apiType) { switch (apiType) { case XmlInterfaces.BasicObjects.ConfirmationType.SMS: return(Contracts.BasicTypes.ConfirmationType.Sms); case XmlInterfaces.BasicObjects.ConfirmationType.USSD: return(Contracts.BasicTypes.ConfirmationType.Ussd); case XmlInterfaces.BasicObjects.ConfirmationType.Auto: return(Contracts.BasicTypes.ConfirmationType.Auto); case XmlInterfaces.BasicObjects.ConfirmationType.Invoice: return(Contracts.BasicTypes.ConfirmationType.Invoice); case XmlInterfaces.BasicObjects.ConfirmationType.SmsWithoutInvoice: return(Contracts.BasicTypes.ConfirmationType.SmsWithoutInvoice); default: throw new ArgumentOutOfRangeException(nameof(apiType)); } }
public ITrustConfirmationInstruction RequestTrust(IOriginalExpressTrust originalExpressTrust) { if (null == originalExpressTrust) { throw new ArgumentNullException(nameof(originalExpressTrust)); } XmlInterfaces.BasicObjects.ConfirmationType confirmationType = ConvertFrom.ContractTypeToApiType(originalExpressTrust.ConfirmationType); ExpressTrustRequest request; switch (originalExpressTrust.Identifier.Type) { case ExtendedIdentifierType.Phone: var phone = originalExpressTrust.Identifier.Value; if (!phone.StartsWith("+")) { phone = $"+{phone}"; } request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse), (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit, (Amount)originalExpressTrust.MonthLimit, Phone.Parse(phone), confirmationType); break; case ExtendedIdentifierType.WmId: request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse), (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit, (Amount)originalExpressTrust.MonthLimit, WmId.Parse(originalExpressTrust.Identifier.Value), confirmationType); break; case ExtendedIdentifierType.Email: MailAddress mailAddress = new MailAddress(originalExpressTrust.Identifier.Value); request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse), (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit, (Amount)originalExpressTrust.MonthLimit, mailAddress, confirmationType); break; case ExtendedIdentifierType.Purse: request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse), (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit, (Amount)originalExpressTrust.MonthLimit, Purse.Parse(originalExpressTrust.Identifier.Value), confirmationType); break; default: throw new InvalidOperationException("originalExpressTrust.Identifier.Type == " + originalExpressTrust.Identifier.Type); } request.DayLimit = (Amount)originalExpressTrust.DayLimit; request.WeekLimit = (Amount)originalExpressTrust.WeekLimit; request.MonthLimit = (Amount)originalExpressTrust.MonthLimit; request.Initializer = Session.AuthenticationService.ObtainInitializer(); ExpressTrustResponse response; try { response = request.Submit(); } catch (WmException exception) { throw new ExternalServiceException(exception.Message, exception); } var instruction = new TrustConfirmationInstruction(response.Reference, ConvertFrom.ApiTypeToContractType(response.ConfirmationType), response.Info, response.SmsReference); return(instruction); }