gpt4 book ai didi

c# - 如何解决错误 "Type provided must be an Enum. Parameter name: enumType"

转载 作者:行者123 更新时间:2023-11-30 17:34:17 29 4
gpt4 key购买 nike

所以我一直在使用 Pay Simple SDK。我收到这个错误。有谁知道如何解决这个问题?

var customerPayment = new NewCustomerPayment<CreditCard>

所以我的模型在 Pay Simple SDK 中。这是用于支付交易。

Controller 代码:

[HttpPost]
[ValidateAntiForgeryToken]
public async System.Threading.Tasks.Task<ActionResult> Create(FormCollection formCollection) {
string username = "jnjk";
string apiKey = "khkh";
string baseUrl = "https://sandbox-api.paysimple.com";
var settings = new PaySimpleSdk.Models.PaySimpleSettings(apiKey, username, baseUrl);

var paymentService = new PaymentService(settings);

var customerPayment = new NewCustomerPayment<CreditCard>()
{

Customer = new Customer
{
FirstName = formCollection["FirstName"],
LastName = formCollection["LastName"],
BillingAddress = (Address)Enum.Parse(typeof(Address), formCollection["BillingAddress"])
},

Account = new CreditCard
{
CreditCardNumber = formCollection["CreditCardNumber"],
ExpirationDate = formCollection["ExpirationDate"],
Issuer = (Issuer)Enum.Parse(typeof(Issuer), formCollection["Issuer"])
},

Payment = new Payment
{
Amount = int.Parse(formCollection["Amount"]),
Cvv = formCollection["Ccv"]
}

};

var newCustomerPayment = await paymentService.CreateNewCustomerPaymentAsync(customerPayment);

return View();
}

来自 sdk 的模型

这是客户模型中的账单地址..

  public Address BillingAddress { get; set; }

这是地址

  public class Address : IValidatable
{
public Address();
public string City { get; set; }
public CountryCode? Country { get; set; }
public StateCode? StateCode { get; set; }
public string StreetAddress1 { get; set; }
public string StreetAddress2 { get; set; }
public string ZipCode { get; set; }
}

最佳答案

你确定 AddressIssuer 是枚举吗?对我来说,它们听起来像是类。 Enum.Parse(Type enumType, string value)如果 enumType 不是枚举类型,则抛出异常。

关于c# - 如何解决错误 "Type provided must be an Enum. Parameter name: enumType",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42736551/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com