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);
        }
예제 #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>
        /// 
        /// </summary>
        ///<param name="doAuthorizationReq"></param>
        ///<param name="credential">An explicit ICredential object that you want to authenticate this call against</param> 
        public DoAuthorizationResponseType DoAuthorization(DoAuthorizationReq doAuthorizationReq, ICredential credential)
        {
            setStandardParams(doAuthorizationReq.DoAuthorizationRequest);
            DefaultSOAPAPICallHandler defaultHandler = new DefaultSOAPAPICallHandler(this.config, doAuthorizationReq.ToXMLString(null, "DoAuthorizationReq"), null, null);
            IAPICallPreHandler apiCallPreHandler = new MerchantAPICallPreHandler(this.config, defaultHandler, credential);
            ((MerchantAPICallPreHandler) apiCallPreHandler).SDKName = SDKName;
            ((MerchantAPICallPreHandler) apiCallPreHandler).SDKVersion = SDKVersion;
            ((MerchantAPICallPreHandler) apiCallPreHandler).PortName = "PayPalAPIAA";

            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(Call(apiCallPreHandler));
            return new DoAuthorizationResponseType(
                xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='DoAuthorizationResponse']")
            );
        }
 /// <summary> 
 /// 
 /// </summary>
 ///<param name="doAuthorizationReq"></param>
 public DoAuthorizationResponseType DoAuthorization(DoAuthorizationReq doAuthorizationReq)
 {
     return DoAuthorization(doAuthorizationReq,(string) null);
 }
 /**
   *AUTO_GENERATED
  	  */
 public DoAuthorizationResponseType DoAuthorization(DoAuthorizationReq doAuthorizationReq, string apiUserName)
 {
     IAPICallPreHandler apiCallPreHandler = null;
      		string portName = "PayPalAPIAA";
     setStandardParams(doAuthorizationReq.DoAuthorizationRequest);
     DefaultSOAPAPICallHandler defaultHandler = new DefaultSOAPAPICallHandler(doAuthorizationReq.ToXMLString(null, "DoAuthorizationReq"), null, null);
     apiCallPreHandler = new MerchantAPICallPreHandler(defaultHandler, apiUserName, getAccessToken(), getAccessTokenSecret());
     ((MerchantAPICallPreHandler) apiCallPreHandler).SDKName = SDKName;
     ((MerchantAPICallPreHandler) apiCallPreHandler).SDKVersion = SDKVersion;
     ((MerchantAPICallPreHandler) apiCallPreHandler).PortName = portName;
     string response = Call(apiCallPreHandler);
     XmlDocument xmlDocument = new XmlDocument();
     xmlDocument.LoadXml(response);
     XmlNode xmlNode = xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='DoAuthorizationResponse']");
     return new DoAuthorizationResponseType(xmlNode);
 }
 /**
   *AUTO_GENERATED
  	  */
 public DoAuthorizationResponseType DoAuthorization(DoAuthorizationReq doAuthorizationReq, string apiUserName)
 {
     setStandardParams(doAuthorizationReq.DoAuthorizationRequest);
     string response = Call("DoAuthorization", doAuthorizationReq.ToXMLString(), apiUserName);
     XmlDocument xmlDocument = new XmlDocument();
     xmlDocument.LoadXml(response);
     XmlNode xmlNode = xmlDocument.SelectSingleNode("*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='DoAuthorizationResponse']");
     return new DoAuthorizationResponseType(xmlNode);
 }
 public DoAuthorizationResponseType DoAuthorization(DoAuthorizationReq DoAuthorizationReq)
 {
     return DoAuthorization(DoAuthorizationReq, null);
 }
        /**
         *
         */
        public DoAuthorizationResponseType DoAuthorization(DoAuthorizationReq DoAuthorizationReq, string apiUsername)
        {
            setStandardParams(DoAuthorizationReq.DoAuthorizationRequest);
            string resp = call("DoAuthorization", DoAuthorizationReq.toXMLString(), apiUsername);

            return new DoAuthorizationResponseType(resp);
        }
        // <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;
    }