public static string CreateRequestData(ZarinPalGatewayAccount account, Invoice invoice) { if (!invoice.AdditionalData.ContainsKey(ZarinPalRequestAdditionalKeyName) || !(invoice.AdditionalData[ZarinPalRequestAdditionalKeyName] is ZarinPalInvoice zarinPalInvoice)) { throw new InvalidOperationException("Request failed. ZarinPal Gateway needs invoice information. Please use the SetZarinPalData method to add the data."); } var email = zarinPalInvoice.Email.IsNullOrEmpty() ? null : XmlHelper.EncodeXmlValue(zarinPalInvoice.Email); var mobile = zarinPalInvoice.Mobile.IsNullOrEmpty() ? null : XmlHelper.EncodeXmlValue(zarinPalInvoice.Mobile); return ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:zar=\"http://zarinpal.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<zar:PaymentRequest>" + $"<zar:MerchantID>{account.MerchantId}</zar:MerchantID>" + $"<zar:Amount>{(long)invoice.Amount}</zar:Amount>" + $"<zar:Description>{XmlHelper.EncodeXmlValue(zarinPalInvoice.Description)}</zar:Description>" + "<!--Optional:-->" + $"<zar:Email>{email}</zar:Email>" + "<!--Optional:-->" + $"<zar:Mobile>{mobile}</zar:Mobile>" + $"<zar:CallbackURL>{XmlHelper.EncodeXmlValue(invoice.CallbackUrl)}</zar:CallbackURL>" + "</zar:PaymentRequest>" + "</soapenv:Body>" + "</soapenv:Envelope>"); }
public static PaymentRequestResult CreateRequestResult(string response, HttpContext httpContext, ZarinPalGatewayAccount account, MessagesOptions messagesOptions) { var status = XmlHelper.GetNodeValueFromXml(response, "Status", "http://zarinpal.com/"); var authority = XmlHelper.GetNodeValueFromXml(response, "Authority", "http://zarinpal.com/"); var isSucceed = string.Equals(status, NumericOkResult, StringComparison.InvariantCultureIgnoreCase); if (!isSucceed) { var message = ZarinPalStatusTranslator.Translate(status, messagesOptions); return(PaymentRequestResult.Failed(message, account.Name)); } var paymentPageUrl = GetWebPageUrl(account.IsSandbox) + authority; var transporterDescriptor = GatewayTransporterDescriptor.CreateRedirect(paymentPageUrl); var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor); return(PaymentRequestResult.Succeed(transporter, account.Name)); }
public static string CreateVerifyData(ZarinPalGatewayAccount account, ZarinPalCallbackResult callbackResult, Money amount) { return ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:zar=\"http://zarinpal.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<zar:PaymentVerification>" + $"<zar:MerchantID>{account.MerchantId}</zar:MerchantID>" + $"<zar:Authority>{callbackResult.Authority}</zar:Authority>" + $"<zar:Amount>{(long)amount}</zar:Amount>" + "</zar:PaymentVerification>" + "</soapenv:Body>" + "</soapenv:Envelope>"); }
public static string CreateRequestData(ZarinPalGatewayAccount account, Invoice invoice) { return ("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:zar=\"http://zarinpal.com/\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<zar:PaymentRequest>" + $"<zar:MerchantID>{account.MerchantId}</zar:MerchantID>" + $"<zar:Amount>{(long)invoice.Amount}</zar:Amount>" + "<zar:Description></zar:Description>" + "<!--Optional:-->" + "<zar:Email></zar:Email>" + "<!--Optional:-->" + "<zar:Mobile></zar:Mobile>" + $"<zar:CallbackURL>{invoice.CallbackUrl}</zar:CallbackURL>" + "</zar:PaymentRequest>" + "</soapenv:Body>" + "</soapenv:Envelope>"); }
public static PaymentRequestResult CreateRequestResult( string response, IHttpContextAccessor httpContextAccessor, ZarinPalGatewayAccount account) { var status = XmlHelper.GetNodeValueFromXml(response, "Status", "http://zarinpal.com/"); var authority = XmlHelper.GetNodeValueFromXml(response, "Authority", "http://zarinpal.com/"); var isSucceed = string.Equals(status, OkResult, StringComparison.InvariantCultureIgnoreCase); if (!isSucceed) { var message = $"Error {status}"; return(PaymentRequestResult.Failed(message, account.Name)); } var paymentPageUrl = GetWebPageUrl(account.IsSandbox) + authority; return(PaymentRequestResult.Succeed(new GatewayRedirect(httpContextAccessor, paymentPageUrl), account.Name)); }