【问题标题】:How to get transaction ID from CIM Transaction Response如何从 CIM 事务响应中获取事务 ID
【发布时间】:2015-02-24 11:46:59
【问题描述】:

我收到了来自授权宝石的以下回复,我想提取牵引号码,即 2226171485

#<AuthorizeNet::CIM::Response:0xc0eafb8 @raw_response=#<Net::HTTPOK 200 OK readbody=true>, @transaction=#<AuthorizeNet::CIM::Transaction:0xbffe21c @fields={:customer_profile_id=>"30751733", :customer_payment_profile_id=>"27849165", :line_items=>[], :amount=>150}, @api_login_id="2yC2cP8t5HEf", @api_transaction_key="2nr96MZ2Bdmu8S3V", @response=#<AuthorizeNet::CIM::Response:0xc0eafb8 ...>, @type="createCustomerProfileTransactionRequest", @verify_ssl=false, @reference_id=nil, @gateway="https://apitest.authorize.net/xml/v1/request.api", @delim_char=",", @encap_char=nil, @custom_fields={}, @transaction_type=:auth_capture, @xml="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<createCustomerProfileTransactionRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">\n  <merchantAuthentication>\n    <name>2yC2cP8t5HEf</name>\n    <transactionKey>2nr96MZ2Bdmu8S3V</transactionKey>\n  </merchantAuthentication>\n  <transaction>\n    <profileTransAuthCapture>\n      <amount>150</amount>\n      <customerProfileId>30751733</customerProfileId>\n      <customerPaymentProfileId>27849165</customerPaymentProfileId>\n    </profileTransAuthCapture>\n  </transaction>\n</createCustomerProfileTransactionRequest>\n">, @root=#<Nokogiri::XML::Element:0x607575a name="createCustomerProfileTransactionResponse" namespace=#<Nokogiri::XML::Namespace:0x60756e2 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Element:0x606c3ee name="messages" namespace=#<Nokogiri::XML::Namespace:0x60756e2 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Element:0x60750a2 name="resultCode" namespace=#<Nokogiri::XML::Namespace:0x60756e2 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x606c060 "Ok">]>, #<Nokogiri::XML::Element:0x606bf84 name="message" namespace=#<Nokogiri::XML::Namespace:0x60756e2 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Element:0x60749f4 name="code" namespace=#<Nokogiri::XML::Namespace:0x60756e2 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x606bbf6 "I00001">]>, #<Nokogiri::XML::Element:0x6074346 name="text" namespace=#<Nokogiri::XML::Namespace:0x60756e2 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x606b976 "Successful.">]>]>]>, #<Nokogiri::XML::Element:0x606d9b0 name="directResponse" namespace=#<Nokogiri::XML::Namespace:0x60756e2 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x606b61a "1,1,1,This transaction has been approved.,XVJDGT,Y,2226171485,,,150.00,CC,auth_capture,36,,,,,,,,,,,baran.khan@ccjk.com,,,,,,,,,,,,,,D16E802BF6C1854F220DF0C88900557A,,2,,,,,,,,,,,XXXX0012,Discover,,,,,,,,,,,,,,,,">]>]>, @result_code="Ok", @message_code="I00001", @message_text="Successful.", @reference_id=nil, @customer_profile_id=nil, @customer_payment_profile_id=nil, @customer_payment_profile_id_list=nil, @customer_shipping_address_id_list=nil, @customer_address_id=nil, @validation_direct_response_list=nil, @validation_direct_response=nil, @direct_response=#<Nokogiri::XML::Element:0x606d9b0 name="directResponse" namespace=#<Nokogiri::XML::Namespace:0x60756e2 href="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> children=[#<Nokogiri::XML::Text:0x606b61a "1,1,1,This transaction has been approved.,XVJDGT,Y,2226171485,,,150.00,CC,auth_capture,36,,,,,,,,,,,baran.khan@ccjk.com,,,,,,,,,,,,,,D16E802BF6C1854F220DF0C88900557A,,2,,,,,,,,,,,XXXX0012,Discover,,,,,,,,,,,,,,,,">]>, @customer_profile_id_list=nil, @address=nil, @payment_profile=nil, @profile=nil> 

【问题讨论】:

    标签: ruby-on-rails ruby authorize.net


    【解决方案1】:

    我已经找到方法了。

    @result.direct_response.fields[:transaction_id]
    

    【讨论】:

      【解决方案2】:

      这是我在 C#.NET 中的实现

      见下面的代码: api_response.directResponse.Split(',')[6] - 交易 ID i CIM

      public static bool CreateTransaction(ref AnetPayment payment, string ANET_API_LOGIN, string ANET_API_TRANSACTION_KEY, string ANET_API_URL)
          {
              bool out_bool = false;
      
              createCustomerProfileTransactionRequest request = new createCustomerProfileTransactionRequest();
              XmlAPIUtilities.PopulateMerchantAuthentication((ANetApiRequest)request, ANET_API_LOGIN, ANET_API_TRANSACTION_KEY);
      
              profileTransactionType new_trans = new profileTransactionType();
      
      
              profileTransAuthCaptureType new_item = new profileTransAuthCaptureType();
              new_item.customerProfileId = payment.customer_profile_id.ToString();
              new_item.customerPaymentProfileId = payment.customer_payment_profile_id.ToString();
              new_item.amount = payment.amount;
      
      
              orderExType order = new orderExType();
              order.invoiceNumber = payment.invoiceNumber;
              order.description = payment.description;
              order.purchaseOrderNumber = payment.purchaseOrderNumber;
              new_item.order = order;
      
      
              new_trans.Item = new_item;
              request.transaction = new_trans;
              request.refId = payment.refId;
      
      
      
              System.Xml.XmlDocument response_xml = null;
              bool bResult = XmlAPIUtilities.PostRequest(request, out response_xml, ANET_API_URL);
              object response = null;
              createCustomerProfileTransactionResponse api_response = null;
      
              if (bResult) bResult = XmlAPIUtilities.ProcessXmlResponse(response_xml, out response);
              if (!(response is createCustomerProfileTransactionResponse))
              {
                  ANetApiResponse ErrorResponse = (ANetApiResponse)response;
                  payment.MessageCode = ErrorResponse.messages.message[0].code;
                  payment.MessageText = ErrorResponse.messages.message[0].text;
                  return out_bool;
              }
              if (bResult) api_response = (createCustomerProfileTransactionResponse)response;
              if (api_response != null)
              {
                  out_bool = (api_response.messages.message[0].code[0] == 'I');
                  payment.ApiDirectResponse = api_response.directResponse;
                  payment.refId = api_response.directResponse.Split(',')[6];
                  payment.MessageCode = api_response.messages.message[0].code;
                  payment.MessageText = api_response.messages.message[0].text;
              }
              return out_bool;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-01
        • 1970-01-01
        相关资源
        最近更新 更多