private static string CreateCumulativeRequestData(Invoice invoice, MellatGatewayAccount account) { var cumulativeAccounts = (List <MellatCumulativeDynamicAccount>)invoice.Properties[CumulativeAccountsKey]; if (cumulativeAccounts.Count > 10) { throw new Exception("Cannot use more than 10 accounts for each Cumulative payment request."); } var additionalData = cumulativeAccounts.Aggregate("", (current, cumulativeAccount) => current + $"{cumulativeAccount};"); return ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:int=\"http://interfaces.core.sw.bps.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<int:bpCumulativeDynamicPayRequest>" + $"<terminalId>{account.TerminalId}</terminalId>" + "<!--Optional:-->" + $"<userName>{account.UserName}</userName>" + "<!--Optional:-->" + $"<userPassword>{account.UserPassword}</userPassword>" + $"<orderId>{invoice.TrackingNumber}</orderId>" + $"<amount>{(long)invoice.Amount}</amount>" + "<!--Optional:-->" + $"<localDate>{DateTime.Now:yyyyMMdd}</localDate>" + "<!--Optional:-->" + $"<localTime>{DateTime.Now:HHmmss}</localTime>" + "<!--Optional:-->" + $"<additionalData>{additionalData}</additionalData>" + "<!--Optional:-->" + $"<callBackUrl>{XmlHelper.EncodeXmlValue(invoice.CallbackUrl)}</callBackUrl>" + "</int:bpCumulativeDynamicPayRequest>" + "</soapenv:Body>" + "</soapenv:Envelope>"); }
private static string CreateSimpleRequestData(Invoice invoice, MellatGatewayAccount account) { var additionalData = invoice.GetMellatAdditionalData(); var payerId = additionalData?.PayerId ?? "0"; return ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:int=\"http://interfaces.core.sw.bps.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<int:bpPayRequest>" + $"<terminalId>{account.TerminalId}</terminalId>" + "<!--Optional:-->" + $"<userName>{account.UserName}</userName>" + "<!--Optional:-->" + $"<userPassword>{account.UserPassword}</userPassword>" + $"<orderId>{invoice.TrackingNumber}</orderId>" + $"<amount>{(long)invoice.Amount}</amount>" + "<!--Optional:-->" + $"<localDate>{DateTime.Now:yyyyMMdd}</localDate>" + "<!--Optional:-->" + $"<localTime>{DateTime.Now:HHmmss}</localTime>" + "<!--Optional:-->" + $"<additionalData>{additionalData?.AdditionalData}</additionalData>" + "<!--Optional:-->" + $"<callBackUrl>{XmlHelper.EncodeXmlValue(invoice.CallbackUrl)}</callBackUrl>" + $"<payerId>{payerId}</payerId>" + "'</int:bpPayRequest>" + "</soapenv:Body>" + "</soapenv:Envelope>"); }
public static string CreateRequestData(Invoice invoice, MellatGatewayAccount account) { if (invoice.Properties == null || !invoice.Properties.ContainsKey(CumulativeAccountsKey)) { return(CreateSimpleRequestData(invoice, account)); } return(CreateCumulativeRequestData(invoice, account)); }
private static string CreateCumulativeRequestData(Invoice invoice, MellatGatewayAccount account) { var cumulativeAccounts = (IList <MellatCumulativeDynamicAccount>)invoice.AdditionalData[CumulativeAccountsKey]; if (cumulativeAccounts.Count > 10) { throw new Exception("Cannot use more than 10 accounts for each Cumulative payment request."); } //var totalAmount = cumulativeAccounts.Sum(cumulativeAccount => cumulativeAccount.Amount); //if (totalAmount != invoice.Amount) //{ // throw new Exception("The total amount of Mellat Cumulative accounts is not equals to the amount of the invoice." + // $"Invoice amount: {invoice.Amount}." + // $"Accounts total amount: {totalAmount}"); //} var additionalData = cumulativeAccounts.Aggregate("", (current, cumulativeAccount) => current + $"{cumulativeAccount};"); return ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:int=\"http://interfaces.core.sw.bps.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<int:bpCumulativeDynamicPayRequest>" + $"<terminalId>{account.TerminalId}</terminalId>" + "<!--Optional:-->" + $"<userName>{account.UserName}</userName>" + "<!--Optional:-->" + $"<userPassword>{account.UserPassword}</userPassword>" + $"<orderId>{invoice.TrackingNumber}</orderId>" + $"<amount>{(long)invoice.Amount}</amount>" + "<!--Optional:-->" + $"<localDate>{DateTime.Now:yyyyMMdd}</localDate>" + "<!--Optional:-->" + $"<localTime>{DateTime.Now:HHmmss}</localTime>" + "<!--Optional:-->" + $"<additionalData>{additionalData}</additionalData>" + "<!--Optional:-->" + $"<callBackUrl>{invoice.CallbackUrl}</callBackUrl>" + "</int:bpCumulativeDynamicPayRequest>" + "</soapenv:Body>" + "</soapenv:Envelope>"); }
public static string CreateRefundData(InvoiceContext context, MellatGatewayAccount account) { return ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:int=\"http://interfaces.core.sw.bps.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<int:bpReversalRequest>" + $"<terminalId>{account.TerminalId}</terminalId>" + "<!--Optional:-->" + $"<userName>{account.UserName}</userName>" + "<!--Optional:-->" + $"<userPassword>{account.UserPassword}</userPassword>" + $"<orderId>{context.Payment.TrackingNumber}</orderId>" + $"<saleOrderId>{context.Payment.TrackingNumber}</saleOrderId>" + $"<saleReferenceId>{context.Payment.TransactionCode}</saleReferenceId>" + "</int:bpReversalRequest>" + "</soapenv:Body>" + "</soapenv:Envelope>"); }