如何从CIM Transaction Response获取事务ID

时间:2014-12-27 16:57:16

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

我从Authorize Gem得到以下回复我想提取牵引号码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> 

2 个答案:

答案 0 :(得分:0)

我找到了这个方法。

@result.direct_response.fields[:transaction_id]

答案 1 :(得分:0)

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

参见下面的代码: api_response.directResponse.Split(&#39;,&#39;)[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;
    }