Exemple #1
0
        /// <summary>
        /// Handle ExecutePayment API call
        /// </summary>
        /// <param name="context"></param>
        private void ExecutePayment(HttpContext context)
        {
            NameValueCollection parameters = context.Request.Params;
            ExecutePaymentRequest req = new ExecutePaymentRequest(
                    new RequestEnvelope("en_US"), parameters["payKey"]);

            // All set. Fire the request            
            AdaptivePaymentsService service = new AdaptivePaymentsService();
            ExecutePaymentResponse resp = null;
            try
            {
                resp = service.ExecutePayment(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("Payment exeucution status", resp.paymentExecStatus);
            }
            displayResponse(context, "ExecutePayment", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                resp.error, redirectUrl);
        }
    // # ExecutePayment API Operation
    // The ExecutePayment API operation lets you execute a payment set up with the Pay API operation with the actionType CREATE. To pay receivers identified in the Pay call, set the pay key from the PayResponse message in the ExecutePaymentRequest message.
    public ExecutePaymentResponse ExecutePaymentAPIOperation()
    {
        // Create the ExecutePaymentResponse object
        ExecutePaymentResponse responseExecutePayment = new ExecutePaymentResponse();

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

            // ExecutePaymentRequest which takes,
            //
            // * `Request Envelope` - Information common to each API operation, such
            // as the language in which an error message is returned.
            // * `Pay Key` - The pay key that identifies the payment for which you
            // want to set payment options. This is the pay key returned in the
            // PayResponse message. Action Type in PayRequest must be `CREATE`
            ExecutePaymentRequest requestExecutePayment = new ExecutePaymentRequest(envelopeRequest, "AP-1VB65877N5917862M");

            // The ID of the funding plan from which to make this payment.
            requestExecutePayment.fundingPlanId = "0";

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

            // # API call
            // Invoke the ExecutePayment method in service wrapper object
            responseExecutePayment = service.ExecutePayment(requestExecutePayment);

            if (responseExecutePayment != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "ExecutePayment API operation - ";
                acknowledgement += responseExecutePayment.responseEnvelope.ack.ToString();
                logger.Info(acknowledgement + "\n");
                Console.WriteLine(acknowledgement + "\n");

                // # Success values
                if (responseExecutePayment.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
                    // * 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
                    logger.Info("Payment Execution Status: " + responseExecutePayment.paymentExecStatus + "\n");
                    Console.WriteLine("Payment Execution Status : " + responseExecutePayment.paymentExecStatus + "\n");
                }
                // # Error Values
                else
                {
                    List <ErrorData> errorMessages = responseExecutePayment.error;
                    foreach (ErrorData error in errorMessages)
                    {
                        logger.Debug("API Error Message : " + error.message);
                        Console.WriteLine("API Error Message : " + error.message + "\n");
                    }
                }
            }
        }
        // # Exception log
        catch (System.Exception ex)
        {
            // Log the exception message
            logger.Debug("Error Message : " + ex.Message);
            Console.WriteLine("Error Message : " + ex.Message);
        }
        return(responseExecutePayment);
    }
Exemple #3
0
        public override ProcessPaymentResult ProcessPayment(ProcessPaymentEvaluationContext context)
        {
            var retVal = new ProcessPaymentResult();

            if (context.Store == null)
            {
                throw new NullReferenceException("no store with this id");
            }

            if (!(!string.IsNullOrEmpty(context.Store.SecureUrl) || !string.IsNullOrEmpty(context.Store.Url)))
            {
                throw new NullReferenceException("store must specify Url or SecureUrl property");
            }

            var url = string.Empty;

            if (!string.IsNullOrEmpty(context.Store.SecureUrl))
            {
                url = context.Store.SecureUrl;
            }
            else
            {
                url = context.Store.Url;
            }

            var config = GetConfigMap();

            var service = new AdaptivePaymentsService(config);

            var request = CreatePaypalRequest(context.Order, context.Payment, url);

            var payResponse = service.Pay(request);
            var setPaymentOptionsResponse = service.SetPaymentOptions(new SetPaymentOptionsRequest {
                payKey = payResponse.payKey, senderOptions = new SenderOptions {
                    referrerCode = "Virto_SP"
                }
            });
            var executePaymentResponse = service.ExecutePayment(new ExecutePaymentRequest {
                payKey = payResponse.payKey, actionType = "PAY", requestEnvelope = new RequestEnvelope {
                    errorLanguage = "en_US"
                }
            });

            if (executePaymentResponse.error != null && executePaymentResponse.error.Count > 0)
            {
                var sb = new StringBuilder();
                foreach (var error in executePaymentResponse.error)
                {
                    sb.AppendLine(error.message);
                }
                retVal.Error            = sb.ToString();
                retVal.NewPaymentStatus = PaymentStatus.Voided;
            }
            else
            {
                retVal.OuterId   = payResponse.payKey;
                retVal.IsSuccess = true;
                var redirectBaseUrl = GetBaseUrl(Mode);
                retVal.RedirectUrl      = string.Format(redirectBaseUrl, retVal.OuterId);
                retVal.NewPaymentStatus = PaymentStatus.Pending;
            }

            return(retVal);
        }