Ejemplo n.º 1
0
        public IPaymentResponse Charge(PaymentRequest request)
        {
            request.Additional.TryGetValue("quantity", out var quantity);
            request.Additional.TryGetValue("paymentMethodType", out var paymentMethodType);
            string cancelUrl  = string.IsNullOrEmpty(request.CancelUrl) ? Setting.CancelUrl : request.CancelUrl;
            string successUrl = string.IsNullOrEmpty(request.ReturnUrl) ? Setting.SuccessUrl : request.ReturnUrl;

            var lineItems = new List <SessionLineItemOptions>
            {
                new SessionLineItemOptions {
                    Name        = request.Name,
                    Description = request.Description,
                    Amount      = long.Parse(request.TotalAmount.ToString()),
                    Currency    = request.Currency,
                    Quantity    = long.Parse(quantity.ToString())
                }
            };

            var paymentMethodTypesList = new List <string>();

            if (paymentMethodType is object[])
            {
                var paymentMethodTypeArray = Array.ConvertAll((object[])paymentMethodType, x => x.ToString());
                paymentMethodTypesList.AddRange(paymentMethodTypeArray);
            }
            else if (paymentMethodType is object)
            {
                paymentMethodTypesList.Add((string)paymentMethodType);
            }

            var options = new SessionCreateOptions
            {
                SuccessUrl         = successUrl,
                CancelUrl          = cancelUrl,
                LineItems          = lineItems,
                PaymentMethodTypes = paymentMethodTypesList,
                ClientReferenceId  = request.Id.ToString()
            };

            var sessionId = StripeUtility.CreateSession(options, Setting.Secretkey).Result;
            var response  = new HiddenFormResponse
            {
                paymemtMethodReferenceId = request.Id.ToString()
            };

            response.html = GenerateHtml(Setting.Publishablekey, sessionId);
            return(response);
        }
        public IPaymentResponse Charge(PaymentRequest request)
        {
            request.Additional.TryGetValue("quantity", out var quantity);
            request.Additional.TryGetValue("cancelUrl", out var cancelUrl);
            request.Additional.TryGetValue("successUrl", out var successUrl);
            request.Additional.TryGetValue("paymentMethodType", out var paymentMethodType);

            var lineItems = new List <SessionLineItemOptions>
            {
                new SessionLineItemOptions {
                    Name        = request.Name,
                    Description = request.Description,
                    Amount      = long.Parse(request.TotalAmount.ToString()),
                    Currency    = request.Currency,
                    Quantity    = long.Parse(quantity.ToString())
                }
            };

            var paymentMethodTypesList = new List <string>();

            if (paymentMethodType is object[])
            {
                var paymentMethodTypeArray = Array.ConvertAll((object[])paymentMethodType, x => x.ToString());
                paymentMethodTypesList.AddRange(paymentMethodTypeArray);
            }
            else if (paymentMethodType is object)
            {
                paymentMethodTypesList.Add((string)paymentMethodType);
            }

            var options = new SessionCreateOptions
            {
                SuccessUrl         = (string)successUrl,
                CancelUrl          = (string)cancelUrl,
                LineItems          = lineItems,
                PaymentMethodTypes = paymentMethodTypesList
            };

            var sessionId = StripeUtility.CreateSession(options, Setting.Secretkey).Result;
            var response  = new HiddenFormResponse
            {
                paymemtMethodReferenceId = sessionId
            };

            response.setFieldValues("publishableKey", Setting.Publishablekey);
            return(response);
        }