当前位置: 首页>>代码示例>>C#>>正文


C# ProcessorArgumentCollection.AsCreditCard方法代码示例

本文整理汇总了C#中ProcessorArgumentCollection.AsCreditCard方法的典型用法代码示例。如果您正苦于以下问题:C# ProcessorArgumentCollection.AsCreditCard方法的具体用法?C# ProcessorArgumentCollection.AsCreditCard怎么用?C# ProcessorArgumentCollection.AsCreditCard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProcessorArgumentCollection的用法示例。


在下文中一共展示了ProcessorArgumentCollection.AsCreditCard方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitializePayment

        /// <summary>
        /// Processes the Authorize and AuthorizeAndCapture transactions
        /// </summary>
        /// <param name="invoice">The <see cref="IInvoice"/> to be paid</param>
        /// <param name="payment">The <see cref="Core.Models.IPayment"/> record</param>
        /// <param name="args"></param>
        /// <returns>The <see cref="Core.Gateways.Payment.IPaymentResult"/></returns>
        public IPaymentResult InitializePayment(IInvoice invoice, IPayment payment, ProcessorArgumentCollection args)
        {
            try
            {            
                var sagePayDirectIntegration = new SagePayAPIIntegration(Settings);
                var request = sagePayDirectIntegration.DirectPaymentRequest();

                var creditCard = args.AsCreditCard();
                 
                SetSagePayApiData(request, invoice, payment, creditCard);                

                // Incredibly frustratingly, the sagepay integration kit provided by sagepay does not support paypal integration with sagepay direct so if this is a paypal transaction, we have to build the post manually.

                if (request.CardType == CardType.PAYPAL)
                {
                    using (var client = new HttpClient())
                    {
                        var values = new Dictionary<string, string> { };

                        // Build the post and fix the values that the integration kit breaks...
                        foreach (var property in request.GetType().GetAllProperties())
                        {
                            if (property.CanRead && property.GetValue(request) != null)
                            {
                                if (property.Name == "VpsProtocol")
                                {
                                    values.Add(property.Name, "3.00");
                                }
                                else if (property.Name == "TransactionType")
                                {
                                    values.Add("TxType", "PAYMENT");
                                }
                                else
                                {
                                    values.Add(property.Name, property.GetValue(request).ToString());
                                }
                            }
                        }

                        var content = new FormUrlEncodedContent(values);

                        var response = client.PostAsync(string.Format("https://{0}.sagepay.com/gateway/service/vspdirect-register.vsp", Settings.Environment), content).Result;

                        var responseString = response.Content.ReadAsStringAsync().Result.Replace("\r\n", "&");

                        NameValueCollection sagePayResponseValues = HttpUtility.ParseQueryString(responseString);
                        if (sagePayResponseValues["Status"] == "PPREDIRECT")
                        {
                            var redirectUrl = sagePayResponseValues["PayPalRedirectURL"] + "&token=" + sagePayResponseValues["token"];
                            payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.SagePayPaymentUrl, redirectUrl);

                            var returnUrl = GetWebsiteUrl() + Settings.ReturnUrl;
                            payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.ReturnUrl, returnUrl);

                            var cancelUrl = GetWebsiteUrl() + Settings.CancelUrl;
                            payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.CancelUrl, cancelUrl);

                            payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.SagePayTransactionCode, sagePayResponseValues["VPSTxId"]);

                            return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, true);

                        }
                        else
                        {
                            return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(sagePayResponseValues["StatusDetail"])), invoice, true);
                        }


                    }

                }

                IDirectPaymentResult result = sagePayDirectIntegration.ProcessDirectPaymentRequest(request, string.Format("https://{0}.sagepay.com/gateway/service/vspdirect-register.vsp", Settings.Environment));
                

                
                if (result.Status == ResponseStatus.OK)
                {
                    payment.Collected = true;
                    payment.Authorized = true;
                    GatewayProviderService service = new GatewayProviderService();
                    service.ApplyPaymentToInvoice(payment.Key, invoice.Key, Core.AppliedPaymentType.Debit, "SagePay: capture authorized", invoice.Total);
                    return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, true);
                }
                else if (result.Status == ResponseStatus.THREEDAUTH)
                {
                    
                    // For 3D Secure we have to show a client side form which posts to the ACS url. 
                      Func<string, string> adjustUrl = (url) =>
                {
                    if (!url.StartsWith("http")) url = GetWebsiteUrl() + (url[0] == '/' ? "" : "/") + url;
                    url = url.Replace("{invoiceKey}", invoice.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
                    url = url.Replace("{paymentKey}", payment.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
//.........这里部分代码省略.........
开发者ID:chrisdaaaaay,项目名称:Merchello.Plugins.SagePay,代码行数:101,代码来源:SagePayDirectPaymentProcessor.cs


注:本文中的ProcessorArgumentCollection.AsCreditCard方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。