public ITransactionProcessResult ProcessPayment(User user, UserPaymentMethod paymentMethod, ITransactionProcessRequest processRequest, bool authorizeOnly = false)
        {
            if (processRequest == null)
            {
                throw new mobSocialException("Can't process null request");
            }

            //check if the plugin is installed and activated
            //depending on the payment amount, we may wish to switch between macro and micro payments
            //check if plugin is installed or not
            //TODO: Change the other payment method to appropriate one for macro payments
            var paymentPluginSystemName = processRequest.Amount < MicroMacroPaymentSwitchingAmount ? "Payments.PayPalDirect" : "Payments.PayPalDirect";

            //if we get an instance, then the plugin is installed
            var plugin = GetPluginInstance(paymentPluginSystemName);

            //plugin should be available and if it's an authorization transaction, the plugin should actually support authorize and capture
            if (plugin == null || (!plugin.CaptureSupported && authorizeOnly))
            {
                return(null);
            }

            //process the payment now
            var result = plugin.Process(processRequest);

            return(result);
        }
Exemple #2
0
        public ITransactionProcessResult Process(ITransactionProcessRequest request, bool authorizeOnly = false)
        {
            var user = _userService.Get(request.UserId);

            if (user == null)
            {
                throw new mobSocialException($"Can't find the user with Id {request.UserId}");
            }
            var creditCard = new CreditCardDetailsType()
            {
                CreditCardNumber = request.GetParameterAs <string>(PaymentParameterNames.CardNumber),
                CVV2             = request.GetParameterAs <string>(PaymentParameterNames.SecurityCode),
                ExpMonth         = request.GetParameterAs <int>(PaymentParameterNames.ExpireMonth),
                ExpYear          = request.GetParameterAs <int>(PaymentParameterNames.ExpireYear),
                CreditCardType   = PayPalHelper.GeCreditCardTypeType(request.GetParameterAs <string>(PaymentParameterNames.CardIssuerType)),
                CardOwner        = new PayerInfoType()
            };


            var paypalCurrency = PayPalHelper.GetPaypalCurrency(request.CurrencyIsoCode);
            var doDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType()
            {
                IPAddress      = WebHelper.GetClientIpAddress(),
                PaymentAction  = authorizeOnly ? PaymentActionCodeType.AUTHORIZATION : PaymentActionCodeType.SALE,
                CreditCard     = creditCard,
                PaymentDetails = new PaymentDetailsType()
                {
                    OrderTotal = new BasicAmountType()
                    {
                        value      = Math.Round(request.Amount, 2).ToString("N", new CultureInfo("en-US")),
                        currencyID = paypalCurrency
                    },
                    Custom       = request.TransactionUniqueId,
                    ButtonSource = "mobSocial"
                }
            };

            var doDirectPaymentRequest = new DoDirectPaymentRequestType {
                Version = ApiVersion,
                DoDirectPaymentRequestDetails = doDirectPaymentRequestDetails
            };

            var paymentRequest = new DoDirectPaymentReq {
                DoDirectPaymentRequest = doDirectPaymentRequest
            };

            var service        = GetPayPalApiInterfaceServiceService();
            var paypalResponse = service.DoDirectPayment(paymentRequest);

            var result = new TransactionResult();

            string error;
            var    success = PayPalHelper.ParseResponseSuccess(paypalResponse, out error);

            if (success)
            {
                result.Success = true;
                result.SetParameter(PaymentParameterNames.AvsCode, paypalResponse.AVSCode);
                result.SetParameter(PaymentParameterNames.Cvv2Code, paypalResponse.CVV2Code);

                if (authorizeOnly)
                {
                    result.SetParameter(PaymentParameterNames.AuthorizationId, paypalResponse.TransactionID);
                    result.SetParameter(PaymentParameterNames.AuthorizationResult, paypalResponse.Ack);
                }
                else
                {
                    result.SetParameter(PaymentParameterNames.CaptureId, paypalResponse.TransactionID);
                    result.SetParameter(PaymentParameterNames.CaptureResult, paypalResponse.Ack);
                }
            }
            else
            {
                result.SetParameter(PaymentParameterNames.ErrorMessage, error);
            }

            return(result);
        }
        public ITransactionProcessResult Process(ITransactionProcessRequest request, bool authorizeOnly = false)
        {
            var user = _userService.Get(request.UserId);
            if (user == null)
            {
                throw new mobSocialException($"Can't find the user with Id {request.UserId}");
            }
            var creditCard = new CreditCardDetailsType() {
                CreditCardNumber = request.GetParameterAs<string>(PaymentParameterNames.CardNumber),
                CVV2 = request.GetParameterAs<string>(PaymentParameterNames.SecurityCode),
                ExpMonth = request.GetParameterAs<int>(PaymentParameterNames.ExpireMonth),
                ExpYear = request.GetParameterAs<int>(PaymentParameterNames.ExpireYear),
                CreditCardType = PayPalHelper.GeCreditCardTypeType(request.GetParameterAs<string>(PaymentParameterNames.CardIssuerType)),
                CardOwner = new PayerInfoType()
            };

            var paypalCurrency = PayPalHelper.GetPaypalCurrency(request.CurrencyIsoCode);
            var doDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType() {
                IPAddress = WebHelper.GetClientIpAddress(),
                PaymentAction = authorizeOnly ? PaymentActionCodeType.AUTHORIZATION : PaymentActionCodeType.SALE,
                CreditCard = creditCard,
                PaymentDetails = new PaymentDetailsType() {
                    OrderTotal = new BasicAmountType() {
                        value = Math.Round(request.Amount, 2).ToString("N", new CultureInfo("en-US")),
                        currencyID = paypalCurrency
                    },
                    Custom = request.TransactionUniqueId,
                    ButtonSource = "mobSocial"
                }
            };

            var doDirectPaymentRequest = new DoDirectPaymentRequestType {
                Version = ApiVersion,
                DoDirectPaymentRequestDetails = doDirectPaymentRequestDetails
            };

            var paymentRequest = new DoDirectPaymentReq {
                DoDirectPaymentRequest = doDirectPaymentRequest
            };

            var service = GetPayPalApiInterfaceServiceService();
            var paypalResponse = service.DoDirectPayment(paymentRequest);

            var result = new TransactionResult();

            string error;
            var success = PayPalHelper.ParseResponseSuccess(paypalResponse, out error);
            if (success)
            {
                result.Success = true;
                result.SetParameter(PaymentParameterNames.AvsCode, paypalResponse.AVSCode);
                result.SetParameter(PaymentParameterNames.Cvv2Code, paypalResponse.CVV2Code);

                if (authorizeOnly)
                {
                    result.SetParameter(PaymentParameterNames.AuthorizationId, paypalResponse.TransactionID);
                    result.SetParameter(PaymentParameterNames.AuthorizationResult, paypalResponse.Ack);
                }
                else
                {
                    result.SetParameter(PaymentParameterNames.CaptureId, paypalResponse.TransactionID);
                    result.SetParameter(PaymentParameterNames.CaptureResult, paypalResponse.Ack);
                }
            }
            else
            {
                result.SetParameter(PaymentParameterNames.ErrorMessage, error);
            }

            return result;
        }
        public ITransactionProcessResult ProcessPayment(User user, UserPaymentMethod paymentMethod, ITransactionProcessRequest processRequest, bool authorizeOnly = false)
        {
            if(processRequest == null)
                throw new mobSocialException("Can't process null request");

            //check if the plugin is installed and activated
            //depending on the payment amount, we may wish to switch between macro and micro payments
            //check if plugin is installed or not
            //TODO: Change the other payment method to appropriate one for macro payments
            var paymentPluginSystemName = processRequest.Amount < MicroMacroPaymentSwitchingAmount ? "Payments.PayPalDirect" : "Payments.PayPalDirect";

            //if we get an instance, then the plugin is installed
            var plugin = GetPluginInstance(paymentPluginSystemName);

            //plugin should be available and if it's an authorization transaction, the plugin should actually support authorize and capture
            if (plugin == null || (!plugin.CaptureSupported && authorizeOnly))
                return null;

               //process the payment now
            var result = plugin.Process(processRequest);
            return result;
        }