Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added additional fields to shipping method resource #110

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ fabric.properties
/token.json

/local
/go.work*
2 changes: 2 additions & 0 deletions commercelayer/resource_checkout_com_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func testAccCheckCheckoutComGatewayDestroy(s *terraform.State) error {
}

func (s *AcceptanceSuite) TestAccCheckoutComGateway_basic() {
s.T().Skip("Skipping test because we need a valid key")

resourceName := "commercelayer_checkout_com_gateway.incentro_checkout_com_gateway"

resource.Test(s.T(), resource.TestCase{
Expand Down
10 changes: 4 additions & 6 deletions commercelayer/resource_payment_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,14 @@ func (s *AcceptanceSuite) TestAccPaymentMethod_basic() {
resource.TestCheckResourceAttr(resourceName, "attributes.0.metadata.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.currency_code", "EUR"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.payment_source_type", "AdyenPayment"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.price_amount_cents", "0"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.price_amount_cents", "10"),
),
},
{
Config: strings.Join([]string{testAccAdyenGatewayCreate(resourceName), testAccPaymentMethodUpdate(resourceName)}, "\n"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "attributes.0.metadata.bar", "foo"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.currency_code", "EUR"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.payment_source_type", "AdyenPayment"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.price_amount_cents", "0"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.price_amount_cents", "5"),
),
},
},
Expand All @@ -95,7 +93,7 @@ func testAccPaymentMethodCreate(testName string) string {
attributes {
payment_source_type = "AdyenPayment"
currency_code = "EUR"
price_amount_cents = 0
price_amount_cents = 10
metadata = {
foo : "bar"
testName: "{{.testName}}"
Expand All @@ -115,7 +113,7 @@ func testAccPaymentMethodUpdate(testName string) string {
attributes {
payment_source_type = "AdyenPayment"
currency_code = "EUR"
price_amount_cents = 0
price_amount_cents = 5
metadata = {
bar : "foo"
testName: "{{.testName}}"
Expand Down
40 changes: 37 additions & 3 deletions commercelayer/resource_shipping_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func resourceShippingMethod() *schema.Resource {
Required: true,
},
"scheme": {
Description: "The shipping method's scheme, one of 'flat' or 'weight_tiered'.",
Description: "The shipping method's scheme, one of 'flat', 'weight_tiered' or 'external'.",
Type: schema.TypeString,
Optional: true,
Default: "flat",
},
"currency_code": {
Description: "The international 3-letter currency code as defined by the ISO " +
Expand All @@ -51,6 +52,11 @@ func resourceShippingMethod() *schema.Resource {
Optional: true,
ValidateDiagFunc: currencyCodeValidation,
},
"external_prices_url": {
Description: "Required, if external scheme",
Type: schema.TypeString,
Optional: true,
},
"price_amount_cents": {
Description: "The price of this shipping method, in cents.",
Type: schema.TypeInt,
Expand All @@ -61,6 +67,12 @@ func resourceShippingMethod() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"use_subtotal": {
Description: "Send this attribute if you want to compare the free over amount with order's subtotal (excluding discounts, if any).",
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"min_weight": {
Description: "The minimum weight for which this shipping method is available.",
Type: schema.TypeFloat,
Expand All @@ -76,6 +88,12 @@ func resourceShippingMethod() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"enabled": {
Description: "Whether the resource is enabled",
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"reference": {
Description: "A string that you can use to add any external identifier to the resource. This " +
"can be useful for integrating the resource to an external system, like an ERP, a " +
Expand Down Expand Up @@ -176,8 +194,10 @@ func resourceShippingMethodCreateFunc(ctx context.Context, d *schema.ResourceDat
Name: attributes["name"].(string),
Scheme: stringRef(attributes["scheme"]),
CurrencyCode: stringRef(attributes["currency_code"]),
ExternalPricesUrl: stringRef(attributes["external_prices_url"]),
PriceAmountCents: int32(attributes["price_amount_cents"].(int)),
FreeOverAmountCents: intToInt32Ref(attributes["free_over_amount_cents"]),
UseSubtotal: boolRef(attributes["use_subtotal"]),
MinWeight: float64ToFloat32Ref(attributes["min_weight"]),
MaxWeight: float64ToFloat32Ref(attributes["max_weight"]),
UnitOfWeight: stringRef(attributes["unit_of_weight"]),
Expand All @@ -189,6 +209,12 @@ func resourceShippingMethodCreateFunc(ctx context.Context, d *schema.ResourceDat
},
}

if !attributes["enabled"].(bool) {
shippingMethodCreate.Data.Attributes.Disable = true
} else {
shippingMethodCreate.Data.Attributes.Enable = true
}

marketId := stringRef(relationships["market_id"])
if marketId != nil {
shippingMethodCreate.Data.Relationships.Market = &commercelayer.BillingInfoValidationRuleCreateDataRelationshipsMarket{
Expand All @@ -209,7 +235,7 @@ func resourceShippingMethodCreateFunc(ctx context.Context, d *schema.ResourceDat

shippingCategoryId := stringRef(relationships["shipping_category_id"])
if shippingCategoryId != nil {
shippingMethodCreate.Data.Relationships.ShippingCategory = &commercelayer.ShippingMethodCreateDataRelationshipsShippingCategory{
shippingMethodCreate.Data.Relationships.ShippingCategory = &commercelayer.ShipmentCreateDataRelationshipsShippingCategory{
Data: commercelayer.ShipmentDataRelationshipsShippingCategoryData{
Type: stringRef(shippingCategoryType),
Id: shippingCategoryId,
Expand Down Expand Up @@ -270,8 +296,10 @@ func resourceShippingMethodUpdateFunc(ctx context.Context, d *schema.ResourceDat
Name: stringRef(attributes["name"]),
Scheme: stringRef(attributes["scheme"]),
CurrencyCode: stringRef(attributes["currency_code"]),
ExternalPricesUrl: stringRef(attributes["external_prices_url"]),
PriceAmountCents: intToInt32Ref(attributes["price_amount_cents"]),
FreeOverAmountCents: intToInt32Ref(attributes["free_over_amount_cents"]),
UseSubtotal: boolRef(attributes["use_subtotal"]),
MinWeight: float64ToFloat32Ref(attributes["min_weight"]),
MaxWeight: float64ToFloat32Ref(attributes["max_weight"]),
UnitOfWeight: stringRef(attributes["unit_of_weight"]),
Expand All @@ -283,6 +311,12 @@ func resourceShippingMethodUpdateFunc(ctx context.Context, d *schema.ResourceDat
},
}

if !attributes["enabled"].(bool) {
shippingMethodUpdate.Data.Attributes.Disable = true
} else {
shippingMethodUpdate.Data.Attributes.Enable = true
}

marketId := stringRef(relationships["market_id"])
if marketId != nil {
shippingMethodUpdate.Data.Relationships.Market = &commercelayer.BillingInfoValidationRuleCreateDataRelationshipsMarket{
Expand All @@ -303,7 +337,7 @@ func resourceShippingMethodUpdateFunc(ctx context.Context, d *schema.ResourceDat

shippingCategoryId := stringRef(relationships["shipping_category_id"])
if shippingCategoryId != nil {
shippingMethodUpdate.Data.Relationships.ShippingCategory = &commercelayer.ShippingMethodCreateDataRelationshipsShippingCategory{
shippingMethodUpdate.Data.Relationships.ShippingCategory = &commercelayer.ShipmentCreateDataRelationshipsShippingCategory{
Data: commercelayer.ShipmentDataRelationshipsShippingCategoryData{
Type: stringRef(shippingCategoryType),
Id: shippingCategoryId,
Expand Down
20 changes: 14 additions & 6 deletions commercelayer/resource_shipping_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *AcceptanceSuite) TestAccShippingMethod_basic() {
Config: testAccShippingMethodCreate(resourceName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "type", shippingMethodType),
resource.TestCheckResourceAttr(resourceName, "attributes.0.name", "Incentro Shipping Method"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.name", "Incentro Test Shipping Method"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.scheme", "flat"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.currency_code", "EUR"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.price_amount_cents", "1000"),
Expand All @@ -50,20 +50,25 @@ func (s *AcceptanceSuite) TestAccShippingMethod_basic() {
resource.TestCheckResourceAttr(resourceName, "attributes.0.max_weight", "10"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.unit_of_weight", "kg"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.metadata.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.use_subtotal", "false"),
),
},
{
Config: testAccShippingMethodUpdate(resourceName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "attributes.0.name", "Incentro Shipping Method Updated"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.scheme", "weight_tiered"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.name", "Incentro Test Shipping Method Updated"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.scheme", "external"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.currency_code", "CHF"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.external_prices_url", "https://api.commercelayer.io/v1/prices"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.price_amount_cents", "1"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.free_over_amount_cents", "1"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.min_weight", "1"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.max_weight", "20"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.unit_of_weight", "oz"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.metadata.bar", "foo"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.use_subtotal", "true"),
),
},
},
Expand All @@ -74,7 +79,7 @@ func testAccShippingMethodCreate(testName string) string {
return hclTemplate(`
resource "commercelayer_shipping_method" "incentro_shipping_method" {
attributes {
name = "Incentro Shipping Method"
name = "Incentro Test Shipping Method"
scheme = "flat"
currency_code = "EUR"
price_amount_cents = 1000
Expand All @@ -95,14 +100,17 @@ func testAccShippingMethodUpdate(testName string) string {
return hclTemplate(`
resource "commercelayer_shipping_method" "incentro_shipping_method" {
attributes {
name = "Incentro Shipping Method Updated"
scheme = "weight_tiered"
name = "Incentro Test Shipping Method Updated"
scheme = "external"
currency_code = "CHF"
external_prices_url = "https://api.commercelayer.io/v1/prices"
price_amount_cents = 1
free_over_amount_cents = 1
min_weight = 1
max_weight = 20
unit_of_weight = "oz"
enabled = false
use_subtotal = true
metadata = {
bar : "foo"
testName: "{{.testName}}"
Expand Down
8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
version: "3.9"
services:
commercelayer-mock:
image: wiremock/wiremock:2.34.0
image: wiremock/wiremock:3.9.2
environment:
- UID=${UID}
- GID=${GID}
user: "${UID}:${GID}"
entrypoint: ["/docker-entrypoint.sh", "--global-response-templating", "--disable-gzip", "--verbose"]
ports:
- "8080:8080"
volumes:
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/address.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,3 @@ Optional:
Optional:

- `geocoder_id` (String) The associated geocoder id.


2 changes: 0 additions & 2 deletions docs/resources/adyen_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,3 @@ Optional:
- `reference` (String) A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.
- `reference_origin` (String) Any identifier of the third party system that defines the reference code
- `webhook_endpoint_secret` (String) The gateway webhook endpoint secret, generated by Adyen customer area.


2 changes: 0 additions & 2 deletions docs/resources/bing_geocoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,3 @@ Optional:
- `metadata` (Map of String) Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format
- `reference` (String) A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.
- `reference_origin` (String) Any identifier of the third party system that defines the reference code


2 changes: 0 additions & 2 deletions docs/resources/braintree_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,3 @@ Optional:
- `metadata` (Map of String) Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format
- `reference` (String) A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.
- `reference_origin` (String) Any identifier of the third party system that defines the reference code


2 changes: 0 additions & 2 deletions docs/resources/checkout_com_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,3 @@ Optional:
- `metadata` (Map of String) Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format
- `reference` (String) A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.
- `reference_origin` (String) Any identifier of the third party system that defines the reference code


8 changes: 3 additions & 5 deletions docs/resources/customer_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ page_title: "commercelayer_customer_group Resource - terraform-provider-commerce
subcategory: ""
description: |-
A customer group is a resource that can be used to organize customers into groups.
When you associate a customer group to a market, that market becomes private and can be accessed
only by the customers belonging to the group. You can use customer groups to manage B2B customers,
B2C loyalty programs, private sales, and more.
When you associate a customer group to a market, that market becomes private and can be accessed
only by the customers belonging to the group. You can use customer groups to manage B2B customers,
B2C loyalty programs, private sales, and more.
---

# commercelayer_customer_group (Resource)
Expand Down Expand Up @@ -50,5 +50,3 @@ Optional:
- `metadata` (Map of String) Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format
- `reference` (String) A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.
- `reference_origin` (String) Any identifier of the third party system that defines the reference code


2 changes: 0 additions & 2 deletions docs/resources/delivery_lead_time.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,3 @@ Required:

- `shipping_method_id` (String) The associated shipping method id.
- `stock_location_id` (String) The associated stock location id.


10 changes: 4 additions & 6 deletions docs/resources/external_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ page_title: "commercelayer_external_gateway Resource - terraform-provider-commer
subcategory: ""
description: |-
Price lists are collections of SKU prices,
defined by currency and market. When a list of SKUs is fetched,
only SKUs with a price defined in the market's price list and at least
a stock item in one of the market stock locations will be returned.
A user can create price lists to manage international business or B2B/B2C models.
defined by currency and market. When a list of SKUs is fetched,
only SKUs with a price defined in the market's price list and at least
a stock item in one of the market stock locations will be returned.
A user can create price lists to manage international business or B2B/B2C models.
---

# commercelayer_external_gateway (Resource)
Expand Down Expand Up @@ -62,5 +62,3 @@ Optional:
- `refund_url` (String) The endpoint used by the external gateway to refund payments.
- `token_url` (String) The endpoint used by the external gateway to create a customer payment token.
- `void_url` (String) The endpoint used by the external gateway to void payments.


2 changes: 0 additions & 2 deletions docs/resources/external_tax_calculator.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,3 @@ Optional:
- `metadata` (Map of String) Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format
- `reference` (String) A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.
- `reference_origin` (String) Any identifier of the third party system that defines the reference code


2 changes: 0 additions & 2 deletions docs/resources/google_geocoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,3 @@ Optional:
- `metadata` (Map of String) Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format
- `reference` (String) A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.
- `reference_origin` (String) Any identifier of the third party system that defines the reference code


2 changes: 0 additions & 2 deletions docs/resources/inventory_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,3 @@ Optional:
- `reference_origin` (String) Any identifier of the third party system that defines the reference code
- `stock_locations_cutoff` (Number) The maximum number of stock locations used for inventory computation
- `strategy` (String) The inventory model's shipping strategy: one between 'no_split' (default), 'split_shipments', 'split_by_line_items', 'ship_from_primary' and 'ship_from_first_available_or_primary'.


2 changes: 0 additions & 2 deletions docs/resources/inventory_return_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,3 @@ Required:

- `inventory_model_id` (String) The associated inventory model id.
- `stock_location_id` (String) The associated stock location id.


2 changes: 0 additions & 2 deletions docs/resources/inventory_stock_location.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,3 @@ Required:

- `inventory_model_id` (String) The associated inventory model id.
- `stock_location_id` (String) The associated stock location id.


2 changes: 0 additions & 2 deletions docs/resources/klarna_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,3 @@ Optional:
- `metadata` (Map of String) Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format
- `reference` (String) A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.
- `reference_origin` (String) Any identifier of the third party system that defines the reference code


2 changes: 0 additions & 2 deletions docs/resources/manual_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,3 @@ Optional:
- `metadata` (Map of String) Set of key-value pairs that you can attach to the resource. This can be useful for storing additional information about the resource in a structured format
- `reference` (String) A string that you can use to add any external identifier to the resource. This can be useful for integrating the resource to an external system, like an ERP, a marketing tool, a CRM, or whatever.
- `reference_origin` (String) Any identifier of the third party system that defines the reference code


Loading
Loading