Skip to content

Commit

Permalink
Feat/additional adyen fields (incentro-ecx#94)
Browse files Browse the repository at this point in the history
* fix: added missing adyen fields

* fix: added remove mocks script
  • Loading branch information
Thomas De Meyer authored May 5, 2023
1 parent 053eac2 commit aaa76b6
Show file tree
Hide file tree
Showing 19 changed files with 301 additions and 288 deletions.
17 changes: 17 additions & 0 deletions .idea/runConfigurations/remove_mocks_sh.xml

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

54 changes: 38 additions & 16 deletions commercelayer/resource_adyen_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ func resourceAdyenGateway() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"api_version": {
Description: "The checkout API version, supported range is from 66 to 68, default is 68.",
Type: schema.TypeString,
Optional: true,
},
"async_api": {
Description: "Indicates if the gateway will leverage on the Adyen notification webhooks.",
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"webhook_endpoint_secret": {
Description: "The gateway webhook endpoint secret, generated by Adyen customer area.",
Type: schema.TypeString,
Optional: true,
},
"public_key": {
Description: "The public key linked to your API credential.",
Type: schema.TypeString,
Expand Down Expand Up @@ -121,14 +137,17 @@ func resourceAdyenGatewayCreateFunc(ctx context.Context, d *schema.ResourceData,
Data: commercelayer.AdyenGatewayCreateData{
Type: adyenGatewaysType,
Attributes: commercelayer.POSTAdyenGateways201ResponseDataAttributes{
Name: attributes["name"].(string),
MerchantAccount: attributes["merchant_account"].(string),
ApiKey: attributes["api_key"].(string),
PublicKey: stringRef(attributes["public_key"]),
LiveUrlPrefix: attributes["live_url_prefix"].(string),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
Metadata: keyValueRef(attributes["metadata"]),
Name: attributes["name"].(string),
MerchantAccount: attributes["merchant_account"].(string),
ApiKey: attributes["api_key"].(string),
ApiVersion: stringRef(attributes["api_version"]),
AsyncApi: boolRef(attributes["async_api"]),
WebhookEndpointSecret: stringRef(attributes["webhook_endpoint_secret"]),
PublicKey: stringRef(attributes["public_key"]),
LiveUrlPrefix: attributes["live_url_prefix"].(string),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
Metadata: keyValueRef(attributes["metadata"]),
},
},
}
Expand Down Expand Up @@ -164,14 +183,17 @@ func resourceAdyenGatewayUpdateFunc(ctx context.Context, d *schema.ResourceData,
Type: adyenGatewaysType,
Id: d.Id(),
Attributes: commercelayer.PATCHAdyenGatewaysAdyenGatewayId200ResponseDataAttributes{
Name: stringRef(attributes["name"]),
MerchantAccount: stringRef(attributes["merchant_account"]),
ApiKey: stringRef(attributes["api_key"]),
PublicKey: stringRef(attributes["public_key"]),
LiveUrlPrefix: stringRef(attributes["live_url_prefix"]),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
Metadata: keyValueRef(attributes["metadata"]),
Name: stringRef(attributes["name"]),
MerchantAccount: stringRef(attributes["merchant_account"]),
ApiKey: stringRef(attributes["api_key"]),
ApiVersion: stringRef(attributes["api_version"]),
AsyncApi: boolRef(attributes["async_api"]),
WebhookEndpointSecret: stringRef(attributes["webhook_endpoint_secret"]),
PublicKey: stringRef(attributes["public_key"]),
LiveUrlPrefix: stringRef(attributes["live_url_prefix"]),
Reference: stringRef(attributes["reference"]),
ReferenceOrigin: stringRef(attributes["reference_origin"]),
Metadata: keyValueRef(attributes["metadata"]),
},
},
}
Expand Down
10 changes: 10 additions & 0 deletions commercelayer/resource_adyen_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ func (s *AcceptanceSuite) TestAccAdyenGateway_basic() {
resource.TestCheckResourceAttr(resourceName, "type", adyenGatewaysType),
resource.TestCheckResourceAttr(resourceName, "attributes.0.name", "Incentro Adyen Gateway"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.metadata.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.api_version", "68"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.async_api", "true"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.webhook_endpoint_secret", "foobar"),
),
},
{
Config: testAccAdyenGatewayUpdate(resourceName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "attributes.0.name", "Incentro Adyen Gateway Changed"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.metadata.bar", "foo"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.api_version", "67"),
resource.TestCheckResourceAttr(resourceName, "attributes.0.async_api", "false"),
),
},
},
Expand All @@ -67,6 +72,9 @@ func testAccAdyenGatewayCreate(testName string) string {
api_key = "xxxx-yyyy-zzzz"
public_key = "xxxx-yyyy-zzzz"
live_url_prefix = "1797a841fbb37ca7-AdyenDemo"
api_version = 68
async_api = true
webhook_endpoint_secret = "foobar"
metadata = {
foo: "bar"
Expand All @@ -86,6 +94,8 @@ func testAccAdyenGatewayUpdate(testName string) string {
api_key = "xxxx-yyyy-zzzz"
public_key = "xxxx-yyyy-zzzz"
live_url_prefix = "1797a841fbb37ca7-AdyenDemo"
api_version = 67
async_api = false
metadata = {
bar: "foo"
Expand Down
16 changes: 11 additions & 5 deletions docs/resources/adyen_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ Configuring a Adyen payment gateway for a market lets you safely process payment
```terraform
resource "commercelayer_adyen_gateway" "incentro_adyen_gateway" {
attributes {
name = "Incentro Adyen Gateway"
merchant_account = "xxxx-yyyy-zzzz"
api_key = "xxxx-yyyy-zzzz"
public_key = "xxxx-yyyy-zzzz"
live_url_prefix = "1797a841fbb37ca7-AdyenDemo"
name = "Incentro Adyen Gateway"
merchant_account = "xxxx-yyyy-zzzz"
api_key = "xxxx-yyyy-zzzz"
public_key = "xxxx-yyyy-zzzz"
live_url_prefix = "1797a841fbb37ca7-AdyenDemo"
api_version = 68
async_api = true
webhook_endpoint_secret = "foobar"
}
}
```
Expand Down Expand Up @@ -48,9 +51,12 @@ Required:

Optional:

- `api_version` (String) The checkout API version, supported range is from 66 to 68, default is 68.
- `async_api` (Boolean) Indicates if the gateway will leverage on the Adyen notification webhooks.
- `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
- `public_key` (String) The public key linked to your API credential.
- `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.


9 changes: 5 additions & 4 deletions docs/resources/payment_method.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ Payment methods represent the type of payment sources (e.g., Credit Card, PayPal
```terraform
resource "commercelayer_adyen_gateway" "incentro_adyen_gateway" {
attributes {
name = "Incentro Adyen Gateway"
metadata = {
foo : "bar"
}
name = "Incentro Adyen Gateway"
merchant_account = "xxxx-yyyy-zzzz"
api_key = "xxxx-yyyy-zzzz"
public_key = "xxxx-yyyy-zzzz"
live_url_prefix = "1797a841fbb37ca7-AdyenDemo"
}
}
Expand Down
15 changes: 9 additions & 6 deletions examples/full/adyen_gateways.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
resource "commercelayer_adyen_gateway" "incentro_adyen_gateway" {
attributes {
name = "Incentro Adyen Gateway"
merchant_account = "xxxx-yyyy-zzzz"
api_key = "xxxx-yyyy-zzzz"
public_key = "xxxx-yyyy-zzzz"
live_url_prefix = "1797a841fbb37ca7-AdyenDemo"
name = "Incentro Adyen Gateway"
merchant_account = "xxxx-yyyy-zzzz"
api_key = "xxxx-yyyy-zzzz"
public_key = "xxxx-yyyy-zzzz"
live_url_prefix = "1797a841fbb37ca7-AdyenDemo"
api_version = 68
async_api = true
webhook_endpoint_secret = "foobar"
}
}
}
15 changes: 9 additions & 6 deletions examples/resources/commercelayer_adyen_gateway/resource.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
resource "commercelayer_adyen_gateway" "incentro_adyen_gateway" {
attributes {
name = "Incentro Adyen Gateway"
merchant_account = "xxxx-yyyy-zzzz"
api_key = "xxxx-yyyy-zzzz"
public_key = "xxxx-yyyy-zzzz"
live_url_prefix = "1797a841fbb37ca7-AdyenDemo"
name = "Incentro Adyen Gateway"
merchant_account = "xxxx-yyyy-zzzz"
api_key = "xxxx-yyyy-zzzz"
public_key = "xxxx-yyyy-zzzz"
live_url_prefix = "1797a841fbb37ca7-AdyenDemo"
api_version = 68
async_api = true
webhook_endpoint_secret = "foobar"
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"id" : "621039b5-4c8d-4848-8425-a455edc424c6",
"name" : "api_adyen_gateways",
"request" : {
"url" : "/api/adyen_gateways",
"method" : "POST",
"bodyPatterns" : [ {
"equalToJson" : "{\"data\":{\"attributes\":{\"api_key\":\"xxxx-yyyy-zzzz\",\"api_version\":\"68\",\"async_api\":true,\"live_url_prefix\":\"1797a841fbb37ca7-AdyenDemo\",\"merchant_account\":\"xxxx-yyyy-zzzz\",\"metadata\":{\"foo\":\"bar\",\"testName\":\"commercelayer_adyen_gateway.incentro_adyen_gateway\"},\"name\":\"Incentro Adyen Gateway\",\"public_key\":\"xxxx-yyyy-zzzz\",\"webhook_endpoint_secret\":\"foobar\"},\"type\":\"adyen_gateways\"}}\n",
"ignoreArrayOrder" : true,
"ignoreExtraElements" : true
} ]
},
"response" : {
"status" : 201,
"body" : "{\"data\":{\"id\":\"dxgWesZzMx\",\"type\":\"adyen_gateways\",\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/adyen_gateways/dxgWesZzMx\"},\"attributes\":{\"name\":\"Incentro Adyen Gateway\",\"created_at\":\"2023-05-05T11:41:33.289Z\",\"updated_at\":\"2023-05-05T11:41:33.289Z\",\"reference\":null,\"reference_origin\":null,\"metadata\":{\"foo\":\"bar\",\"testName\":\"commercelayer_adyen_gateway.incentro_adyen_gateway\"},\"live_url_prefix\":\"1797a841fbb37ca7-AdyenDemo\",\"async_api\":true,\"webhook_endpoint_secret\":\"foobar\",\"webhook_endpoint_url\":\"https://core.commercelayer.io/webhook_callbacks/adyen_gateways/dxgWesZzMx\"},\"relationships\":{\"payment_methods\":{\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/adyen_gateways/dxgWesZzMx/relationships/payment_methods\",\"related\":\"https://the-green-brand-245.commercelayer.io/api/adyen_gateways/dxgWesZzMx/payment_methods\"}},\"adyen_payments\":{\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/adyen_gateways/dxgWesZzMx/relationships/adyen_payments\",\"related\":\"https://the-green-brand-245.commercelayer.io/api/adyen_gateways/dxgWesZzMx/adyen_payments\"}}},\"meta\":{\"mode\":\"test\",\"organization_id\":\"VyjBZFOWJy\"}}}",
"headers" : {
"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" : "2",
"X-Ratelimit-Period" : "300",
"Content-Type" : "application/vnd.api+json",
"Etag" : "W/\"29ccdbb83901a03cc349a3e808b0976c\"",
"Cache-Control" : "max-age=0, private, must-revalidate",
"X-Request-Id" : "9dab72a2-cc84-472c-ab6b-43231091ce5a",
"Strict-Transport-Security" : "max-age=63072000; includeSubDomains",
"Accept-Ranges" : "bytes",
"Date" : "Fri, 05 May 2023 11:41:33 GMT",
"Vary" : "Accept, Origin"
}
},
"uuid" : "621039b5-4c8d-4848-8425-a455edc424c6",
"persistent" : true,
"insertionIndex" : 888
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"id" : "12960e84-c7bc-4288-b60d-354aa2ecda71",
"name" : "api_adyen_gateways_dxgweszzmx",
"request" : {
"url" : "/api/adyen_gateways/dxgWesZzMx",
"method" : "GET"
},
"response" : {
"status" : 200,
"body" : "{\"data\":{\"id\":\"dxgWesZzMx\",\"type\":\"adyen_gateways\",\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/adyen_gateways/dxgWesZzMx\"},\"attributes\":{\"name\":\"Incentro Adyen Gateway Changed\",\"created_at\":\"2023-05-05T11:41:33.289Z\",\"updated_at\":\"2023-05-05T11:41:33.988Z\",\"reference\":null,\"reference_origin\":null,\"metadata\":{\"bar\":\"foo\",\"testName\":\"commercelayer_adyen_gateway.incentro_adyen_gateway\"},\"live_url_prefix\":\"1797a841fbb37ca7-AdyenDemo\",\"async_api\":false,\"webhook_endpoint_secret\":\"foobar\",\"webhook_endpoint_url\":\"https://core.commercelayer.io/webhook_callbacks/adyen_gateways/dxgWesZzMx\"},\"relationships\":{\"payment_methods\":{\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/adyen_gateways/dxgWesZzMx/relationships/payment_methods\",\"related\":\"https://the-green-brand-245.commercelayer.io/api/adyen_gateways/dxgWesZzMx/payment_methods\"}},\"adyen_payments\":{\"links\":{\"self\":\"https://the-green-brand-245.commercelayer.io/api/adyen_gateways/dxgWesZzMx/relationships/adyen_payments\",\"related\":\"https://the-green-brand-245.commercelayer.io/api/adyen_gateways/dxgWesZzMx/adyen_payments\"}}},\"meta\":{\"mode\":\"test\",\"organization_id\":\"VyjBZFOWJy\"}}}",
"headers" : {
"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" : "6",
"X-Ratelimit-Period" : "300",
"Content-Type" : "application/vnd.api+json",
"Etag" : "W/\"4a191070327aed5d1c11b253ae6b6f5c\"",
"Cache-Control" : "max-age=0, private, must-revalidate",
"X-Request-Id" : "ed4e9496-a499-4d2d-a7a8-4f6c98cb3dc7",
"Strict-Transport-Security" : "max-age=63072000; includeSubDomains",
"Accept-Ranges" : "bytes",
"Date" : "Fri, 05 May 2023 11:41:34 GMT",
"Vary" : "Accept, Origin"
}
},
"uuid" : "12960e84-c7bc-4288-b60d-354aa2ecda71",
"persistent" : true,
"scenarioName" : "scenario-1-api-adyen_gateways-dxgWesZzMx",
"requiredScenarioState" : "scenario-1-api-adyen_gateways-dxgWesZzMx-3",
"newScenarioState" : "scenario-1-api-adyen_gateways-dxgWesZzMx-4",
"insertionIndex" : 892
}
Loading

0 comments on commit aaa76b6

Please sign in to comment.