コード例 #1
0
        public void WebProfileGetTest()
        {
            var profileId = "XP-VKRN-ZPNE-AXGJ-YFZM";
            var profile   = WebProfile.Get(UnitTestUtil.GetApiContext(), profileId);

            Assert.AreEqual(profileId, profile.id);
        }
コード例 #2
0
        public void WebProfileGetTest()
        {
            var profileId = "XP-5CQ3-3XSL-DDAA-MATK";
            var profile   = WebProfile.Get(TestingUtil.GetApiContext(), profileId);

            Assert.AreEqual(profileId, profile.id);
        }
コード例 #3
0
        public void WebProfileCreateAndGetTest()
        {
            try
            {
                // Create the profile
                var apiContext = TestingUtil.GetApiContext();
                var profile    = WebProfileTest.GetWebProfile();
                profile.name = Guid.NewGuid().ToString();
                var response = profile.Create(apiContext);
                Assert.IsNotNull(response);
                Assert.IsNotNull(response.id);

                // Get the profile
                var profileId        = response.id;
                var retrievedProfile = WebProfile.Get(apiContext, profileId);
                Assert.AreEqual(profileId, retrievedProfile.id);

                // Delete the profile
                retrievedProfile.Delete(apiContext);
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
コード例 #4
0
        public void WebProfileUpdateTest()
        {
            // Create a new profile
            var profileName = Guid.NewGuid().ToString();
            var profile     = WebProfileTest.GetWebProfile();

            profile.name = profileName;
            var createdProfile = profile.Create(TestingUtil.GetApiContext());

            // Get the profile object for the new profile
            profile = WebProfile.Get(TestingUtil.GetApiContext(), createdProfile.id);

            // Update the profile
            var newName = "New " + profileName;

            profile.name = newName;
            profile.Update(TestingUtil.GetApiContext());

            // Get the profile again and verify it was successfully updated.
            var retrievedProfile = WebProfile.Get(TestingUtil.GetApiContext(), profile.id);

            Assert.AreEqual(newName, retrievedProfile.name);

            // Delete the profile
            profile.Delete(TestingUtil.GetApiContext());
        }
コード例 #5
0
        public void WebProfileDeleteTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                this.RecordConnectionDetails();

                // Create a new profile
                var profileName = Guid.NewGuid().ToString();
                var profile     = WebProfileTest.GetWebProfile();
                profile.name = profileName;
                var createdProfile = profile.Create(apiContext);
                this.RecordConnectionDetails();

                // Get the profile object for the new profile
                profile = WebProfile.Get(apiContext, createdProfile.id);
                this.RecordConnectionDetails();

                // Delete the profile
                profile.Delete(apiContext);
                this.RecordConnectionDetails();

                Assert.AreEqual(204, (int)PayPalResource.LastResponseDetails.Value.StatusCode);
            }
            catch (ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }
コード例 #6
0
        public void WebProfileDeleteTest()
        {
            try
            {
                // Create a new profile
                var profileName = Guid.NewGuid().ToString();
                var profile     = WebProfileTest.GetWebProfile();
                profile.name = profileName;
                var createdProfile = profile.Create(TestingUtil.GetApiContext());

                // Get the profile object for the new profile
                profile = WebProfile.Get(TestingUtil.GetApiContext(), createdProfile.id);

                // Delete the profile
                profile.Delete(TestingUtil.GetApiContext());

                // Attempt to get the profile. This should result in an exception.
                TestingUtil.AssertThrownException <PayPal.HttpException>(() => { WebProfile.Get(TestingUtil.GetApiContext(), profile.id); });
            }
            catch (ConnectionException ex)
            {
                TestingUtil.WriteConnectionExceptionDetails(ex);
                throw;
            }
        }
コード例 #7
0
        public void WebProfilePartialUpdateTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                this.RecordConnectionDetails();

                // Create a new profile
                var profileName = Guid.NewGuid().ToString();
                var profile     = WebProfileTest.GetWebProfile();
                profile.name = profileName;
                var createdProfile = profile.Create(apiContext);
                this.RecordConnectionDetails();

                // Get the profile object for the new profile
                profile = WebProfile.Get(apiContext, createdProfile.id);
                this.RecordConnectionDetails();

                // Partially update the profile
                var newName = "New " + profileName;
                var patch1  = new Patch
                {
                    op    = "add",
                    path  = "/presentation/brand_name",
                    value = newName
                };

                var patch2 = new Patch
                {
                    op   = "remove",
                    path = "/flow_config/landing_page_type"
                };

                var patchRequest = new PatchRequest
                {
                    patch1,
                    patch2
                };

                profile.PartialUpdate(apiContext, patchRequest);
                this.RecordConnectionDetails();

                // Get the profile again and verify it was successfully updated via the patch commands.
                var retrievedProfile = WebProfile.Get(apiContext, profile.id);
                this.RecordConnectionDetails();

                Assert.AreEqual(newName, retrievedProfile.presentation.brand_name);
                Assert.IsTrue(string.IsNullOrEmpty(retrievedProfile.flow_config.landing_page_type));

                // Delete the profile
                profile.Delete(apiContext);
                this.RecordConnectionDetails();
            }
            catch (ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }
コード例 #8
0
        protected override void RunSample()
        {
            // ### Api Context
            // Pass in a `APIContext` object to authenticate
            // the call and to send a unique request id
            // (that ensures idempotency). The SDK generates
            // a request id if you do not pass one explicitly.
            // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
            var apiContext = Configuration.GetAPIContext();

            // Setup the profile we want to create
            var profile = new WebProfile()
            {
                name         = Guid.NewGuid().ToString(),
                presentation = new Presentation()
                {
                    brand_name           = "Sample brand",
                    locale_code          = "US",
                    logo_image           = "https://www.paypal.com/",
                    note_to_seller_label = "Thx",
                    return_url_label     = "Retreat!"
                },
                input_fields = new InputFields()
                {
                    address_override = 1,
                    allow_note       = true,
                    no_shipping      = 0
                },
                flow_config = new FlowConfig()
                {
                    bank_txn_pending_url   = "https://www.paypal.com/",
                    landing_page_type      = "billing",
                    user_action            = "commit",
                    return_uri_http_method = "GET"
                },
                temporary = true
            };

            #region Track Workflow
            //--------------------
            this.flow.AddNewRequest("Create profile", profile);
            //--------------------
            #endregion

            // Create the profile
            var response = profile.Create(apiContext);

            #region Track Workflow
            //--------------------
            this.flow.RecordResponse(response);
            //--------------------
            #endregion

            #region Cleanup
            // Cleanup by deleting the newly-created profile
            var retrievedProfile = WebProfile.Get(apiContext, response.id);
            retrievedProfile.Delete(apiContext);
            #endregion
        }
コード例 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var CurrContext  = HttpContext.Current;
            var profile      = new WebProfile();
            var patchRequest = new PatchRequest();

            try
            {
                var apiContext = Configuration.GetAPIContext();

                // Setup the profile we want to create
                profile.name                             = Guid.NewGuid().ToString();
                profile.presentation                     = new Presentation();
                profile.presentation.brand_name          = "Sample brand";
                profile.presentation.locale_code         = "US";
                profile.presentation.logo_image          = "https://www.paypal.com/";
                profile.input_fields                     = new InputFields();
                profile.input_fields.address_override    = 1;
                profile.input_fields.allow_note          = true;
                profile.input_fields.no_shipping         = 0;
                profile.flow_config                      = new FlowConfig();
                profile.flow_config.bank_txn_pending_url = "https://www.paypal.com/";
                profile.flow_config.landing_page_type    = "billing";

                // Create the profile
                var response = profile.Create(apiContext);

                // Create a patch and add it to the PatchRequest object used to
                // perform the partial update on the profile.
                var patch1 = new Patch();
                patch1.op    = "add";
                patch1.path  = "/presentation/brand_name";
                patch1.value = "New brand name";
                patchRequest.Add(patch1);

                var patch2 = new Patch();
                patch2.op   = "remove";
                patch2.path = "/flow_config/landing_page_type";
                patchRequest.Add(patch1);

                // Get the profile object and partially update the profile.
                var retrievedProfile = WebProfile.Get(apiContext, response.id);
                retrievedProfile.PartialUpdate(apiContext, patchRequest);

                CurrContext.Items.Add("ResponseJson", "Experience profile successfully updated.");

                // Delete the newly-created profile
                retrievedProfile.Delete(apiContext);
            }
            catch (Exception ex)
            {
                CurrContext.Items.Add("Error", ex.Message);
            }

            CurrContext.Items.Add("RequestJson", patchRequest.ConvertToJson());

            Server.Transfer("~/Response.aspx");
        }
コード例 #10
0
        public void WebProfileCreateTest()
        {
            var profile = WebProfileTest.GetWebProfile();

            profile.name = Guid.NewGuid().ToString();
            var response = profile.Create(TestingUtil.GetApiContext());

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.id);

            // Delete the profile
            profile = WebProfile.Get(TestingUtil.GetApiContext(), response.id);
            profile.Delete(TestingUtil.GetApiContext());
        }
コード例 #11
0
    public void SaveProfile()
    {
        // get the selected user's profile
        WebProfile profile = Profile;

        if (username.Length > 0)
        {
            profile = WebProfile.Get(username);
        }

        // Subscriptions
        profile.Preferences.Newsletter = ddlNewsletter.SelectedValue;

        // Personal Info
        profile.Personal.FirstName = txtFirstName.Text;
        profile.Personal.LastName  = txtLastName.Text;
        profile.Personal.Gender    = ddlGenders.SelectedValue;
        if (txtBirthDate.Text.Trim().Length > 0)
        {
            profile.Personal.BirthDate = DateTime.Parse(txtBirthDate.Text);
        }
        profile.Personal.Occupation = ddlOccupations.SelectedValue;
        profile.Personal.Website    = txtWebsite.Text;

        // Address Info
        profile.Address.Country    = ddlCountries.SelectedValue;
        profile.Address.Address    = txtAddress.Text;
        profile.Address.AptNumber  = txtAptNumber.Text;
        profile.Address.City       = txtCity.Text;
        profile.Address.State      = txtState.Text;
        profile.Address.PostalCode = txtPostalCode.Text;

        // Contact Info
        profile.Contacts.DayTimePhone    = txtDayTimePhone.Text;
        profile.Contacts.DayTimePhoneExt = txtDayTimePhoneExt.Text;
        profile.Contacts.EveningPhone    = txtEveningPhone.Text;
        profile.Contacts.EveningPhoneExt = txtEveningPhoneExt.Text;
        profile.Contacts.CellPhone       = txtCellPhone.Text;
        profile.Contacts.FaxBusiness     = txtBusinessFax.Text;
        profile.Contacts.FaxHome         = txtHomeFax.Text;

        // this is what we will call from the button click
        // to save the user's profile
        profile.Save();
    }
コード例 #12
0
        public void WebProfileDeleteTest()
        {
            // Create a new profile
            var profileName = Guid.NewGuid().ToString();
            var profile     = WebProfileTest.GetWebProfile();

            profile.name = profileName;
            var createdProfile = profile.Create(UnitTestUtil.GetApiContext());

            // Get the profile object for the new profile
            profile = WebProfile.Get(UnitTestUtil.GetApiContext(), createdProfile.id);

            // Delete the profile
            profile.Delete(UnitTestUtil.GetApiContext());

            // Attempt to get the profile. This should result in an exception.
            UnitTestUtil.AssertThrownException <PayPal.Exception.HttpException>(() => { WebProfile.Get(UnitTestUtil.GetApiContext(), profile.id); });
        }
コード例 #13
0
        public void WebProfilePartialUpdateTest()
        {
            try
            {
                // Create a new profile
                var profileName = Guid.NewGuid().ToString();
                var profile     = WebProfileTest.GetWebProfile();
                profile.name = profileName;
                var createdProfile = profile.Create(TestingUtil.GetApiContext());

                // Get the profile object for the new profile
                profile = WebProfile.Get(TestingUtil.GetApiContext(), createdProfile.id);

                // Partially update the profile
                var newName = "New " + profileName;
                var patch1  = new Patch();
                patch1.op    = "add";
                patch1.path  = "/presentation/brand_name";
                patch1.value = newName;

                var patch2 = new Patch();
                patch2.op   = "remove";
                patch2.path = "/flow_config/landing_page_type";

                var patchRequest = new PatchRequest();
                patchRequest.Add(patch1);
                patchRequest.Add(patch2);

                profile.PartialUpdate(TestingUtil.GetApiContext(), patchRequest);

                // Get the profile again and verify it was successfully updated via the patch commands.
                var retrievedProfile = WebProfile.Get(TestingUtil.GetApiContext(), profile.id);
                Assert.AreEqual(newName, retrievedProfile.presentation.brand_name);
                Assert.IsTrue(string.IsNullOrEmpty(retrievedProfile.flow_config.landing_page_type));

                // Delete the profile
                profile.Delete(TestingUtil.GetApiContext());
            }
            finally
            {
                TestingUtil.RecordConnectionDetails();
            }
        }
コード例 #14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var CurrContext = HttpContext.Current;
            var profile     = new WebProfile();

            try
            {
                var apiContext = Configuration.GetAPIContext();

                // Setup the profile we want to create
                profile.name                             = Guid.NewGuid().ToString();
                profile.presentation                     = new Presentation();
                profile.presentation.brand_name          = "Sample brand";
                profile.presentation.locale_code         = "US";
                profile.presentation.logo_image          = "https://www.paypal.com/";
                profile.input_fields                     = new InputFields();
                profile.input_fields.address_override    = 1;
                profile.input_fields.allow_note          = true;
                profile.input_fields.no_shipping         = 0;
                profile.flow_config                      = new FlowConfig();
                profile.flow_config.bank_txn_pending_url = "https://www.paypal.com/";
                profile.flow_config.landing_page_type    = "billing";

                // Create the profile
                var response = profile.Create(apiContext);

                // Get the profile using the ID returned from the previous Create() call.
                var retrievedProfile = WebProfile.Get(apiContext, response.id);

                CurrContext.Items.Add("ResponseJson", JObject.Parse(retrievedProfile.ConvertToJson()).ToString(Formatting.Indented));

                // Delete the newly-created profile
                retrievedProfile.Delete(apiContext);
            }
            catch (Exception ex)
            {
                CurrContext.Items.Add("Error", ex.Message);
            }

            Server.Transfer("~/Response.aspx");
        }
コード例 #15
0
        public void WebProfileUpdateTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                this.RecordConnectionDetails();

                // Create a new profile
                var profileName = Guid.NewGuid().ToString();
                var profile     = WebProfileTest.GetWebProfile();
                profile.name = profileName;
                var createdProfile = profile.Create(apiContext);
                this.RecordConnectionDetails();

                // Get the profile object for the new profile
                profile = WebProfile.Get(apiContext, createdProfile.id);
                this.RecordConnectionDetails();

                // Update the profile
                var newName = "New " + profileName;
                profile.name = newName;
                profile.Update(apiContext);
                this.RecordConnectionDetails();

                // Get the profile again and verify it was successfully updated.
                var retrievedProfile = WebProfile.Get(apiContext, profile.id);
                this.RecordConnectionDetails();

                Assert.AreEqual(newName, retrievedProfile.name);

                // Delete the profile
                profile.Delete(apiContext);
                this.RecordConnectionDetails();
            }
            catch (ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }
コード例 #16
0
        public void WebProfileDeleteTest()
        {
            try
            {
                // Create a new profile
                var profileName = Guid.NewGuid().ToString();
                var profile     = WebProfileTest.GetWebProfile();
                profile.name = profileName;
                var createdProfile = profile.Create(TestingUtil.GetApiContext());

                // Get the profile object for the new profile
                profile = WebProfile.Get(TestingUtil.GetApiContext(), createdProfile.id);

                // Delete the profile
                profile.Delete(TestingUtil.GetApiContext());
                Assert.AreEqual(204, (int)PayPalResource.LastResponseDetails.Value.StatusCode);
            }
            finally
            {
                TestingUtil.RecordConnectionDetails();
            }
        }
コード例 #17
0
        protected override void RunSample()
        {
            // ### Api Context
            // Pass in a `APIContext` object to authenticate
            // the call and to send a unique request id
            // (that ensures idempotency). The SDK generates
            // a request id if you do not pass one explicitly.
            // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
            var apiContext = Configuration.GetAPIContext();

            // Setup the profile we want to create
            var profile = new WebProfile()
            {
                name         = Guid.NewGuid().ToString(),
                presentation = new Presentation()
                {
                    brand_name  = "Sample brand",
                    locale_code = "US",
                    logo_image  = "https://www.paypal.com/"
                },
                input_fields = new InputFields()
                {
                    address_override = 1,
                    allow_note       = true,
                    no_shipping      = 0
                },
                flow_config = new FlowConfig()
                {
                    bank_txn_pending_url = "https://www.paypal.com/",
                    landing_page_type    = "billing"
                }
            };

            #region Track Workflow
            //--------------------
            this.flow.AddNewRequest("Create profile", profile);
            //--------------------
            #endregion

            // Create the profile
            var response = profile.Create(apiContext);

            #region Track Workflow
            //--------------------
            this.flow.RecordResponse(response);
            //--------------------
            #endregion

            // Create a patch and add it to the PatchRequest object used to
            // perform the partial update on the profile.
            var patchRequest = new PatchRequest()
            {
                new Patch()
                {
                    op    = "add",
                    path  = "/presentation/brand_name",
                    value = "New brand name"
                },
                new Patch()
                {
                    op   = "remove",
                    path = "/flow_config/landing_page_type"
                }
            };

            #region Track Workflow
            //--------------------
            this.flow.AddNewRequest("Retrieve profile details", description: "ID: " + response.id);
            //--------------------
            #endregion

            // Get the profile object and partially update the profile.
            var retrievedProfile = WebProfile.Get(apiContext, response.id);

            #region Track Workflow
            //--------------------
            this.flow.RecordResponse(retrievedProfile);
            this.flow.AddNewRequest("Partially update profile", patchRequest);
            //--------------------
            #endregion

            retrievedProfile.PartialUpdate(apiContext, patchRequest);

            #region Track Workflow
            //--------------------
            this.flow.RecordActionSuccess("Profile updated successfully");
            //--------------------
            #endregion

            #region Cleanup
            // Cleanup by deleting the newly-created profile
            retrievedProfile.Delete(apiContext);
            #endregion
        }
コード例 #18
0
        /// <summary>
        /// Creates Web Experience profile using portal branding and payment configuration.
        /// </summary>
        /// <param name="paymentConfig">The Payment configuration.</param>
        /// <param name="brandConfig">The branding configuration.</param>
        /// <param name="countryIso2Code">The locale code used by the web experience profile. Example-US.</param>
        /// <returns>The created web experience profile id.</returns>
        public static string CreateWebExperienceProfile(PaymentConfiguration paymentConfig, BrandingConfiguration brandConfig, string countryIso2Code)
        {
            try
            {
                Dictionary <string, string> configMap = new Dictionary <string, string>();
                configMap.Add("clientId", paymentConfig.ClientId);
                configMap.Add("clientSecret", paymentConfig.ClientSecret);
                configMap.Add("mode", paymentConfig.AccountType);
                configMap.Add("connectionTimeout", "120000");

                string accessToken = new OAuthTokenCredential(configMap).GetAccessToken();
                var    apiContext  = new APIContext(accessToken);
                apiContext.Config = configMap;

                // Pickup logo & brand name from branding configuration.
                // create the web experience profile.
                var profile = new WebProfile
                {
                    name         = Guid.NewGuid().ToString(),
                    presentation = new Presentation
                    {
                        brand_name  = brandConfig.OrganizationName,
                        logo_image  = brandConfig.HeaderImage?.ToString(),
                        locale_code = countryIso2Code
                    },
                    input_fields = new InputFields()
                    {
                        address_override = 1,
                        allow_note       = false,
                        no_shipping      = 1
                    },
                    flow_config = new FlowConfig()
                    {
                        landing_page_type = "billing"
                    }
                };

                var createdProfile = profile.Create(apiContext);

                // Now that new experience profile is created hence delete the older one.
                if (!string.IsNullOrWhiteSpace(paymentConfig.WebExperienceProfileId))
                {
                    try
                    {
                        WebProfile existingWebProfile = WebProfile.Get(apiContext, paymentConfig.WebExperienceProfileId);
                        existingWebProfile.Delete(apiContext);
                    }
                    catch
                    {
                    }
                }

                return(createdProfile.id);
            }
            catch (PayPalException paypalException)
            {
                if (paypalException is IdentityException)
                {
                    // thrown when API Context couldn't be setup.
                    IdentityException identityFailure = paypalException as IdentityException;
                    IdentityError     failureDetails  = identityFailure.Details;
                    if (failureDetails != null && failureDetails.error.ToLower() == "invalid_client")
                    {
                        throw new PartnerDomainException(ErrorCode.PaymentGatewayIdentityFailureDuringConfiguration).AddDetail("ErrorMessage", Resources.PaymentGatewayIdentityFailureDuringConfiguration);
                    }
                }

                // if this is not an identity exception rather some other issue.
                throw new PartnerDomainException(ErrorCode.PaymentGatewayFailure).AddDetail("ErrorMessage", paypalException.Message);
            }
        }
コード例 #19
0
    private void Page_Load()
    {
        // check if username exists in the query string
        username = Request.QueryString["username"];
        if (username == null || username == "")
        {
            Response.Redirect("default.aspx");
        }

        // get membership user account based on username sent in query string
        user = System.Web.Security.Membership.GetUser(username);
        UserUpdateMessage.Text = "";

        // get selected user's password start.................................................................
        string password = "******";

        if (Membership.Provider.PasswordFormat != MembershipPasswordFormat.Hashed)
        {
            password = System.Web.Security.Membership.Providers["MembershipProviderAdmin"].GetPassword(username, null);
        }
        lblCurrentPassword.Text = password;
        // get selected user's password end...................................................................

        // Get Profile start....................................................
        if (!Page.IsPostBack)
        {
            // get country names from app_code folder
            // bind country names to the dropdown list
            ddlCountries.DataSource = CountryNames.CountryNames.GetCountries();
            ddlCountries.DataBind();

            // get the selected user's profile based on query string
            WebProfile profile = Profile;
            if (username.Length > 0)
            {
                profile = WebProfile.Get(username);
            }

            // Subscriptions
            ddlNewsletter.SelectedValue = profile.Preferences.Newsletter;

            // Personal Info
            txtFirstName.Text        = profile.Personal.FirstName;
            txtLastName.Text         = profile.Personal.LastName;
            ddlGenders.SelectedValue = profile.Personal.Gender;
            if (profile.Personal.BirthDate != DateTime.MinValue)
            {
                txtBirthDate.Text = profile.Personal.BirthDate.ToShortDateString();
            }
            ddlOccupations.SelectedValue = profile.Personal.Occupation;
            txtWebsite.Text = profile.Personal.Website;

            // Address Info
            ddlCountries.SelectedValue = profile.Address.Country;
            txtAddress.Text            = profile.Address.Address;
            txtAptNumber.Text          = profile.Address.AptNumber;
            txtCity.Text       = profile.Address.City;
            txtState.Text      = profile.Address.State;
            txtPostalCode.Text = profile.Address.PostalCode;

            // Contact Info
            txtDayTimePhone.Text    = profile.Contacts.DayTimePhone;
            txtDayTimePhoneExt.Text = profile.Contacts.DayTimePhoneExt;
            txtEveningPhone.Text    = profile.Contacts.EveningPhone;
            txtEveningPhoneExt.Text = profile.Contacts.EveningPhoneExt;
            txtCellPhone.Text       = profile.Contacts.CellPhone;
            txtBusinessFax.Text     = profile.Contacts.FaxBusiness;
            txtHomeFax.Text         = profile.Contacts.FaxHome;
        }
        // Get Profile end.......................................................
    }