From cd22892aeca121dc7d276ec9c05b8d4b9407a165 Mon Sep 17 00:00:00 2001 From: Alex Pliutau Date: Thu, 23 Nov 2017 09:15:11 +0700 Subject: [PATCH] Make one-line if err != nil conditions --- authorization.go | 19 +++++++------------ billing.go | 4 ++-- identity.go | 9 +++------ order.go | 12 ++++-------- payment.go | 17 +++++++---------- payout.go | 12 ++++-------- sale.go | 9 +++------ vault.go | 19 +++++++++---------- webprofile.go | 15 +++++---------- 9 files changed, 44 insertions(+), 72 deletions(-) diff --git a/authorization.go b/authorization.go index 2a40610..344bae5 100644 --- a/authorization.go +++ b/authorization.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "net/http" + "strconv" ) // GetAuthorization returns an authorization by ID @@ -17,8 +18,7 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) { auth := &Authorization{} - err = c.SendWithAuth(req, auth) - if err != nil { + if err = c.SendWithAuth(req, auth); err != nil { 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" // Endpoint: POST /v1/payments/authorization/ID/capture func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) { - isFinalStr := "false" - if isFinalCapture { - isFinalStr = "true" - } + isFinalStr := strconv.FormatBool(isFinalCapture) + 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) if err != nil { @@ -41,8 +39,7 @@ func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture b capture := &Capture{} - err = c.SendWithAuth(req, capture) - if err != nil { + if err = c.SendWithAuth(req, capture); err != nil { return capture, err } @@ -60,8 +57,7 @@ func (c *Client) VoidAuthorization(authID string) (*Authorization, error) { auth := &Authorization{} - err = c.SendWithAuth(req, auth) - if err != nil { + if err = c.SendWithAuth(req, auth); err != nil { return auth, err } @@ -80,8 +76,7 @@ func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorizat auth := &Authorization{} - err = c.SendWithAuth(req, auth) - if err != nil { + if err = c.SendWithAuth(req, auth); err != nil { return auth, err } diff --git a/billing.go b/billing.go index 355b673..5653411 100644 --- a/billing.go +++ b/billing.go @@ -85,8 +85,8 @@ func (c *Client) ExecuteApprovedAgreement(token string) (*ExecuteAgreementRespon req.Header.Set("Authorization", "Bearer "+c.Token.Token) e := ExecuteAgreementResponse{} - err = c.SendWithAuth(req, &e) - if err != nil { + + if err = c.SendWithAuth(req, &e); err != nil { return &e, err } diff --git a/identity.go b/identity.go index e2dd304..0328308 100644 --- a/identity.go +++ b/identity.go @@ -24,8 +24,7 @@ func (c *Client) GrantNewAccessTokenFromAuthCode(code string, redirectURI string req.Header.Add("Content-Type", "application/x-www-form-urlencoded") - err = c.SendWithBasicAuth(req, token) - if err != nil { + if err = c.SendWithBasicAuth(req, token); err != nil { return token, err } @@ -47,8 +46,7 @@ func (c *Client) GrantNewAccessTokenFromRefreshToken(refreshToken string) (*Toke return token, err } - err = c.SendWithAuth(req, token) - if err != nil { + if err = c.SendWithAuth(req, token); err != nil { return token, err } @@ -66,8 +64,7 @@ func (c *Client) GetUserInfo(schema string) (*UserInfo, error) { return &u, err } - err = c.SendWithAuth(req, &u) - if err != nil { + if err = c.SendWithAuth(req, &u); err != nil { return &u, err } diff --git a/order.go b/order.go index f148d79..8449be6 100644 --- a/order.go +++ b/order.go @@ -12,8 +12,7 @@ func (c *Client) GetOrder(orderID string) (*Order, error) { return order, err } - err = c.SendWithAuth(req, order) - if err != nil { + if err = c.SendWithAuth(req, order); err != nil { return order, err } @@ -34,8 +33,7 @@ func (c *Client) AuthorizeOrder(orderID string, amount *Amount) (*Authorization, return auth, err } - err = c.SendWithAuth(req, auth) - if err != nil { + if err = c.SendWithAuth(req, auth); err != nil { return auth, err } @@ -58,8 +56,7 @@ func (c *Client) CaptureOrder(orderID string, amount *Amount, isFinalCapture boo return capture, err } - err = c.SendWithAuth(req, capture) - if err != nil { + if err = c.SendWithAuth(req, capture); err != nil { return capture, err } @@ -77,8 +74,7 @@ func (c *Client) VoidOrder(orderID string) (*Order, error) { return order, err } - err = c.SendWithAuth(req, order) - if err != nil { + if err = c.SendWithAuth(req, order); err != nil { return order, err } diff --git a/payment.go b/payment.go index b8d11c8..a87a497 100644 --- a/payment.go +++ b/payment.go @@ -35,8 +35,8 @@ func (c *Client) CreateDirectPaypalPayment(amount Amount, redirectURI string, ca req.Header.Set("Authorization", "Bearer "+c.Token.Token) p := PaymentResponse{} - err = c.SendWithAuth(req, &p) - if err != nil { + + if err = c.SendWithAuth(req, &p); err != nil { return &p, err } @@ -58,8 +58,7 @@ func (c *Client) CreatePayment(p Payment) (*CreatePaymentResp, error) { response := &CreatePaymentResp{} - err = c.SendWithAuth(req, response) - if err != nil { + if err = c.SendWithAuth(req, response); err != nil { return response, err } @@ -79,8 +78,8 @@ func (c *Client) ExecuteApprovedPayment(paymentID string, payerID string) (*Exec req.Header.Set("Authorization", "Bearer "+c.Token.Token) e := ExecuteResponse{} - err = c.SendWithAuth(req, &e) - if err != nil { + + if err = c.SendWithAuth(req, &e); err != nil { return &e, err } @@ -101,8 +100,7 @@ func (c *Client) GetPayment(paymentID string) (*Payment, error) { return &p, err } - err = c.SendWithAuth(req, &p) - if err != nil { + if err = c.SendWithAuth(req, &p); err != nil { return &p, err } @@ -123,8 +121,7 @@ func (c *Client) GetPayments() ([]Payment, error) { return p.Payments, err } - err = c.SendWithAuth(req, &p) - if err != nil { + if err = c.SendWithAuth(req, &p); err != nil { return p.Payments, err } diff --git a/payout.go b/payout.go index a0420e1..8db6046 100644 --- a/payout.go +++ b/payout.go @@ -15,8 +15,7 @@ func (c *Client) CreateSinglePayout(p Payout) (*PayoutResponse, error) { response := &PayoutResponse{} - err = c.SendWithAuth(req, response) - if err != nil { + if err = c.SendWithAuth(req, response); err != nil { return response, err } @@ -35,8 +34,7 @@ func (c *Client) GetPayout(payoutBatchID string) (*PayoutResponse, error) { response := &PayoutResponse{} - err = c.SendWithAuth(req, response) - if err != nil { + if err = c.SendWithAuth(req, response); err != nil { return response, err } @@ -55,8 +53,7 @@ func (c *Client) GetPayoutItem(payoutItemID string) (*PayoutItemResponse, error) response := &PayoutItemResponse{} - err = c.SendWithAuth(req, response) - if err != nil { + if err = c.SendWithAuth(req, response); err != nil { return response, err } @@ -75,8 +72,7 @@ func (c *Client) CancelPayoutItem(payoutItemID string) (*PayoutItemResponse, err response := &PayoutItemResponse{} - err = c.SendWithAuth(req, response) - if err != nil { + if err = c.SendWithAuth(req, response); err != nil { return response, err } diff --git a/sale.go b/sale.go index 1fe6e0e..17eb303 100644 --- a/sale.go +++ b/sale.go @@ -14,8 +14,7 @@ func (c *Client) GetSale(saleID string) (*Sale, error) { return sale, err } - err = c.SendWithAuth(req, sale) - if err != nil { + if err = c.SendWithAuth(req, sale); err != nil { return sale, err } @@ -37,8 +36,7 @@ func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error) { return refund, err } - err = c.SendWithAuth(req, refund) - if err != nil { + if err = c.SendWithAuth(req, refund); err != nil { return refund, err } @@ -56,8 +54,7 @@ func (c *Client) GetRefund(refundID string) (*Refund, error) { return refund, err } - err = c.SendWithAuth(req, refund) - if err != nil { + if err = c.SendWithAuth(req, refund); err != nil { return refund, err } diff --git a/vault.go b/vault.go index 1ddc6b7..634683e 100644 --- a/vault.go +++ b/vault.go @@ -13,8 +13,8 @@ func (c *Client) StoreCreditCard(cc CreditCard) (*CreditCard, error) { } response := CreditCard{} - err = c.SendWithAuth(req, &response) - if err != nil { + + if err = c.SendWithAuth(req, &response); err != nil { return nil, err } @@ -29,8 +29,7 @@ func (c *Client) DeleteCreditCard(id string) error { return err } - err = c.SendWithAuth(req, nil) - if err != nil { + if err = c.SendWithAuth(req, nil); err != nil { return err } @@ -46,8 +45,8 @@ func (c *Client) GetCreditCard(id string) (*CreditCard, error) { } response := CreditCard{} - err = c.SendWithAuth(req, &response) - if err != nil { + + if err = c.SendWithAuth(req, &response); err != nil { return nil, err } @@ -72,8 +71,8 @@ func (c *Client) GetCreditCards(ccf *CreditCardsFilter) (*CreditCards, error) { } response := CreditCards{} - err = c.SendWithAuth(req, &response) - if err != nil { + + if err = c.SendWithAuth(req, &response); err != nil { return nil, err } @@ -89,8 +88,8 @@ func (c *Client) PatchCreditCard(id string, ccf []CreditCardField) (*CreditCard, } response := CreditCard{} - err = c.SendWithAuth(req, &response) - if err != nil { + + if err = c.SendWithAuth(req, &response); err != nil { return nil, err } diff --git a/webprofile.go b/webprofile.go index c771315..f2feca0 100644 --- a/webprofile.go +++ b/webprofile.go @@ -19,8 +19,7 @@ func (c *Client) CreateWebProfile(wp WebProfile) (*WebProfile, error) { response := &WebProfile{} - err = c.SendWithAuth(req, response) - if err != nil { + if err = c.SendWithAuth(req, response); err != nil { return response, err } @@ -40,8 +39,7 @@ func (c *Client) GetWebProfile(profileID string) (*WebProfile, error) { return &wp, err } - err = c.SendWithAuth(req, &wp) - if err != nil { + if err = c.SendWithAuth(req, &wp); err != nil { return &wp, err } @@ -65,8 +63,7 @@ func (c *Client) GetWebProfiles() ([]WebProfile, error) { return wps, err } - err = c.SendWithAuth(req, &wps) - if err != nil { + if err = c.SendWithAuth(req, &wps); err != nil { return wps, err } @@ -90,8 +87,7 @@ func (c *Client) SetWebProfile(wp WebProfile) error { return err } - err = c.SendWithAuth(req, nil) - if err != nil { + if err = c.SendWithAuth(req, nil); err != nil { return err } @@ -111,8 +107,7 @@ func (c *Client) DeleteWebProfile(profileID string) error { return err } - err = c.SendWithAuth(req, nil) - if err != nil { + if err = c.SendWithAuth(req, nil); err != nil { return err }