public override void ProcessCallback(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs)
 {
     //not needed for offline payment
     throw new NotImplementedException();
 }
Example #2
0
        public override void Invoke(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs)
        {
            var args    = Assert.ResultNotNull(paymentArgs as ActiveCommerce.Payments.PaymentArgs, "PaymentArgs must be of type ActiveCommerce.Payments.PaymentArgs");
            var details = Assert.ResultNotNull(args.PaymentDetails as InvoicePaymentDetails, "PaymentDetails must be of type InvoicePaymentDetails");

            if (string.IsNullOrWhiteSpace(details.PurchaseOrderNumber))
            {
                TransactionDetails.ProviderMessage = "Invalid Purchase Order";
                PaymentStatus = PaymentStatus.Failure;
                return;
            }

            //TODO: additional validation of purchase order number could go here if needed

            TransactionDetails.ProviderMessage = "OK";
            PaymentStatus = PaymentStatus.Succeeded;
        }
        public override void Invoke(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs)
        {
            string status;
            var    checkout = Sitecore.Ecommerce.Context.Entity.GetInstance <ICheckOut>() as IInvoicePayment;

            if (checkout == null)
            {
                status             = "Could not find Purchase Order Number";
                this.PaymentStatus = PaymentStatus.Failure;
                Sitecore.Diagnostics.Log.Warn(string.Format("Could not find {0} checkout data when processing invoice payment", typeof(IInvoicePayment)), this);
            }
            else if (string.IsNullOrWhiteSpace(checkout.PurchaseOrderNumber))
            {
                status             = "Invalid Purchase Order";
                this.PaymentStatus = PaymentStatus.Failure;
            }
            //TODO: additional validation of purchase order number could go here if needed
            else
            {
                status             = "OK";
                this.PaymentStatus = PaymentStatus.Succeeded;
            }

            var transactionData = Sitecore.Ecommerce.Context.Entity.Resolve <ITransactionData>();

            transactionData.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber,
                                               this.PaymentStatus.ToString(),
                                               null,
                                               paymentArgs.ShoppingCart.Totals.TotalPriceIncVat.ToString(),
                                               paymentArgs.ShoppingCart.Currency.Code,
                                               string.Empty,
                                               string.Empty,
                                               status,
                                               string.Empty);
        }
        /// <summary>
        /// You must implement this method for any integrated/onsite payment provider.
        /// </summary>
        public override void Invoke(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs)
        {
            //read credit card and cart from PaymentArgs
            var args       = Assert.ResultNotNull(paymentArgs as ActiveCommerce.Payments.PaymentArgs, "PaymentArgs must be of type ActiveCommerce.Payments.PaymentArgs");
            var creditCard = Assert.ResultNotNull(args.PaymentDetails as ActiveCommerce.Payments.CreditCardInfo, "PaymentDetails must be of type ActiveCommerce.Payments.CreditCardInfo");
            var cart       = Assert.ResultNotNull(args.ShoppingCart as ShoppingCart, "Cart must be of type ActiveCommerce.Carts.ShoppingCart");

            //PaymentSystem contains values configured on payment item
            var paymentService = new MockPaymentService
            {
                EndpointUrl = paymentSystem.PaymentUrl,
                Username    = paymentSystem.Username,
                Password    = paymentSystem.Password
            };

            //XML settings can be read from PaymentSystem using PaymentSettingsReader
            var settingsReader   = new Sitecore.Ecommerce.Payments.PaymentSettingsReader(paymentSystem);
            var authorizeSetting = settingsReader.GetSetting("authorizeOnly");
            var authorizeOnly    = authorizeSetting != null &&
                                   Boolean.TrueString.ToLower().Equals(authorizeSetting.ToLower());

            //read values from cart as needed to construct payment gateway request
            var request = new Request
            {
                RequestType         = authorizeOnly ? RequestType.Authorize : RequestType.AuthorizeAndCapture,
                Amount              = cart.Totals.TotalPriceIncVat,
                Currency            = cart.Currency.Code,
                MerchantOrderNumber = cart.OrderNumber,
                BillToAddress       = new Address
                {
                    Address1   = cart.CustomerInfo.BillingAddress.Address,
                    Address2   = cart.CustomerInfo.BillingAddress.Address2,
                    City       = cart.CustomerInfo.BillingAddress.City,
                    State      = cart.CustomerInfo.BillingAddress.State,
                    Country    = cart.CustomerInfo.BillingAddress.Country.Code,
                    PostalCode = cart.CustomerInfo.BillingAddress.Zip,
                    Email      = cart.CustomerInfo.Email,
                    Phone      = cart.CustomerInfo.BillingAddress.GetPhoneNumber()
                },
                CreditCard = new CreditCard
                {
                    CardNumber   = creditCard.CardNumber,
                    CardType     = creditCard.CardType,
                    Expiration   = creditCard.ExpirationDate.ToString("MM/yy"),
                    SecurityCode = creditCard.SecurityCode
                }
            };
            var response = paymentService.ExecuteRequest(request);

            //IMPORTANT: Set the PaymentStatus based on response from the payment gateway
            if (response.ResponseStatus == ResponseStatus.Success)
            {
                this.PaymentStatus = authorizeOnly ? PaymentStatus.Reserved : PaymentStatus.Captured;

                //If authorize/capture doesn't apply, just set as success:
                //this.PaymentStatus = PaymentStatus.Succeeded;
            }
            else
            {
                this.PaymentStatus = PaymentStatus.Failure;
            }

            //IMPORTANT: Save payment details
            TransactionDetails.TransactionNumber = response.TransactionId;
            TransactionDetails.AuthorizationCode = response.AuthorizationCode;
            TransactionDetails.ProviderStatus    = response.ResponseStatus.ToString();
            TransactionDetails.ProviderMessage   = response.Message;
            TransactionDetails.ProviderErrorCode = response.ResponseCode;

            //IMPORTANT: If a reservation / auth only, save the reservation ticket
            if (this.PaymentStatus == PaymentStatus.Reserved)
            {
                TransactionDetails.ReservationTicket = new ReservationTicket
                {
                    InvoiceNumber     = cart.OrderNumber,
                    Amount            = cart.Totals.TotalPriceIncVat,
                    AuthorizationCode = response.AuthorizationCode,
                    TransactionNumber = response.TransactionId
                };
            }
        }
        /// <summary>
        /// Allows the issue of a credit to a card after a captured transaction. Used in particular
        /// when order processing fails if a payment gateway is configured for authorize-and-capture.
        /// </summary>
        public virtual void Credit(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs, ReservationTicket reservationTicket)
        {
            var paymentService = new MockPaymentService
            {
                EndpointUrl = paymentSystem.PaymentUrl,
                Username    = paymentSystem.Username,
                Password    = paymentSystem.Password
            };

            //amount to credit can be found on the reservation ticket
            var request = new Request
            {
                RequestType         = RequestType.Credit,
                MerchantOrderNumber = reservationTicket.InvoiceNumber,
                TransactionId       = reservationTicket.TransactionNumber,
                Amount = reservationTicket.Amount
            };
            var response = paymentService.ExecuteRequest(request);

            //IMPORTANT: Set PaymentStatus based on response from gateway
            this.PaymentStatus = response.ResponseStatus == ResponseStatus.Success ?
                                 PaymentStatus.Succeeded : PaymentStatus.Failure;
        }
        /// <summary>
        /// Allows for capturing of a payment reservation. Not used by Active Commerce
        /// out of the box, but would be useful if you wish to automate capture in your
        /// Active Commerce implementation.
        /// </summary>
        public virtual void Capture(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs, ReservationTicket reservationTicket, decimal amount)
        {
            var paymentService = new MockPaymentService
            {
                EndpointUrl = paymentSystem.PaymentUrl,
                Username    = paymentSystem.Username,
                Password    = paymentSystem.Password
            };

            //Capture usually requires confirmation of amount to capture,
            //which can be found on the reservation ticket
            var request = new Request
            {
                RequestType         = RequestType.CaptureReservation,
                MerchantOrderNumber = reservationTicket.InvoiceNumber,
                TransactionId       = reservationTicket.TransactionNumber,
                Currency            = paymentArgs.ShoppingCart.Currency.Code,
                Amount = reservationTicket.Amount
            };
            var response = paymentService.ExecuteRequest(request);

            //IMPORTANT: Set PaymentStatus based on response from gateway
            this.PaymentStatus = response.ResponseStatus == ResponseStatus.Success ?
                                 PaymentStatus.Succeeded : PaymentStatus.Failure;
        }
Example #7
0
        public virtual void Credit(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs, ReservationTicket reservationTicket)
        {
            var args = Assert.ResultNotNull(paymentArgs as ActiveCommerce.Payments.PaymentArgs, "PaymentArgs must be of type ActiveCommerce.Payments.PaymentArgs");
            var card = Assert.ResultNotNull(args.PaymentDetails as GiftCardInfo, "PaymentDetails must be of type GiftCardInfo");

            try
            {
                GiftCardManager.Credit(card, args.Amount);
            }
            catch (Exception e)
            {
                PaymentStatus = PaymentStatus.Failure;
                Log.Error(string.Format("Unable to credit gift card: TranactionID={0}; Customer={1}; OrderNumber={2}", reservationTicket.TransactionNumber, paymentArgs.ShoppingCart.GetCustomerNameForLog(), paymentArgs.ShoppingCart.OrderNumber), e, this);
                return;
            }
            PaymentStatus = PaymentStatus.Succeeded;
        }
Example #8
0
        public override void Invoke(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs)
        {
            var args = Assert.ResultNotNull(paymentArgs as ActiveCommerce.Payments.PaymentArgs, "PaymentArgs must be of type ActiveCommerce.Payments.PaymentArgs");
            var card = Assert.ResultNotNull(args.PaymentDetails as GiftCardInfo, "PaymentDetails must be of type GiftCardInfo");

            try
            {
                GiftCardManager.Debit(card, args.Amount);
            }
            catch (Exception e)
            {
                TransactionDetails.ProviderMessage = e.Message;
                PaymentStatus = PaymentStatus.Failure;
                return;
            }
            TransactionDetails.TransactionNumber = Guid.NewGuid().ToString();
            PaymentStatus = PaymentStatus.Succeeded;
        }