The value of the order’s transaction identification number returned by a PayPal product. Required Character length and limits: 19 single-byte characters maximum
Inheritance: AbstractRequestType
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object

            DoAuthorizationRequestType request =
                new DoAuthorizationRequestType();

            // (Required) Value of the order's transaction identification number returned by PayPal.
            request.TransactionID = transactionId.Value;
            CurrencyCodeType currency = (CurrencyCodeType)
                Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue);
            // (Required) Amount to authorize.
            request.Amount = new BasicAmountType(currency, amount.Value);

            // Invoke the API
            DoAuthorizationReq wrapper = new DoAuthorizationReq();
            wrapper.DoAuthorizationRequest = 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 DoAuthorization method in service wrapper object
            DoAuthorizationResponseType doAuthorizationResponse =
                    service.DoAuthorization(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, doAuthorizationResponse);
        }
Example #2
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            // Create request object

            DoAuthorizationRequestType request =
                new DoAuthorizationRequestType();

            request.TransactionID = transactionId.Value;
            CurrencyCodeType currency = (CurrencyCodeType)
                Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue);
            request.Amount = new BasicAmountType(currency, amount.Value);

            // Invoke the API
            DoAuthorizationReq wrapper = new DoAuthorizationReq();
            wrapper.DoAuthorizationRequest = request;
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();
            DoAuthorizationResponseType doAuthorizationResponse =
                    service.DoAuthorization(wrapper);

            // Check for API return status
            setKeyResponseObjects(service, doAuthorizationResponse);
        }
        // <summary>
        /// Handles DoAuthorization
        /// </summary>
        /// <param name="contextHttp"></param>
        private void DoAuthorization(HttpContext contextHttp)
        {
            NameValueCollection parameters = contextHttp.Request.Params;

            // 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();

            // Creating service wrapper object to make an API call by loading configuration map.
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);

            DoAuthorizationReq req = new DoAuthorizationReq();

            // 'Amount' which takes mandatory params:
            // * 'currencyCode'
            // * 'amount'
            BasicAmountType amount = new BasicAmountType(((CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), parameters["currencyCode"])), parameters["amt"]);

            // 'DoAuthorizationRequest' which takes mandatory params:
            // * 'Transaction ID' - Value of the order's transaction identification
            // number returned by PayPal.
            // * 'Amount' - Amount to authorize.
            DoAuthorizationRequestType reqType = new DoAuthorizationRequestType(parameters["authID"], amount);

            req.DoAuthorizationRequest = reqType;
            DoAuthorizationResponseType response = null;
            try
            {
                response = service.DoAuthorization(req);
            }
            catch (System.Exception ex)
            {
                contextHttp.Response.Write(ex.StackTrace);
                return;
            }

            Dictionary<string, string> responseValues = new Dictionary<string, string>();
            string redirectUrl = null;

            if (!response.Ack.ToString().Trim().ToUpper().Equals(AckCode.FAILURE.ToString()) && !response.Ack.ToString().Trim().ToUpper().Equals(AckCode.FAILUREWITHWARNING.ToString()))
            {
                responseValues.Add("Acknowledgement", response.Ack.ToString().Trim().ToUpper());
                responseValues.Add("TransactionId", response.TransactionID);
            }
            else
            {
                responseValues.Add("Acknowledgement", response.Ack.ToString().Trim().ToUpper());
            }

            Display(contextHttp, "DoAuthorization", "DoAuthorization", responseValues, service.getLastRequest(), service.getLastResponse(), response.Errors, redirectUrl);
        }
    //# DoAuthorization API Operation
    //Authorize a payment. 
    public DoAuthorizationResponseType DoAuthorizationAPIOperation()
    {
        // Create the DoAuthorizationResponseType object
        DoAuthorizationResponseType responseDoAuthorizationResponseType = new DoAuthorizationResponseType();

        try
        {
            // Create the DoAuthorizationReq object
            DoAuthorizationReq doAuthorization = new DoAuthorizationReq();

            // `Amount` which takes mandatory params:
            // 
            // * `currencyCode`
            // * `amount`
            BasicAmountType amount = new BasicAmountType(CurrencyCodeType.USD, "4.00");

            // `DoAuthorizationRequest` which takes mandatory params:
            // 
            // * `Transaction ID` - Value of the order's transaction identification
            // number returned by PayPal.
            // * `Amount` - Amount to authorize.
            DoAuthorizationRequestType doAuthorizationRequest = new DoAuthorizationRequestType("O-4VR15106P7416533H", amount);
            doAuthorization.DoAuthorizationRequest = doAuthorizationRequest;

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

            // # API call
            // Invoke the DoAuthorization method in service wrapper object
            responseDoAuthorizationResponseType = service.DoAuthorization(doAuthorization);

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

                // # Success values
                if (responseDoAuthorizationResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // Authorization identification number
                    logger.Info("Transaction ID : " + responseDoAuthorizationResponseType.TransactionID + "\n");
                    Console.WriteLine("Transaction ID : " + responseDoAuthorizationResponseType.TransactionID + "\n");

                }
                // # Error Values                
                else
                {
                    // Access error values from error list using getter methods
                    List<ErrorType> errorMessages = responseDoAuthorizationResponseType.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 responseDoAuthorizationResponseType;
    }