Exemplo n.º 1
0
        /**
         * Countries Supported:
         *     AU - Australia
         *     AT - Austria
         *     BE - Belgium
         *     BR - Brazil
         *     CA - Canada
         *     CZ - Czech Republic
         *     FR - France
         *     DE - Germany
         *     GR - Greece
         *     HK - Hong Kong
         *     IE - Ireland
         *     IT - Italy
         *     JP - Japan
         *     LU - Luxembourg
         *     MX - Mexico
         *     NL - Netherlands
         *     NZ - New Zealand (Aotearoa)
         *     PL - Poland
         *     PT - Portugal
         *     RU - Russian Federation
         *     SG - Singapore
         *     ZA - South Africa
         *     ES - Spain
         *     CH - Switzerland
         *     UK - United Kingdom
         *     US - United States
         *
         *
         *
         *
         *
         */
        public AddPaymentCardResponse AddPaymentCard(AddPaymentCardRequest addPaymentCardRequest, string apiUserName)
        {
            string  response = Call("AddPaymentCard", addPaymentCardRequest.ToNVPString(""), apiUserName);
            NVPUtil util     = new NVPUtil();

            return(AddPaymentCardResponse.CreateInstance(util.ParseNVPString(response), "", -1));
        }
        /// <summary>
        /// Countries Supported:
        /// AU - Australia
        /// AT - Austria
        /// BE
        /// - Belgium
        /// BR - Brazil
        /// CA - Canada
        /// CZ - Czech Republic
        /// FR - France
        /// DE -
        /// Germany
        /// GR - Greece
        /// HK - Hong Kong
        /// IE - Ireland
        /// IT - Italy
        /// JP - Japan
        /// LU -
        /// Luxembourg
        /// MX - Mexico
        /// NL - Netherlands
        /// NZ - New Zealand (Aotearoa)
        /// PL -
        /// Poland
        /// PT - Portugal
        /// RU - Russian Federation
        /// SG - Singapore
        /// ZA - South
        /// Africa
        /// ES - Spain
        /// CH - Switzerland
        /// UK - United Kingdom
        /// US - United
        /// States
        ///
        ///
        ///
        ///
        ///
        /// </summary>
        ///<param name="addPaymentCardRequest"></param>
        ///<param name="credential">An explicit ICredential object that you want to authenticate this call against</param>
        public AddPaymentCardResponse AddPaymentCard(AddPaymentCardRequest addPaymentCardRequest, ICredential credential)
        {
            IAPICallPreHandler apiCallPreHandler = new PlatformAPICallPreHandler(this.config, addPaymentCardRequest.ToNVPString(string.Empty), ServiceName, "AddPaymentCard", credential);

            ((PlatformAPICallPreHandler)apiCallPreHandler).SDKName    = SDKName;
            ((PlatformAPICallPreHandler)apiCallPreHandler).SDKVersion = SDKVersion;
            ((PlatformAPICallPreHandler)apiCallPreHandler).PortName   = "AdaptiveAccounts";

            NVPUtil util = new NVPUtil();

            return(AddPaymentCardResponse.CreateInstance(util.ParseNVPString(Call(apiCallPreHandler)), string.Empty, -1));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handle AddPaymentCard API call
        /// </summary>
        /// <param name="context"></param>
        private void AddPaymentCard(HttpContext context)
        {
            NameValueCollection parameters = context.Request.Params;

            NameType nameOnCard = new NameType(parameters["firstName"], parameters["lastName"]);

            if (parameters["salutation"] != "")
            {
                nameOnCard.salutation = parameters["salutation"];
            }
            if (parameters["middleName"] != "")
            {
                nameOnCard.middleName = parameters["middleName"];
            }
            if (parameters["suffix"] != "")
            {
                nameOnCard.suffix = parameters["suffix"];
            }

            AddressType billingAddress = new AddressType(parameters["line1"], parameters["countryCode"]);

            if (parameters["line2"] != "")
            {
                billingAddress.line2 = parameters["line2"];
            }
            if (parameters["city"] != "")
            {
                billingAddress.city = parameters["city"];
            }
            if (parameters["state"] != "")
            {
                billingAddress.state = parameters["state"];
            }
            if (parameters["postalCode"] != "")
            {
                billingAddress.postalCode = parameters["postalCode"];
            }

            CardTypeType cardType =
                (CardTypeType)Enum.Parse(typeof(CardTypeType), parameters["cardType"]);
            ConfirmationType confirmationType =
                (ConfirmationType)Enum.Parse(typeof(ConfirmationType), parameters["confirmationType"]);

            // Create API request object
            AddPaymentCardRequest req = new AddPaymentCardRequest(new RequestEnvelope(), nameOnCard, billingAddress,
                                                                  parameters["cardNumber"], cardType, confirmationType);

            // set optional parameters
            if (parameters["accountId"] != "")
            {
                req.accountId = parameters["accountId"];
            }
            if (parameters["emailAddress"] != "")
            {
                req.emailAddress = parameters["emailAddress"];
            }
            if (parameters["createAccountKey"] != "")
            {
                req.createAccountKey = parameters["createAccountKey"];
            }
            if (parameters["cardOwnerDateOfBirth"] != "")
            {
                req.cardOwnerDateOfBirth = parameters["cardOwnerDateOfBirth"];
            }
            if (parameters["expirationMonth"] != "" && parameters["expirationYear"] != "")
            {
                req.expirationDate = new CardDateType(
                    Int32.Parse(parameters["expirationMonth"]),
                    Int32.Parse(parameters["expirationYear"]));
            }
            if (parameters["cardVerificationNumber"] != "")
            {
                req.cardVerificationNumber = parameters["cardVerificationNumber"];
            }
            if (parameters["startMonth"] != "" && parameters["startYear"] != "")
            {
                req.expirationDate = new CardDateType(
                    Int32.Parse(parameters["startMonth"]),
                    Int32.Parse(parameters["startYear"]));
            }
            if (parameters["issueNumber"] != "")
            {
                req.issueNumber = parameters["issueNumber"];
            }
            if (confirmationType == ConfirmationType.WEB &&
                (parameters["returnURL"] != "" || parameters["returnURLDescription"] != "" ||
                 parameters["cancelURL"] != "" || parameters["cancelURLDescription"] != ""))
            {
                req.webOptions = new WebOptionsType();
                if (parameters["returnURL"] != "")
                {
                    req.webOptions.returnUrl = parameters["returnURL"];
                }
                if (parameters["returnURLDescription"] != "")
                {
                    req.webOptions.returnUrlDescription = parameters["returnURLDescription"];
                }
                if (parameters["cancelURL"] != "")
                {
                    req.webOptions.cancelUrl = parameters["cancelURL"];
                }
                if (parameters["cancelURLDescription"] != "")
                {
                    req.webOptions.cancelUrlDescription = parameters["cancelURLDescription"];
                }
            }

            // All set. Fire the request
            AdaptiveAccountsService service = new AdaptiveAccountsService();
            AddPaymentCardResponse  resp    = null;

            try
            {
                resp = service.AddPaymentCard(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("Execution status", resp.execStatus.ToString());
                keyResponseParams.Add("Funding source key", resp.fundingSourceKey);
            }
            displayResponse(context, "AddPaymentCard", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                            resp.error, redirectUrl);
        }
Exemplo n.º 4
0
        public AddPaymentCardResponse AddPaymentCard(AddPaymentCardRequest request)
        {
            AddPaymentCardResponse AddPaymentCardResponse = null;

            PayLoad = null;

            try
            {
                APIProfile.EndPointAppend = Endpoint + "AddPaymentCard";

                if (APIProfile.RequestDataformat == "SOAP11")
                {
                    PayLoad = SoapEncoder.Encode(request);
                }
                else if (APIProfile.RequestDataformat == "XML")
                {
                    PayLoad = PayPal.Platform.SDK.XMLEncoder.Encode(request);
                }
                else
                {
                    PayLoad = PayPal.Platform.SDK.JSONSerializer.ToJavaScriptObjectNotation(request);
                }
                res = CallAPI();

                if (APIProfile.RequestDataformat == "JSON")
                {
                    object obj = JSONSerializer.JsonDecode(res.ToString(), typeof(PayPal.Services.Private.AA.AddPaymentCardResponse));
                    if (obj.GetType() == typeof(PayPal.Services.Private.AA.AddPaymentCardResponse))
                    {
                        AddPaymentCardResponse = (PayPal.Services.Private.AA.AddPaymentCardResponse)obj;
                    }
                    string name = Enum.GetName(AddPaymentCardResponse.responseEnvelope.ack.GetType(), AddPaymentCardResponse.responseEnvelope.ack);

                    if (name == "Failure")
                    {
                        this.result = "FAILURE";
                        TransactionException tranactionEx = new TransactionException(PayLoadFromat.JSON, res.ToString());
                        this.lastError = tranactionEx;
                    }
                }

                else if (res.ToString().ToUpper().Replace("<ACK>FAILURE</ACK>", "").Length != res.ToString().Length)
                {
                    this.result = "FAILURE";

                    if (APIProfile.RequestDataformat == "SOAP11")
                    {
                        TransactionException tranactionEx = new TransactionException(PayLoadFromat.SOAP11, res.ToString());
                        this.lastError = tranactionEx;
                    }
                    else if (APIProfile.RequestDataformat == "XML")
                    {
                        TransactionException tranactionEx = new TransactionException(PayLoadFromat.XML, res.ToString());
                        this.lastError = tranactionEx;
                    }
                    else
                    {
                        TransactionException tranactionEx = new TransactionException(PayLoadFromat.JSON, res.ToString());
                        this.lastError = tranactionEx;
                    }
                }
                else
                {
                    if (APIProfile.RequestDataformat == "SOAP11")
                    {
                        AddPaymentCardResponse = (PayPal.Services.Private.AA.AddPaymentCardResponse)SoapEncoder.Decode(res.ToString(), typeof(PayPal.Services.Private.AA.AddPaymentCardResponse));
                    }
                    else if (APIProfile.RequestDataformat == "XML")
                    {
                        AddPaymentCardResponse = (PayPal.Services.Private.AA.AddPaymentCardResponse)XMLEncoder.Decode(res.ToString(), typeof(PayPal.Services.Private.AA.AddPaymentCardResponse));
                    }
                    else
                    {
                        object obj = JSONSerializer.JsonDecode(res.ToString(), typeof(PayPal.Services.Private.AA.AddPaymentCardResponse));
                        if (obj.GetType() == typeof(PayPal.Services.Private.AA.AddPaymentCardResponse))
                        {
                            AddPaymentCardResponse = (PayPal.Services.Private.AA.AddPaymentCardResponse)obj;
                        }
                    }
                    this.result = "SUCCESS";
                }
            }
            catch (FATALException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new FATALException("Error occurred in AdapativePayments ->  method.", ex);
            }
            return(AddPaymentCardResponse);
        }
        /// <summary>
        /// Handle AddPaymentCard API call
        /// </summary>
        /// <param name="context"></param>
        private void AddPaymentCard(HttpContext context)
        {
            // #AddPaymentCard API
            // The AddPaymentCard API operation lets your application set up payment cards as funding sources for PayPal accounts.
            NameValueCollection parameters = context.Request.Params;

            // (Required) Name (as it appears on the card) of the payment card holder.
            // (Required) First name of the account or payment card holder. (Required) Last name of the account or payment card holder.
            NameType nameOnCard = new NameType(parameters["firstName"], parameters["lastName"]);

            // (Optional) A salutation for the account or payment card holder.
            if (parameters["salutation"] != string.Empty)
            {
                nameOnCard.salutation = parameters["salutation"];
            }

            //(Optional) Middle name of the account or payment card holder.
            if (parameters["middleName"] != string.Empty)
            {
                nameOnCard.middleName = parameters["middleName"];
            }

            // (Optional) A suffix for the account or payment card holder.
            if (parameters["suffix"] != string.Empty)
            {
                nameOnCard.suffix = parameters["suffix"];
            }

            // (Optional) Billing address of the payment card holder. See
            // AddressType Fields for details.
            AddressType billingAddress = new AddressType(parameters["line1"], parameters["countryCode"]);

            // (Optional) The second line of the address. Note: This field
            // is required for Brazilian addresses.
            if (parameters["line2"] != string.Empty)
            {
                billingAddress.line2 = parameters["line2"];
            }

            // (Required) The city.
            if (parameters["city"] != string.Empty)
            {
                billingAddress.city = parameters["city"];
            }

            // (Optional) The state code.
            if (parameters["state"] != string.Empty)
            {
                billingAddress.state = parameters["state"];
            }

            // (Optional) The zip or postal code.
            if (parameters["postalCode"] != string.Empty)
            {
                billingAddress.postalCode = parameters["postalCode"];
            }

            // (Required) The type of payment card to add.
            CardTypeType cardType =
                (CardTypeType)Enum.Parse(typeof(CardTypeType), parameters["cardType"]);
            ConfirmationType confirmationType =
                (ConfirmationType)Enum.Parse(typeof(ConfirmationType), parameters["confirmationType"]);

            // (Required) The payment card number.
            AddPaymentCardRequest req = new AddPaymentCardRequest(new RequestEnvelope(), nameOnCard, billingAddress,
                                                                  parameters["cardNumber"], cardType, confirmationType);

            // Optional) Unique identification number of the PayPal account
            // to which to add the payment card. You must pass either an
            // accountId or an emailAddress in this request. You can't leave
            // both fields out of the message.
            if (parameters["accountId"] != string.Empty)
            {
                req.accountId = parameters["accountId"];
            }

            // (Optional) Email address that uniquely identifies the PayPal
            // account to which to add the payment card.
            if (parameters["emailAddress"] != string.Empty)
            {
                req.emailAddress = parameters["emailAddress"];
            }

            // (Required if confirmationType is NONE) Unique identifier of
            //  the account to which to add a payment card. Use in cases
            //  where the payment card is being added without the account
            //  holder's explicit confirmation. The value to pass is returned
            //  in the createAccountKey field of a CreateAccount response. A
            //  create account key response expires after 60 minutes. If you
            //  pass an expired key to an Adaptive Accounts API, an error is
            //  returned
            if (parameters["createAccountKey"] != string.Empty)
            {
                req.createAccountKey = parameters["createAccountKey"];
            }

            // (Optional) Date of birth of the payment card holder.
            if (parameters["cardOwnerDateOfBirth"] != string.Empty)
            {
                req.cardOwnerDateOfBirth = parameters["cardOwnerDateOfBirth"];
            }

            // (Optional) Expiration date of the payment card.
            if (parameters["expirationMonth"] != string.Empty && parameters["expirationYear"] != string.Empty)
            {
                req.expirationDate = new CardDateType(
                    Convert.ToInt32(parameters["expirationMonth"]),
                    Convert.ToInt32(parameters["expirationYear"]));
            }

            // The verification code of the payment card. This parameter is
            // generally required for calls in which confirmationType is
            // NONE. With the appropriate account review, this parameter can
            // be optional.
            if (parameters["cardVerificationNumber"] != string.Empty)
            {
                req.cardVerificationNumber = parameters["cardVerificationNumber"];
            }

            // (Optional) Start date of the payment card.
            if (parameters["startMonth"] != string.Empty && parameters["startYear"] != string.Empty)
            {
                req.startDate = new CardDateType(
                    Convert.ToInt32(parameters["startMonth"]),
                    Convert.ToInt32(parameters["startYear"]));
            }

            // (Optional) 2-digit issue number of the payment card (for
            // Maestro cards only).
            if (parameters["issueNumber"] != string.Empty)
            {
                req.issueNumber = parameters["issueNumber"];
            }

            // (Optional) Structure in which to pass the URLs for the return
            // and cancelation web flows
            if (confirmationType == ConfirmationType.WEB &&
                (parameters["returnURL"] != string.Empty || parameters["returnURLDescription"] != string.Empty ||
                 parameters["cancelURL"] != string.Empty || parameters["cancelURLDescription"] != string.Empty))
            {
                req.webOptions = new WebOptionsType();

                // (Optional) The URL to which PayPal returns the account holder
                // once he or she completes confirmation of the payment card
                // addition
                if (parameters["returnURL"] != string.Empty)
                {
                    req.webOptions.returnUrl = parameters["returnURL"];
                }
                if (parameters["returnURLDescription"] != string.Empty)
                {
                    req.webOptions.returnUrlDescription = parameters["returnURLDescription"];
                }

                // (Optional) The URL to which PayPal returns the account holder
                // if he or she cancels confirmation of the payment card
                // addition.
                if (parameters["cancelURL"] != string.Empty)
                {
                    req.webOptions.cancelUrl = parameters["cancelURL"];
                }
                if (parameters["cancelURLDescription"] != string.Empty)
                {
                    req.webOptions.cancelUrlDescription = parameters["cancelURLDescription"];
                }
            }

            // Create the AdaptiveAccounts service object to make the API call
            AdaptiveAccountsService service = null;
            AddPaymentCardResponse  resp    = 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 AdaptiveAccountsService(configurationMap);

                // # API call
                // Invoke the CreateAccount method in service wrapper object
                resp = service.AddPaymentCard(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))
            {
                redirectUrl = resp.redirectURL;
                keyResponseParams.Add("Execution status", resp.execStatus.ToString());
                keyResponseParams.Add("Funding source key", resp.fundingSourceKey);

                //Selenium Test Case
                keyResponseParams.Add("Acknowledgement", resp.responseEnvelope.ack.ToString());
                keyResponseParams.Add("Redirect To PayPal", resp.redirectURL);
            }
            displayResponse(context, "AddPaymentCard", keyResponseParams, service.getLastRequest(), service.getLastResponse(),
                            resp.error, redirectUrl);
        }