Пример #1
0
        /// <summary>
        /// Handle GetAvailableShippingAddresses API call
        /// </summary>
        /// <param name="context"></param>
        private void GetAvailableShippingAddresses(HttpContext context)
        {
            NameValueCollection parameters = context.Request.Params;
            GetAvailableShippingAddressesRequest req = new GetAvailableShippingAddressesRequest(
                    new RequestEnvelope("en_US"), parameters["key"]);

            // All set. Fire the request
            AdaptivePaymentsService service = new AdaptivePaymentsService();
            GetAvailableShippingAddressesResponse resp = null;
            try
            {
                resp = service.GetAvailableShippingAddresses(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))
            {
                int idx = 1;
                foreach(Address addr in resp.availableAddress)
                {
                    keyResponseParams.Add("Address name " + idx, addr.addresseeName);
                    keyResponseParams.Add("Address Id " + idx, addr.addressId);
                    if (addr.baseAddress != null)
                    {
                        keyResponseParams.Add("Address line " + idx, addr.baseAddress.line1);
                        keyResponseParams.Add("City " + idx, addr.baseAddress.city);
                        keyResponseParams.Add("State " + idx, addr.baseAddress.state);

                        //Selenium Test Case
                        keyResponseParams.Add("Acknowledgement", resp.responseEnvelope.ack.ToString());
                    }
                }
            }
            displayResponse(context, "GetAvailableShippingAddresses", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                resp.error, redirectUrl);
        }
        /// <summary>
        /// Handle GetAvailableShippingAddresses API call
        /// </summary>
        /// <param name="contextHttp"></param>
        private void GetAvailableShippingAddresses(HttpContext contextHttp)
        {
            NameValueCollection parameters = contextHttp.Request.Params;

            // error language : (Required) RFC 3066 language in which error 
            // messages are returned; by default it is en_US, which is the only language currently supported.
            // key : (Required) The payment paykey that identifies the account holder 
            GetAvailableShippingAddressesRequest request = new GetAvailableShippingAddressesRequest(
                    new RequestEnvelope("en_US"), parameters["key"]);
       
            AdaptivePaymentsService service = null;
            GetAvailableShippingAddressesResponse response = null;
            try
            {
                // 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 and loading
                // configuration map for your credentials and endpoint
                service = new AdaptivePaymentsService(configurationMap);
                response = service.GetAvailableShippingAddresses(request);
            }
            catch (System.Exception e)
            {
                contextHttp.Response.Write(e.Message);
                return;
            }

            Dictionary<string, string> responseValues = new Dictionary<string, string>();
            string redirectUrl = null;
            if (!(response.responseEnvelope.ack == AckCode.FAILURE) &&
                !(response.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
            {
                int idx = 1;
                foreach(Address addr in response.availableAddress) 
                {
                    // The name associated with the address.
                    responseValues.Add("Address name " + idx, addr.addresseeName);
                    // The ID associated with the address.
                    responseValues.Add("Address Id " + idx, addr.addressId);
                    if (addr.baseAddress != null)
                    {
                        // Street address.
                        responseValues.Add("Address line " + idx, addr.baseAddress.line1);
                        // The city of the address.
                        responseValues.Add("City " + idx, addr.baseAddress.city);
                        // The state for the address
                        responseValues.Add("State " + idx, addr.baseAddress.state);

                        
                        responseValues.Add("Acknowledgement", response.responseEnvelope.ack.ToString());
                    }
                }
            }
            Display(contextHttp, "GetAvailableShippingAddresses", responseValues, service.getLastRequest(), service.getLastResponse(), response.error, redirectUrl);
        }