deprecate a few inconsistently named things and but keep aliases.

This commit is contained in:
Thomas Frössman 2021-01-20 09:28:04 +01:00
parent e83fd911e0
commit 3b835ea26a
4 changed files with 34 additions and 20 deletions

View File

@ -9,8 +9,8 @@ import (
)
type (
// CreateBillingResp struct
CreateBillingResp struct {
// CreateBillingResponse struct
CreateBillingResponse struct {
ID string `json:"id,omitempty"`
State string `json:"state,omitempty"`
PaymentDefinitions []PaymentDefinition `json:"payment_definitions,omitempty"`
@ -20,33 +20,42 @@ type (
Links []Link `json:"links,omitempty"`
}
// CreateAgreementResp struct
CreateAgreementResp struct {
// CreateBillingResp deprecated, use CreateBillingResponse instead.
CreateBillingResp = CreateBillingResponse
// CreateAgreementResponse struct
CreateAgreementResponse struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Plan BillingPlan `json:"plan,omitempty"`
Plan BillingPlan `json:"plan,omitempty"`
Links []Link `json:"links,omitempty"`
StartTime time.Time `json:"start_time,omitempty"`
}
// CreateAgreementResp is deprecated, use CreateAgreementResponse instead.
CreateAgreementResp = CreateAgreementResponse
// BillingPlanListParams struct
BillingPlanListParams struct {
ListParams
Status string `json:"status,omitempty"` //Allowed values: CREATED, ACTIVE, INACTIVE, ALL.
}
//BillingPlanListResp struct
BillingPlanListResp struct {
//BillingPlanListResponse struct
BillingPlanListResponse struct {
SharedListResponse
Plans []BillingPlan `json:"plans,omitempty"`
}
// BillingPlanListResp is deprecated, use BillingPlanListResponse instead.
BillingPlanListResp = BillingPlanListResponse
)
// CreateBillingPlan creates a billing plan in Paypal
// Endpoint: POST /v1/payments/billing-plans
func (c *Client) CreateBillingPlan(ctx context.Context, plan BillingPlan) (*CreateBillingResp, error) {
func (c *Client) CreateBillingPlan(ctx context.Context, plan BillingPlan) (*CreateBillingResponse, error) {
req, err := c.NewRequest(ctx, http.MethodPost, fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans"), plan)
response := &CreateBillingResp{}
response := &CreateBillingResponse{}
if err != nil {
return response, err
}
@ -85,14 +94,14 @@ func (c *Client) ActivatePlan(ctx context.Context, planID string) error {
// CreateBillingAgreement creates an agreement for specified plan
// Endpoint: POST /v1/payments/billing-agreements
func (c *Client) CreateBillingAgreement(ctx context.Context, a BillingAgreement) (*CreateAgreementResp, error) {
func (c *Client) CreateBillingAgreement(ctx context.Context, a BillingAgreement) (*CreateAgreementResponse, error) {
// PayPal needs only ID, so we will remove all fields except Plan ID
a.Plan = BillingPlan{
ID: a.Plan.ID,
}
req, err := c.NewRequest(ctx, http.MethodPost, fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-agreements"), a)
response := &CreateAgreementResp{}
response := &CreateAgreementResponse{}
if err != nil {
return response, err
}
@ -126,9 +135,9 @@ func (c *Client) ExecuteApprovedAgreement(ctx context.Context, token string) (*E
// ListBillingPlans lists billing-plans
// Endpoint: GET /v1/payments/billing-plans
func (c *Client) ListBillingPlans(ctx context.Context, bplp BillingPlanListParams) (*BillingPlanListResp, error) {
func (c *Client) ListBillingPlans(ctx context.Context, bplp BillingPlanListParams) (*BillingPlanListResponse, error) {
req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/billing-plans"), nil)
response := &BillingPlanListResp{}
response := &BillingPlanListResponse{}
if err != nil {
return response, err
}

View File

@ -20,7 +20,7 @@ func Example() {
}
}
func ExampleClient_CreateSinglePayout_Venmo() {
func ExampleClient_CreatePayout_Venmo() {
// Initialize client
c, err := paypal.NewClient("clientID", "secretID", paypal.APIBaseSandBox)
if err != nil {
@ -55,5 +55,5 @@ func ExampleClient_CreateSinglePayout_Venmo() {
},
}
c.CreateSinglePayout(context.Background(), payout)
c.CreatePayout(context.Background(), payout)
}

View File

@ -65,12 +65,12 @@ func TestCreateVenmoPayout(t *testing.T) {
},
}
res, err := c.CreateSinglePayout(context.Background(), payout)
res, err := c.CreatePayout(context.Background(), payout)
assert.NoError(t, err, "should accept venmo wallet")
assert.Greater(t, len(res.Items), 0)
}
func TestCreateSinglePayout(t *testing.T) {
func TestCreatePayout(t *testing.T) {
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
c.GetAccessToken(context.Background())
@ -94,7 +94,7 @@ func TestCreateSinglePayout(t *testing.T) {
},
}
c.CreateSinglePayout(context.Background(), payout)
c.CreatePayout(context.Background(), payout)
}
func TestStoreCreditCard(t *testing.T) {

View File

@ -5,10 +5,10 @@ import (
"fmt"
)
// CreateSinglePayout submits a payout with an asynchronous API call, which immediately returns the results of a PayPal payment.
// CreatePayout submits a payout with an asynchronous API call, which immediately returns the results of a PayPal payment.
// For email payout set RecipientType: "EMAIL" and receiver email into Receiver
// Endpoint: POST /v1/payments/payouts
func (c *Client) CreateSinglePayout(ctx context.Context, p Payout) (*PayoutResponse, error) {
func (c *Client) CreatePayout(ctx context.Context, p Payout) (*PayoutResponse, error) {
req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/payouts"), p)
response := &PayoutResponse{}
@ -23,6 +23,11 @@ func (c *Client) CreateSinglePayout(ctx context.Context, p Payout) (*PayoutRespo
return response, nil
}
// CreateSinglePayout is deprecated, use CreatePayout instead.
func (c *Client) CreateSinglePayout(ctx context.Context, p Payout) (*PayoutResponse, error) {
return c.CreatePayout(ctx, p)
}
// GetPayout shows the latest status of a batch payout along with the transaction status and other data for individual items.
// Also, returns IDs for the individual payout items. You can use these item IDs in other calls.
// Endpoint: GET /v1/payments/payouts/ID