Example #1
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();

            // (Required) A timestamped token, the value of which was returned by SetExpressCheckout response.
            // Character length and limitations: 20 single-byte characters
            request.Token = token.Value;

            // Invoke the API
            GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq();

            wrapper.GetExpressCheckoutDetailsRequest = request;

            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
            Dictionary <string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            // # API call
            // Invoke the GetExpressCheckoutDetails method in service wrapper object
            GetExpressCheckoutDetailsResponseType ecResponse = service.GetExpressCheckoutDetails(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, ecResponse);
        }
Example #2
0
        /**
         *
         */
        public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetails(GetExpressCheckoutDetailsReq GetExpressCheckoutDetailsReq, string apiUsername)
        {
            setStandardParams(GetExpressCheckoutDetailsReq.GetExpressCheckoutDetailsRequest);
            string resp = call("GetExpressCheckoutDetails", GetExpressCheckoutDetailsReq.toXMLString(), apiUsername);

            return(new GetExpressCheckoutDetailsResponseType(resp));
        }
        /// <summary>
        /// Performs the GetExpressCheckoutDetails operation.
        /// </summary>
        /// <param name="payment">
        /// The payment.
        /// </param>
        /// <param name="token">
        /// The token.
        /// </param>
        /// <param name="record">
        /// The record.
        /// </param>
        /// <returns>
        /// The <see cref="PayPalExpressTransactionRecord"/>.
        /// </returns>
        internal PayPalExpressTransactionRecord GetExpressCheckoutDetails(IPayment payment, string token, PayPalExpressTransactionRecord record)
        {
            record.Success = true;
            ExpressCheckoutResponse result = null;

            try
            {
                var getDetailsRequest = new GetExpressCheckoutDetailsReq
                {
                    GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token)
                };

                var service  = GetPayPalService();
                var response = service.GetExpressCheckoutDetails(getDetailsRequest);
                result = _responseFactory.Build(response, token);

                if (result.Success())
                {
                    record.Data.PayerId = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
                }
            }
            catch (Exception ex)
            {
                result = _responseFactory.Build(ex);
            }

            record.GetExpressCheckoutDetails = result;
            record.Success = result.Success();
            return(record);
        }
Example #4
0
        public ActionResult PaymentDetails(string token)
        {
            if (token.IsNullOrWhiteSpace())
            {
                return(RedirectToAction("PayPalCancel"));
            }
            GetExpressCheckoutDetailsReq          req         = PayPalHelper.GetGetExpressCheckoutDetailsReq(token);
            CustomSecurityHeaderType              credentials = PayPalHelper.GetPayPalCredentials();
            PayPalAPIAAInterfaceClient            client      = new PayPalAPIAAInterfaceClient();
            GetExpressCheckoutDetailsResponseType response    = client.GetExpressCheckoutDetails(ref credentials, req);

            if (response.Errors != null && response.Errors.Length > 0)
            {
                throw new Exception("Exception occured when calling PayPal: " + response.Errors[0].LongMessage);
            }
            GetExpressCheckoutDetailsResponseDetailsType respDetails = response.GetExpressCheckoutDetailsResponseDetails;
            Order order = PayPalHelper.UpdateOrderAfterAuthentication(respDetails.Custom, respDetails.PayerInfo.PayerID);
            var   model = new PaymentModel
            {
                Order     = order,
                BuyerName = respDetails.PayerInfo.PayerName.FirstName + respDetails.PayerInfo.PayerName.LastName
            };

            Session["CheckoutDetails"] = response;
            return(View("PaymentDetails", model));
        }
Example #5
0
        public ActionResult GetExpressCheckout(string token, string orderId)
        {
            var config  = ConfigManager.Instance.GetProperties();
            var service = new PayPalAPIInterfaceServiceService(config);
            var request = new GetExpressCheckoutDetailsReq
            {
                GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType
                {
                    Token = token
                }
            };

            var response = service.GetExpressCheckoutDetails(request);

            if (response.Ack.ToString().Trim().ToUpper().Equals(AckCodeType.SUCCESS.ToString()))
            {
                _orderService = new OrderService();
                var isMarked = _orderService.MarkOrderAsPaid(orderId);

                // TODO process this exception
                if (!isMarked)
                {
                    throw new Exception("Order was not marked as paid");
                }
                return(SuccessTransaction());
            }

            return(ErrorTransaction());
        }
Example #6
0
 public static PayerInfoType GetExpressCheckout(string token)
 {
     System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
     using (var client = new PayPalAPIAAInterfaceClient(new BasicHttpsBinding(), new EndpointAddress(EndpointUrl)))
     {
         var credentials = new CustomSecurityHeaderType()
         {
             Credentials = new UserIdPasswordType()
             {
                 Username  = APIUserName,
                 Password  = APIPassword,
                 Signature = APISignature
             }
         };
         GetExpressCheckoutDetailsReq req = new GetExpressCheckoutDetailsReq()
         {
             GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType()
             {
                 Version = "121.0",
                 Token   = token
             }
         };
         var    resp   = client.GetExpressCheckoutDetails(ref credentials, req);
         string errors = CheckErrors(resp);
         if (errors == String.Empty)
         {
             return(resp.GetExpressCheckoutDetailsResponseDetails.PayerInfo);
         }
         return(new PayerInfoType()
         {
             PayerID = errors
         });
     }
 }
Example #7
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            PayPalAPIInterfaceServiceService service      = new PayPalAPIInterfaceServiceService();
            GetExpressCheckoutDetailsReq     getECWrapper = new GetExpressCheckoutDetailsReq();

            getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token.Value);
            GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper);

            // Create request object
            DoExpressCheckoutPaymentRequestType        request        = new DoExpressCheckoutPaymentRequestType();
            DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = requestDetails;

            requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
            requestDetails.Token          = token.Value;
            requestDetails.PayerID        = payerId.Value;
            requestDetails.PaymentAction  = (PaymentActionCodeType)
                                            Enum.Parse(typeof(PaymentActionCodeType), paymentAction.SelectedValue);

            // Invoke the API
            DoExpressCheckoutPaymentReq wrapper = new DoExpressCheckoutPaymentReq();

            wrapper.DoExpressCheckoutPaymentRequest = request;
            DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, doECResponse);
        }
Example #8
0
        public void DoExpressCheckoutPayment(string token, string payerId)
        {
            var service      = new PayPalAPIInterfaceServiceService();
            var getECWrapper = new GetExpressCheckoutDetailsReq {
                GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token)
            };

            var request        = new DoExpressCheckoutPaymentRequestType();
            var requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = requestDetails;

            var getECResponse = service.GetExpressCheckoutDetails(getECWrapper);

            requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
            requestDetails.Token          = token;
            requestDetails.PayerID        = payerId;
            requestDetails.PaymentAction  = PaymentActionCodeType.SALE;

            var wrapper = new DoExpressCheckoutPaymentReq {
                DoExpressCheckoutPaymentRequest = request
            };

            var doECResponse = service.DoExpressCheckoutPayment(wrapper);

            var ack = doECResponse.Ack.HasValue ? doECResponse.Ack.Value : AckCodeType.FAILURE;

            AssertCheckoutResponse(ack, doECResponse.Errors);
        }
    // # GetExpressCheckout API Operation
    // The GetExpressCheckoutDetails API operation obtains information about an Express Checkout transaction
    public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetailsAPIOperation()
    {
        // Create the GetExpressCheckoutDetailsResponseType object
        GetExpressCheckoutDetailsResponseType responseGetExpressCheckoutDetailsResponseType = new GetExpressCheckoutDetailsResponseType();

        try
        {
            // Create the GetExpressCheckoutDetailsReq object
            GetExpressCheckoutDetailsReq getExpressCheckoutDetails = new GetExpressCheckoutDetailsReq();

            // A timestamped token, the value of which was returned by `SetExpressCheckout` response
            GetExpressCheckoutDetailsRequestType getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType("EC-11U13522TP7143059");
            getExpressCheckoutDetails.GetExpressCheckoutDetailsRequest = getExpressCheckoutDetailsRequest;

            // Create the service wrapper object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();

            // # API call
            // Invoke the GetExpressCheckoutDetails method in service wrapper object
            responseGetExpressCheckoutDetailsResponseType = service.GetExpressCheckoutDetails(getExpressCheckoutDetails);

            if (responseGetExpressCheckoutDetailsResponseType != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "GetExpressCheckoutDetails API Operation - ";
                acknowledgement += responseGetExpressCheckoutDetailsResponseType.Ack.ToString();
                logger.Info(acknowledgement + "\n");
                Console.WriteLine(acknowledgement + "\n");

                // # Success values
                if (responseGetExpressCheckoutDetailsResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // Unique PayPal Customer Account identification number. This
                    // value will be null unless you authorize the payment by
                    // redirecting to PayPal after `SetExpressCheckout` call.
                    logger.Info("Payer ID : " + responseGetExpressCheckoutDetailsResponseType.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID + "\n");
                    Console.WriteLine("Payer ID : " + responseGetExpressCheckoutDetailsResponseType.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID + "\n");
                }
                // # Error Values
                else
                {
                    List <ErrorType> errorMessages = responseGetExpressCheckoutDetailsResponseType.Errors;
                    foreach (ErrorType error in errorMessages)
                    {
                        logger.Debug("API Error Message : " + error.LongMessage);
                        Console.WriteLine("API Error Message : " + error.LongMessage + "\n");
                    }
                }
            }
        }
        // # Exception log
        catch (System.Exception ex)
        {
            // Log the exception message
            logger.Debug("Error Message : " + ex.Message);
            Console.WriteLine("Error Message : " + ex.Message);
        }
        return(responseGetExpressCheckoutDetailsResponseType);
    }
        /**
         * AUTO_GENERATED
         */
        public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetails(GetExpressCheckoutDetailsReq getExpressCheckoutDetailsReq, string apiUserName)
        {
            setStandardParams(getExpressCheckoutDetailsReq.GetExpressCheckoutDetailsRequest);
            string      response    = Call("GetExpressCheckoutDetails", getExpressCheckoutDetailsReq.ToXMLString(), apiUserName);
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(response);
            XmlNode xmlNode = xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='GetExpressCheckoutDetailsResponse']");

            return(new GetExpressCheckoutDetailsResponseType(xmlNode));
        }
        public IPaymentResult CompletePayment(IInvoice invoice, IPayment payment, string token, string payerId)
        {
            var config = new Dictionary <string, string>
            {
                { "mode", "sandbox" },
                { "account1.apiUsername", _settings.ApiUsername },
                { "account1.apiPassword", _settings.ApiPassword },
                { "account1.apiSignature", _settings.ApiSignature }
            };
            var service = new PayPalAPIInterfaceServiceService(config);

            var getExpressCheckoutDetails = new GetExpressCheckoutDetailsReq
            {
                GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token)
            };
            var expressCheckoutDetailsResponse = service.GetExpressCheckoutDetails(getExpressCheckoutDetails);

            if (expressCheckoutDetailsResponse != null)
            {
                if (expressCheckoutDetailsResponse.Ack == AckCodeType.SUCCESS)
                {
                    // do express checkout
                    var doExpressCheckoutPayment = new DoExpressCheckoutPaymentReq();
                    var doExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType
                    {
                        Token          = token,
                        PayerID        = payerId,
                        PaymentDetails = new List <PaymentDetailsType> {
                            GetPaymentDetails(invoice)
                        }
                    };

                    var doExpressCheckoutPaymentRequest =
                        new DoExpressCheckoutPaymentRequestType(doExpressCheckoutPaymentRequestDetails);
                    doExpressCheckoutPayment.DoExpressCheckoutPaymentRequest = doExpressCheckoutPaymentRequest;

                    var doExpressCheckoutPaymentResponse = service.DoExpressCheckoutPayment(doExpressCheckoutPayment);

                    if (doExpressCheckoutPaymentResponse != null)
                    {
                        if (doExpressCheckoutPaymentResponse.Ack == AckCodeType.SUCCESS)
                        {
                            payment.Authorized = true;
                            payment.Collected  = true;
                            return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, true));
                        }
                    }
                }
            }

            return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, false));
        }
Example #12
0
        public static GetExpressCheckoutDetailsReq GetGetExpressCheckoutDetailsReq(string token)
        {
            GetExpressCheckoutDetailsReq req = new GetExpressCheckoutDetailsReq()
            {
                GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType()
                {
                    Version = ConfigurationManager.AppSettings["PayPalAPIVersion"],
                    Token   = token
                }
            };

            return(req);
        }
Example #13
0
        public static PayPalConfirmPaymentModel GetPayment(string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException("token");
            }

            Dictionary <string, string>      config       = PayPal.Api.ConfigManager.Instance.GetProperties();
            PayPalAPIInterfaceServiceService service      = new PayPalAPIInterfaceServiceService(config);
            GetExpressCheckoutDetailsReq     getECWrapper = new GetExpressCheckoutDetailsReq();

            getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token);

            GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper);

            DoExpressCheckoutPaymentRequestType        request        = new DoExpressCheckoutPaymentRequestType();
            DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = requestDetails;

            requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
            requestDetails.Token          = getECResponse.GetExpressCheckoutDetailsResponseDetails.Token;
            requestDetails.PayerID        = getECResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;

            DoExpressCheckoutPaymentReq wrapper = new DoExpressCheckoutPaymentReq();

            wrapper.DoExpressCheckoutPaymentRequest = request;
            DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(wrapper);

            if (doECResponse.Ack == AckCodeType.SUCCESS)
            {
                var paymentInfo = doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.First();

                var confirmModel = new PayPalConfirmPaymentModel
                {
                    Success          = true,
                    PaymentRequestID = paymentInfo.PaymentRequestID,
                    OrderTotal       = decimal.Parse(paymentInfo.GrossAmount.value),
                    OrderDate        = string.IsNullOrEmpty(paymentInfo.PaymentDate)
                                                ? DateTimeOffset.Parse(paymentInfo.PaymentDate)
                                                : (DateTimeOffset?)null
                };
                return(confirmModel);
            }
            return(new PayPalConfirmPaymentModel
            {
                Success = false,
                ErrorMessage = string.Join(". ", doECResponse.Errors.Select(x => x.LongMessage).ToList())
            });
        }
 GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetailsRequest(IPaymentGatewaySettings settings, string token)
 {
     GetExpressCheckoutDetailsReq req = new GetExpressCheckoutDetailsReq();
     GetExpressCheckoutDetailsResponseType result = null;
     var request = new GetExpressCheckoutDetailsRequestType();
     req.GetExpressCheckoutDetailsRequest = request;
     request.Token = token;
     request.Version = API_VERSION;
     var service = GetPayPalAAInterfaceClient(settings);
     CustomSecurityHeaderType customSecurityHeader = new CustomSecurityHeaderType();
     GetExpressCheckoutDetailsResponseType response = service.GetExpressCheckoutDetails(ref customSecurityHeader, req);
     result = response;
     return response;
 }
Example #15
0
        private GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetailsResponse(FinancialGateway financialGateway, String token, out string errorMessage)
        {
            errorMessage = string.Empty;


            // Create the GetExpressCheckoutDetailsResponseType object
            GetExpressCheckoutDetailsResponseType responseGetExpressCheckoutDetailsResponseType = new GetExpressCheckoutDetailsResponseType();

            try
            {
                // Create the GetExpressCheckoutDetailsReq object
                GetExpressCheckoutDetailsReq getExpressCheckoutDetails = new GetExpressCheckoutDetailsReq();

                // A timestamped token, the value of which was returned by `SetExpressCheckout` response
                GetExpressCheckoutDetailsRequestType getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token);
                getExpressCheckoutDetails.GetExpressCheckoutDetailsRequest = getExpressCheckoutDetailsRequest;

                // Create the service wrapper object to make the API call
                PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(GetCredentials(financialGateway));

                // # API call
                // Invoke the GetExpressCheckoutDetails method in service wrapper object
                responseGetExpressCheckoutDetailsResponseType = service.GetExpressCheckoutDetails(getExpressCheckoutDetails);

                if (responseGetExpressCheckoutDetailsResponseType != null)
                {
                    // # Success values
                    if (responseGetExpressCheckoutDetailsResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                    {
                        return(responseGetExpressCheckoutDetailsResponseType);
                    }
                    // # Error Values
                    else
                    {
                        List <ErrorType> errorMessages = responseGetExpressCheckoutDetailsResponseType.Errors;
                        foreach (ErrorType error in errorMessages)
                        {
                            errorMessage += "API Error Message : " + error.LongMessage + "\n";
                        }
                    }
                }
            }
            // # Exception log
            catch (System.Exception ex)
            {
                errorMessage += "Error Message : " + ex.Message;
            }
            return(null);
        }
Example #16
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
            Dictionary <string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            GetExpressCheckoutDetailsReq getECWrapper = new GetExpressCheckoutDetailsReq();

            // (Required) A timestamped token, the value of which was returned by SetExpressCheckout response.
            // Character length and limitations: 20 single-byte characters
            getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token.Value);
            // # API call
            // Invoke the GetExpressCheckoutDetails method in service wrapper object
            GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper);

            // Create request object
            DoExpressCheckoutPaymentRequestType        request        = new DoExpressCheckoutPaymentRequestType();
            DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = requestDetails;

            requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
            // (Required) The timestamped token value that was returned in the SetExpressCheckout response and passed in the GetExpressCheckoutDetails request.
            requestDetails.Token = token.Value;
            // (Required) Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
            requestDetails.PayerID = payerId.Value;
            // (Required) How you want to obtain payment. It is one of the following values:
            // * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
            // * Order – This payment is an order authorization subject to settlement with PayPal Authorization and Capture.
            // * Sale – This is a final sale for which you are requesting payment.
            // Note: You cannot set this value to Sale in the SetExpressCheckout request and then change this value to Authorization in the DoExpressCheckoutPayment request.
            requestDetails.PaymentAction = (PaymentActionCodeType)
                                           Enum.Parse(typeof(PaymentActionCodeType), paymentAction.SelectedValue);

            // Invoke the API
            DoExpressCheckoutPaymentReq wrapper = new DoExpressCheckoutPaymentReq();

            wrapper.DoExpressCheckoutPaymentRequest = request;
            // # API call
            // Invoke the DoExpressCheckoutPayment method in service wrapper object
            DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, doECResponse);
        }
Example #17
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();

            request.Token = token.Value;

            // Invoke the API
            GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq();

            wrapper.GetExpressCheckoutDetailsRequest = request;
            PayPalAPIInterfaceServiceService      service    = new PayPalAPIInterfaceServiceService();
            GetExpressCheckoutDetailsResponseType ecResponse = service.GetExpressCheckoutDetails(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, ecResponse);
        }
Example #18
0
        private GetExpressCheckoutDetailsResponseType _GetExpressCheckoutDetails(string token)
        {
            var wrapper = new GetExpressCheckoutDetailsReq {
                GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType {
                    Token = token
                }
            };
            var          response = _payPalApiService.GetExpressCheckoutDetails(wrapper, GetApiUserName());
            var          custom0  = response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails[0].Custom.Split('|')[0];
            ProductNames productName;

            if (!Enum.TryParse(custom0, true, out productName))
            {
                throw new KatushaProductNameNotFoundException(custom0);
            }
            return(response);
        }
Example #19
0
        public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetails(string token)
        {
            var result   = new GetExpressCheckoutDetailsResponseType();
            var settings = Services.Settings.LoadSetting <PayPalExpressPaymentSettings>(Services.StoreContext.CurrentStore.Id);

            using (var service = GetApiAaService(settings))
            {
                var req = new GetExpressCheckoutDetailsReq();
                req.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType
                {
                    Token   = token,
                    Version = ApiVersion
                };

                result = service.GetExpressCheckoutDetails(req);
            }
            return(result);
        }
        public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetails(string token)
        {
            var result = new GetExpressCheckoutDetailsResponseType();

            using (var service = new PayPalAPIAASoapBinding())
            {
                var req = new GetExpressCheckoutDetailsReq();
                req.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType
                {
                    Token   = token,
                    Version = PayPalHelper.GetApiVersion()
                };

                service.Url = PayPalHelper.GetPaypalServiceUrl(Settings);
                service.RequesterCredentials = PayPalHelper.GetPaypalApiCredentials(Settings);
                result = service.GetExpressCheckoutDetails(req);
            }
            return(result);
        }
Example #21
0
        public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetails(string token)
        {
            var result   = new GetExpressCheckoutDetailsResponseType();
            var settings = CommonServices.Settings.LoadSetting <PayPalExpressPaymentSettings>(CommonServices.StoreContext.CurrentStore.Id);

            using (var service = new PayPalAPIAASoapBinding())
            {
                var req = new GetExpressCheckoutDetailsReq();
                req.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType
                {
                    Token   = token,
                    Version = PayPalHelper.GetApiVersion()
                };

                service.Url = PayPalHelper.GetPaypalServiceUrl(settings);
                service.RequesterCredentials = PayPalHelper.GetPaypalApiCredentials(settings);
                result = service.GetExpressCheckoutDetails(req);
            }
            return(result);
        }
Example #22
0
        public Commerce.Common.Address GetExpressCheckout(string token)
        {
            //PayerInfo payer = new PayerInfo();
            Commerce.Common.Address payer = new Commerce.Common.Address();

            PayPalSvc.GetExpressCheckoutDetailsReq         req         = new GetExpressCheckoutDetailsReq();
            PayPalSvc.GetExpressCheckoutDetailsRequestType requestType = new GetExpressCheckoutDetailsRequestType();


            requestType.Token   = token;
            requestType.Version = PayPalServiceUtility.PayPalAPIVersionNumber;

            req.GetExpressCheckoutDetailsRequest = requestType;

            PayPalSvc.GetExpressCheckoutDetailsResponseType response = service2.GetExpressCheckoutDetails(req);

            string sOut = "";

            string errors = this.CheckErrors(response);

            if (errors == string.Empty)
            {
                string ack = response.Ack.ToString();
                payer.Email         = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
                payer.PayPalPayerID = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
                payer.FirstName     = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName;
                payer.LastName      = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName;
                payer.Address1      = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
                payer.Address2      = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
                payer.City          = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
                payer.StateOrRegion = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
                payer.Zip           = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
                payer.PayPalToken   = response.GetExpressCheckoutDetailsResponseDetails.Token;
                payer.Country       = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName;
            }
            else
            {
                payer.PayPalPayerID = errors;
            }
            return(payer);
        }
        /// <summary>
        /// Gets a paypal express checkout result
        /// </summary>
        /// <param name="token">paypal express checkout token</param>
        /// <returns>Paypal payer</returns>
        public PaypalPayer GetExpressCheckout(string token)
        {
            InitSettings();
            GetExpressCheckoutDetailsReq         req     = new GetExpressCheckoutDetailsReq();
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();

            req.GetExpressCheckoutDetailsRequest = request;

            request.Token   = token;
            request.Version = this.APIVersion;

            GetExpressCheckoutDetailsResponseType response = service2.GetExpressCheckoutDetails(req);

            string error;

            if (!PaypalHelper.CheckSuccess(response, out error))
            {
                throw new NopException(error);
            }

            PaypalPayer payer = new PaypalPayer();

            payer.PayerEmail        = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
            payer.FirstName         = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName;
            payer.LastName          = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName;
            payer.CompanyName       = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerBusiness;
            payer.Address1          = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
            payer.Address2          = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
            payer.City              = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
            payer.State             = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
            payer.Zipcode           = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
            payer.Phone             = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone;
            payer.PaypalCountryName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName;
            payer.CountryCode       = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
            payer.PayerID           = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
            payer.Token             = response.GetExpressCheckoutDetailsResponseDetails.Token;
            return(payer);
        }
Example #24
0
        public DoExpressCheckoutPaymentResponseType DoExpressCheckout(HttpResponseBase response, string token)
        {
            var getCheckoutRequest = new GetExpressCheckoutDetailsRequestType();

            getCheckoutRequest.Token = token;
            var getCheckOutInfo = new GetExpressCheckoutDetailsReq();

            getCheckOutInfo.GetExpressCheckoutDetailsRequest = getCheckoutRequest;
            var service     = new PayPalAPIInterfaceServiceService();
            var getResponse = service.GetExpressCheckoutDetails(getCheckOutInfo);
            var doRequest   = new DoExpressCheckoutPaymentRequestType();
            var requestInfo = new DoExpressCheckoutPaymentRequestDetailsType();

            doRequest.DoExpressCheckoutPaymentRequestDetails = requestInfo;
            requestInfo.PaymentDetails = getResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
            requestInfo.Token          = token;
            requestInfo.PayerID        = getResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
            requestInfo.PaymentAction  = PaymentActionCodeType.SALE;
            var wrapper = new DoExpressCheckoutPaymentReq();

            wrapper.DoExpressCheckoutPaymentRequest = doRequest;
            return(service.DoExpressCheckoutPayment(wrapper));
        }
        /// <summary>
        /// Performs the GetExpressCheckoutDetails operation.
        /// </summary>
        /// <param name="payment">
        /// The payment.
        /// </param>
        /// <param name="token">
        /// The token.
        /// </param>
        /// <param name="record">
        /// The record.
        /// </param>
        /// <returns>
        /// The <see cref="PayPalExpressTransactionRecord"/>.
        /// </returns>
        internal PayPalExpressTransactionRecord GetExpressCheckoutDetails(IPayment payment, string token, PayPalExpressTransactionRecord record)
        {
            record.Success = true;
            ExpressCheckoutResponse result = null;
            try
            {
                var getDetailsRequest = new GetExpressCheckoutDetailsReq
                {
                    GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token)
                };

                var service = GetPayPalService();
                var response = service.GetExpressCheckoutDetails(getDetailsRequest);
                result = _responseFactory.Build(response, token);

                if (result.Success())
                {
                    record.Data.PayerId = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
                }
            }
            catch (Exception ex)
            {
                result = _responseFactory.Build(ex);
            }

            record.GetExpressCheckoutDetails = result;
            record.Success = result.Success();
            return record;
        }
Example #26
0
        public IPaymentResult AuthorizePayment(IInvoice invoice, IPayment payment, string token, string payerId)
        {
            var service = GetPayPalService();

            var getExpressCheckoutReq = new GetExpressCheckoutDetailsReq()
            {
                GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token)
            };

            GetExpressCheckoutDetailsResponseType expressCheckoutDetailsResponse;

            try {
                expressCheckoutDetailsResponse = service.GetExpressCheckoutDetails(getExpressCheckoutReq);
                if (expressCheckoutDetailsResponse.Ack != AckCodeType.SUCCESS && expressCheckoutDetailsResponse.Ack != AckCodeType.SUCCESSWITHWARNING)
                {
                    return(new PaymentResult(Attempt <IPayment> .Fail(payment, CreateErrorResult(expressCheckoutDetailsResponse.Errors)), invoice, false));
                }
            } catch (Exception ex) {
                return(new PaymentResult(Attempt <IPayment> .Fail(payment, ex), invoice, false));
            }

            // check if already do
            if (payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.PaymentAuthorized) != "true")
            {
                // do express checkout
                var doExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType(new DoExpressCheckoutPaymentRequestDetailsType
                {
                    Token          = token,
                    PayerID        = payerId,
                    PaymentDetails = new List <PaymentDetailsType> {
                        CreatePayPalPaymentDetails(invoice)
                    }
                });
                var doExpressCheckoutPayment = new DoExpressCheckoutPaymentReq()
                {
                    DoExpressCheckoutPaymentRequest = doExpressCheckoutPaymentRequest
                };

                DoExpressCheckoutPaymentResponseType doExpressCheckoutPaymentResponse;
                try {
                    doExpressCheckoutPaymentResponse = service.DoExpressCheckoutPayment(doExpressCheckoutPayment);
                    if (doExpressCheckoutPaymentResponse.Ack != AckCodeType.SUCCESS && doExpressCheckoutPaymentResponse.Ack != AckCodeType.SUCCESSWITHWARNING)
                    {
                        return(new PaymentResult(Attempt <IPayment> .Fail(payment, CreateErrorResult(doExpressCheckoutPaymentResponse.Errors)), invoice, false));
                    }
                } catch (Exception ex) {
                    return(new PaymentResult(Attempt <IPayment> .Fail(payment, ex), invoice, false));
                }

                var transactionId = doExpressCheckoutPaymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID;
                var currency      = doExpressCheckoutPaymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].GrossAmount.currencyID;
                var amount        = doExpressCheckoutPaymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].GrossAmount.value;

                // do authorization
                var doAuthorizationResponse = service.DoAuthorization(new DoAuthorizationReq
                {
                    DoAuthorizationRequest = new DoAuthorizationRequestType
                    {
                        TransactionID = transactionId,
                        Amount        = new BasicAmountType(currency, amount)
                    }
                });
                if (doAuthorizationResponse.Ack != AckCodeType.SUCCESS && doAuthorizationResponse.Ack != AckCodeType.SUCCESSWITHWARNING)
                {
                    return(new PaymentResult(Attempt <IPayment> .Fail(payment, CreateErrorResult(doAuthorizationResponse.Errors)), invoice, false));
                }

                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizationId, doAuthorizationResponse.TransactionID);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AmountCurrencyId, currency.ToString());
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.PaymentAuthorized, "true");
            }

            payment.Authorized = true;

            return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, true));
        }
        private PayerInfo GetPayerInfo(string token, string payerId)
        {
            var payer   = new PayerInfo();
            var req     = new GetExpressCheckoutDetailsReq();
            var request = new GetExpressCheckoutDetailsRequestType();

            req.GetExpressCheckoutDetailsRequest = request;
            request.Token   = token;
            request.Version = Settings.Version;
            // System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            var credentials = PaypalSecurityHeader();
            GetExpressCheckoutDetailsResponseType response = _paypalService2.GetExpressCheckoutDetails(ref credentials, req);

            if (response.Ack == AckCodeType.Success)
            {
                try
                {
                    payer.Email = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
                }
                catch (Exception)
                {
                    payer.Email = "";
                }

                payer.FirstName = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName;
                payer.LastName  = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName;

                if (response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerStatusSpecified == true)
                {
                    if (response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerStatus == PayPalUserStatusCodeType.verified)
                    {
                        payer.IsVerify = true;
                    }
                    payer.AccountVerifyCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerStatus.ToString();
                }


                payer.Address1    = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
                payer.Address2    = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
                payer.City        = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
                payer.State       = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
                payer.PostCode    = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
                payer.PhoneNo     = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone;
                payer.Country     = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName;
                payer.CountryCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
                payer.PayerId     = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
                payer.Token       = response.GetExpressCheckoutDetailsResponseDetails.Token;

                //if (response.GetExpressCheckoutDetailsResponseDetails.Note > "")
                //{
                //    payer.note = payer.note + response.GetExpressCheckoutDetailsResponseDetails.Note;
                //}
                //payer.OrderTotal = response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails(0).OrderTotal.Value;
                //payer.IsValid = true;
                if (response.GetExpressCheckoutDetailsResponseDetails.BillingAddress == null)
                {
                    payer.Address1 = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
                    payer.Address2 = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
                    payer.City     = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
                    payer.State    = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
                    payer.PostCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
                    payer.Country  = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountryName;

                    if (response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.AddressStatusSpecified == true)
                    {
                        if (response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.AddressStatus == AddressStatusCodeType.Confirmed)
                        {
                            payer.IsValidAddress = true;
                        }
                        payer.AddressVerifyCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.AddressStatus.ToString();
                    }
                }
                else
                {
                    payer.Address1 = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.Street1;
                    payer.Address2 = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.Street2;
                    payer.City     = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.CityName;
                    payer.State    = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.StateOrProvince;
                    payer.PostCode = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.PostalCode;
                    payer.Country  = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.CountryName;
                    if (response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.AddressStatusSpecified == true)
                    {
                        if (response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.AddressStatus == AddressStatusCodeType.Confirmed)
                        {
                            payer.IsValidAddress = true;
                        }
                        payer.AddressVerifyCode = response.GetExpressCheckoutDetailsResponseDetails.BillingAddress.AddressStatus.ToString();
                    }
                }

                //Shipping addd-----------------------------

                if (response.GetExpressCheckoutDetailsResponseDetails.PayerInfo == null)
                {
                    payer.Address1    = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
                    payer.Address2    = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
                    payer.City        = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
                    payer.State       = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
                    payer.PostCode    = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
                    payer.CountryCode = response.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
                }
            }
            return(payer);
        }
Example #28
0
        private ActionResult ProcessingResult_PayPal(ProcessingResultModel model)
        {
            if (model == null)
            {
                throw new System.ArgumentNullException("model");
            }
            PaymentResultContext context = new PaymentResultContext();

            context.Order = model.order;
            if (model.success == true)
            {
                if (model.token == null)
                {
                    throw new System.ArgumentNullException("token");
                }
                if (model.payerID == null)
                {
                    throw new System.ArgumentNullException("payerID");
                }
                GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();
                request.Version = "104.0";
                request.Token   = model.token;
                GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq();
                wrapper.GetExpressCheckoutDetailsRequest = request;
                System.Collections.Generic.Dictionary <string, string> config = PaymentController.PayPal_CreateConfig();
                PayPalAPIInterfaceServiceService      service    = new PayPalAPIInterfaceServiceService(config);
                GetExpressCheckoutDetailsResponseType ecResponse = service.GetExpressCheckoutDetails(wrapper);
                if (ecResponse == null)
                {
                    throw new System.Exception("checkout details result is null");
                }
                if (ecResponse.Errors != null && ecResponse.Errors.Count > 0)
                {
                    ecResponse.Errors.ForEach(delegate(ErrorType m)
                    {
                        context.Errors.Add(m.LongMessage);
                    });
                }
                if (ecResponse.Ack == AckCodeType.SUCCESS || ecResponse.Ack == AckCodeType.SUCCESSWITHWARNING)
                {
                    GetExpressCheckoutDetailsResponseDetailsType details = ecResponse.GetExpressCheckoutDetailsResponseDetails;
                    if (details == null)
                    {
                        throw new System.Exception("details object is null");
                    }
                    if (string.IsNullOrEmpty(details.InvoiceID))
                    {
                        throw new System.Exception("invoiceID not found");
                    }
                    if (details.PaymentDetails == null)
                    {
                        throw new System.Exception("payment details is null");
                    }
                    System.Collections.Generic.List <PaymentDetailsType> paymentDetails = new System.Collections.Generic.List <PaymentDetailsType>();
                    foreach (PaymentDetailsType payment in details.PaymentDetails)
                    {
                        paymentDetails.Add(new PaymentDetailsType
                        {
                            NotifyURL     = null,
                            PaymentAction = payment.PaymentAction,
                            OrderTotal    = payment.OrderTotal
                        });
                    }
                    DoExpressCheckoutPaymentRequestType paymentRequest = new DoExpressCheckoutPaymentRequestType();
                    paymentRequest.Version = "104.0";
                    paymentRequest.DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType
                    {
                        PaymentDetails = paymentDetails,
                        Token          = model.token,
                        PayerID        = model.payerID
                    };
                    DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(new DoExpressCheckoutPaymentReq
                    {
                        DoExpressCheckoutPaymentRequest = paymentRequest
                    });
                    if (doECResponse == null)
                    {
                        throw new System.Exception("payment result is null");
                    }
                    if (doECResponse.Errors != null && doECResponse.Errors.Count > 0)
                    {
                        doECResponse.Errors.ForEach(delegate(ErrorType m)
                        {
                            context.Errors.Add(m.LongMessage);
                        });
                    }
                    if (doECResponse.Ack == AckCodeType.SUCCESS || doECResponse.Ack == AckCodeType.SUCCESSWITHWARNING)
                    {
                        ConfirmInvoiceResult invoiceResult = BookingProvider.ConfirmInvoice(details.InvoiceID.Trim());
                        Tracing.DataTrace.TraceEvent(TraceEventType.Information, 0, "PAYPAL transaction: invoice: '{0}', invoice confirmation: '{1}'", new object[]
                        {
                            details.InvoiceID,
                            invoiceResult.IsSuccess ? "SUCCESS" : "FAILED"
                        });
                        if (!invoiceResult.IsSuccess)
                        {
                            context.Errors.Add(string.Format("invoice confirmation error: {0}", invoiceResult.ErrorMessage));
                        }
                        else
                        {
                            context.Success = true;

                            BookingProvider.AcceptInvoice(Convert.ToInt32(context.Order));
                        }
                    }
                }
            }
            else
            {
                context.Errors.Add(PaymentStrings.PaymentCancelled);
            }
            return(base.View("_ProcessingResult", context));
        }
Example #29
0
        public PaymentResponse Payment(string token, string payerId)
        {
            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(_payPalConfiguration);

            GetExpressCheckoutDetailsReq getECWrapper = new GetExpressCheckoutDetailsReq();

            // (Required) A timestamped token, the value of which was returned by SetExpressCheckout response.
            // Character length and limitations: 20 single-byte characters
            getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token);
            // # API call
            // Invoke the GetExpressCheckoutDetails method in service wrapper object
            GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper);

            // Create request object
            DoExpressCheckoutPaymentRequestType        request        = new DoExpressCheckoutPaymentRequestType();
            DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();

            request.DoExpressCheckoutPaymentRequestDetails = requestDetails;

            requestDetails.ButtonSource = "PTSH";

            requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
            // (Required) The timestamped token value that was returned in the SetExpressCheckout response and passed in the GetExpressCheckoutDetails request.
            requestDetails.Token = token;
            // (Required) Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
            requestDetails.PayerID = payerId;
            // (Required) How you want to obtain payment. It is one of the following values:
            // * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
            // * Order – This payment is an order authorization subject to settlement with PayPal Authorization and Capture.
            // * Sale – This is a final sale for which you are requesting payment.
            // Note: You cannot set this value to Sale in the SetExpressCheckout request and then change this value to Authorization in the DoExpressCheckoutPayment request.
            requestDetails.PaymentAction = PaymentActionCodeType.SALE;

            // Invoke the API
            DoExpressCheckoutPaymentReq wrapper = new DoExpressCheckoutPaymentReq();

            wrapper.DoExpressCheckoutPaymentRequest = request;
            // # API call
            // Invoke the DoExpressCheckoutPayment method in service wrapper object
            DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(wrapper);

            // Check for API return status

            if (doECResponse.Ack.Equals(AckCodeType.FAILURE) ||
                (doECResponse.Errors != null && doECResponse.Errors.Any()))
            {
                return(null);
            }
            string transactionId = doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID;

            if (doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PendingReason != null && doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PendingReason != PendingStatusCodeType.NONE)
            {
                CancelTransaction(transactionId);

                throw new Exception(
                          doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PendingReason.ToString() + transactionId);
            }
            return(new PaymentResponse
            {
                TransactionId = transactionId,
                Price = float.Parse(requestDetails.PaymentDetails[0].OrderTotal.value)
            });
        }
Example #30
0
 /// <remarks/>
 public void GetExpressCheckoutDetailsAsync(GetExpressCheckoutDetailsReq GetExpressCheckoutDetailsReq, object userState) {
     if ((this.GetExpressCheckoutDetailsOperationCompleted == null)) {
         this.GetExpressCheckoutDetailsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetExpressCheckoutDetailsOperationCompleted);
     }
     this.InvokeAsync("GetExpressCheckoutDetails", new object[] {
                 GetExpressCheckoutDetailsReq}, this.GetExpressCheckoutDetailsOperationCompleted, userState);
 }
Example #31
0
 /// <remarks/>
 public void GetExpressCheckoutDetailsAsync(GetExpressCheckoutDetailsReq GetExpressCheckoutDetailsReq) {
     this.GetExpressCheckoutDetailsAsync(GetExpressCheckoutDetailsReq, null);
 }
Example #32
0
        //GET : PayPal/PaymentSuccess
        public async Task <ActionResult> PaymentSuccess(Guid invoiceId)
        {
            GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType();

            request.Version = "104.0";
            request.Token   = Request["token"];
            GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq();

            wrapper.GetExpressCheckoutDetailsRequest = request;

            //define sdk configuration
            Dictionary <string, string> sdkConfig = new Dictionary <string, string>();

            sdkConfig.Add("mode", ConfigurationManager.AppSettings["paypal.mode"]);
            sdkConfig.Add("account1.apiUsername", ConfigurationManager.AppSettings["paypal.apiUsername"]);
            sdkConfig.Add("account1.apiPassword", ConfigurationManager.AppSettings["paypal.apiPassword"]);
            sdkConfig.Add("account1.apiSignature", ConfigurationManager.AppSettings["paypal.apiSignature"]);
//            sdkConfig.Add("acct1.UserName", ConfigurationManager.AppSettings["paypal.apiUsername"]);
//            sdkConfig.Add("acct1.Password", ConfigurationManager.AppSettings["paypal.apiPassword"]);
//            sdkConfig.Add("acct1.Signature", ConfigurationManager.AppSettings["paypal.apiSignature"]);

            PayPalAPIInterfaceServiceService      s          = new PayPalAPIInterfaceServiceService(sdkConfig);
            GetExpressCheckoutDetailsResponseType ecResponse = s.GetExpressCheckoutDetails(wrapper);

            if (ecResponse.Ack.HasValue &&
                ecResponse.Ack.Value.ToString() != "FAILURE" &&
                ecResponse.Errors.Count == 0)
            {
                double paymentAmount = 0.0;
                double.TryParse(ecResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails.FirstOrDefault().OrderTotal.value, out paymentAmount);

                PaymentDetailsType paymentDetail = new PaymentDetailsType();
                paymentDetail.NotifyURL     = "http://replaceIpnUrl.com";
                paymentDetail.PaymentAction = (PaymentActionCodeType)EnumUtils.GetValue("Sale", typeof(PaymentActionCodeType));
                paymentDetail.OrderTotal    = new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("USD", typeof(CurrencyCodeType)), paymentAmount + "");
                List <PaymentDetailsType> paymentDetails = new List <PaymentDetailsType>();
                paymentDetails.Add(paymentDetail);

                DoExpressCheckoutPaymentRequestType doExpressCheckoutPaymentRequestType = new DoExpressCheckoutPaymentRequestType();
                request.Version = "104.0";
                DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
                requestDetails.PaymentDetails = paymentDetails;
                requestDetails.Token          = Request["token"];
                requestDetails.PayerID        = Request["PayerID"];
                doExpressCheckoutPaymentRequestType.DoExpressCheckoutPaymentRequestDetails = requestDetails;

                DoExpressCheckoutPaymentReq doExpressCheckoutPaymentReq = new DoExpressCheckoutPaymentReq();
                doExpressCheckoutPaymentReq.DoExpressCheckoutPaymentRequest = doExpressCheckoutPaymentRequestType;

                s = new PayPalAPIInterfaceServiceService(sdkConfig);
                DoExpressCheckoutPaymentResponseType doECResponse = s.DoExpressCheckoutPayment(doExpressCheckoutPaymentReq);

                if (doECResponse.Ack.HasValue &&
                    doECResponse.Ack.Value.ToString() != "FAILURE" &&
                    doECResponse.Errors.Count == 0)
                {
                    //create payment object for invoice
                    PaymentService       paymentService       = new PaymentService(this.db);
                    PaymentMethodService paymentMethodService = new PaymentMethodService(this.db);
                    var ccPymtMethod = paymentMethodService.GetCreditCardPaymentMethod(UserContact);

                    if (ccPymtMethod == null)
                    {
                        try
                        {
                            PaymentMethodTypeService paymentMethodTypeService = new PaymentMethodTypeService(this.db);
                            string ccTypeCode = GNPaymentMethodType.Types.CREDIT_CARD.GetCode();
                            var    ccType     = this.db.GNPaymentMethodTypes
                                                .Where(pt => pt.Name == ccTypeCode).FirstOrDefault();

                            await paymentMethodService.Insert(UserContact, new GNPaymentMethod
                            {
                                GNAccountId           = UserContact.GNOrganization.Account.Id,
                                GNPaymentMethodTypeId = ccType.Id,
                                Description           = "PAYPAL",
                                IsDefault             = true,
                                IsActive = true,
                                UsedForRecurrentPayments = false,
                                PCITokenId     = "X",
                                LastFourDigits = "X",
                                ExpirationDate = DateTime.MaxValue,
                                CreateDateTime = DateTime.Now,
                                CreatedBy      = UserContact.Id
                            });
                        }
                        catch (Exception e)
                        {
                            LogUtil.Error(logger, "Error adding PayPal Credit Card payment method!!", e);
                        }

                        ccPymtMethod = paymentMethodService.GetCreditCardPaymentMethod(UserContact);

                        if (ccPymtMethod == null)
                        {
                            throw new Exception("Credit Card Payment Method Not Found!!");
                        }
                    }

                    var ecPaymentInfo = doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.FirstOrDefault();

                    double grossAmount = 0.0;
                    double.TryParse(ecPaymentInfo.GrossAmount.value, out grossAmount);

                    if (grossAmount != 0.0)
                    {
                        try
                        {
                            var payment = new GNPayment
                            {
                                Id                = Guid.NewGuid(),
                                GNInvoiceId       = invoiceId,
                                GNPaymentMethodId = ccPymtMethod.Id,
                                PaymentDate       = DateTime.Now,
                                TotalAmount       = grossAmount,
                                Status            = ecPaymentInfo.PaymentStatus.Value.ToString(),
                                ExternalTxnId     = ecPaymentInfo.TransactionID,
                                CreateDateTime    = DateTime.Now,
                                CreatedBy         = UserContact.Id
                            };

                            this.AddInvoiceToPayment(payment);

                            await paymentService.Insert(UserContact, payment);
                        }
                        catch (Exception e)
                        {
                            LogUtil.Error(logger, "Error inserting payment!!", e);
                        }
                    }
                    else
                    {
                        throw new Exception("Payment Amount of 0.0 Not Allowed!!");
                    }
                }
            }

            return(RedirectToAction("MyBillingPayments", "Account"));
        }
Example #33
0
        public virtual async Task <VerifyPaymentResult> VerifyPayment(TblInvoices invoice)
        {
            var result = new VerifyPaymentResult();
            var token  = invoice.PaymentGatewayToken;

            var request = HttpContext.Current.Request;

            if (string.IsNullOrWhiteSpace(request.QueryString["Status"]) ||
                string.IsNullOrWhiteSpace(request.QueryString["token"]))
            {
                result.ErrorMessage = _localizationService.GetResource("Plugin.PaymentMethod.PayPal.StatusOrTokenInvalid");
                return(result);
            }
            if (!request.QueryString["Status"].Equals("OK"))
            {
                result.ErrorMessage = _localizationService.GetResource("Plugin.PaymentMethod.PayPal.StatusFieldIsNotOK");
                return(result);
            }

            await Task.Run(() =>
            {
                try
                {
                    var service      = new PayPalAPIInterfaceServiceService(GetPayPalConfig());
                    var getEcWrapper = new GetExpressCheckoutDetailsReq
                    {
                        GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(token)
                    };
                    var getEcResponse  = service.GetExpressCheckoutDetails(getEcWrapper);
                    var ecRequest      = new DoExpressCheckoutPaymentRequestType();
                    var requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
                    ecRequest.DoExpressCheckoutPaymentRequestDetails = requestDetails;
                    requestDetails.PaymentDetails = getEcResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
                    requestDetails.Token          = token;
                    requestDetails.PayerID        = getEcResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
                    requestDetails.PaymentAction  = PaymentActionCodeType.SALE;
                    var wrapper = new DoExpressCheckoutPaymentReq {
                        DoExpressCheckoutPaymentRequest = ecRequest
                    };
                    var doEcResponse = service.DoExpressCheckoutPayment(wrapper);

                    if (doEcResponse.Ack == AckCodeType.SUCCESS)
                    {
                        result.IsSuccess     = true;
                        result.TransactionId = doEcResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID;
                    }
                    else
                    {
                        foreach (var error in doEcResponse.Errors)
                        {
                            result.ErrorMessage +=
                                $"[{error.SeverityCode}] {error.ErrorCode} : {error.LongMessage} </br>";
                        }
                    }
                }
                catch
                {
                    result.ErrorMessage = _localizationService.GetResource("Plugin.PaymentMethod.PayPal.ServiceUnavailable");
                }
            });

            return(result);
        }
Example #34
0
 public GetExpressCheckoutDetailsResponseType GetExpressCheckoutDetails(GetExpressCheckoutDetailsReq GetExpressCheckoutDetailsReq)
 {
     return(GetExpressCheckoutDetails(GetExpressCheckoutDetailsReq, null));
 }