Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Feat/add external order validation url to market #87

Merged
29 changes: 29 additions & 0 deletions .idea/runConfigurations/run_resource_market_test_go.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 21 additions & 14 deletions commercelayer/resource_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func resourceMarket() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"external_order_validation_url": {
Description: "The URL used to validate orders by an external source.",
Type: schema.TypeString,
Optional: 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 @@ -150,13 +155,14 @@ func resourceMarketCreateFunc(ctx context.Context, d *schema.ResourceData, i int
Data: commercelayer.MarketCreateData{
Type: marketType,
Attributes: commercelayer.POSTMarkets201ResponseDataAttributes{
Name: attributes["name"].(string),
FacebookPixelId: stringRef(attributes["facebook_pixel_id"]),
CheckoutUrl: stringRef(attributes["checkout_url"]),
ExternalPricesUrl: stringRef(attributes["external_prices_url"]),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
Metadata: keyValueRef(attributes["metadata"]),
Name: attributes["name"].(string),
FacebookPixelId: stringRef(attributes["facebook_pixel_id"]),
CheckoutUrl: stringRef(attributes["checkout_url"]),
ExternalPricesUrl: stringRef(attributes["external_prices_url"]),
ExternalOrderValidationUrl: stringRef(attributes["external_order_validation_url"]),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
Metadata: keyValueRef(attributes["metadata"]),
},
Relationships: &commercelayer.MarketCreateDataRelationships{
Merchant: commercelayer.MarketCreateDataRelationshipsMerchant{
Expand Down Expand Up @@ -231,13 +237,14 @@ func resourceMarketUpdateFunc(ctx context.Context, d *schema.ResourceData, i int
Type: marketType,
Id: d.Id(),
Attributes: commercelayer.PATCHMarketsMarketId200ResponseDataAttributes{
Name: stringRef(attributes["name"]),
FacebookPixelId: stringRef(attributes["facebook_pixel_id"]),
CheckoutUrl: stringRef(attributes["checkout_url"]),
ExternalPricesUrl: stringRef(attributes["external_prices_url"]),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
Metadata: keyValueRef(attributes["metadata"]),
Name: stringRef(attributes["name"]),
FacebookPixelId: stringRef(attributes["facebook_pixel_id"]),
CheckoutUrl: stringRef(attributes["checkout_url"]),
ExternalPricesUrl: stringRef(attributes["external_prices_url"]),
ExternalOrderValidationUrl: stringRef(attributes["external_order_validation_url"]),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
Metadata: keyValueRef(attributes["metadata"]),
},
Relationships: &commercelayer.MarketUpdateDataRelationships{
Merchant: &commercelayer.MarketCreateDataRelationshipsMerchant{
Expand Down
4 changes: 4 additions & 0 deletions commercelayer/resource_market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func testAccMarketCreate(testName string) string {
attributes {
name = "Incentro Market"
facebook_pixel_id = "pixel"
external_order_validation_url = "https://www.example.com"

metadata = {
testName: "{{.testName}}"
}
Expand All @@ -95,6 +97,8 @@ func testAccMarketUpdate(testName string) string {
attributes {
name = "Incentro Market Changed"
facebook_pixel_id = "pixelchanged"
external_order_validation_url = "https://www.example.com"

metadata = {
testName: "{{.testName}}"
}
Expand Down
3 changes: 2 additions & 1 deletion examples/full/market.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ resource "commercelayer_market" "incentro_market" {
//TODO: check why these are considered invalid
# checkout_url = "http://example.url"
# external_prices_url = "http://example.url"
facebook_pixel_id = "pixel"
facebook_pixel_id = "pixel"
external_order_validation_url = "https://www.example.com"
}

relationships {
Expand Down
5 changes: 3 additions & 2 deletions examples/resources/commercelayer_market/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ resource "commercelayer_price_list" "incentro_price_list" {

resource "commercelayer_market" "incentro_market" {
attributes {
name = "Incentro Market"
facebook_pixel_id = "pixel"
name = "Incentro Market"
facebook_pixel_id = "pixel"
external_order_validation_url = "https://www.example.com"
}

relationships {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-docs v0.13.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.23.0
github.com/incentro-dc/go-commercelayer-sdk v0.0.3
github.com/incentro-dc/go-commercelayer-sdk v0.0.4
github.com/ladydascalie/currency v1.5.0
github.com/stretchr/testify v1.7.2
golang.org/x/oauth2 v0.0.0-20220630143837-2104d58473e0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/incentro-dc/go-commercelayer-sdk v0.0.3 h1:CGXIPsrG9NE0ZilMpfSRsmMCbBXLgZef3JSWC/oiRhU=
github.com/incentro-dc/go-commercelayer-sdk v0.0.3/go.mod h1:7o1L5RRkJ6Fw04+Hvjqt/dCDonYA+it1Leug5rtE+/s=
github.com/incentro-dc/go-commercelayer-sdk v0.0.4 h1:9EaFccOB6fNqfkrqUZGhoAvet8gQdEOXuHD2XYjIYIk=
github.com/incentro-dc/go-commercelayer-sdk v0.0.4/go.mod h1:7o1L5RRkJ6Fw04+Hvjqt/dCDonYA+it1Leug5rtE+/s=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id" : "aeca9872-fcb0-4985-83a7-87199f955dc4",
"name" : "api_addresses",
"request" : {
"url" : "/api/addresses",
"method" : "POST",
"bodyPatterns" : [ {
"equalToJson" : "{\"data\":{\"attributes\":{\"business\":true,\"city\":\"Rotterdam\",\"company\":\"Incentro\",\"country_code\":\"NL\",\"line_1\":\"Van Nelleweg 1\",\"metadata\":{\"foo\":\"bar\",\"testName\":\"commercelayer_market.incentro_market\"},\"phone\":\"+31(0)10 20 20 544\",\"state_code\":\"ZH\",\"zip_code\":\"3044 BC\"},\"type\":\"addresses\"}}\n",
"ignoreArrayOrder" : true,
"ignoreExtraElements" : true
} ]
},
"response" : {
"status" : 201,
"body" : "{\"data\":{\"id\":\"dAJxuvNDAk\",\"type\":\"addresses\",\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk\"},\"attributes\":{\"business\":true,\"first_name\":null,\"last_name\":null,\"company\":\"Incentro\",\"full_name\":\"Incentro\",\"line_1\":\"Van Nelleweg 1\",\"line_2\":null,\"city\":\"Rotterdam\",\"zip_code\":\"3044 BC\",\"state_code\":\"ZH\",\"country_code\":\"NL\",\"phone\":\"+31(0)10 20 20 544\",\"full_address\":\"Van Nelleweg 1, 3044 BC Rotterdam ZH (NL) +31(0)10 20 20 544\",\"name\":\"Incentro, Van Nelleweg 1, 3044 BC Rotterdam ZH (NL) +31(0)10 20 20 544\",\"email\":null,\"notes\":null,\"lat\":null,\"lng\":null,\"is_localized\":false,\"is_geocoded\":false,\"provider_name\":null,\"map_url\":null,\"static_map_url\":null,\"billing_info\":null,\"created_at\":\"2023-02-01T09:33:05.734Z\",\"updated_at\":\"2023-02-01T09:33:05.734Z\",\"reference\":null,\"reference_origin\":null,\"metadata\":{\"foo\":\"bar\",\"testName\":\"commercelayer_market.incentro_market\"}},\"relationships\":{\"geocoder\":{\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk/relationships/geocoder\",\"related\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk/geocoder\"}}},\"meta\":{\"mode\":\"test\",\"organization_id\":\"VyjBZFOWJy\"}}}",
"headers" : {
"Server" : "Cowboy",
"X-Frame-Options" : "SAMEORIGIN",
"X-Xss-Protection" : "1; mode=block",
"X-Content-Type-Options" : "nosniff",
"X-Download-Options" : "noopen",
"X-Permitted-Cross-Domain-Policies" : "none",
"Referrer-Policy" : "strict-origin-when-cross-origin",
"X-Ratelimit-Limit" : "600",
"X-Ratelimit-Count" : "4",
"X-Ratelimit-Period" : "300",
"Content-Type" : "application/vnd.api+json",
"Etag" : "W/\"fcc67a0674feba0337787a86303cbdb2\"",
"Cache-Control" : "max-age=0, private, must-revalidate",
"X-Request-Id" : "3681d86b-ec83-4f0b-8bfc-4d408eeb3f49",
"Strict-Transport-Security" : "max-age=63072000; includeSubDomains",
"Via" : "1.1 vegur, 1.1 varnish",
"Accept-Ranges" : "bytes",
"Date" : "Wed, 01 Feb 2023 09:33:05 GMT",
"X-Served-By" : "cache-ams21033-AMS",
"X-Cache" : "MISS",
"X-Cache-Hits" : "0",
"X-Timer" : "S1675243986.659787,VS0,VE91",
"Vary" : "Accept, Origin"
}
},
"uuid" : "aeca9872-fcb0-4985-83a7-87199f955dc4",
"persistent" : true,
"insertionIndex" : 348
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"id" : "18e8c0d9-cf3b-48a3-aca4-ef782fdb51b5",
"name" : "api_addresses_dajxuvndak",
"request" : {
"url" : "/api/addresses/dAJxuvNDAk",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"data\":{\"id\":\"dAJxuvNDAk\",\"type\":\"addresses\",\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk\"},\"attributes\":{\"business\":true,\"first_name\":null,\"last_name\":null,\"company\":\"Incentro\",\"full_name\":\"Incentro\",\"line_1\":\"Van Nelleweg 1\",\"line_2\":null,\"city\":\"Rotterdam\",\"zip_code\":\"3044 BC\",\"state_code\":\"ZH\",\"country_code\":\"NL\",\"phone\":\"+31(0)10 20 20 544\",\"full_address\":\"Van Nelleweg 1, 3044 BC Rotterdam ZH (NL) +31(0)10 20 20 544\",\"name\":\"Incentro, Van Nelleweg 1, 3044 BC Rotterdam ZH (NL) +31(0)10 20 20 544\",\"email\":null,\"notes\":null,\"lat\":null,\"lng\":null,\"is_localized\":false,\"is_geocoded\":false,\"provider_name\":null,\"map_url\":null,\"static_map_url\":null,\"billing_info\":null,\"created_at\":\"2023-02-01T09:33:05.734Z\",\"updated_at\":\"2023-02-01T09:33:05.734Z\",\"reference\":null,\"reference_origin\":null,\"metadata\":{\"foo\":\"bar\",\"testName\":\"commercelayer_market.incentro_market\"}},\"relationships\":{\"geocoder\":{\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk/relationships/geocoder\",\"related\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk/geocoder\"}}},\"meta\":{\"mode\":\"test\",\"organization_id\":\"VyjBZFOWJy\"}}}",
"headers" : {
"Server" : "Cowboy",
"X-Frame-Options" : "SAMEORIGIN",
"X-Xss-Protection" : "1; mode=block",
"X-Content-Type-Options" : "nosniff",
"X-Download-Options" : "noopen",
"X-Permitted-Cross-Domain-Policies" : "none",
"Referrer-Policy" : "strict-origin-when-cross-origin",
"X-Ratelimit-Limit" : "600",
"X-Ratelimit-Count" : "9",
"X-Ratelimit-Period" : "300",
"Content-Type" : "application/vnd.api+json",
"Etag" : "W/\"fcc67a0674feba0337787a86303cbdb2\"",
"Cache-Control" : "max-age=0, private, must-revalidate",
"X-Request-Id" : "40479df7-9b30-4629-92a2-38851de224e5",
"Strict-Transport-Security" : "max-age=63072000; includeSubDomains",
"Via" : "1.1 vegur, 1.1 varnish",
"Accept-Ranges" : "bytes",
"Date" : "Wed, 01 Feb 2023 09:33:06 GMT",
"X-Served-By" : "cache-ams21053-AMS",
"X-Cache" : "MISS",
"X-Cache-Hits" : "0",
"X-Timer" : "S1675243987.504529,VS0,VE86",
"Vary" : "Accept, Origin"
}
},
"uuid" : "18e8c0d9-cf3b-48a3-aca4-ef782fdb51b5",
"persistent" : true,
"scenarioName" : "scenario-3-api-addresses-dAJxuvNDAk",
"requiredScenarioState" : "Started",
"newScenarioState" : "scenario-3-api-addresses-dAJxuvNDAk-2",
"insertionIndex" : 354
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"id" : "2a46a0c4-f004-42a8-8f11-ef01dbf0eca0",
"name" : "api_addresses_dajxuvndak",
"request" : {
"url" : "/api/addresses/dAJxuvNDAk",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"data\":{\"id\":\"dAJxuvNDAk\",\"type\":\"addresses\",\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk\"},\"attributes\":{\"business\":true,\"first_name\":null,\"last_name\":null,\"company\":\"Incentro\",\"full_name\":\"Incentro\",\"line_1\":\"Van Nelleweg 1\",\"line_2\":null,\"city\":\"Rotterdam\",\"zip_code\":\"3044 BC\",\"state_code\":\"ZH\",\"country_code\":\"NL\",\"phone\":\"+31(0)10 20 20 544\",\"full_address\":\"Van Nelleweg 1, 3044 BC Rotterdam ZH (NL) +31(0)10 20 20 544\",\"name\":\"Incentro, Van Nelleweg 1, 3044 BC Rotterdam ZH (NL) +31(0)10 20 20 544\",\"email\":null,\"notes\":null,\"lat\":null,\"lng\":null,\"is_localized\":false,\"is_geocoded\":false,\"provider_name\":null,\"map_url\":null,\"static_map_url\":null,\"billing_info\":null,\"created_at\":\"2023-02-01T09:33:05.734Z\",\"updated_at\":\"2023-02-01T09:33:05.734Z\",\"reference\":null,\"reference_origin\":null,\"metadata\":{\"foo\":\"bar\",\"testName\":\"commercelayer_market.incentro_market\"}},\"relationships\":{\"geocoder\":{\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk/relationships/geocoder\",\"related\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk/geocoder\"}}},\"meta\":{\"mode\":\"test\",\"organization_id\":\"VyjBZFOWJy\"}}}",
"headers" : {
"Server" : "Cowboy",
"X-Frame-Options" : "SAMEORIGIN",
"X-Xss-Protection" : "1; mode=block",
"X-Content-Type-Options" : "nosniff",
"X-Download-Options" : "noopen",
"X-Permitted-Cross-Domain-Policies" : "none",
"Referrer-Policy" : "strict-origin-when-cross-origin",
"X-Ratelimit-Limit" : "600",
"X-Ratelimit-Count" : "17",
"X-Ratelimit-Period" : "300",
"Content-Type" : "application/vnd.api+json",
"Etag" : "W/\"fcc67a0674feba0337787a86303cbdb2\"",
"Cache-Control" : "max-age=0, private, must-revalidate",
"X-Request-Id" : "6607f408-2a1f-4256-a7af-b5f9a12b14f4",
"Strict-Transport-Security" : "max-age=63072000; includeSubDomains",
"Via" : "1.1 vegur, 1.1 varnish",
"Accept-Ranges" : "bytes",
"Date" : "Wed, 01 Feb 2023 09:33:08 GMT",
"X-Served-By" : "cache-ams21059-AMS",
"X-Cache" : "MISS",
"X-Cache-Hits" : "0",
"X-Timer" : "S1675243988.002027,VS0,VE39",
"Vary" : "Accept, Origin"
}
},
"uuid" : "2a46a0c4-f004-42a8-8f11-ef01dbf0eca0",
"persistent" : true,
"scenarioName" : "scenario-3-api-addresses-dAJxuvNDAk",
"requiredScenarioState" : "scenario-3-api-addresses-dAJxuvNDAk-3",
"insertionIndex" : 365
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"id" : "7b7ca7c2-a88d-407f-b6d2-566f597e4ca1",
"name" : "api_addresses_dajxuvndak",
"request" : {
"url" : "/api/addresses/dAJxuvNDAk",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"data\":{\"id\":\"dAJxuvNDAk\",\"type\":\"addresses\",\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk\"},\"attributes\":{\"business\":true,\"first_name\":null,\"last_name\":null,\"company\":\"Incentro\",\"full_name\":\"Incentro\",\"line_1\":\"Van Nelleweg 1\",\"line_2\":null,\"city\":\"Rotterdam\",\"zip_code\":\"3044 BC\",\"state_code\":\"ZH\",\"country_code\":\"NL\",\"phone\":\"+31(0)10 20 20 544\",\"full_address\":\"Van Nelleweg 1, 3044 BC Rotterdam ZH (NL) +31(0)10 20 20 544\",\"name\":\"Incentro, Van Nelleweg 1, 3044 BC Rotterdam ZH (NL) +31(0)10 20 20 544\",\"email\":null,\"notes\":null,\"lat\":null,\"lng\":null,\"is_localized\":false,\"is_geocoded\":false,\"provider_name\":null,\"map_url\":null,\"static_map_url\":null,\"billing_info\":null,\"created_at\":\"2023-02-01T09:33:05.734Z\",\"updated_at\":\"2023-02-01T09:33:05.734Z\",\"reference\":null,\"reference_origin\":null,\"metadata\":{\"foo\":\"bar\",\"testName\":\"commercelayer_market.incentro_market\"}},\"relationships\":{\"geocoder\":{\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk/relationships/geocoder\",\"related\":\"https://the-green-brand-245.commercelayer.io/api/addresses/dAJxuvNDAk/geocoder\"}}},\"meta\":{\"mode\":\"test\",\"organization_id\":\"VyjBZFOWJy\"}}}",
"headers" : {
"Server" : "Cowboy",
"X-Frame-Options" : "SAMEORIGIN",
"X-Xss-Protection" : "1; mode=block",
"X-Content-Type-Options" : "nosniff",
"X-Download-Options" : "noopen",
"X-Permitted-Cross-Domain-Policies" : "none",
"Referrer-Policy" : "strict-origin-when-cross-origin",
"X-Ratelimit-Limit" : "600",
"X-Ratelimit-Count" : "12",
"X-Ratelimit-Period" : "300",
"Content-Type" : "application/vnd.api+json",
"Etag" : "W/\"fcc67a0674feba0337787a86303cbdb2\"",
"Cache-Control" : "max-age=0, private, must-revalidate",
"X-Request-Id" : "f63d1396-9910-43fd-8ac2-655c125d666e",
"Strict-Transport-Security" : "max-age=63072000; includeSubDomains",
"Via" : "1.1 vegur, 1.1 varnish",
"Accept-Ranges" : "bytes",
"Date" : "Wed, 01 Feb 2023 09:33:07 GMT",
"X-Served-By" : "cache-ams21053-AMS",
"X-Cache" : "MISS",
"X-Cache-Hits" : "0",
"X-Timer" : "S1675243987.103024,VS0,VE78",
"Vary" : "Accept, Origin"
}
},
"uuid" : "7b7ca7c2-a88d-407f-b6d2-566f597e4ca1",
"persistent" : true,
"scenarioName" : "scenario-3-api-addresses-dAJxuvNDAk",
"requiredScenarioState" : "scenario-3-api-addresses-dAJxuvNDAk-2",
"newScenarioState" : "scenario-3-api-addresses-dAJxuvNDAk-3",
"insertionIndex" : 359
}
Loading