diff --git a/const.go b/const.go index 60b0dcb..feec746 100644 --- a/const.go +++ b/const.go @@ -76,4 +76,26 @@ const ( type CaptureType string const ( CaptureTypeOutstandingBalance CaptureType = "OUTSTANDING_BALANCE" +) + +type ProductType string +type ProductCategory string //Doc: https://developer.paypal.com/docs/api/catalog-products/v1/#definition-product_category +const ( + ProductTypePhysical ProductType = "PHYSICAL" + ProductTypeDigital ProductType = "DIGITAL" + ProductTypeService ProductType = "SERVICE" + + ProductCategorySoftware ProductCategory = "SOFTWARE" + ProductCategorySoftwareComputerAndDataProcessingServices ProductCategory = "COMPUTER_AND_DATA_PROCESSING_SERVICES" + ProductCategorySoftwareDigitalGames ProductCategory = "DIGITAL_GAMES" + ProductCategorySoftwareGameSoftware ProductCategory = "GAME_SOFTWARE" + ProductCategorySoftwareGames ProductCategory = "GAMES" + ProductCategorySoftwareGeneral ProductCategory = "GENERAL" + ProductCategorySoftwareGraphicAndCommercialDesign ProductCategory = "GRAPHIC_AND_COMMERCIAL_DESIGN" + ProductCategorySoftwareOemSoftware ProductCategory = "OEM_SOFTWARE" + ProductCategorySoftwareOnlineGaming ProductCategory = "ONLINE_GAMING" + ProductCategorySoftwareOnlineGamingCurrency ProductCategory = "ONLINE_GAMING_CURRENCY" + ProductCategorySoftwareOnlineServices ProductCategory = "ONLINE_SERVICES" + ProductCategorySoftwareOther ProductCategory = "OTHER" + ProductCategorySoftwareServices ProductCategory = "SERVICES" ) \ No newline at end of file diff --git a/integration_test.go b/integration_test.go index b0c2c38..c39246b 100644 --- a/integration_test.go +++ b/integration_test.go @@ -226,8 +226,8 @@ func TestProduct(t *testing.T) { productData := Product{ Name: "Test Product", Description: "A Test Product", - Category: PRODUCT_CATEGORY_SOFTWARE, - Type: PRODUCT_TYPE_SERVICE, + Category: ProductCategorySoftware, + Type: ProductTypeService, ImageUrl: "https://example.com/image.png", HomeUrl: "https://example.com", } diff --git a/products.go b/products.go index 61e0367..1376a94 100644 --- a/products.go +++ b/products.go @@ -6,9 +6,6 @@ import ( ) type ( - ProductType string - ProductCategory string - // Product struct Product struct { ID string `json:"id,omitempty"` @@ -60,13 +57,7 @@ func (self *Product) GetUpdatePatch() []Patch { } } -const ( - PRODUCT_TYPE_PHYSICAL ProductType = "PHYSICAL" - PRODUCT_TYPE_DIGITAL ProductType = "DIGITAL" - PRODUCT_TYPE_SERVICE ProductType = "SERVICE" - PRODUCT_CATEGORY_SOFTWARE ProductCategory = "software" -) // CreateProduct creates a product // Doc: https://developer.paypal.com/docs/api/catalog-products/v1/#products_create diff --git a/subscription_plan.go b/subscription_plan.go index 30f1a45..9a9b7c9 100644 --- a/subscription_plan.go +++ b/subscription_plan.go @@ -13,10 +13,10 @@ type ( ProductId string `json:"product_id"` Name string `json:"name"` Status SubscriptionPlanStatus `json:"status"` - Description SubscriptionPlanStatus `json:"description,omitempty"` + Description string `json:"description,omitempty"` BillingCycles []BillingCycle `json:"billing_cycles"` - PaymentPreferences PaymentPreferences `json:"payment_preferences"` - Taxes Taxes `json:"taxes"` + PaymentPreferences *PaymentPreferences `json:"payment_preferences"` + Taxes *Taxes `json:"taxes"` QuantitySupported bool `json:"quantity_supported"` //Indicates whether you can subscribe to this plan by providing a quantity for the goods or service. } @@ -88,35 +88,41 @@ func (self *SubscriptionPlan) GetUpdatePatch() []Patch { Path: "/description", Value: self.Description, }, - { + } + + if self.Taxes != nil { + result = append(result, Patch{ + Operation: "replace", + Path: "/taxes/percentage", + Value: self.Taxes.Percentage, + }) + } + + if self.PaymentPreferences != nil { + if self.PaymentPreferences.SetupFee != nil { + result = append(result, Patch{ + Operation: "replace", + Path: "/payment_preferences/setup_fee", + Value: self.PaymentPreferences.SetupFee, + }, + ) + } + + result = append(result, []Patch{{ Operation: "replace", Path: "/payment_preferences/auto_bill_outstanding", Value: self.PaymentPreferences.AutoBillOutstanding, }, - { - Operation: "replace", - Path: "/payment_preferences/payment_failure_threshold", - Value: self.PaymentPreferences.PaymentFailureThreshold, - }, - { - Operation: "replace", - Path: "/payment_preferences/setup_fee_failure_action", - Value: self.PaymentPreferences.SetupFeeFailureAction, - }, - { - Operation: "replace", - Path: "/taxes/percentage", - Value: self.Taxes.Percentage, - }, - } - - if self.PaymentPreferences.SetupFee != nil { - result = append(result, Patch{ - Operation: "replace", - Path: "/payment_preferences/setup_fee", - Value: self.PaymentPreferences.SetupFee, - }, - ) + { + Operation: "replace", + Path: "/payment_preferences/payment_failure_threshold", + Value: self.PaymentPreferences.PaymentFailureThreshold, + }, + { + Operation: "replace", + Path: "/payment_preferences/setup_fee_failure_action", + Value: self.PaymentPreferences.SetupFeeFailureAction, + }}...) } return result @@ -163,9 +169,9 @@ func (c *Client) GetSubscriptionPlan(planId string) (*SubscriptionPlan, error) { // List all plans // Doc: https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list // Endpoint: GET /v1/billing/plans -func (c *Client) ListSubscriptionPlans(params *SubscriptionPlanListParameters) (*ListProductsResponse, error) { +func (c *Client) ListSubscriptionPlans(params *SubscriptionPlanListParameters) (*ListSubscriptionPlansResponse, error) { req, err := c.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", c.APIBase, "/v1/billing/plans"), nil) - response := &ListProductsResponse{} + response := &ListSubscriptionPlansResponse{} if err != nil { return response, err }