所以我一直在使用Pay Simple SDK。我收到了这个错误。有谁知道如何解决这个问题?
var customerPayment = new NewCustomerPayment<CreditCard>
所以我的模型在Pay Simple SDK中。这是付款交易。
控制器代码:
[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; }
}
答案 0 :(得分:0)
您确定Address
和Issuer
是枚举吗?他们听起来像是我的课程。如果enumType
不是枚举类型,则Enum.Parse(Type enumType, string value)
会抛出异常。
答案 1 :(得分:0)
根据您的代码,您的原始地址数据位于FormCollection
,这是某种形式的NameValueCollection
。所以你需要知道formCollection["BillingAddress"]
的内容是什么样的。
如果这是某种形式的json或map,那么你可以使用Json解析器或通过反射解析它并填充你的Address
类。
注意:如果您向我们展示了这个密钥的价值,如果这不能回答您的问题,将会有所帮助。
答案 2 :(得分:0)
我已经通过这样做解决了我的问题...
BillingAddress =
{
StreetAddress1 = formCollection["StreetAddress1"],
StreetAddress2 = formCollection["StreetAddress2"],
City = formCollection["City"],
StateCode = (StateCode)Enum.Parse(typeof(StateCode), formCollection["StateCode"]),
Country = (CountryCode)Enum.Parse(typeof(CountryCode), formCollection["Country"]),
ZipCode = formCollection["ZipCode"]
}