Ejemplo n.º 1
0
        /// <summary>
        /// Handle PreapprovalDetails API call
        /// </summary>
        /// <param name="context"></param>
        private void PreapprovalDetails(HttpContext context)
        {
            NameValueCollection parameters = context.Request.Params;
            PreapprovalDetailsRequest req = new PreapprovalDetailsRequest(new RequestEnvelope("en_US"), 
                parameters["preapprovalKey"]);
            // set optional parameters
            if (parameters["getBillingAddress"] != "")
                req.getBillingAddress = Boolean.Parse(parameters["getBillingAddress"]);

            // All set. Fire the request            
            AdaptivePaymentsService service = new AdaptivePaymentsService();
            PreapprovalDetailsResponse resp = null;
            try
            {
                resp = service.PreapprovalDetails(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("Status", resp.status);
                keyResponseParams.Add("Starting date", resp.startingDate);
                keyResponseParams.Add("Ending date", resp.endingDate);
                keyResponseParams.Add("Sender email", resp.senderEmail);
                keyResponseParams.Add("Currency code", resp.currencyCode);
                keyResponseParams.Add("Maximum amount (across all payments)", resp.maxTotalAmountOfAllPayments.ToString());                
            }
            displayResponse(context, "PreapprovalDetails", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                resp.error, redirectUrl);
        }
Ejemplo n.º 2
0
    // # PreapprovalDetails API Operation
    // Use the PreapprovalDetails API operation to obtain information about an agreement between you and a sender for making payments on the sender’s behalf.
    public PreapprovalDetailsResponse PreapprovalDetailsAPIOperation()
    {
        // Create the PreapprovalDetailsResponse object
        PreapprovalDetailsResponse responsePreapprovalDetails = new PreapprovalDetailsResponse();

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

            // PreapprovalDetailsRequest object which takes mandatory params:
            //
            // * `Request Envelope` - Information common to each API operation, such
            // as the language in which an error message is returned.
            // * `Preapproval Key` - A preapproval key that identifies the
            // preapproval for which you want to retrieve details. The preapproval
            // key is returned in the PreapprovalResponse message.
            PreapprovalDetailsRequest preapprovDetailsRequest = new PreapprovalDetailsRequest(
                envelopeRequest, "PA-1KM93450LF5424305");

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

            // # API call
            // Invoke the PreapprovalDetails method in service wrapper object
            responsePreapprovalDetails = service.PreapprovalDetails(preapprovDetailsRequest);

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

                // # Success values
                if (responsePreapprovalDetails.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // First date for which the preapproval is valid.
                    logger.Info("Starting Date : " + responsePreapprovalDetails.startingDate + "\n");
                    Console.WriteLine("Starting Date : " + responsePreapprovalDetails.startingDate + "\n");
                }
                // # Error Values
                else
                {
                    List <ErrorData> errorMessages = responsePreapprovalDetails.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(responsePreapprovalDetails);
    }