C# Authorize.net 创建配置文件问题
C# Authorize.net Create Profile Issue
下面的代码正在为卡充电,但它没有创建配置文件....有什么提示吗?我假设我遗漏了什么,或者使用了错误的类型...
var opaqueData = new opaqueDataType { dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT", dataValue = paymentNonce };
//standard api call to retrieve response
var paymentType = new paymentType { Item = opaqueData };
var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // authorize and capture transaction
amount = paymentAmount,
payment = paymentType,
customer = new customerDataType()
{
type = customerTypeEnum.individual,
id = userID.ToString()
},
profile = new customerProfilePaymentType()
{
createProfile = true
}
};
var request = new createTransactionRequest { transactionRequest = transactionRequest };
// instantiate the contoller that will call the service
var controller = new createTransactionController(request);
const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
ServicePointManager.SecurityProtocol = Tls12;
controller.Execute();
// get the response from the service (errors contained if any)
var response = controller.GetApiResponse();
更新:
由于显然不允许使用 OpaqueData,因此我将其更改为手动制作配置文件。我收到以下错误:"Error: I00001 Successful."
// Add Payment method to Customer.
customerPaymentProfileType opaquePaymentProfile = new customerPaymentProfileType();
opaquePaymentProfile.payment = paymentType;
opaquePaymentProfile.customerType = customerTypeEnum.individual;
var request2 = new createCustomerPaymentProfileRequest
{
paymentProfile = opaquePaymentProfile,
validationMode = validationModeEnum.none,
customerProfileId = userID.ToString()
};
var controller2 = new createCustomerPaymentProfileController(request2);
controller2.Execute();
//Send Request to EndPoint
createCustomerPaymentProfileResponse response2 = controller2.GetApiResponse();
if (response2 != null && response2.messages.resultCode == messageTypeEnum.Ok)
{
if (response2 != null && response2.messages.message != null)
{
//Console.WriteLine("Success, createCustomerPaymentProfileID : " + response.customerPaymentProfileId);
}
}
else
{
Utility.AppendTextToFile("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text, Server.MapPath("/pub/auth.txt"));
}
更新 #2
非常困惑,因为 auth.net 文档说此代码表示成功...那么为什么我看不到已创建的 CIM 付款方式??? RESPONSE CODE DOCS
更新 #3
所以我打印出主要响应消息而不是 CIM 请求消息,呃。实际错误是:"E00114 Invalid OTS Token."
根据文档,该错误通常来自使用过的密钥,因此我现在生成 2 个密钥(一个用于处理,一个用于通过 CIM 存储)但现在出现此错误:"E00040 The record cannot be found."...任何想法?
所以这个问题的答案是:
- 您无法使用不透明的卡数据自动创建付款配置文件,因此答案是在您成功收费后手动创建。
- 您不能使用相同的不透明卡数据进行充电和存储,因为它们是一次性使用的,所以对于我的网络方法,我最终传递了 2 个不透明数据密钥。
您必须拨打不同的电话来设置全新客户和现有客户只是添加一张新卡。我在下面粘贴了我的最终解决方案的摘录:
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = (System.Configuration.ConfigurationManager.AppSettings["Authorize-Live"].ToUpper() == "TRUE" ? AuthorizeNet.Environment.PRODUCTION : AuthorizeNet.Environment.SANDBOX);
// define the merchant information (authentication / transaction id)
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = (System.Configuration.ConfigurationManager.AppSettings["Authorize-Live"].ToUpper() == "TRUE" ? System.Configuration.ConfigurationManager.AppSettings["Authorize-LoginID"] : System.Configuration.ConfigurationManager.AppSettings["Authorize-LoginID-SandBox"]),
ItemElementName = ItemChoiceType.transactionKey,
Item = (System.Configuration.ConfigurationManager.AppSettings["Authorize-Live"].ToUpper() == "TRUE" ? System.Configuration.ConfigurationManager.AppSettings["Authorize-TransactionKey"] : System.Configuration.ConfigurationManager.AppSettings["Authorize-TransactionKey-SandBox"])
};
if (paymentNonce.Trim() != "")
{
//set up data based on transaction
var opaqueData = new opaqueDataType { dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT", dataValue = paymentNonce };
//standard api call to retrieve response
var paymentType = new paymentType { Item = opaqueData };
var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // authorize and capture transaction
amount = paymentAmount,
payment = paymentType,
customer = new customerDataType()
{
type = customerTypeEnum.individual,
id = "YOUR_DB_USERID"
},
profile = new customerProfilePaymentType()
{
createProfile = false
}
};
var request = new createTransactionRequest { transactionRequest = transactionRequest };
// instantiate the contoller that will call the service
var controller = new createTransactionController(request);
const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
ServicePointManager.SecurityProtocol = Tls12;
controller.Execute();
// get the response from the service (errors contained if any)
var response = controller.GetApiResponse();
//validate
if (response != null)
{
if (response.messages.resultCode == messageTypeEnum.Ok)
{
if (response.transactionResponse.messages != null)
{
responseData.Success = true;
transactionID = response.transactionResponse.transId;
string merchID = "STORED AUTHORIZE.NET CUSTOMERID, return blank string if none!";
var opaqueData2 = new opaqueDataType { dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT", dataValue = paymentNonce2 };
//standard api call to retrieve response
var paymentType2 = new paymentType { Item = opaqueData2 };
customerPaymentProfileType opaquePaymentProfile = new customerPaymentProfileType();
opaquePaymentProfile.payment = paymentType2;
opaquePaymentProfile.customerType = customerTypeEnum.individual;
if (merchID == "")
{
// CREATE NEW AUTH.NET AIM CUSTOMER
List<customerPaymentProfileType> paymentProfileList = new List<customerPaymentProfileType>();
paymentProfileList.Add(opaquePaymentProfile);
customerProfileType customerProfile = new customerProfileType();
customerProfile.merchantCustomerId = "YOUR_DB_USERID";
customerProfile.paymentProfiles = paymentProfileList.ToArray();
var cimRequest = new createCustomerProfileRequest { profile = customerProfile, validationMode = validationModeEnum.none };
var cimController = new createCustomerProfileController(cimRequest); // instantiate the contoller that will call the service
cimController.Execute();
createCustomerProfileResponse cimResponse = cimController.GetApiResponse();
if (cimResponse != null && cimResponse.messages.resultCode == messageTypeEnum.Ok)
{
if (cimResponse != null && cimResponse.messages.message != null)
{
// STORE cimResponse.customerProfileId IN DATABASE FOR USER
}
}
else
{
for (int i = 0; i < cimResponse.messages.message.Length; i++)
Utility.AppendTextToFile("New Error (" + merchID + ") #" + i.ToString() + ": " + cimResponse.messages.message[i].code + " " + cimResponse.messages.message[i].text, Server.MapPath("/pub/auth.txt"));
}
}
else
{
// ADD PAYMENT PROFILE TO EXISTING AUTH.NET AIM CUSTOMER
var cimRequest = new createCustomerPaymentProfileRequest
{
paymentProfile = opaquePaymentProfile,
validationMode = validationModeEnum.none,
customerProfileId = merchID.Trim()
};
var cimController = new createCustomerPaymentProfileController(cimRequest);
cimController.Execute();
//Send Request to EndPoint
createCustomerPaymentProfileResponse cimResponse = cimController.GetApiResponse();
if (cimResponse != null && cimResponse.messages.resultCode == messageTypeEnum.Ok)
{
if (cimResponse != null && cimResponse.messages.message != null)
{
//Console.WriteLine("Success, createCustomerPaymentProfileID : " + response.customerPaymentProfileId);
}
}
else
{
for (int i = 0; i < cimResponse.messages.message.Length; i++)
Utility.AppendTextToFile("Add Error (" + merchID + ") #" + i.ToString() + ": " + cimResponse.messages.message[i].code + " " + cimResponse.messages.message[i].text, Server.MapPath("/pub/auth.txt"));
}
}
}
else
{
responseData.Message = "Card Declined";
responseData.Success = false;
if (response.transactionResponse.errors != null)
{
responseData.Message = response.transactionResponse.errors[0].errorText;
}
}
}
else
{
responseData.Message = "Failed Transaction";
responseData.Success = false;
if (response.transactionResponse != null && response.transactionResponse.errors != null)
{
responseData.Message = response.transactionResponse.errors[0].errorText;
}
else
{
responseData.Message = response.messages.message[0].text;
}
}
}
else
{
responseData.Message = "Failed Transaction, Try Again!";
responseData.Success = false;
}
}
else
{
// RUN PAYMENT WITH STORED PAYMENT PROFILE ID
customerProfilePaymentType profileToCharge = new customerProfilePaymentType();
profileToCharge.customerProfileId = CustomerID;
profileToCharge.paymentProfile = new paymentProfile { paymentProfileId = PaymentID };
var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),
amount = paymentAmount,
profile = profileToCharge
};
var request = new createTransactionRequest { transactionRequest = transactionRequest };
// instantiate the collector that will call the service
var controller = new createTransactionController(request);
controller.Execute();
// get the response from the service (errors contained if any)
var response = controller.GetApiResponse();
//validate
if (response != null)
{
if (response.messages.resultCode == messageTypeEnum.Ok)
{
if (response.transactionResponse.messages != null)
{
responseData.Success = true;
transactionID = response.transactionResponse.transId;
}
else
{
responseData.Message = "Card Declined";
responseData.Success = false;
if (response.transactionResponse.errors != null)
{
responseData.Message = response.transactionResponse.errors[0].errorText;
}
}
}
else
{
responseData.Message = "Failed Transaction";
responseData.Success = false;
if (response.transactionResponse != null && response.transactionResponse.errors != null)
{
responseData.Message = response.transactionResponse.errors[0].errorText;
}
else
{
responseData.Message = response.messages.message[0].text;
}
}
}
else
{
responseData.Message = "Failed Transaction, Try Again!";
responseData.Success = false;
}
}
下面的代码正在为卡充电,但它没有创建配置文件....有什么提示吗?我假设我遗漏了什么,或者使用了错误的类型...
var opaqueData = new opaqueDataType { dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT", dataValue = paymentNonce };
//standard api call to retrieve response
var paymentType = new paymentType { Item = opaqueData };
var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // authorize and capture transaction
amount = paymentAmount,
payment = paymentType,
customer = new customerDataType()
{
type = customerTypeEnum.individual,
id = userID.ToString()
},
profile = new customerProfilePaymentType()
{
createProfile = true
}
};
var request = new createTransactionRequest { transactionRequest = transactionRequest };
// instantiate the contoller that will call the service
var controller = new createTransactionController(request);
const SslProtocols _Tls12 = (SslProtocols)0x00000C00;
const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
ServicePointManager.SecurityProtocol = Tls12;
controller.Execute();
// get the response from the service (errors contained if any)
var response = controller.GetApiResponse();
更新: 由于显然不允许使用 OpaqueData,因此我将其更改为手动制作配置文件。我收到以下错误:"Error: I00001 Successful."
// Add Payment method to Customer.
customerPaymentProfileType opaquePaymentProfile = new customerPaymentProfileType();
opaquePaymentProfile.payment = paymentType;
opaquePaymentProfile.customerType = customerTypeEnum.individual;
var request2 = new createCustomerPaymentProfileRequest
{
paymentProfile = opaquePaymentProfile,
validationMode = validationModeEnum.none,
customerProfileId = userID.ToString()
};
var controller2 = new createCustomerPaymentProfileController(request2);
controller2.Execute();
//Send Request to EndPoint
createCustomerPaymentProfileResponse response2 = controller2.GetApiResponse();
if (response2 != null && response2.messages.resultCode == messageTypeEnum.Ok)
{
if (response2 != null && response2.messages.message != null)
{
//Console.WriteLine("Success, createCustomerPaymentProfileID : " + response.customerPaymentProfileId);
}
}
else
{
Utility.AppendTextToFile("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text, Server.MapPath("/pub/auth.txt"));
}
更新 #2 非常困惑,因为 auth.net 文档说此代码表示成功...那么为什么我看不到已创建的 CIM 付款方式??? RESPONSE CODE DOCS
更新 #3 所以我打印出主要响应消息而不是 CIM 请求消息,呃。实际错误是:"E00114 Invalid OTS Token." 根据文档,该错误通常来自使用过的密钥,因此我现在生成 2 个密钥(一个用于处理,一个用于通过 CIM 存储)但现在出现此错误:"E00040 The record cannot be found."...任何想法?
所以这个问题的答案是:
- 您无法使用不透明的卡数据自动创建付款配置文件,因此答案是在您成功收费后手动创建。
- 您不能使用相同的不透明卡数据进行充电和存储,因为它们是一次性使用的,所以对于我的网络方法,我最终传递了 2 个不透明数据密钥。
您必须拨打不同的电话来设置全新客户和现有客户只是添加一张新卡。我在下面粘贴了我的最终解决方案的摘录:
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = (System.Configuration.ConfigurationManager.AppSettings["Authorize-Live"].ToUpper() == "TRUE" ? AuthorizeNet.Environment.PRODUCTION : AuthorizeNet.Environment.SANDBOX); // define the merchant information (authentication / transaction id) ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType() { name = (System.Configuration.ConfigurationManager.AppSettings["Authorize-Live"].ToUpper() == "TRUE" ? System.Configuration.ConfigurationManager.AppSettings["Authorize-LoginID"] : System.Configuration.ConfigurationManager.AppSettings["Authorize-LoginID-SandBox"]), ItemElementName = ItemChoiceType.transactionKey, Item = (System.Configuration.ConfigurationManager.AppSettings["Authorize-Live"].ToUpper() == "TRUE" ? System.Configuration.ConfigurationManager.AppSettings["Authorize-TransactionKey"] : System.Configuration.ConfigurationManager.AppSettings["Authorize-TransactionKey-SandBox"]) }; if (paymentNonce.Trim() != "") { //set up data based on transaction var opaqueData = new opaqueDataType { dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT", dataValue = paymentNonce }; //standard api call to retrieve response var paymentType = new paymentType { Item = opaqueData }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // authorize and capture transaction amount = paymentAmount, payment = paymentType, customer = new customerDataType() { type = customerTypeEnum.individual, id = "YOUR_DB_USERID" }, profile = new customerProfilePaymentType() { createProfile = false } }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the contoller that will call the service var controller = new createTransactionController(request); const SslProtocols _Tls12 = (SslProtocols)0x00000C00; const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12; ServicePointManager.SecurityProtocol = Tls12; controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); //validate if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse.messages != null) { responseData.Success = true; transactionID = response.transactionResponse.transId; string merchID = "STORED AUTHORIZE.NET CUSTOMERID, return blank string if none!"; var opaqueData2 = new opaqueDataType { dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT", dataValue = paymentNonce2 }; //standard api call to retrieve response var paymentType2 = new paymentType { Item = opaqueData2 }; customerPaymentProfileType opaquePaymentProfile = new customerPaymentProfileType(); opaquePaymentProfile.payment = paymentType2; opaquePaymentProfile.customerType = customerTypeEnum.individual; if (merchID == "") { // CREATE NEW AUTH.NET AIM CUSTOMER List<customerPaymentProfileType> paymentProfileList = new List<customerPaymentProfileType>(); paymentProfileList.Add(opaquePaymentProfile); customerProfileType customerProfile = new customerProfileType(); customerProfile.merchantCustomerId = "YOUR_DB_USERID"; customerProfile.paymentProfiles = paymentProfileList.ToArray(); var cimRequest = new createCustomerProfileRequest { profile = customerProfile, validationMode = validationModeEnum.none }; var cimController = new createCustomerProfileController(cimRequest); // instantiate the contoller that will call the service cimController.Execute(); createCustomerProfileResponse cimResponse = cimController.GetApiResponse(); if (cimResponse != null && cimResponse.messages.resultCode == messageTypeEnum.Ok) { if (cimResponse != null && cimResponse.messages.message != null) { // STORE cimResponse.customerProfileId IN DATABASE FOR USER } } else { for (int i = 0; i < cimResponse.messages.message.Length; i++) Utility.AppendTextToFile("New Error (" + merchID + ") #" + i.ToString() + ": " + cimResponse.messages.message[i].code + " " + cimResponse.messages.message[i].text, Server.MapPath("/pub/auth.txt")); } } else { // ADD PAYMENT PROFILE TO EXISTING AUTH.NET AIM CUSTOMER var cimRequest = new createCustomerPaymentProfileRequest { paymentProfile = opaquePaymentProfile, validationMode = validationModeEnum.none, customerProfileId = merchID.Trim() }; var cimController = new createCustomerPaymentProfileController(cimRequest); cimController.Execute(); //Send Request to EndPoint createCustomerPaymentProfileResponse cimResponse = cimController.GetApiResponse(); if (cimResponse != null && cimResponse.messages.resultCode == messageTypeEnum.Ok) { if (cimResponse != null && cimResponse.messages.message != null) { //Console.WriteLine("Success, createCustomerPaymentProfileID : " + response.customerPaymentProfileId); } } else { for (int i = 0; i < cimResponse.messages.message.Length; i++) Utility.AppendTextToFile("Add Error (" + merchID + ") #" + i.ToString() + ": " + cimResponse.messages.message[i].code + " " + cimResponse.messages.message[i].text, Server.MapPath("/pub/auth.txt")); } } } else { responseData.Message = "Card Declined"; responseData.Success = false; if (response.transactionResponse.errors != null) { responseData.Message = response.transactionResponse.errors[0].errorText; } } } else { responseData.Message = "Failed Transaction"; responseData.Success = false; if (response.transactionResponse != null && response.transactionResponse.errors != null) { responseData.Message = response.transactionResponse.errors[0].errorText; } else { responseData.Message = response.messages.message[0].text; } } } else { responseData.Message = "Failed Transaction, Try Again!"; responseData.Success = false; } } else { // RUN PAYMENT WITH STORED PAYMENT PROFILE ID customerProfilePaymentType profileToCharge = new customerProfilePaymentType(); profileToCharge.customerProfileId = CustomerID; profileToCharge.paymentProfile = new paymentProfile { paymentProfileId = PaymentID }; var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), amount = paymentAmount, profile = profileToCharge }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; // instantiate the collector that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); //validate if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) { if (response.transactionResponse.messages != null) { responseData.Success = true; transactionID = response.transactionResponse.transId; } else { responseData.Message = "Card Declined"; responseData.Success = false; if (response.transactionResponse.errors != null) { responseData.Message = response.transactionResponse.errors[0].errorText; } } } else { responseData.Message = "Failed Transaction"; responseData.Success = false; if (response.transactionResponse != null && response.transactionResponse.errors != null) { responseData.Message = response.transactionResponse.errors[0].errorText; } else { responseData.Message = response.messages.message[0].text; } } } else { responseData.Message = "Failed Transaction, Try Again!"; responseData.Success = false; } }