簡體   English   中英

C#Authorize.net創建配置文件問題

[英]C# Authorize.net Create Profile Issue

以下代碼正在為卡收費,但是它並未創建個人資料...。有什么提示嗎? 我以為我錯過了什么,或者使用了錯誤的Type ...

            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,因此我將其更改為手動創建配置文件。 我收到以下錯誤:“錯誤:I00001成功。”

// 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付款方式已創建? 響應代碼文檔

更新#3因此,我正在打印主要響應消息,而不是CIM請求消息。 實際錯誤為:“ E00114無效的OTS令牌”。 根據文檔,該錯誤通常是由使用過的密鑰引起的,因此我現在生成2個密鑰(一個要處理,一個要通過CIM存儲),但是現在出現此錯誤:“ E00040找不到記錄。”。 ...有任何想法嗎?

因此,此問題的答案是:

  1. 您無法使用不透明的卡數據自動創建付款資料,因此答案是在成功扣款后手動進行設置。
  2. 您不能使用相同的不透明卡數據進行充電和存儲,因為它們是一次使用,因此對於我的Web方法,我最終傳遞了2個不透明數據密鑰。
  3. 您必須撥打不同的電話才能建立一個全新的客戶和僅添加新卡的現有客戶。 我在下面粘貼了我的最終解決方案的摘錄:

      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; } } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM