Skip to content

Commit 3439655

Browse files
authored
Merge pull request #390 from ovh/376-ovh_vrack-creation-default-payment-mean-does-not-work-for-payment_mean
Fix issue to be able to order with BankAccount or CreditCard
2 parents b9d9355 + 057b24d commit 3439655

24 files changed

+41
-63
lines changed

ovh/data_hosting_privatedatabase_database_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ data "ovh_order_cart" "mycart" {
2424
2525
resource "ovh_hosting_privatedatabase" "database" {
2626
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
27-
payment_mean = "ovh-account"
2827
display_name = "%s"
2928
3029
plan {

ovh/data_hosting_privatedatabase_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ data "ovh_order_cart" "mycart" {
2424
2525
resource "ovh_hosting_privatedatabase" "database" {
2626
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
27-
payment_mean = "ovh-account"
2827
display_name = "%s"
2928
3029
plan {

ovh/data_hosting_privatedatabase_user_grant_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ data "ovh_order_cart" "mycart" {
2424
2525
resource "ovh_hosting_privatedatabase" "database" {
2626
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
27-
payment_mean = "ovh-account"
2827
display_name = "%s"
2928
3029
plan {

ovh/data_hosting_privatedatabase_user_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ data "ovh_order_cart" "mycart" {
2424
2525
resource "ovh_hosting_privatedatabase" "database" {
2626
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
27-
payment_mean = "ovh-account"
2827
display_name = "%s"
2928
3029
plan {

ovh/data_hosting_privatedatabase_whitelist_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ data "ovh_order_cart_product_plan" "database" {
2424
2525
resource "ovh_hosting_privatedatabase" "database" {
2626
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
27-
payment_mean = "ovh-account"
2827
display_name = "%s"
2928
3029
plan {

ovh/data_ip_service_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ data "ovh_order_cart_product_plan" "ipblock" {
2323
2424
resource "ovh_ip_service" "ipblock" {
2525
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
26-
payment_mean = "ovh-account"
2726
description = "%s"
2827
2928
plan {

ovh/data_me_paymentmean_bankaccount.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func dataSourceMePaymentmeanBankaccount() *schema.Resource {
6060
Computed: true,
6161
},
6262
},
63+
DeprecationMessage: "paymentmean API is deprecated. In order process, the account default payment method is used.",
6364
}
6465
}
6566

ovh/data_me_paymentmean_creditcard.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func dataSourceMePaymentmeanCreditcard() *schema.Resource {
6262
Computed: true,
6363
},
6464
},
65+
DeprecationMessage: "paymentmean API is deprecated. In order process, the account default payment method is used.",
6566
}
6667
}
6768

ovh/order.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ func genericOrderSchema(withOptions bool) map[string]*schema.Schema {
4141
},
4242
"payment_mean": {
4343
Type: schema.TypeString,
44-
Required: true,
44+
Optional: true,
4545
ForceNew: true,
46+
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.",
4647
Description: "Ovh payment mode",
4748
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
4849
err := helpers.ValidateStringEnum(strings.ToLower(v.(string)), []string{
@@ -303,6 +304,16 @@ func orderCreate(d *schema.ResourceData, meta interface{}, product string) error
303304
}
304305
}
305306

307+
// get defaultPayment
308+
paymentIds := []int64{}
309+
endpoint = "/me/payment/method?default=true"
310+
if err := config.OVHClient.Get(endpoint, &paymentIds); err != nil {
311+
return fmt.Errorf("calling Get %s \n\t %q", endpoint, err)
312+
}
313+
if len(paymentIds) == 0 {
314+
return fmt.Errorf("no default payment found")
315+
}
316+
306317
// Create Order
307318
log.Printf("[DEBUG] Will create order %s for cart: %s", product, cart.CartId)
308319
order := &MeOrder{}
@@ -313,33 +324,18 @@ func orderCreate(d *schema.ResourceData, meta interface{}, product string) error
313324
}
314325

315326
// Pay Order
316-
log.Printf("[DEBUG] Will pay order %d", order.OrderId)
317-
318-
var paymentMeanOpts *MeOrderPaymentOpts
319-
paymentMean := d.Get("payment_mean").(string)
320-
321-
switch strings.ToLower(paymentMean) {
322-
case "default-payment-mean":
323-
paymentMeanOpts, err = MePaymentMeanDefaultPaymentOpts(config.OVHClient)
324-
if err != nil {
325-
return fmt.Errorf("Could not order product: %v.", err)
326-
}
327-
if paymentMeanOpts == nil {
328-
return fmt.Errorf("Could not find any default payment mean to order product.")
329-
}
330-
case "ovh-account":
331-
paymentMeanOpts = MePaymentMeanOvhAccountPaymentOpts
332-
case "fidelity":
333-
paymentMeanOpts = MePaymentMeanFidelityAccountPaymentOpts
334-
default:
335-
return fmt.Errorf("Unsupported payment mean. This is a bug with the provider.")
336-
}
327+
log.Printf("[DEBUG] Will pay order %d with PaymentId %d", order.OrderId, paymentIds[0])
337328

338329
endpoint = fmt.Sprintf(
339-
"/me/order/%d/payWithRegisteredPaymentMean",
330+
"/me/order/%d/pay",
340331
order.OrderId,
341332
)
342-
if err := config.OVHClient.Post(endpoint, paymentMeanOpts, nil); err != nil {
333+
var paymentMethodOpts = &MeOrderPaymentMethodOpts{
334+
PaymentMethod: PaymentMethod{
335+
Id: paymentIds[0],
336+
},
337+
}
338+
if err := config.OVHClient.Post(endpoint, paymentMethodOpts, nil); err != nil {
343339
return fmt.Errorf("calling Post %s:\n\t %q", endpoint, err)
344340
}
345341

ovh/resource_cloud_project_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ data "ovh_order_cart_product_plan" "cloud" {
2929
resource "ovh_cloud_project" "cloud" {
3030
ovh_subsidiary = data.ovh_order_cart.mycart.ovh_subsidiary
3131
description = "%s"
32-
payment_mean = "fidelity"
33-
32+
3433
plan {
3534
duration = data.ovh_order_cart_product_plan.cloud.selected_price.0.duration
3635
plan_code = data.ovh_order_cart_product_plan.cloud.plan_code

0 commit comments

Comments
 (0)