Sau đây là thử nghiệm, nhưng chỉ chừng mực những gì các câu hỏi ban đầu lớn lên (Thử nghiệm nó nhiều hơn cho tôi?), tôi đã viết nó bằng cách sử dụng ví dụ XML được cung cấp và bằng cách sao chép mã cho mã AddCreditCard.
Khi bạn đều được thực hiện cập nhật các mã sau đây sẽ làm việc:
var cg = new CustomerGateway("login", "transkey", ServiceMode.Test);
var c = cg.CreateCustomer("[email protected]", "test customer");
//just to show that we didn't break CC
cg.AddCreditCard(c.ProfileID, "cc#", 07, 2011);
cg.AddBankAccount(c.ProfileID, "Peter", "bankaccoung#", "routing#");
//tostring doesn't actually do much... but if you break on it you can see the details for both the CC and the bank info.
foreach (PaymentProfile pp in cg.GetCustomer(c.ProfileID).PaymentProfiles)
{
Console.WriteLine(pp.ToString());
}
Trước tiên, tải mã nguồn C# cho các API từ http://developer.authorize.net/downloads/.
Khi xem lại mã, tôi có thể thấy 4 tệp sử dụng "creditCardType", đây là các tệp SubscriptionRequest.cs, CustomerGateway.cs, PaymentProfile.cs và AnetApiSchema.cs (lần cuối chúng tôi không phải chạm vào). Chúng ta cũng cần xem 'creditCardMaskedType', được sử dụng trong PaymentProfile.cs, Transaction.cs và AnetApiSchema.cs. Bất kỳ nơi nào các tệp này xuất hiện, chúng tôi cũng cần đảm bảo chúng tôi cũng hỗ trợ các cân bằng bankAccount.
Mở giải pháp AuthorizeNET. Chúng tôi sẽ nhảy xung quanh một chút thông qua các tập tin được liệt kê ở trên.
Trong CustomerGateway.cs thêm khối mã sau đây:
/// <summary>
/// Adds a bank account profile to the user and returns the profile ID
/// </summary>
/// <returns></returns>
public string AddBankAccount(string profileID, string nameOnAccount, string accountNumber, string routingNumber)
{
var req = new createCustomerPaymentProfileRequest();
req.customerProfileId = profileID;
req.paymentProfile = new customerPaymentProfileType();
req.paymentProfile.payment = new paymentType();
bankAccountType new_bank = new bankAccountType();
new_bank.nameOnAccount = nameOnAccount;
new_bank.accountNumber = accountNumber;
new_bank.routingNumber = routingNumber;
req.paymentProfile.payment.Item = new_bank;
var response = (createCustomerPaymentProfileResponse)_gateway.Send(req);
return response.customerPaymentProfileId;
}
Trong PaymentProfile.cs thêm một số tài sản công cộng
public string BankNameOnAccount {get; set; }
public string BankAccountNumber { get; set; }
public string BankRoutingNumber { get; set; }
Sửa đổi các khối sau của các nhà xây dựng PaymentProfile(customerPaymentProfileMaskedType apiType)
:
if (apiType.payment != null) {
if(apiType.payment.Item is bankAccountMaskedType) {
var bankAccount = (bankAccountMaskedType)apiType.payment.Item;
this.BankNameOnAccount = bankAccount.nameOnAccount;
this.BankAccountNumber = bankAccount.accountNumber;
this.BankRoutingNumber = bankAccount.routingNumber;
}
else if (apiType.payment.Item is creditCardMaskedType)
{
var card = (creditCardMaskedType)apiType.payment.Item;
this.CardType = card.cardType;
this.CardNumber = card.cardNumber;
this.CardExpiration = card.expirationDate;
}
}
Thêm khối này đến PaymentProfile.ToAPI()
phương pháp:
if (!string.IsNullOrEmpty(this.BankAccountNumber))
{
bankAccountType new_bank = new bankAccountType();
new_bank.nameOnAccount = BankNameOnAccount;
new_bank.accountNumber = BankAccountNumber;
new_bank.routingNumber = BankRoutingNumber;
result.payment.Item = new_bank;
}
Thêm các thuộc tính nào sau đây để SubscriptionRequest.cs> Lớp SubscriptionRequest (xung quanh dòng 187)
public string BankNameOnAccount {get; set; }
public string BankAccountNumber { get; set; }
public string BankRoutingNumber { get; set; }
Thêm mục khác nếu chặn TWICE để đăng kýYêu cầu. Lần đầu tiên là trong phương pháp ToAPI, thứ hai là trong phương pháp ToUpdateableAPI, trong cả hai trường hợp nó đi sau khi kiểm tra null số CC.
else if (!String.IsNullOrEmpty(this.BankAccountNumber))
{
bankAccountType new_bank = new bankAccountType();
new_bank.nameOnAccount = BankNameOnAccount;
new_bank.accountNumber = BankAccountNumber;
new_bank.routingNumber = BankRoutingNumber;
sub.payment = new paymentType();
sub.payment.Item = new_bank;
}
Thêm các thuộc tính nào sau đây để Transaction.cs
public string BankNameOnAccount { get; set; }
public string BankAccountNumber { get; set; }
public string BankRoutingNumber { get; set; }
Trong Transaction.cs trong NewFromResponse tĩnh (transactionDetailsType trans) phương pháp, tìm ra khối để kiểm tra cho trans.payment != null
và tinh chỉnh như:
if (trans.payment != null) {
if (trans.payment.Item.GetType() == typeof(creditCardMaskedType))
{
var cc = (creditCardMaskedType)trans.payment.Item;
result.CardNumber = cc.cardNumber;
result.CardExpiration = cc.expirationDate;
result.CardType = cc.cardType;
}
else if (trans.payment.Item.GetType() == typeof(bankAccountMaskedType))
{
var bankAccount = (bankAccountMaskedType)trans.payment.Item;
result.BankNameOnAccount = bankAccount.nameOnAccount;
result.BankAccountNumber = bankAccount.accountNumber;
result.BankRoutingNumber = bankAccount.routingNumber;
}
}
@Ramhound để bạn nói rằng tôi không thể lưu trữ thông tin tài khoản ngân hàng bằng CIM? – Greg
@Ramhound sử dụng mã mẫu CIM trên trang web của họ, họ cho phép bạn tạo hồ sơ thanh toán cho khách hàng của mình để khi họ đăng nhập lại, họ không phải nhập lại thông tin thanh toán (vì Authorize.Net CIM lưu nó) nên tôi không 't có để lưu nó hoặc thậm chí có quyền truy cập trực tiếp vào nó với ứng dụng của tôi – Greg
@Ramhound Giải thích điều này sau đó https://dl.dropbox.com/u/3115379/ProofThatCIMStoresBankAccountInformation.png – Greg