예제 #1
0
        public HttpResponseMessage AuthorizePayment(Guid invoiceKey, Guid paymentKey, string token, string payerId)
        {
            var invoice = _invoiceService.GetByKey(invoiceKey);
            var payment = _paymentService.GetByKey(paymentKey);

            if (invoice == null || payment == null || String.IsNullOrEmpty(token) || String.IsNullOrEmpty(payerId))
            {
                var ex = new NullReferenceException(string.Format("Invalid argument exception. Arguments: invoiceKey={0}, paymentKey={1}, token={2}, payerId={3}.", invoiceKey, paymentKey, token, payerId));
                LogHelper.Error <PayPalApiController>("Payment is not authorized.", ex);
                throw ex;
            }

            var result = _processor.AuthorizePayment(invoice, payment, token, payerId);

            _gatewayProviderService.Save(payment);

            if (!result.Payment.Success)
            {
                LogHelper.Error <PayPalApiController>("Payment is not authorized.", result.Payment.Exception);
                throw result.Payment.Exception;
            }

            // redirect to Home page
            var response = Request.CreateResponse(HttpStatusCode.Moved);

            response.Headers.Location = new Uri(PayPalPaymentProcessor.GetWebsiteUrl());
            return(response);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PayPalApiController"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>.
        /// </param>
        public PayPalApiController(IMerchelloContext merchelloContext)
        {
            if (merchelloContext == null) throw new ArgumentNullException("merchelloContext");

	        var providerKey = new Guid(Constants.PayPalPaymentGatewayProviderKey);
            var provider = (PayPalPaymentGatewayProvider)merchelloContext.Gateways.Payment.GetProviderByKey(providerKey);

            if (provider  == null)
            {
                var ex = new NullReferenceException("The PayPalPaymentGatewayProvider could not be resolved.  The provider must be activiated");
                LogHelper.Error<PayPalApiController>("PayPalPaymentGatewayProvider not activated.", ex);
                throw ex;
            }

            _merchelloContext = merchelloContext;
            _processor = new PayPalPaymentProcessor(provider.ExtendedData.GetProcessorSettings());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PayPalApiController"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>.
        /// </param>
        public PayPalApiController(IMerchelloContext merchelloContext)
        {
            if (merchelloContext == null)
            {
                throw new ArgumentNullException("merchelloContext");
            }

            var providerKey = new Guid(Constants.PayPalPaymentGatewayProviderKey);
            var provider    = (PayPalPaymentGatewayProvider)merchelloContext.Gateways.Payment.GetProviderByKey(providerKey);

            if (provider == null)
            {
                var ex = new NullReferenceException("The PayPalPaymentGatewayProvider could not be resolved.  The provider must be activiated");
                LogHelper.Error <PayPalApiController>("PayPalPaymentGatewayProvider not activated.", ex);
                throw ex;
            }

            _merchelloContext = merchelloContext;
            _processor        = new PayPalPaymentProcessor(provider.ExtendedData.GetProcessorSettings());
        }
 public PayPalPaymentGatewayMethod(IGatewayProviderService gatewayProviderService, IPaymentMethod paymentMethod, ExtendedDataCollection providerExtendedData)
     : base(gatewayProviderService, paymentMethod)
 {
     _processor = new PayPalPaymentProcessor(providerExtendedData.GetProcessorSettings());
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PayPalPaymentGatewayMethod"/> class.
 /// </summary>
 /// <param name="gatewayProviderService">
 /// The gateway provider service.
 /// </param>
 /// <param name="paymentMethod">
 /// The payment method.
 /// </param>
 /// <param name="providerExtendedData">
 /// The provider extended data.
 /// </param>
 public PayPalPaymentGatewayMethod(IGatewayProviderService gatewayProviderService, IPaymentMethod paymentMethod, ExtendedDataCollection providerExtendedData)
     : base(gatewayProviderService, paymentMethod)
 {
     _processor = new PayPalPaymentProcessor(providerExtendedData.GetProcessorSettings());
 }