mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 10:21:03 +01:00
Make one-line if err != nil conditions
This commit is contained in:
parent
be5f959441
commit
cd22892aec
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetAuthorization returns an authorization by ID
|
// GetAuthorization returns an authorization by ID
|
||||||
|
@ -17,8 +18,7 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
|
||||||
|
|
||||||
auth := &Authorization{}
|
auth := &Authorization{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, auth)
|
if err = c.SendWithAuth(req, auth); err != nil {
|
||||||
if err != nil {
|
|
||||||
return auth, err
|
return auth, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,10 +29,8 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
|
||||||
// To use this method, the original payment must have Intent set to "authorize"
|
// To use this method, the original payment must have Intent set to "authorize"
|
||||||
// Endpoint: POST /v1/payments/authorization/ID/capture
|
// Endpoint: POST /v1/payments/authorization/ID/capture
|
||||||
func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) {
|
func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) {
|
||||||
isFinalStr := "false"
|
isFinalStr := strconv.FormatBool(isFinalCapture)
|
||||||
if isFinalCapture {
|
|
||||||
isFinalStr = "true"
|
|
||||||
}
|
|
||||||
buf := bytes.NewBuffer([]byte("{\"amount\":{\"currency\":\"" + a.Currency + "\",\"total\":\"" + a.Total + "\"},\"is_final_capture\":" + isFinalStr + "}"))
|
buf := bytes.NewBuffer([]byte("{\"amount\":{\"currency\":\"" + a.Currency + "\",\"total\":\"" + a.Total + "\"},\"is_final_capture\":" + isFinalStr + "}"))
|
||||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/authorization/"+authID+"/capture"), buf)
|
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/authorization/"+authID+"/capture"), buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -41,8 +39,7 @@ func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture b
|
||||||
|
|
||||||
capture := &Capture{}
|
capture := &Capture{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, capture)
|
if err = c.SendWithAuth(req, capture); err != nil {
|
||||||
if err != nil {
|
|
||||||
return capture, err
|
return capture, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +57,7 @@ func (c *Client) VoidAuthorization(authID string) (*Authorization, error) {
|
||||||
|
|
||||||
auth := &Authorization{}
|
auth := &Authorization{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, auth)
|
if err = c.SendWithAuth(req, auth); err != nil {
|
||||||
if err != nil {
|
|
||||||
return auth, err
|
return auth, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,8 +76,7 @@ func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorizat
|
||||||
|
|
||||||
auth := &Authorization{}
|
auth := &Authorization{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, auth)
|
if err = c.SendWithAuth(req, auth); err != nil {
|
||||||
if err != nil {
|
|
||||||
return auth, err
|
return auth, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,8 +85,8 @@ func (c *Client) ExecuteApprovedAgreement(token string) (*ExecuteAgreementRespon
|
||||||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||||
|
|
||||||
e := ExecuteAgreementResponse{}
|
e := ExecuteAgreementResponse{}
|
||||||
err = c.SendWithAuth(req, &e)
|
|
||||||
if err != nil {
|
if err = c.SendWithAuth(req, &e); err != nil {
|
||||||
return &e, err
|
return &e, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,7 @@ func (c *Client) GrantNewAccessTokenFromAuthCode(code string, redirectURI string
|
||||||
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
err = c.SendWithBasicAuth(req, token)
|
if err = c.SendWithBasicAuth(req, token); err != nil {
|
||||||
if err != nil {
|
|
||||||
return token, err
|
return token, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +46,7 @@ func (c *Client) GrantNewAccessTokenFromRefreshToken(refreshToken string) (*Toke
|
||||||
return token, err
|
return token, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, token)
|
if err = c.SendWithAuth(req, token); err != nil {
|
||||||
if err != nil {
|
|
||||||
return token, err
|
return token, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,8 +64,7 @@ func (c *Client) GetUserInfo(schema string) (*UserInfo, error) {
|
||||||
return &u, err
|
return &u, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, &u)
|
if err = c.SendWithAuth(req, &u); err != nil {
|
||||||
if err != nil {
|
|
||||||
return &u, err
|
return &u, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
order.go
12
order.go
|
@ -12,8 +12,7 @@ func (c *Client) GetOrder(orderID string) (*Order, error) {
|
||||||
return order, err
|
return order, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, order)
|
if err = c.SendWithAuth(req, order); err != nil {
|
||||||
if err != nil {
|
|
||||||
return order, err
|
return order, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +33,7 @@ func (c *Client) AuthorizeOrder(orderID string, amount *Amount) (*Authorization,
|
||||||
return auth, err
|
return auth, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, auth)
|
if err = c.SendWithAuth(req, auth); err != nil {
|
||||||
if err != nil {
|
|
||||||
return auth, err
|
return auth, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +56,7 @@ func (c *Client) CaptureOrder(orderID string, amount *Amount, isFinalCapture boo
|
||||||
return capture, err
|
return capture, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, capture)
|
if err = c.SendWithAuth(req, capture); err != nil {
|
||||||
if err != nil {
|
|
||||||
return capture, err
|
return capture, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +74,7 @@ func (c *Client) VoidOrder(orderID string) (*Order, error) {
|
||||||
return order, err
|
return order, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, order)
|
if err = c.SendWithAuth(req, order); err != nil {
|
||||||
if err != nil {
|
|
||||||
return order, err
|
return order, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
payment.go
17
payment.go
|
@ -35,8 +35,8 @@ func (c *Client) CreateDirectPaypalPayment(amount Amount, redirectURI string, ca
|
||||||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||||
|
|
||||||
p := PaymentResponse{}
|
p := PaymentResponse{}
|
||||||
err = c.SendWithAuth(req, &p)
|
|
||||||
if err != nil {
|
if err = c.SendWithAuth(req, &p); err != nil {
|
||||||
return &p, err
|
return &p, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +58,7 @@ func (c *Client) CreatePayment(p Payment) (*CreatePaymentResp, error) {
|
||||||
|
|
||||||
response := &CreatePaymentResp{}
|
response := &CreatePaymentResp{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, response)
|
if err = c.SendWithAuth(req, response); err != nil {
|
||||||
if err != nil {
|
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,8 +78,8 @@ func (c *Client) ExecuteApprovedPayment(paymentID string, payerID string) (*Exec
|
||||||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||||
|
|
||||||
e := ExecuteResponse{}
|
e := ExecuteResponse{}
|
||||||
err = c.SendWithAuth(req, &e)
|
|
||||||
if err != nil {
|
if err = c.SendWithAuth(req, &e); err != nil {
|
||||||
return &e, err
|
return &e, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,8 +100,7 @@ func (c *Client) GetPayment(paymentID string) (*Payment, error) {
|
||||||
return &p, err
|
return &p, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, &p)
|
if err = c.SendWithAuth(req, &p); err != nil {
|
||||||
if err != nil {
|
|
||||||
return &p, err
|
return &p, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,8 +121,7 @@ func (c *Client) GetPayments() ([]Payment, error) {
|
||||||
return p.Payments, err
|
return p.Payments, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, &p)
|
if err = c.SendWithAuth(req, &p); err != nil {
|
||||||
if err != nil {
|
|
||||||
return p.Payments, err
|
return p.Payments, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
payout.go
12
payout.go
|
@ -15,8 +15,7 @@ func (c *Client) CreateSinglePayout(p Payout) (*PayoutResponse, error) {
|
||||||
|
|
||||||
response := &PayoutResponse{}
|
response := &PayoutResponse{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, response)
|
if err = c.SendWithAuth(req, response); err != nil {
|
||||||
if err != nil {
|
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +34,7 @@ func (c *Client) GetPayout(payoutBatchID string) (*PayoutResponse, error) {
|
||||||
|
|
||||||
response := &PayoutResponse{}
|
response := &PayoutResponse{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, response)
|
if err = c.SendWithAuth(req, response); err != nil {
|
||||||
if err != nil {
|
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +53,7 @@ func (c *Client) GetPayoutItem(payoutItemID string) (*PayoutItemResponse, error)
|
||||||
|
|
||||||
response := &PayoutItemResponse{}
|
response := &PayoutItemResponse{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, response)
|
if err = c.SendWithAuth(req, response); err != nil {
|
||||||
if err != nil {
|
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,8 +72,7 @@ func (c *Client) CancelPayoutItem(payoutItemID string) (*PayoutItemResponse, err
|
||||||
|
|
||||||
response := &PayoutItemResponse{}
|
response := &PayoutItemResponse{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, response)
|
if err = c.SendWithAuth(req, response); err != nil {
|
||||||
if err != nil {
|
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
sale.go
9
sale.go
|
@ -14,8 +14,7 @@ func (c *Client) GetSale(saleID string) (*Sale, error) {
|
||||||
return sale, err
|
return sale, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, sale)
|
if err = c.SendWithAuth(req, sale); err != nil {
|
||||||
if err != nil {
|
|
||||||
return sale, err
|
return sale, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +36,7 @@ func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error) {
|
||||||
return refund, err
|
return refund, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, refund)
|
if err = c.SendWithAuth(req, refund); err != nil {
|
||||||
if err != nil {
|
|
||||||
return refund, err
|
return refund, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,8 +54,7 @@ func (c *Client) GetRefund(refundID string) (*Refund, error) {
|
||||||
return refund, err
|
return refund, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, refund)
|
if err = c.SendWithAuth(req, refund); err != nil {
|
||||||
if err != nil {
|
|
||||||
return refund, err
|
return refund, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
vault.go
19
vault.go
|
@ -13,8 +13,8 @@ func (c *Client) StoreCreditCard(cc CreditCard) (*CreditCard, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
response := CreditCard{}
|
response := CreditCard{}
|
||||||
err = c.SendWithAuth(req, &response)
|
|
||||||
if err != nil {
|
if err = c.SendWithAuth(req, &response); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,7 @@ func (c *Client) DeleteCreditCard(id string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, nil)
|
if err = c.SendWithAuth(req, nil); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +45,8 @@ func (c *Client) GetCreditCard(id string) (*CreditCard, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
response := CreditCard{}
|
response := CreditCard{}
|
||||||
err = c.SendWithAuth(req, &response)
|
|
||||||
if err != nil {
|
if err = c.SendWithAuth(req, &response); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +71,8 @@ func (c *Client) GetCreditCards(ccf *CreditCardsFilter) (*CreditCards, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
response := CreditCards{}
|
response := CreditCards{}
|
||||||
err = c.SendWithAuth(req, &response)
|
|
||||||
if err != nil {
|
if err = c.SendWithAuth(req, &response); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,8 +88,8 @@ func (c *Client) PatchCreditCard(id string, ccf []CreditCardField) (*CreditCard,
|
||||||
}
|
}
|
||||||
|
|
||||||
response := CreditCard{}
|
response := CreditCard{}
|
||||||
err = c.SendWithAuth(req, &response)
|
|
||||||
if err != nil {
|
if err = c.SendWithAuth(req, &response); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@ func (c *Client) CreateWebProfile(wp WebProfile) (*WebProfile, error) {
|
||||||
|
|
||||||
response := &WebProfile{}
|
response := &WebProfile{}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, response)
|
if err = c.SendWithAuth(req, response); err != nil {
|
||||||
if err != nil {
|
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +39,7 @@ func (c *Client) GetWebProfile(profileID string) (*WebProfile, error) {
|
||||||
return &wp, err
|
return &wp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, &wp)
|
if err = c.SendWithAuth(req, &wp); err != nil {
|
||||||
if err != nil {
|
|
||||||
return &wp, err
|
return &wp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +63,7 @@ func (c *Client) GetWebProfiles() ([]WebProfile, error) {
|
||||||
return wps, err
|
return wps, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, &wps)
|
if err = c.SendWithAuth(req, &wps); err != nil {
|
||||||
if err != nil {
|
|
||||||
return wps, err
|
return wps, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +87,7 @@ func (c *Client) SetWebProfile(wp WebProfile) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, nil)
|
if err = c.SendWithAuth(req, nil); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,8 +107,7 @@ func (c *Client) DeleteWebProfile(profileID string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.SendWithAuth(req, nil)
|
if err = c.SendWithAuth(req, nil); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user