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

Fix issue to be able to order with BankAccount or CreditCard #390

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ovh/data_hosting_privatedatabase_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ data "ovh_order_cart" "mycart" {

resource "ovh_hosting_privatedatabase" "database" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
display_name = "%s"

plan {
Expand Down
1 change: 0 additions & 1 deletion ovh/data_hosting_privatedatabase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ data "ovh_order_cart" "mycart" {

resource "ovh_hosting_privatedatabase" "database" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
display_name = "%s"

plan {
Expand Down
1 change: 0 additions & 1 deletion ovh/data_hosting_privatedatabase_user_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ data "ovh_order_cart" "mycart" {

resource "ovh_hosting_privatedatabase" "database" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
display_name = "%s"

plan {
Expand Down
1 change: 0 additions & 1 deletion ovh/data_hosting_privatedatabase_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ data "ovh_order_cart" "mycart" {

resource "ovh_hosting_privatedatabase" "database" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
display_name = "%s"

plan {
Expand Down
1 change: 0 additions & 1 deletion ovh/data_hosting_privatedatabase_whitelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ data "ovh_order_cart_product_plan" "database" {

resource "ovh_hosting_privatedatabase" "database" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
display_name = "%s"

plan {
Expand Down
1 change: 0 additions & 1 deletion ovh/data_ip_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ data "ovh_order_cart_product_plan" "ipblock" {

resource "ovh_ip_service" "ipblock" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
description = "%s"

plan {
Expand Down
1 change: 1 addition & 0 deletions ovh/data_me_paymentmean_bankaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func dataSourceMePaymentmeanBankaccount() *schema.Resource {
Computed: true,
},
},
DeprecationMessage: "paymentmean API is deprecated. In order process, the account default payment method is used.",
}
}

Expand Down
1 change: 1 addition & 0 deletions ovh/data_me_paymentmean_creditcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func dataSourceMePaymentmeanCreditcard() *schema.Resource {
Computed: true,
},
},
DeprecationMessage: "paymentmean API is deprecated. In order process, the account default payment method is used.",
}
}

Expand Down
44 changes: 20 additions & 24 deletions ovh/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ func genericOrderSchema(withOptions bool) map[string]*schema.Schema {
},
"payment_mean": {
Type: schema.TypeString,
Required: true,
Optional: true,
ForceNew: true,
Deprecated: "This field is not anymore used since the API has been deprecated in favor of /payment/mean. Now, the default payment mean is used.",
Description: "Ovh payment mode",
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
err := helpers.ValidateStringEnum(strings.ToLower(v.(string)), []string{
Expand Down Expand Up @@ -303,6 +304,16 @@ func orderCreate(d *schema.ResourceData, meta interface{}, product string) error
}
}

// get defaultPayment
paymentIds := []int64{}
endpoint = "/me/payment/method?default=true"
if err := config.OVHClient.Get(endpoint, &paymentIds); err != nil {
return fmt.Errorf("calling Get %s \n\t %q", endpoint, err)
}
if len(paymentIds) == 0 {
return fmt.Errorf("no default payment found")
}

// Create Order
log.Printf("[DEBUG] Will create order %s for cart: %s", product, cart.CartId)
order := &MeOrder{}
Expand All @@ -313,33 +324,18 @@ func orderCreate(d *schema.ResourceData, meta interface{}, product string) error
}

// Pay Order
log.Printf("[DEBUG] Will pay order %d", order.OrderId)

var paymentMeanOpts *MeOrderPaymentOpts
paymentMean := d.Get("payment_mean").(string)

switch strings.ToLower(paymentMean) {
case "default-payment-mean":
paymentMeanOpts, err = MePaymentMeanDefaultPaymentOpts(config.OVHClient)
if err != nil {
return fmt.Errorf("Could not order product: %v.", err)
}
if paymentMeanOpts == nil {
return fmt.Errorf("Could not find any default payment mean to order product.")
}
case "ovh-account":
paymentMeanOpts = MePaymentMeanOvhAccountPaymentOpts
case "fidelity":
paymentMeanOpts = MePaymentMeanFidelityAccountPaymentOpts
default:
return fmt.Errorf("Unsupported payment mean. This is a bug with the provider.")
}
log.Printf("[DEBUG] Will pay order %d with PaymentId %d", order.OrderId, paymentIds[0])

endpoint = fmt.Sprintf(
"/me/order/%d/payWithRegisteredPaymentMean",
"/me/order/%d/pay",
order.OrderId,
)
if err := config.OVHClient.Post(endpoint, paymentMeanOpts, nil); err != nil {
var paymentMethodOpts = &MeOrderPaymentMethodOpts{
PaymentMethod: PaymentMethod{
Id: paymentIds[0],
},
}
if err := config.OVHClient.Post(endpoint, paymentMethodOpts, nil); err != nil {
return fmt.Errorf("calling Post %s:\n\t %q", endpoint, err)
}

Expand Down
3 changes: 1 addition & 2 deletions ovh/resource_cloud_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ data "ovh_order_cart_product_plan" "cloud" {
resource "ovh_cloud_project" "cloud" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
description = "%s"
payment_mean = "fidelity"


plan {
duration = data.ovh_order_cart_product_plan.cloud.selected_price.0.duration
plan_code = data.ovh_order_cart_product_plan.cloud.plan_code
Expand Down
1 change: 0 additions & 1 deletion ovh/resource_domain_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ data "ovh_order_cart_product_plan" "zone" {

resource "ovh_domain_zone" "zone" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "fidelity"

plan {
duration = data.ovh_order_cart_product_plan.zone.selected_price.0.duration
Expand Down
1 change: 0 additions & 1 deletion ovh/resource_hosting_privatedatabase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ data "ovh_order_cart_product_plan" "database" {

resource "ovh_hosting_privatedatabase" "database" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
display_name = "%s"

plan {
Expand Down
1 change: 0 additions & 1 deletion ovh/resource_ip_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ data "ovh_order_cart_product_plan" "ipblock" {

resource "ovh_ip_service" "ipblock" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
description = "%s"

plan {
Expand Down
2 changes: 0 additions & 2 deletions ovh/resource_iploadbalancing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ data "ovh_order_cart_product_options_plan" "bhs" {
resource "ovh_iploadbalancing" "iplb-lb1" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
display_name = "%s"
payment_mean = "ovh-account"

plan {
duration = data.ovh_order_cart_product_plan.iplb.selected_price.0.duration
Expand All @@ -57,7 +56,6 @@ const testAccIpLoadbalancingInternal = `
resource "ovh_iploadbalancing" "iplb-internal" {
ovh_subsidiary = "fr"
display_name = "%s"
payment_mean = "fidelity"

plan {
catalog_name = "iplb_private_beta"
Expand Down
2 changes: 0 additions & 2 deletions ovh/resource_vrack_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ resource "ovh_vrack" "vrack" {
description = data.ovh_order_cart.mycart.description
name = data.ovh_order_cart.mycart.description
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "fidelity"

plan {
duration = data.ovh_order_cart_product_plan.vrack.selected_price.0.duration
Expand All @@ -48,7 +47,6 @@ data "ovh_order_cart_product_plan" "ipblock" {

resource "ovh_ip_service" "ipblock" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
description = data.ovh_order_cart.mycart.description

plan {
Expand Down
1 change: 0 additions & 1 deletion ovh/resource_vrack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ data "ovh_order_cart_product_plan" "vrack" {
resource "ovh_vrack" "vrack" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
name = "%s"
payment_mean = "fidelity"
description = "%s"

plan {
Expand Down
6 changes: 6 additions & 0 deletions ovh/types_me_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ type MeOrderPaymentOpts struct {
PaymentMean string `json:"paymentMean"`
PaymentMeanId *int64 `json:"paymentMeanId,omitEmpty"`
}
type MeOrderPaymentMethodOpts struct {
PaymentMethod PaymentMethod `json:"paymentMethod"`
}
type PaymentMethod struct {
Id int64 `json:"id"`
}
4 changes: 1 addition & 3 deletions website/docs/r/cloud_project.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Orders a public cloud project.

## Important

This resource is in beta state. Use with caution.
-> __NOTE__ To order a product with terraform, your account needs to have a default payment method defined. This can be done in the [console](https://www.ovh.com/manager/#/dedicated/billing/payment/method) or via API with the [/me/payment/method](https://api.ovh.com/console/#/me/payment/method~GET) routes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-> __NOTE__ To order a product with terraform, your account needs to have a default payment method defined. This can be done in the [console](https://www.ovh.com/manager/#/dedicated/billing/payment/method) or via API with the [/me/payment/method](https://api.ovh.com/console/#/me/payment/method~GET) routes
-> __NOTE__ To order a product through Terraform, your account needs to have a default payment method defined. This can be done in the [OVHcloud Control Panel](https://www.ovh.com/manager/#/dedicated/billing/payment/method) or via API with the [/me/payment/method](https://api.ovh.com/console/#/me/payment/method~GET) endpoint.


## Example Usage

Expand All @@ -32,7 +32,6 @@ data "ovh_order_cart_product_plan" "cloud" {
resource "ovh_cloud_project" "my_cloud_project" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
description = "my cloud project"
payment_mean = "fidelity"

plan {
duration = data.ovh_order_cart_product_plan.cloud.selected_price.0.duration
Expand All @@ -48,7 +47,6 @@ The following arguments are supported:

* `description` - A description associated with the user.
* `ovh_subsidiary` - (Required) OVHcloud Subsidiary
* `payment_mean` - (Required) OVHcloud payment mode (One of "default-payment-mean", "fidelity", "ovh-account")
* `plan` - (Required) Product Plan to order
* `duration` - (Required) duration
* `plan_code` - (Required) Plan code
Expand Down
7 changes: 4 additions & 3 deletions website/docs/r/hosting_privatedatabase.html.markdown
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add in the documentation the requirement to have a default payment mean :)

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ description: |-

Creates an OVHcloud managed private cloud database.

## Important

-> __NOTE__ To order a product with terraform, your account needs to have a default payment method defined. This can be done in the [console](https://www.ovh.com/manager/#/dedicated/billing/payment/method) or via API with the [/me/payment/method](https://api.ovh.com/console/#/me/payment/method~GET) routes

## Example Usage

```hcl
Expand All @@ -27,7 +31,6 @@ data "ovh_order_cart_product_plan" "database" {

resource "ovh_hosting_privatedatabase" "database" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
display_name = "Postgresql-12"

plan {
Expand Down Expand Up @@ -58,7 +61,6 @@ The following arguments are supported:

* `description` - Custom description on your privatedatabase order.
* `ovh_subsidiary` - (Required) OVHcloud Subsidiary
* `payment_mean` - (Required) OVHcloud payment mode (One of "default-payment-mean", "fidelity", "ovh-account")
* `plan` - (Required) Product Plan to order
* `duration` - (Required) duration.
* `plan_code` - (Required) Plan code.
Expand Down Expand Up @@ -93,7 +95,6 @@ The following attributes are exported:
* `quantity` - quantity
* `quantity` - quantity
* `ovh_subsidiary` - OVHcloud Subsidiary
* `payment_mean` - OVHcloud payment mode
* `plan` - Product Plan
* `catalog_name` - Catalog name
* `configuration` - Representation of a configuration item for personalizing product
Expand Down
6 changes: 1 addition & 5 deletions website/docs/r/ip_service.html.markdown
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add in the documentation the requirement to have a default payment mean :)

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ Orders an ip service.
This resource orders an OVHcloud product for a long period of time and may generate heavy costs !
Use with caution.

__NOTE__ 1: the "default-payment-mean" will scan your registered bank accounts, credit card and paypal payment means to find your default payment mean.

__NOTE__ 2: this resource is in beta state. Use with caution.
-> __NOTE__ To order a product with terraform, your account needs to have a default payment method defined. This can be done in the [console](https://www.ovh.com/manager/#/dedicated/billing/payment/method) or via API with the [/me/payment/method](https://api.ovh.com/console/#/me/payment/method~GET) routes


## Example Usage
Expand All @@ -38,7 +36,6 @@ data "ovh_order_cart_product_plan" "ipblock" {

resource "ovh_ip_service" "ipblock" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "ovh-account"
description = "my ip block"

plan {
Expand All @@ -60,7 +57,6 @@ The following arguments are supported:

* `description` - Custom description on your ip.
* `ovh_subsidiary` - (Required) OVHcloud Subsidiary
* `payment_mean` - (Required) OVHcloud payment mode (One of "default-payment-mean", "fidelity", "ovh-account")
* `plan` - (Required) Product Plan to order
* `duration` - (Required) duration
* `plan_code` - (Required) Plan code
Expand Down
5 changes: 2 additions & 3 deletions website/docs/r/iploadbalancing.html.markdown
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add in the documentation the requirement to have a default payment mean :)

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Orders an IP load balancing.
~> __WARNING__ This resource orders an OVHcloud product for a long period of time and may generate heavy costs!
Use with caution.

-> __NOTE__ The "default-payment-mean" will scan your registered bank accounts, credit card and paypal payment means to find your default payment mean.
-> __NOTE__ To order a product with terraform, your account needs to have a default payment method defined. This can be done in the [console](https://www.ovh.com/manager/#/dedicated/billing/payment/method) or via API with the [/me/payment/method](https://api.ovh.com/console/#/me/payment/method~GET) routes


## Example Usage

Expand Down Expand Up @@ -43,7 +44,6 @@ data "ovh_order_cart_product_options_plan" "bhs" {
resource "ovh_iploadbalancing" "iplb-lb1" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
display_name = "my ip loadbalancing"
payment_mean = "ovh-account"

plan {
duration = data.ovh_order_cart_product_plan.iplb.selected_price.0.duration
Expand All @@ -65,7 +65,6 @@ The following arguments are supported:

* `display_name` - Set the name displayed in ManagerV6 for your iplb (max 50 chars)
* `ovh_subsidiary` - (Required) OVHcloud Subsidiary
* `payment_mean` - (Required) OVHcloud payment mode (One of "default-payment-mean", "fidelity", "ovh-account")
* `plan` - (Required) Product Plan to order
* `duration` - (Required) duration
* `plan_code` - (Required) Plan code
Expand Down
4 changes: 1 addition & 3 deletions website/docs/r/ovh_domain_zone.html.markdown
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add in the documentation the requirement to have a default payment mean :)

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Creates a domain zone.

## Important

~> __WARNING__ This resource is in beta state. Use with caution.
-> __NOTE__ To order a product with terraform, your account needs to have a default payment method defined. This can be done in the [console](https://www.ovh.com/manager/#/dedicated/billing/payment/method) or via API with the [/me/payment/method](https://api.ovh.com/console/#/me/payment/method~GET) routes

## Example Usage

Expand All @@ -30,7 +30,6 @@ data "ovh_order_cart_product_plan" "zone" {

resource "ovh_domain_zone" "zone" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
payment_mean = "fidelity"

plan {
duration = data.ovh_order_cart_product_plan.zone.selected_price.0.duration
Expand All @@ -55,7 +54,6 @@ resource "ovh_domain_zone" "zone" {
The following arguments are supported:

* `ovh_subsidiary` - (Required) OVHcloud Subsidiary
* `payment_mean` - (Required) OVHcloud payment mode (One of "default-payment-mean", "fidelity", "ovh-account")
* `plan` - (Required) Product Plan to order
* `duration` - (Required) duration
* `plan_code` - (Required) Plan code
Expand Down
6 changes: 2 additions & 4 deletions website/docs/r/vrack.html.markdown
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add in the documentation the requirement to have a default payment mean :)

Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Orders a vrack.

## Important

~> __WARNING__ This resource is in beta state. Use with caution.
-> __NOTE__ To order a product with terraform, your account needs to have a default payment method defined. This can be done in the [console](https://www.ovh.com/manager/#/dedicated/billing/payment/method) or via API with the [/me/payment/method](https://api.ovh.com/console/#/me/payment/method~GET) routes

-> __NOTE__ Currently, the OVHcloud API doesn't support Vrack termination. You have to open a support ticket to ask for vrack termination. Otherwise, you may hit vrack quota issues.
-> __WARNING__ Currently, the OVHcloud API doesn't support Vrack termination. You have to open a support ticket to ask for vrack termination. Otherwise, you may hit vrack quota issues.

## Example Usage

Expand All @@ -34,7 +34,6 @@ data "ovh_order_cart_product_plan" "vrack" {
resource "ovh_vrack" "vrack" {
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
name = "my vrack"
payment_mean = "fidelity"
description = "my vrack"

plan {
Expand All @@ -51,7 +50,6 @@ The following arguments are supported:
* `description` - yourvrackdescription
* `name` - yourvrackname
* `ovh_subsidiary` - (Required) OVHcloud Subsidiary
* `payment_mean` - (Required) OVHcloud payment mode (One of "default-payment-mean", "fidelity", "ovh-account")
* `plan` - (Required) Product Plan to order
* `duration` - (Required) duration
* `plan_code` - (Required) Plan code
Expand Down
Loading