paypale/webprofile.go

116 lines
2.6 KiB
Go
Raw Normal View History

2016-10-25 21:44:10 +02:00
package paypalsdk
import (
"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
func (c *Client) CreateWebProfile(wp WebProfile) (*WebProfile, error) {
url := fmt.Sprintf("%s%s", c.APIBase, "/v1/payment-experience/web-profiles")
req, err := c.NewRequest("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>
func (c *Client) GetWebProfile(profileID string) (*WebProfile, error) {
var wp WebProfile
url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", profileID)
req, err := http.NewRequest("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 == "" {
return &wp, fmt.Errorf("paypalsdk: unable to get web profile with ID = %s", profileID)
}
return &wp, nil
}
// GetWebProfiles retreieves web experience profiles from Paypal
//
// Endpoint: GET /v1/payment-experience/web-profiles
func (c *Client) GetWebProfiles() ([]WebProfile, error) {
var wps []WebProfile
url := fmt.Sprintf("%s%s", c.APIBase, "/v1/payment-experience/web-profiles")
req, err := http.NewRequest("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
func (c *Client) SetWebProfile(wp WebProfile) error {
if wp.ID == "" {
return fmt.Errorf("paypalsdk: no ID specified for WebProfile")
}
url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", wp.ID)
req, err := c.NewRequest("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
func (c *Client) DeleteWebProfile(profileID string) error {
url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", profileID)
req, err := c.NewRequest("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
}