See PayPal Developer documentation for more information.
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 }
/// <summary> /// Create a web experience profile by passing the name of the profile and other profile details in the request JSON to the request URI. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <param name="webProfile">WebProfile object to be created as a PayPal resource.</param> /// <returns>CreateProfileResponse</returns> public static CreateProfileResponse Create(APIContext apiContext, WebProfile webProfile) { // Validate the arguments to be used in the request ArgumentValidator.ValidateAndSetupAPIContext(apiContext); // Configure and send the request var resourcePath = "v1/payment-experience/web-profiles"; return PayPalResource.ConfigureAndExecute<CreateProfileResponse>(apiContext, HttpMethod.POST, resourcePath, webProfile.ConvertToJson()); }
/// <summary> /// Update a web experience profile by passing the ID of the profile to the request URI. In addition, pass the profile details in the request JSON. If your request does not include values for all profile detail fields, the previously set values for the omitted fields are removed by this operation. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <param name="profile">WebProfile resource to update.</param> public static void Update(APIContext apiContext, WebProfile profile) { // Validate the arguments to be used in the request ArgumentValidator.ValidateAndSetupAPIContext(apiContext); ArgumentValidator.Validate(profile, "profile"); // Configure and send the request var pattern = "v1/payment-experience/web-profiles/{0}"; var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { profile.id }); PayPalResource.ConfigureAndExecute(apiContext, HttpMethod.PUT, resourcePath, profile.ConvertToJson()); }
/// <summary> /// Updates a web experience profile. Pass the ID of the profile to the request URI and pass the profile details in the JSON request body. If your request omits any profile detail fields, the operation removes the previously set values for those fields. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> public void Update(APIContext apiContext) { WebProfile.Update(apiContext, this); }
/// <summary> /// Creates a web experience profile. Pass the profile name and details in the JSON request body. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <returns>CreateProfileResponse</returns> public CreateProfileResponse Create(APIContext apiContext) { return(WebProfile.Create(apiContext, this)); }
/// <summary> /// Deletes a web experience profile, by ID. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> public void Delete(APIContext apiContext) { WebProfile.Delete(apiContext, this.id); }
/// <summary> /// Partially-updates a web experience profile. Pass the profile ID to the request URI. Pass a patch object with the operation, path of the profile location to update, and, if needed, a new value to complete the operation in the JSON request body. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <param name="patchRequest">PatchRequest</param> public void PartialUpdate(APIContext apiContext, PatchRequest patchRequest) { WebProfile.PartialUpdate(apiContext, this.id, patchRequest); }
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(); string payerId = Request.Params["PayerID"]; if (string.IsNullOrEmpty(payerId)) { // Create the web experience profile var profile = new WebProfile { name = Guid.NewGuid().ToString(), presentation = new Presentation { brand_name = "PayPal .NET SDK", locale_code = "US", logo_image = "https://raw.githubusercontent.com/wiki/paypal/PayPal-NET-SDK/images/homepage.jpg" }, input_fields = new InputFields { no_shipping = 1 } }; // ^ Ignore workflow code segment #region Track Workflow this.flow.AddNewRequest("Create new web experience profile (NOTE: This only needs to be done once)", profile); #endregion var createdProfile = profile.Create(apiContext); // ^ Ignore workflow code segment #region Track Workflow this.flow.RecordResponse(createdProfile); #endregion // Setup the redirect URI to use. The guid value is used to keep the flow information. var baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/PaymentWithPayPal.aspx?"; var guid = Convert.ToString((new Random()).Next(100000)); baseURI += "guid=" + guid + "&webProfileId=" + createdProfile.id; // Create the payment var payment = new Payment { intent = "sale", experience_profile_id = createdProfile.id, payer = new Payer { payment_method = "paypal" }, transactions = new List<Transaction> { new Transaction { description = "Ticket information.", item_list = new ItemList { items = new List<Item> { new Item { name = "Concert ticket", currency = "USD", price = "20.00", quantity = "2", sku = "ticket_sku" } } }, amount = new Amount { currency = "USD", total = "45.00", details = new Details { tax = "5.00", subtotal = "40.00" } } } }, redirect_urls = new RedirectUrls { return_url = baseURI + "&return=true", cancel_url = baseURI + "&cancel=true" } }; // ^ Ignore workflow code segment #region Track Workflow this.flow.AddNewRequest("Create PayPal payment", payment); #endregion var createdPayment = payment.Create(apiContext); // ^ Ignore workflow code segment #region Track Workflow this.flow.RecordResponse(createdPayment); #endregion // Use the returned payment's approval URL to redirect the buyer to PayPal and approve the payment. var approvalUrl = createdPayment.GetApprovalUrl(); this.flow.RecordRedirectUrl("Redirect to PayPal to approve the payment...", approvalUrl); Session.Add(guid, createdPayment.id); Session.Add("flow-" + guid, this.flow); } else { var guid = Request.Params["guid"]; var webProfileId = Request.Params["webProfileId"]; var isReturnSet = Request.Params["return"]; // ^ Ignore workflow code segment #region Track Workflow this.flow = Session["flow-" + guid] as RequestFlow; this.RegisterSampleRequestFlow(); this.flow.RecordApproval("PayPal payment approved successfully."); #endregion if (string.IsNullOrEmpty(isReturnSet)) { // ^ Ignore workflow code segment #region Track Workflow this.flow.RecordApproval("PayPal payment canceled by buyer."); #endregion } else { // ^ Ignore workflow code segment #region Track Workflow this.flow.RecordApproval("PayPal payment approved successfully."); #endregion // Using the information from the redirect, setup the payment to execute. var paymentId = Session[guid] as string; var paymentExecution = new PaymentExecution() { payer_id = payerId }; var payment = new Payment() { id = paymentId }; // ^ Ignore workflow code segment #region Track Workflow this.flow.AddNewRequest("Execute PayPal payment", payment); #endregion // Execute the payment. var executedPayment = payment.Execute(apiContext, paymentExecution); // ^ Ignore workflow code segment #region Track Workflow this.flow.RecordResponse(executedPayment); #endregion } // Cleanup - Because there's a limit to the number of experience profile IDs you can create, // we'll delete the one that was created for this sample. WebProfile.Delete(apiContext, webProfileId); // For more information, please visit [PayPal Developer REST API Reference](https://developer.paypal.com/docs/api/). } }
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); this.flow.AddNewRequest("Retrieve profile details", description: "ID: " + response.id); //-------------------- #endregion // Get the profile object and update the profile. var retrievedProfile = WebProfile.Get(apiContext, response.id); #region Track Workflow //-------------------- this.flow.RecordResponse(retrievedProfile); //-------------------- #endregion retrievedProfile.name = "A new name"; #region Track Workflow //-------------------- this.flow.AddNewRequest("Update profile", retrievedProfile); //-------------------- #endregion retrievedProfile.Update(apiContext); #region Track Workflow //-------------------- this.flow.RecordActionSuccess("Profile updated successfully"); //-------------------- #endregion #region Cleanup // Cleanup by deleting the newly-created profile retrievedProfile.Delete(apiContext); #endregion }