public PaymentCompleteResult Complete(PaymentMethod currentPayment, string orderRef)
        {
            PaymentCompleteResult result = new PaymentCompleteResult()
            {
                Success = false
            };

            if (currentPayment.RequireAddressUpdate)
            {
                Log.Info("MasterPass is using best practice flow");
                Log.InfoFormat("Finalizing transaction for payment with ID:{0} belonging to order with ID: {1}",
                               currentPayment.Payment.Id, currentPayment.OrderGroupId);
                var total    = currentPayment.Cart.Total.RoundToLong();
                var totalVat = currentPayment.Cart.TaxTotal.RoundToLong();
                var finalizeTransactionResult = _paymentManager.FinalizeTransaction(orderRef, total, totalVat,
                                                                                    currentPayment.Payment.ClientIpAddress);

                if (!finalizeTransactionResult.Success)
                {
                    Log.InfoFormat(
                        "Finalize transaction failed for payment with ID:{0} belonging to order with ID: {1}. Reason ErrorCode: {2} Description: {3}",
                        currentPayment.Payment.Id, currentPayment.OrderGroupId,
                        finalizeTransactionResult.Status.ErrorCode,
                        finalizeTransactionResult.Status.Description);
                    return(result);
                }

                Log.InfoFormat(
                    "Successfully called finalize transaction for payment with ID:{0} belonging to order with ID: {1}",
                    currentPayment.Payment.Id, currentPayment.OrderGroupId);
            }
            else
            {
                Log.Info("MasterPass is using redirect flow");
            }

            if (_paymentCompleter != null)
            {
                result = _paymentCompleter.Complete(currentPayment, orderRef);
            }

            return(result);
        }
        public PaymentCompleteResult Complete(PaymentMethod currentPayment, string orderRef)
        {
            Log.InfoFormat("Updating transaction details for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);
            string transactionString = ((Mediachase.Commerce.Orders.Payment)currentPayment.Payment).AuthorizationCode;

            Log.InfoFormat("Transaction number is:{0} for payment with ID:{1} belonging to order with ID: {2}", transactionString, currentPayment.Payment.Id, currentPayment.OrderGroupId);

            int transactionNumber;

            if (!Int32.TryParse(transactionString, out transactionNumber))
            {
                Log.ErrorFormat("Could not parse Transaction number:{0} to an Int for payment with ID:{1} belonging to order with ID: {2}", transactionString, currentPayment.Payment.Id, currentPayment.OrderGroupId);
                return(new PaymentCompleteResult());
            }

            TransactionResult transactionDetails = _paymentManager.GetTransactionDetails(transactionNumber);
            bool updated = false;

            if (transactionDetails != null)
            {
                updated = UpdateOrderAddress(currentPayment, transactionDetails);
            }

            PaymentCompleteResult result = new PaymentCompleteResult {
                Success = true
            };

            if (_paymentCompleter != null)
            {
                result = _paymentCompleter.Complete(currentPayment, orderRef);
            }

            if (updated)
            {
                Log.InfoFormat("Successfully updated transaction details for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);
            }

            result.Success = updated;
            return(result);
        }
        public PaymentCompleteResult Complete(PaymentMethod currentPayment, string orderRef)
        {
            Log.InfoFormat("Completing payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);
            CompleteResult completeResult = _paymentManager.Complete(orderRef);

            if (!completeResult.Success || string.IsNullOrWhiteSpace(completeResult.TransactionNumber))
            {
                return new PaymentCompleteResult {
                           TransactionErrorCode = completeResult.ErrorDetails != null ? completeResult.ErrorDetails.TransactionErrorCode : string.Empty
                }
            }
            ;

            if (completeResult.GetTransactionDetails)
            {
                Log.InfoFormat("Retrieving transaction details for payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);

                if (_paymentCompleter == null)
                {
                    _paymentCompleter = new UpdateTransactionDetails(null, _paymentManager);
                }
                _paymentCompleter = new UpdateTransactionDetails(_paymentCompleter, _paymentManager);
            }

            _paymentActions.UpdatePaymentInformation(currentPayment, completeResult.TransactionNumber, completeResult.PaymentMethod);

            PaymentCompleteResult result = new PaymentCompleteResult {
                Success = true
            };

            if (_paymentCompleter != null)
            {
                result = _paymentCompleter.Complete(currentPayment, orderRef);
            }

            Log.InfoFormat("Successfully completed payment with ID:{0} belonging to order with ID: {1}", currentPayment.Payment.Id, currentPayment.OrderGroupId);
            return(result);
        }
    }