diff --git a/subscription.go b/subscription.go new file mode 100644 index 0000000..c6760b6 --- /dev/null +++ b/subscription.go @@ -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 +} diff --git a/types.go b/types.go index 7395e81..7146d0d 100644 --- a/types.go +++ b/types.go @@ -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