Added GetSubscriptionDetails method (#135)

* Issue #133

Added GetSubscriptionDetails method

* Issue #133
This commit is contained in:
Alessandro Sechi 2020-03-27 12:05:56 +01:00 committed by GitHub
parent 8686a619a4
commit 6f0fe4d870
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 0 deletions

37
subscription.go Normal file
View File

@ -0,0 +1,37 @@
package paypal
import (
"fmt"
"net/http"
"time"
)
type (
// SubscriptionDetailResp struct
SubscriptionDetailResp struct {
ID string `json:"id,omitempty"`
PlanID string `json:"plan_id,omitempty"`
StartTime time.Time `json:"start_time,omitempty"`
Quantity string `json:"quantity,omitempty"`
ShippingAmount ShippingAmount `json:"shipping_amount,omitempty"`
Subscriber Subscriber `json:"subscriber,omitempty"`
BillingInfo BillingInfo `json:"billing_info,omitempty"`
CreateTime time.Time `json:"create_time,omitempty"`
UpdateTime time.Time `json:"update_time,omitempty"`
Links []Link `json:"links,omitempty"`
Status string `json:"status,omitempty"`
StatusUpdateTime time.Time `json:"status_update_time,omitempty"`
}
)
// GetSubscriptionDetails shows details for a subscription, by ID.
// Endpoint: GET /v1/billing/subscriptions/
func (c *Client) GetSubscriptionDetails(subscriptionID string) (*SubscriptionDetailResp, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("%s/v1/billing/subscriptions/%s", c.APIBase, subscriptionID), nil)
response := &SubscriptionDetailResp{}
if err != nil {
return response, err
}
err = c.SendWithAuth(req, response)
return response, err
}

View File

@ -265,6 +265,15 @@ type (
OverrideMerchantPreferences *MerchantPreferences `json:"override_merchant_preferences,omitempty"`
}
// BillingInfo struct
BillingInfo struct {
OutstandingBalance AmountPayout `json:"outstanding_balance,omitempty"`
CycleExecutions []CycleExecutions `json:"cycle_executions,omitempty"`
LastPayment LastPayment `json:"last_payment,omitempty"`
NextBillingTime time.Time `json:"next_billing_time,omitempty"`
FailedPaymentsCount int `json:"failed_payments_count,omitempty"`
}
// BillingPlan struct
BillingPlan struct {
ID string `json:"id,omitempty"`
@ -359,6 +368,21 @@ type (
Value string `json:"value,omitempty"`
}
// CycleExecutions struct
CycleExecutions struct {
TenureType string `json:"tenure_type,omitempty"`
Sequence int `json:"sequence,omitempty"`
CyclesCompleted int `json:"cycles_completed,omitempty"`
CyclesRemaining int `json:"cycles_remaining,omitempty"`
TotalCycles int `json:"total_cycles,omitempty"`
}
// LastPayment struct
LastPayment struct {
Amount Money `json:"amount,omitempty"`
Time time.Time `json:"time,omitempty"`
}
// Details structure used in Amount structures as optional value
Details struct {
Subtotal string `json:"subtotal,omitempty"`
@ -778,6 +802,12 @@ type (
SenderBatchID string `json:"sender_batch_id,omitempty"`
}
//ShippingAmount struct
ShippingAmount struct {
CurrencyCode string `json:"currency_code,omitempty"`
Value string `json:"value,omitempty"`
}
// ShippingAddress struct
ShippingAddress struct {
RecipientName string `json:"recipient_name,omitempty"`
@ -812,6 +842,13 @@ type (
Address *ShippingDetailAddressPortable `json:"address,omitempty"`
}
// Subscriber struct
Subscriber struct {
ShippingAddress ShippingDetail `json:"shipping_address,omitempty"`
Name CreateOrderPayerName `json:"name,omitempty"`
EmailAddress string `json:"email_address,omitempty"`
}
expirationTime int64
// TokenResponse is for API response for the /oauth2/token endpoint