mirror of
https://github.com/plutov/paypal.git
synced 2025-02-02 15:10:36 +01:00
Fixed incorrect response type in ListSubscriptionPlans (#153)
* Update billing plan * Update billing plan * Update billing plan * Kickstart product creation * Added product api * Added list product api and refactored some similar structs * Reverted endpoint for old billing plans * Added subscription plans create get update list * Added subscription plans activate/deactivate/update pricing scheme * Added integration tests for subscription plans * go fmt * Add subscriptions API * Removed AWS library added by mistake * reverted billing plans url * resolved MR discussions * Fixed but in listing subscription plans, and some constants * Fixed wrong type for subscription plan description * Fixed updating issue Co-authored-by: rami <admin@okitoo.net>
This commit is contained in:
parent
d355a65df0
commit
0461b35d07
22
const.go
22
const.go
|
@ -77,3 +77,25 @@ type CaptureType string
|
||||||
const (
|
const (
|
||||||
CaptureTypeOutstandingBalance CaptureType = "OUTSTANDING_BALANCE"
|
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"
|
||||||
|
)
|
|
@ -226,8 +226,8 @@ func TestProduct(t *testing.T) {
|
||||||
productData := Product{
|
productData := Product{
|
||||||
Name: "Test Product",
|
Name: "Test Product",
|
||||||
Description: "A Test Product",
|
Description: "A Test Product",
|
||||||
Category: PRODUCT_CATEGORY_SOFTWARE,
|
Category: ProductCategorySoftware,
|
||||||
Type: PRODUCT_TYPE_SERVICE,
|
Type: ProductTypeService,
|
||||||
ImageUrl: "https://example.com/image.png",
|
ImageUrl: "https://example.com/image.png",
|
||||||
HomeUrl: "https://example.com",
|
HomeUrl: "https://example.com",
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
ProductType string
|
|
||||||
ProductCategory string
|
|
||||||
|
|
||||||
// Product struct
|
// Product struct
|
||||||
Product struct {
|
Product struct {
|
||||||
ID string `json:"id,omitempty"`
|
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
|
// CreateProduct creates a product
|
||||||
// Doc: https://developer.paypal.com/docs/api/catalog-products/v1/#products_create
|
// Doc: https://developer.paypal.com/docs/api/catalog-products/v1/#products_create
|
||||||
|
|
|
@ -13,10 +13,10 @@ type (
|
||||||
ProductId string `json:"product_id"`
|
ProductId string `json:"product_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Status SubscriptionPlanStatus `json:"status"`
|
Status SubscriptionPlanStatus `json:"status"`
|
||||||
Description SubscriptionPlanStatus `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
BillingCycles []BillingCycle `json:"billing_cycles"`
|
BillingCycles []BillingCycle `json:"billing_cycles"`
|
||||||
PaymentPreferences PaymentPreferences `json:"payment_preferences"`
|
PaymentPreferences *PaymentPreferences `json:"payment_preferences"`
|
||||||
Taxes Taxes `json:"taxes"`
|
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.
|
QuantitySupported bool `json:"quantity_supported"` //Indicates whether you can subscribe to this plan by providing a quantity for the goods or service.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,27 @@ func (self *SubscriptionPlan) GetUpdatePatch() []Patch {
|
||||||
Path: "/description",
|
Path: "/description",
|
||||||
Value: self.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",
|
Operation: "replace",
|
||||||
Path: "/payment_preferences/auto_bill_outstanding",
|
Path: "/payment_preferences/auto_bill_outstanding",
|
||||||
Value: self.PaymentPreferences.AutoBillOutstanding,
|
Value: self.PaymentPreferences.AutoBillOutstanding,
|
||||||
|
@ -102,21 +122,7 @@ func (self *SubscriptionPlan) GetUpdatePatch() []Patch {
|
||||||
Operation: "replace",
|
Operation: "replace",
|
||||||
Path: "/payment_preferences/setup_fee_failure_action",
|
Path: "/payment_preferences/setup_fee_failure_action",
|
||||||
Value: self.PaymentPreferences.SetupFeeFailureAction,
|
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,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -163,9 +169,9 @@ func (c *Client) GetSubscriptionPlan(planId string) (*SubscriptionPlan, error) {
|
||||||
// List all plans
|
// List all plans
|
||||||
// Doc: https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list
|
// Doc: https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list
|
||||||
// Endpoint: GET /v1/billing/plans
|
// 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)
|
req, err := c.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", c.APIBase, "/v1/billing/plans"), nil)
|
||||||
response := &ListProductsResponse{}
|
response := &ListSubscriptionPlansResponse{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user