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

Unable to provision payment method with payment_source_type "ExternalPayment" #11

Closed
Bart-Kuipers opened this issue Nov 26, 2024 · 3 comments · Fixed by #13
Closed

Unable to provision payment method with payment_source_type "ExternalPayment" #11

Bart-Kuipers opened this issue Nov 26, 2024 · 3 comments · Fixed by #13
Labels
bug Something isn't working

Comments

@Bart-Kuipers
Copy link

Version information

  • terraform: 1.9.8
  • terraform provider: 0.20.0

Describe the bug

Trying to provision a commercelayer_payment_method resource with attributes.payment_source_type = "ExternalPayment" fails with the following error:

Error: 422 Unprocessable Entity: {"errors":[{"title":"is invalid","detail":"payment_source_type - is invalid","code":"VALIDATION_ERROR","source":{"pointer":"/data/attributes/payment_source_type"},"status":"422","meta":{"error":"invalid"}}]}

To Reproduce

  1. Create a single new terraform config with the following content:
terraform {
  required_providers {
    commercelayer = {
      source = "labd/commercelayer"
      version = ">= 0.20.0"
    }
  }
}

variable "commercelayer_client_id" {
  description = "Commerce Layer client ID"
  type        = string
  default     = ""
}

variable "commercelayer_client_secret" {
  description = "Commerce Layer client secret"
  type        = string
  default     = ""
}

variable "commercelayer_auth_endpoint" {
  description = "Commerce Layer authentication endpoint"
  type        = string
  default     = ""
}

variable "commercelayer_api_endpoint" {
  description = "Commerce Layer API endpoint"
  type        = string
  default     = ""
}

provider "commercelayer" {
  client_id     = var.commercelayer_client_id
  client_secret = var.commercelayer_client_secret
  api_endpoint  = var.commercelayer_api_endpoint
  auth_endpoint = var.commercelayer_auth_endpoint
}



resource "commercelayer_manual_gateway" "manual_gateway" {
  attributes {
    name = "Manual gateway"
  }
}

resource "commercelayer_payment_method" "manual_payment_method" {
  attributes {
    payment_source_type = "ExternalPayment"
    currency_code       = "EUR"
    price_amount_cents  = 0
  }

  relationships {
    payment_gateway_id = commercelayer_manual_gateway.manual_gateway.id
  }
}

  1. Expose the required env variables
  2. Try to apply the config
  3. Apply fails with 422 error code

Expected behavior

The payment method should have been created succesfully

@Bart-Kuipers Bart-Kuipers added bug Something isn't working triage Needs triage labels Nov 26, 2024
@demeyerthom

This comment has been minimized.

@demeyerthom demeyerthom removed the triage Needs triage label Nov 29, 2024
@demeyerthom
Copy link
Member

demeyerthom commented Nov 29, 2024

Hi @Bart-Kuipers looks like you were connecting the wrong type of payment gateway. It should be as follows:

For external payment methods:

resource "commercelayer_external_gateway" "external_gateway" {
  attributes {
    name = "External gateway"
  }
}

resource "commercelayer_payment_method" "external_payment_method" {
  attributes {
    payment_source_type = "ExternalPayment"
    currency_code       = "EUR"
    price_amount_cents  = 100
  }

  relationships {
    payment_gateway_id = commercelayer_external_gateway.external_gateway.id
  }
}

For manual gateways (e.g. wire transfers or credit cards):

resource "commercelayer_manual_gateway" "manual_gateway" {
  attributes {
    name = "Manual gateway"
  }
}

resource "commercelayer_payment_method" "manual_payment_method" {
  attributes {
    payment_source_type = "WireTransfer"
    currency_code       = "EUR"
    price_amount_cents  = 100
  }

  relationships {
    payment_gateway_id = commercelayer_manual_gateway.manual_gateway.id
  }
}

@Bart-Kuipers
Copy link
Author

Hi @demeyerthom,

Thanks for looking into this. You're completely right about using the wrong payment gateway, this was not obvious from the CL documentation. Sorry about that, and thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants