Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PaymentProcessor"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>e
        /// <param name="request">
        /// The request.
        /// </param>
        public PaymentProcessor(IMerchelloContext merchelloContext, PaymentRequestDisplay request)
        {
            Mandate.ParameterNotNull(merchelloContext, "merchelloContext");

            this._merchelloContext = merchelloContext;

            this.Initialize(request);
        }
Example #2
0
        /// <summary>
        /// Initializes "this" object
        /// </summary>
        /// <param name="request">
        /// The incoming <see cref="PaymentRequestDisplay"/>
        /// </param>
        private void Initialize(PaymentRequestDisplay request)
        {
            this._invoice = this._merchelloContext.Services.InvoiceService.GetByKey(request.InvoiceKey);

            if (request.PaymentKey != null)
                this._payment = this._merchelloContext.Services.PaymentService.GetByKey(request.PaymentKey.Value);

            this._paymentGatewayMethod =
                this._merchelloContext.Gateways.Payment.GetPaymentGatewayMethodByKey(request.PaymentMethodKey);

            this._amount = request.Amount;

            foreach (var arg in request.ProcessorArgs)
            {
                this._args.Add(arg.Key, arg.Value);
            }
        }
Example #3
0
        public PaymentResultDisplay VoidPayment(PaymentRequestDisplay request)
        {
            var processor = new PaymentProcessor(MerchelloContext, request);

            var voided = processor.Void();

            var result = new PaymentResultDisplay()
            {
                Success = voided.Payment.Success,
                Invoice = voided.Invoice.ToInvoiceDisplay(),
                Payment = voided.Payment.Result.ToPaymentDisplay(),
                ApproveOrderCreation = voided.ApproveOrderCreation
            };

            if (voided.Payment.Success)
            {
                voided.Payment.Result.AuditPaymentVoided();
            }

            return result;
        }
Example #4
0
        /// <summary>
        /// Returns a payment result for an refund operation
        /// 
        /// GET /umbraco/Merchello/PaymentApi/RefundPayment/
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="PaymentDisplay"/>.
        /// </returns>
        public PaymentResultDisplay RefundPayment(PaymentRequestDisplay request)
        {
            var processor = new PaymentProcessor(MerchelloContext, request);

            var refund = processor.Refund();

            var result = new PaymentResultDisplay()
            {
                Success = refund.Payment.Success,
                Invoice = refund.Invoice.ToInvoiceDisplay(),
                Payment = refund.Payment.Result.ToPaymentDisplay(),
                ApproveOrderCreation = refund.ApproveOrderCreation
            };

            if (refund.Payment.Success)
            {
               refund.Payment.Result.AuditPaymentRefunded(request.Amount);
            }

            return result;
        }
Example #5
0
        public PaymentResultDisplay CapturePayment(PaymentRequestDisplay request)
        {
            var processor = new PaymentProcessor(MerchelloContext, request);

            var capture = processor.Capture();

            var result = new PaymentResultDisplay()
            {
                Success = capture.Payment.Success,
                Invoice = capture.Invoice.ToInvoiceDisplay(),
                Payment = capture.Payment.Result.ToPaymentDisplay(),
                ApproveOrderCreation = capture.ApproveOrderCreation
            };

            if (!capture.Payment.Success)
            {
                capture.Payment.Result.AuditPaymentDeclined();
            }
            else
            {
                capture.Payment.Result.AuditPaymentCaptured(request.Amount);
            }

            return result;
        }
Example #6
0
        public PaymentResultDisplay AuthorizePayment(PaymentRequestDisplay request)
        {
            var processor = new PaymentProcessor(MerchelloContext, request);
            var authorize = processor.Authorize();

            var result = new PaymentResultDisplay()
            {
                Success = authorize.Payment.Success,
                Invoice = authorize.Invoice.ToInvoiceDisplay(),
                Payment = authorize.Payment.Result.ToPaymentDisplay(),
                ApproveOrderCreation = authorize.ApproveOrderCreation
            };

            if (!authorize.Payment.Success)
            {
                authorize.Payment.Result.AuditPaymentDeclined();
            }
            else
            {
                authorize.Payment.Result.AuditPaymentAuthorize(authorize.Invoice);
            }

            return result;
        }