コード例 #1
0
        /// <summary>
        /// Gets execution status of a payment by PayKey
        /// </summary>
        /// <param name="payKey"></param>
        /// <returns></returns>
        public PaymentExecStatusSEnum GetPaymentExecutionStatus(string payKey)
        {
            Check.Require(string.IsNullOrEmpty(payKey) == false, "PayPalService.GetPaymentStatus: PayKey is required.");

            PaymentDetailsRequest request = new PaymentDetailsRequest(new RequestEnvelope("en_US"));

            request.payKey = payKey;

            Dictionary <string, string> configurationMap = FWUtils.ConfigUtils.GetAppSettings().Paypal.GetAcctAndConfig();
            AdaptivePaymentsService     service          = new AdaptivePaymentsService(configurationMap);
            PaymentDetailsResponse      response         = service.PaymentDetails(request);

            string ack = response.responseEnvelope.ack.ToString().Trim().ToUpper();

            // if no error happened
            if (!ack.Equals(AckCode.FAILURE.ToString()) &&
                !ack.Equals(AckCode.FAILUREWITHWARNING.ToString()))
            {
                PaymentExecStatusSEnum execStatus = new PaymentExecStatusSEnum(response.status);
                return(execStatus);
            }
            else
            {
                throw new UserException(GetPayPalErrorString(response.error));
            }
        }
        public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
        {
            var retVal = new PostProcessPaymentResult();

            var service = new AdaptivePaymentsService(GetConfiguration());

            var response = service.PaymentDetails(new PaymentDetailsRequest
            {
                payKey          = context.OuterId,
                requestEnvelope = new RequestEnvelope {
                    errorLanguage = "en_US"
                }
            });

            if (response.status == "COMPLETED")
            {
                context.Payment.CapturedDate = DateTime.UtcNow;
                retVal.IsSuccess             = context.Payment.IsApproved = true;
                retVal.NewPaymentStatus      = context.Payment.PaymentStatus = PaymentStatus.Paid;
            }
            else if (response.status == "INCOMPLETE" && response.status == "ERROR" && response.status == "REVERSALERROR")
            {
                if (response.error != null && response.error.Count > 0)
                {
                    var sb = new StringBuilder();
                    foreach (var error in response.error)
                    {
                        sb.AppendLine(error.message);
                    }
                    retVal.ErrorMessage = sb.ToString();
                }
                else
                {
                    retVal.ErrorMessage = "payment canceled";
                }

                context.Payment.VoidedDate = DateTime.UtcNow;
                retVal.NewPaymentStatus    = context.Payment.PaymentStatus = PaymentStatus.Voided;
            }
            else
            {
                retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Pending;
            }

            return(retVal);
        }
コード例 #3
0
        /// <summary>
        /// Handle PaymentDetails API call
        /// </summary>
        /// <param name="context"></param>
        private void PaymentDetails(HttpContext context)
        {
            NameValueCollection parameters = context.Request.Params;
            PaymentDetailsRequest req = new PaymentDetailsRequest(new RequestEnvelope("en_US")); 
            // set optional parameters
            if (parameters["payKey"] != "")
                req.payKey = parameters["payKey"];
            if (parameters["transactionId"] != "")
                req.transactionId = parameters["transactionId"];
            if (parameters["trackingId"] != "")
                req.trackingId = parameters["trackingId"];

            // All set. Fire the request            
            AdaptivePaymentsService service = new AdaptivePaymentsService();
            PaymentDetailsResponse resp = null;
            try
            {
                resp = service.PaymentDetails(req);
            }
            catch (System.Exception e)
            {
                context.Response.Write(e.Message);
                return;
            }

            // Display response values. 
            Dictionary<string, string> keyResponseParams = new Dictionary<string, string>();
            string redirectUrl = null;
            if (!(resp.responseEnvelope.ack == AckCode.FAILURE) &&
                !(resp.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
            {                
                keyResponseParams.Add("Pay key", resp.payKey);
                keyResponseParams.Add("Payment execution status", resp.status);
                keyResponseParams.Add("Sender email", resp.senderEmail);
            }
            displayResponse(context, "PaymentDetails", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                resp.error, redirectUrl);
        }
コード例 #4
0
        private static bool PaypalHandleBuyerPaidAndWeNeedToVerify(ITradelrRepository repository)
        {
            bool haveChanges             = false;
            var  paymentsNeededVerifying = repository.GetPayments(PaymentMethodType.Paypal, PaymentStatus.Charging);

            foreach (var payment in paymentsNeededVerifying)
            {
                var configurationMap = Configuration.GetAcctAndConfig();

                var service = new AdaptivePaymentsService(configurationMap);

                var detailsRequest = new PaymentDetailsRequest
                {
                    payKey          = payment.redirectUrl.ToPayPalPayKey(),
                    requestEnvelope = new RequestEnvelope
                    {
                        errorLanguage
                            =
                                "en_US"
                    },
                    trackingId = payment.reference
                };

                PaymentDetailsResponse resp = null;
                bool haveError = false;
                try
                {
                    resp = service.PaymentDetails(detailsRequest);
                }
                catch (Exception ex)
                {
                    var affectedInvoice = payment.order;
                    Syslog.Write(
                        string.Format(
                            "Failed to process payment for order {0}, payment amount of {1} deleted",
                            affectedInvoice.id, payment.paidAmount));
                    Syslog.Write(ex);
                    haveError = true;
                }
                if (!haveError && resp.responseEnvelope.ack == AckCode.SUCCESS)
                {
                    var transaction = new Transaction(payment.order, repository, null);

                    switch (resp.status)
                    {
                    case "COMPLETED":
                        transaction.UpdatePaymentStatus(payment, PaymentStatus.Accepted);

                        transaction.AddPaidAmount(payment.paidAmount);          // <------- order status is updated inside here

                        // send download links if digital order
                        if (transaction.HasDigitalOrderItems())
                        {
                            transaction.SendDownloadLinksEmail();
                        }
                        haveChanges = true;
                        break;

                    case "ERROR":
                        transaction.UpdatePaymentStatus(payment, PaymentStatus.Declined);

                        haveChanges = true;
                        break;

                    case "EXPIRED":
                        repository.DeletePayment(payment);
                        haveChanges = true;
                        break;
                    }
                }
            }
            return(haveChanges);
        }
コード例 #5
0
ファイル: Map.aspx.cs プロジェクト: Aseeraa/KCGameOn
        private static bool checkPayPal()
        {
            if (!String.IsNullOrEmpty(SessionVariables.UserName))
            {
                if (checkForUpdate())
                {
                    PaymentDetailsResponse responsePaymentDetails = new PaymentDetailsResponse();

                    try
                    {
                        // # PaymentDetailsRequest
                        // The code for the language in which errors are returned
                        RequestEnvelope envelopeRequest = new RequestEnvelope();
                        envelopeRequest.errorLanguage = "en_US";

                        // PaymentDetailsRequest which takes,
                        // `Request Envelope` - Information common to each API operation, such
                        // as the language in which an error message is returned.
                        PaymentDetailsRequest requestPaymentDetails = new PaymentDetailsRequest(envelopeRequest);

                        // You must specify either,
                        //
                        // * `Pay Key` - The pay key that identifies the payment for which you want to retrieve details. This is the pay key returned in the PayResponse message.
                        // * `Transaction ID` - The PayPal transaction ID associated with the payment. The IPN message associated with the payment contains the transaction ID.
                        // `payDetailsRequest.transactionId = transactionId`
                        // * `Tracking ID` - The tracking ID that was specified for this payment in the PayRequest message.
                        // `requestPaymentDetails.trackingId = trackingId`
                        requestPaymentDetails.payKey = SessionVariables.paymentKey;

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

                        // # API call
                        // Invoke the PaymentDetails method in service wrapper object
                        responsePaymentDetails = service.PaymentDetails(requestPaymentDetails);

                        if (responsePaymentDetails != null)
                        {
                            // Response envelope acknowledgement
                            string acknowledgement = "PaymentDetails API Operation - ";
                            acknowledgement += responsePaymentDetails.responseEnvelope.ack.ToString();
                            Console.WriteLine(acknowledgement + "\n");

                            // # Success values
                            if (responsePaymentDetails.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                            {
                                // The status of the payment. Possible values are:
                                //
                                // * CREATED - The payment request was received; funds will be
                                // transferred once the payment is approved
                                // * COMPLETED - The payment was successful
                                // * INCOMPLETE - Some transfers succeeded and some failed for a
                                // parallel payment or, for a delayed chained payment, secondary
                                // receivers have not been paid
                                // * ERROR - The payment failed and all attempted transfers failed
                                // or all completed transfers were successfully reversed
                                // * REVERSALERROR - One or more transfers failed when attempting
                                // to reverse a payment
                                // * PROCESSING - The payment is in progress
                                // * PENDING - The payment is awaiting processing
                                if (responsePaymentDetails.status == "COMPLETED")
                                {
                                    updatePayTable();
                                    return(true);
                                }
                            }
                            // # Error Values
                            else
                            {
                                return(false);
                                //List<ErrorData> errorMessages = responsePaymentDetails.error;
                                //foreach (ErrorData error in errorMessages)
                                //{
                                //}
                            }
                        }
                    }
                    // # Exception log
                    catch (System.Exception ex)
                    {
                        return(false);
                        // Log the exception message
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }