Esempio n. 1
0
 public static string CreateVerifyData(SamanCallbackResult callbackResult, SamanGatewayAccount account)
 {
     return
         ("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:Foo\">" +
          "<soapenv:Header/>" +
          "<soapenv:Body>" +
          "<urn:verifyTransaction soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
          $"<String_1 xsi:type=\"xsd:string\">{callbackResult.TransactionId}</String_1>" +
          $"<String_2 xsi:type=\"xsd:string\">{account.MerchantId}</String_2>" +
          "</urn:verifyTransaction>" +
          "</soapenv:Body>" +
          "</soapenv:Envelope>");
 }
Esempio n. 2
0
 private static string CreateTokenRequest(Invoice invoice, SamanGatewayAccount account)
 {
     return
         ("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:Foo\">" +
          "<soapenv:Header/>" +
          "<soapenv:Body>" +
          "<urn:RequestToken soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
          $"<TermID xsi:type=\"xsd:string\">{account.MerchantId}</TermID>" +
          $"<ResNum xsi:type=\"xsd:string\">{invoice.TrackingNumber}</ResNum>" +
          $"<TotalAmount xsi:type=\"xsd:long\">{(long)invoice.Amount}</TotalAmount>" +
          "</urn:RequestToken>" +
          "</soapenv:Body>" +
          "</soapenv:Envelope>");
 }
Esempio n. 3
0
 public static string CreateRefundData(InvoiceContext context, Money amount, SamanGatewayAccount account)
 {
     return
         ("<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:Foo\">" +
          "<soapenv:Header/>" +
          "<soapenv:Body>" +
          "<urn:reverseTransaction soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
          $"<String_1 xsi:type=\"xsd:string\">{context.Payment.TransactionCode}</String_1>" +
          $"<String_2 xsi:type=\"xsd:string\">{(long)amount}</String_2>" +
          $"<Username xsi:type=\"xsd:string\">{account.MerchantId}</Username>" +
          $"<Password xsi:type=\"xsd:string\">{account.Password}</Password>" +
          "</urn:reverseTransaction>" +
          "</soapenv:Body>" +
          "</soapenv:Envelope>");
 }
Esempio n. 4
0
        private static async Task <PaymentRequestResult> CreateMobilePaymentRequest(
            Invoice invoice,
            HttpContext httpContext,
            SamanGatewayAccount account,
            HttpClient httpClient,
            SamanGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions,
            CancellationToken cancellationToken)
        {
            var data = new SamanMobilePaymentTokenRequest
            {
                TerminalId  = account.MerchantId,
                ResNum      = invoice.TrackingNumber.ToString(),
                Amount      = invoice.Amount,
                RedirectUrl = invoice.CallbackUrl,
                Action      = "Token"
            };

            var responseMessage = await httpClient.PostJsonAsync(gatewayOptions.MobileApiTokenUrl, data, cancellationToken);

            var response = await responseMessage.Content.ReadAsStringAsync();

            var tokenResponse = JsonConvert.DeserializeObject <SamanMobilePaymentTokenResponse>(response);

            if (tokenResponse == null)
            {
                var message = $"{messagesOptions.InvalidDataReceivedFromGateway} Serialized token response is null.";
                return(PaymentRequestResult.Failed(message, account.Name));
            }

            if (tokenResponse.Status == -1)
            {
                return(PaymentRequestResult.Failed(tokenResponse.GetError(), account.Name));
            }

            var result = PaymentRequestResult.SucceedWithPost(
                account.Name,
                httpContext,
                gatewayOptions.MobilePaymentPageUrl,
                new Dictionary <string, string>
            {
                { "Token", tokenResponse.Token }
            });

            result.DatabaseAdditionalData.Add(MobileGatewayKey, true.ToString());

            return(result);
        }
Esempio n. 5
0
        public static Task <PaymentRequestResult> CreateRequest(
            Invoice invoice,
            HttpContext httpContext,
            SamanGatewayAccount account,
            HttpClient httpClient,
            SamanGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions,
            CancellationToken cancellationToken)
        {
            if (invoice.IsSamanMobileGatewayEnabled())
            {
                return(CreateMobilePaymentRequest(invoice, httpContext, account, httpClient, gatewayOptions, messagesOptions, cancellationToken));
            }

            return(CreateWebPaymentRequest(invoice, httpContext, account, httpClient, gatewayOptions, messagesOptions, cancellationToken));
        }
Esempio n. 6
0
        private static async Task <PaymentRequestResult> CreateWebPaymentRequest(
            Invoice invoice,
            HttpContext httpContext,
            SamanGatewayAccount account,
            HttpClient httpClient,
            SamanGatewayOptions gatewayOptions,
            MessagesOptions messagesOptions,
            CancellationToken cancellationToken)
        {
            var data = CreateTokenRequest(invoice, account);

            var responseMessage = await httpClient.PostXmlAsync(gatewayOptions.WebApiTokenUrl, data, cancellationToken);

            var response = await responseMessage.Content.ReadAsStringAsync();

            var token = XmlHelper.GetNodeValueFromXml(response, "result");

            string message   = null;
            var    isSucceed = true;

            if (token.IsNullOrEmpty())
            {
                message   = $"{messagesOptions.InvalidDataReceivedFromGateway} Token is null or empty.";
                isSucceed = false;
            }
            else if (long.TryParse(token, out var longToken) && longToken < 0)
            {
                message   = SamanResultTranslator.Translate(longToken, messagesOptions);
                isSucceed = false;
            }

            if (!isSucceed)
            {
                return(PaymentRequestResult.Failed(message, account.Name));
            }

            return(PaymentRequestResult.SucceedWithPost(
                       account.Name,
                       httpContext,
                       gatewayOptions.WebPaymentPageUrl,
                       new Dictionary <string, string>
            {
                { "Token", token },
                { "RedirectURL", invoice.CallbackUrl }
            }));
        }
Esempio n. 7
0
        public static PaymentRequestResult CreateRequestResult(Invoice invoice, IHttpContextAccessor httpContextAccessor, SamanGatewayAccount account)
        {
            var transporter = new GatewayPost(
                httpContextAccessor,
                PaymentPageUrl,
                new Dictionary <string, string>
            {
                { "Amount", invoice.Amount.ToLongString() },
                { "MID", account.MerchantId },
                { "ResNum", invoice.TrackingNumber.ToString() },
                { "RedirectURL", invoice.CallbackUrl }
            });

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }