Example #1
0
        public bool Capture(PaymentMethod currentPayment)
        {
            Mediachase.Commerce.Orders.Payment payment = (Mediachase.Commerce.Orders.Payment)currentPayment.Payment;
            Log.InfoFormat("Capturing payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId);

            int transactionId;

            if (!int.TryParse(payment.AuthorizationCode, out transactionId))
            {
                Log.ErrorFormat("Could not get PayEx transaction ID from payment with ID:{0} belonging to order with ID: {1}", payment.Id, payment.OrderGroupId);
                return(false);
            }
            Log.InfoFormat("PayEx transaction ID is {0} on payment with ID:{1} belonging to order with ID: {2}", transactionId, payment.Id, payment.OrderGroupId);

            long          amount      = payment.Amount.RoundToLong();
            string        orderNumber = OrderNumberFormatter.MakeNumeric(currentPayment.PurchaseOrder.TrackingNumber);
            CaptureResult result      = _paymentManager.Capture(transactionId, amount, orderNumber, currentPayment.Payment.Vat, string.Empty);

            bool success = false;

            if (result.Success && !string.IsNullOrWhiteSpace(result.TransactionNumber))
            {
                Log.InfoFormat("Setting PayEx transaction number to {0} on payment with ID:{1} belonging to order with ID: {2} during capture", result.TransactionNumber, payment.Id, payment.OrderGroupId);
                payment.ValidationCode = result.TransactionNumber;
                payment.AcceptChanges();
                success = true;
                Log.InfoFormat("Successfully captured payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);
            }

            if (_paymentCapturer != null)
            {
                return(_paymentCapturer.Capture(currentPayment) && success);
            }
            return(success);
        }
        public PaymentInformation(long lowestUnitPrice, string priceArgList, string currency, int vat, string orderId, string productNumber, string description, string clientIpAddress,
                                  string additionalValues, string returnUrl, string view, string cancelUrl, string clientLanguage, string purchaseOperation)
        {
            if (!string.IsNullOrWhiteSpace(priceArgList))
            {
                Price        = 0;
                PriceArgList = string.Format(priceArgList, lowestUnitPrice);
            }
            else
            {
                Price        = lowestUnitPrice;
                PriceArgList = string.Empty;
            }

            Currency          = currency;
            Vat               = vat;
            OrderId           = OrderNumberFormatter.MakeNumeric(orderId);
            ProductNumber     = productNumber;
            Description       = description;
            ClientIpAddress   = clientIpAddress;
            ClientIdentifier  = string.Empty; // The information in this field is only used if you are implementing Credit Card in the direct model. And the direct model is not supported by this provider
            AdditionalValues  = additionalValues;
            ReturnUrl         = string.Format(returnUrl, orderId);
            View              = view;
            AgreementRef      = string.Empty; // The provider does not support recurring payments
            CancelUrl         = cancelUrl;
            ClientLanguage    = clientLanguage;
            PurchaseOperation = purchaseOperation;
        }
        public bool Credit(PaymentMethod currentPayment)
        {
            Mediachase.Commerce.Orders.Payment payment = (Mediachase.Commerce.Orders.Payment)currentPayment.Payment;
            Log.InfoFormat("Crediting payment with ID:{0} belonging to order with ID: {1}, by order lines", payment.Id, payment.OrderGroupId);

            int transactionId;

            if (!int.TryParse(payment.AuthorizationCode, out transactionId))
            {
                Log.ErrorFormat("Could not get PayEx Transaction Id from purchase order with ID: {0}", currentPayment.PurchaseOrder.Id);
                return(false);
            }
            Log.InfoFormat("PayEx transaction ID is {0} on payment with ID:{1} belonging to order with ID: {2}", transactionId, payment.Id, payment.OrderGroupId);

            CreditResult result      = null;
            string       orderNumber = OrderNumberFormatter.MakeNumeric(currentPayment.PurchaseOrder.TrackingNumber);

            foreach (OrderForm orderForm in currentPayment.PurchaseOrder.OrderForms)
            {
                foreach (LineItem lineItem in orderForm.LineItems)
                {
                    result = _paymentManager.CreditOrderLine(transactionId, lineItem.CatalogEntryId, orderNumber);
                }
            }

            bool success = false;

            if (result != null && !string.IsNullOrWhiteSpace(result.TransactionNumber))
            {
                Log.InfoFormat("Setting PayEx transaction number to {0} on payment with ID:{1} belonging to order with ID: {2} during credit", result.TransactionNumber, payment.Id, payment.OrderGroupId);
                payment.TransactionID = result.TransactionNumber;
                payment.AcceptChanges();
                success = true;
                Log.InfoFormat("Successfully credited payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);
            }

            if (_paymentCreditor != null)
            {
                return(_paymentCreditor.Credit(currentPayment) && success);
            }
            return(success);
        }