github.com/plutov/paypal/v4@v4.7.1/webprofile.go (about) 1 package paypal 2 3 import ( 4 "context" 5 "fmt" 6 "net/http" 7 ) 8 9 // CreateWebProfile creates a new web experience profile in Paypal 10 // 11 // Allows for the customisation of the payment experience 12 // 13 // Endpoint: POST /v1/payment-experience/web-profiles 14 func (c *Client) CreateWebProfile(ctx context.Context, wp WebProfile) (*WebProfile, error) { 15 url := fmt.Sprintf("%s%s", c.APIBase, "/v1/payment-experience/web-profiles") 16 req, err := c.NewRequest(ctx, "POST", url, wp) 17 response := &WebProfile{} 18 19 if err != nil { 20 return response, err 21 } 22 23 if err = c.SendWithAuth(req, response); err != nil { 24 return response, err 25 } 26 27 return response, nil 28 } 29 30 // GetWebProfile gets an exists payment experience from Paypal 31 // 32 // Endpoint: GET /v1/payment-experience/web-profiles/<profile-id> 33 func (c *Client) GetWebProfile(ctx context.Context, profileID string) (*WebProfile, error) { 34 var wp WebProfile 35 36 url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", profileID) 37 req, err := http.NewRequestWithContext(ctx, "GET", url, nil) 38 39 if err != nil { 40 return &wp, err 41 } 42 43 if err = c.SendWithAuth(req, &wp); err != nil { 44 return &wp, err 45 } 46 47 if wp.ID == "" { 48 return &wp, fmt.Errorf("paypal: unable to get web profile with ID = %s", profileID) 49 } 50 51 return &wp, nil 52 } 53 54 // GetWebProfiles retrieves web experience profiles from Paypal 55 // 56 // Endpoint: GET /v1/payment-experience/web-profiles 57 func (c *Client) GetWebProfiles(ctx context.Context) ([]WebProfile, error) { 58 var wps []WebProfile 59 60 url := fmt.Sprintf("%s%s", c.APIBase, "/v1/payment-experience/web-profiles") 61 req, err := http.NewRequestWithContext(ctx, "GET", url, nil) 62 63 if err != nil { 64 return wps, err 65 } 66 67 if err = c.SendWithAuth(req, &wps); err != nil { 68 return wps, err 69 } 70 71 return wps, nil 72 } 73 74 // SetWebProfile sets a web experience profile in Paypal with given id 75 // 76 // Endpoint: PUT /v1/payment-experience/web-profiles 77 func (c *Client) SetWebProfile(ctx context.Context, wp WebProfile) error { 78 79 if wp.ID == "" { 80 return fmt.Errorf("paypal: no ID specified for WebProfile") 81 } 82 83 url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", wp.ID) 84 85 req, err := c.NewRequest(ctx, "PUT", url, wp) 86 87 if err != nil { 88 return err 89 } 90 91 if err = c.SendWithAuth(req, nil); err != nil { 92 return err 93 } 94 95 return nil 96 } 97 98 // DeleteWebProfile deletes a web experience profile from Paypal with given id 99 // 100 // Endpoint: DELETE /v1/payment-experience/web-profiles 101 func (c *Client) DeleteWebProfile(ctx context.Context, profileID string) error { 102 103 url := fmt.Sprintf("%s%s%s", c.APIBase, "/v1/payment-experience/web-profiles/", profileID) 104 105 req, err := c.NewRequest(ctx, "DELETE", url, nil) 106 107 if err != nil { 108 return err 109 } 110 111 if err = c.SendWithAuth(req, nil); err != nil { 112 return err 113 } 114 115 return nil 116 }