paypale/webprofile.go

117 lines
2.7 KiB
Go
Raw Normal View History

2019-08-21 15:50:20 +02:00
package paypal
2016-10-25 21:44:10 +02:00
import (
2021-01-03 10:28:52 +01:00
"context"
2016-10-25 21:44:10 +02:00
"fmt"
"net/http"
)
// CreateWebProfile creates a new web experience profile in Paypal
//
// Allows for the customisation of the payment experience
//
// Endpoint: POST /v1/payment-experience/web-profiles
2021-01-03 10:28:52 +01:00
func (c *Client) CreateWebProfile(ctx context.Context, wp WebProfile) (*WebProfile, error) {
2016-10-25 21:44:10 +02:00
url := fmt.Sprintf("%s%s", c.APIBase, "/v1/payment-experience/web-profiles")
2021-01-03 10:28:52 +01:00
req, err := c.NewRequest(ctx, "POST", url, wp)
2019-06-16 04:39:08 +02:00
response := &WebProfile{}
2016-10-25 21:44:10 +02:00
if err != nil {
2019-06-16 04:39:08 +02:00
return response, err
2016-10-25 21:44:10 +02:00
}
2017-11-23 03:15:11 +01:00
if err = c.SendWithAuth(req, response); err != nil {
2016-10-25 21:44:10 +02:00
return response, err
}
return response, nil
}
// GetWebProfile gets an exists payment experience from Paypal
//
// Endpoint: GET /v1/payment-experience/web-profiles/<profile-id>
2021-01-03 10:28:52 +01:00
func (c *Client) GetWebProfile(ctx context.Context, profileID string) (*WebProfile, error) {
2016-10-25 21:44:10 +02:00
var wp WebProfile
url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", profileID)
2021-01-03 10:28:52 +01:00
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
2016-10-25 21:44:10 +02:00
if err != nil {
return &wp, err
}
2017-11-23 03:15:11 +01:00
if err = c.SendWithAuth(req, &wp); err != nil {
2016-10-25 21:44:10 +02:00
return &wp, err
}
if wp.ID == "" {
2019-08-21 15:50:20 +02:00
return &wp, fmt.Errorf("paypal: unable to get web profile with ID = %s", profileID)
2016-10-25 21:44:10 +02:00
}
return &wp, nil
}
2021-09-12 20:53:49 +02:00
// GetWebProfiles retrieves web experience profiles from Paypal
2016-10-25 21:44:10 +02:00
//
// Endpoint: GET /v1/payment-experience/web-profiles
2021-01-03 10:28:52 +01:00
func (c *Client) GetWebProfiles(ctx context.Context) ([]WebProfile, error) {
2016-10-25 21:44:10 +02:00
var wps []WebProfile
url := fmt.Sprintf("%s%s", c.APIBase, "/v1/payment-experience/web-profiles")
2021-01-03 10:28:52 +01:00
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
2016-10-25 21:44:10 +02:00
if err != nil {
return wps, err
}
2017-11-23 03:15:11 +01:00
if err = c.SendWithAuth(req, &wps); err != nil {
2016-10-25 21:44:10 +02:00
return wps, err
}
return wps, nil
}
// SetWebProfile sets a web experience profile in Paypal with given id
//
// Endpoint: PUT /v1/payment-experience/web-profiles
2021-01-03 10:28:52 +01:00
func (c *Client) SetWebProfile(ctx context.Context, wp WebProfile) error {
2016-10-25 21:44:10 +02:00
if wp.ID == "" {
2019-08-21 15:50:20 +02:00
return fmt.Errorf("paypal: no ID specified for WebProfile")
2016-10-25 21:44:10 +02:00
}
url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", wp.ID)
2021-01-03 10:28:52 +01:00
req, err := c.NewRequest(ctx, "PUT", url, wp)
2016-10-25 21:44:10 +02:00
if err != nil {
return err
}
2017-11-23 03:15:11 +01:00
if err = c.SendWithAuth(req, nil); err != nil {
2016-10-25 21:44:10 +02:00
return err
}
return nil
}
// DeleteWebProfile deletes a web experience profile from Paypal with given id
//
// Endpoint: DELETE /v1/payment-experience/web-profiles
2021-01-03 10:28:52 +01:00
func (c *Client) DeleteWebProfile(ctx context.Context, profileID string) error {
2016-10-25 21:44:10 +02:00
url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", profileID)
2021-01-03 10:28:52 +01:00
req, err := c.NewRequest(ctx, "DELETE", url, nil)
2016-10-25 21:44:10 +02:00
if err != nil {
return err
}
2017-11-23 03:15:11 +01:00
if err = c.SendWithAuth(req, nil); err != nil {
2016-10-25 21:44:10 +02:00
return err
}
return nil
}