public int CreateVoterPass(BattleType BattleType, int BattleId, MobSocialProcessPaymentResultModel PaymentResponse, CustomerPaymentMethod PaymentMethod, decimal Amount)
        {
            //first we'll create an order, let's first get the associated product for voter pass
            var voterPassProduct = GetVoterPassProduct(BattleType);

            //place an order on user's behalf
            var order = new Order()
            {
                CreatedOnUtc    = DateTime.UtcNow,
                CustomerId      = _workContext.CurrentCustomer.Id,
                StoreId         = _storeContext.CurrentStore.Id,
                BillingAddress  = _workContext.CurrentCustomer.Addresses.First(),
                ShippingAddress = _workContext.CurrentCustomer.Addresses.First(),
                AuthorizationTransactionCode   = PaymentResponse.ProcessPaymentResult.AuthorizationTransactionCode,
                AuthorizationTransactionId     = PaymentResponse.ProcessPaymentResult.AuthorizationTransactionId,
                AuthorizationTransactionResult = PaymentResponse.ProcessPaymentResult.AuthorizationTransactionResult,
                CustomerIp                   = _webHelper.GetCurrentIpAddress(),
                OrderStatus                  = OrderStatus.Complete,
                PaymentStatus                = PaymentResponse.ProcessPaymentResult.NewPaymentStatus,
                ShippingStatus               = ShippingStatus.ShippingNotRequired,
                PaymentMethodSystemName      = "MobSocial.Payments." + PaymentMethod.PaymentMethod.ToString(),
                OrderTotal                   = Amount,
                OrderSubtotalExclTax         = Amount,
                OrderSubTotalDiscountInclTax = Amount,
                OrderGuid            = Guid.NewGuid(),
                CustomerCurrencyCode = _workContext.WorkingCurrency.CurrencyCode,
                CurrencyRate         = _workContext.WorkingCurrency.Rate
            };
            var orderItem = new OrderItem()
            {
                OrderItemGuid    = Guid.NewGuid(),
                ProductId        = voterPassProduct.Id,
                UnitPriceExclTax = Amount,
                UnitPriceInclTax = Amount,
                PriceInclTax     = Amount,
                PriceExclTax     = Amount,
                Quantity         = 1
            };

            order.OrderItems.Add(orderItem);
            //save the order now
            _orderService.InsertOrder(order);

            //now add this voter pass for future reference
            var voterPass = new VoterPass()
            {
                BattleId         = BattleId,
                BattleType       = BattleType,
                CustomerId       = _workContext.CurrentCustomer.Id,
                DateCreated      = DateTime.UtcNow,
                DateUpdated      = DateTime.UtcNow,
                Status           = PassStatus.NotUsed,
                VoterPassOrderId = order.Id
            };

            //save this pass details
            this.Insert(voterPass);

            return(order.Id);
        }
Esempio n. 2
0
        public MobSocialProcessPaymentResultModel ProcessPayment(Customer Customer, CustomerPaymentMethod PaymentMethod, decimal PaymentAmount, bool AuthorizeOnly = false)
        {
            //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 = PaymentAmount < 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.SupportCapture && AuthorizeOnly))
            {
                return(null);
            }

            //default to first billing address
            Customer.BillingAddress = Customer.BillingAddress ?? Customer.Addresses.First();

            var key  = _mobSecurityService.GetSavedEncryptionKey();
            var salt = _mobSecurityService.GetSavedSalt();

            //decrypt card number stored for processing
            var cardNumber = _mobSecurityService.Decrypt(PaymentMethod.CardNumber, key, salt); //decrypt the card info

            //now create a payment processing request
            var paymentProcessingRequest = new ProcessPaymentRequest()
            {
                CustomerId              = Customer.Id,
                OrderTotal              = PaymentAmount,
                CreditCardName          = PaymentMethod.NameOnCard,
                CreditCardExpireMonth   = int.Parse(PaymentMethod.ExpireMonth),
                CreditCardExpireYear    = int.Parse(PaymentMethod.ExpireYear),
                PaymentMethodSystemName = paymentPluginSystemName,
                CreditCardType          = PaymentMethod.CardIssuerType,
                CreditCardNumber        = cardNumber,
                StoreId = _storeContext.CurrentStore.Id
            };

            var resultModel = new MobSocialProcessPaymentResultModel()
            {
                ProcessPaymentResult    = plugin.ProcessPayment(paymentProcessingRequest),
                PaymentMethodSystemName = paymentPluginSystemName
            };

            return(resultModel);
        }