Search code examples
phpxmlauthorize.netauthorize.net-cim

Authorize.Net CIM trying to create a profile and do a transaction one after the other


I am using John Conde's AuthnetXML class he made for Authorize.Net. I am trying to create a profileID and a paymentprofileid for a user using createCustomerProfileRequest and then if created I apply the newly created customerprofileid and customerpaymentprofileid to the createCustomerProfileTransactionRequest and try and put a transaction through.

When it first goes through The account is created but the page goes white like something broke, I then click f5 to push through and it goes through fine. The way it is build is if the user has the ids already I bypass part one. ( creating the profiles ) I feel like it wont let me to two calls to the api one after the other or maybe the account needs a minute to propagate on the server?

Has anyone encountered something like this before?


Solution

  • I have seen anything like this. I whipped up an example that more or less did what you're trying to do and didn't experience any issues so I posted here for you to compare to your code. Hopefully it is helpful for you:

    <?php
    
        require('../../config.inc.php');
        require('../../AuthnetXML.class.php');
    
        $xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetXML::USE_DEVELOPMENT_SERVER);
        $xml->createCustomerProfileRequest(array(
            'profile' => array(
                'merchantCustomerId' => '87658',
                'email' => '[email protected]',
                'paymentProfiles' => array(
                    'billTo' => array(
                        'firstName' => 'John',
                        'lastName' => 'Smith',
                        'address' => '123 Main Street',
                        'city' => 'Townsville',
                        'state' => 'NJ',
                        'zip' => '12345',
                        'phoneNumber' => '800-555-1234'
                    ),
                    'payment' => array(
                        'creditCard' => array(
                        'cardNumber' => '4111111111111111',
                        'expirationDate' => '2016-08',
                        ),
                    ),
                ),
                'shipToList' => array(
                    'firstName' => 'John',
                    'lastName' => 'Smith',
                    'address' => '123 Main Street',
                    'city' => 'Townsville',
                    'state' => 'NJ',
                    'zip' => '12345',
                    'phoneNumber' => '800-555-1234'
                ),
            ),
            'validationMode' => 'liveMode'
        ));
    
        $profile_id          = $xml->customerProfileId;
        $payment_profile_id  = $xml->customerPaymentProfileIdList->numericString;
        $shipping_profile_id = $xml->customerShippingAddressIdList->numericString;
    
        $xml = new AuthnetXML(AUTHNET_LOGIN, AUTHNET_TRANSKEY, AuthnetXML::USE_DEVELOPMENT_SERVER);
        $xml->createCustomerProfileTransactionRequest(array(
            'transaction' => array(
                'profileTransAuthCapture' => array(
                    'amount' => '10.95',
                    'customerProfileId' => $profile_id,
                    'customerPaymentProfileId' => $payment_profile_id,
                    'customerShippingAddressId' => $shipping_profile_id,
                    'order' => array(
                        'invoiceNumber' => 'INV000001',
                        'description' => 'description of transaction',
                        'purchaseOrderNumber' => 'PONUM000001'
                    ),
                    'taxExempt' => 'false',
                    'recurringBilling' => 'false',
                    'cardCode' => '000'
                )
            ),
            'extraOptions' => '<![CDATA[x_customer_ip=100.0.0.1]]>'
        ));
    
        echo $xml;
    ?>
    

    Here's the XML that was sent back and forth:

    createCustomerProfileRequest

    <?xml version="1.0"?>
    <createCustomerProfileRequest>
      <merchantAuthentication>
        <name>cnpdev4289</name>
        <transactionKey>SR2P8g4jdEn7vFLQ</transactionKey>
      </merchantAuthentication>
      <profile>
        <merchantCustomerId>87658</merchantCustomerId>
        <email>[email protected]</email>
        <paymentProfiles>
          <billTo>
            <firstName>John</firstName>
            <lastName>Smith</lastName>
            <address>123 Main Street</address>
            <city>Townsville</city>
            <state>NJ</state>
            <zip>12345</zip>
            <phoneNumber>800-555-1234</phoneNumber>
          </billTo>
          <payment>
            <creditCard>
              <cardNumber>4111111111111111</cardNumber>
              <expirationDate>2016-08</expirationDate>
            </creditCard>
          </payment>
        </paymentProfiles>
        <shipToList>
          <firstName>John</firstName>
          <lastName>Smith</lastName>
          <address>123 Main Street</address>
          <city>Townsville</city>
          <state>NJ</state>
          <zip>12345</zip>
          <phoneNumber>800-555-1234</phoneNumber>
        </shipToList>
      </profile>
      <validationMode>liveMode</validationMode>
    </createCustomerProfileRequest>
    
    
    <?xml version="1.0" encoding="utf-8"?>
    <createCustomerProfileResponse>
      <messages>
        <resultCode>Ok</resultCode>
        <message>
          <code>I00001</code>
          <text>Successful.</text>
        </message>
      </messages>
      <customerProfileId>11234435</customerProfileId>
      <customerPaymentProfileIdList>
        <numericString>10232106</numericString>
      </customerPaymentProfileIdList>
      <customerShippingAddressIdList>
        <numericString>10454653</numericString>
      </customerShippingAddressIdList>
      <validationDirectResponseList>
        <string>1,1,1,This transaction has been approved.,0ZSYP6,Y,2180917446,none,Test transaction for ValidateCustomerPaymentProfile.,0.00,CC,auth_only,87658,John,Smith,,123 Main Street,Townsville,NJ,12345,,800-555-1234,,[email protected],,,,,,,,,0.00,0.00,0.00,FALSE,none,CE4F0E75B0703C40FE109A7B0B2E0575,,2,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,</string>
      </validationDirectResponseList>
    </createCustomerProfileResponse>
    

    createCustomerProfileTransactionRequest

    <?xml version="1.0"?>
    <createCustomerProfileTransactionRequest>
      <merchantAuthentication>
        <name>cnpdev4289</name>
        <transactionKey>SR2P8g4jdEn7vFLQ</transactionKey>
      </merchantAuthentication>
      <transaction>
        <profileTransAuthCapture>
          <amount>10.95</amount>
          <customerProfileId>11234435</customerProfileId>
          <customerPaymentProfileId>10232106</customerPaymentProfileId>
          <customerShippingAddressId>10454653</customerShippingAddressId>
          <order>
            <invoiceNumber>INV000001</invoiceNumber>
            <description>description of transaction</description>
            <purchaseOrderNumber>PONUM000001</purchaseOrderNumber>
          </order>
          <taxExempt>false</taxExempt>
          <recurringBilling>false</recurringBilling>
          <cardCode>000</cardCode>
        </profileTransAuthCapture>
      </transaction>
      <extraOptions>&lt;![CDATA[x_customer_ip=100.0.0.1]]&gt;</extraOptions>
    </createCustomerProfileTransactionRequest>  
    
    <?xml version="1.0" encoding="utf-8"?>
    <createCustomerProfileTransactionResponse>
      <messages>
        <resultCode>Ok</resultCode>
        <message>
          <code>I00001</code>
          <text>Successful.</text>
        </message>
      </messages>
      <directResponse>1,1,1,This transaction has been approved.,S6HDI6,Y,2180917449,INV000001,description of transaction,10.95,CC,auth_capture,87658,John,Smith,,123 Main Street,Townsville,NJ,12345,,800-555-1234,,[email protected],John,Smith,,123 Main Street,Townsville,NJ,12345,,,,,FALSE,PONUM000001,F0FA82F73AA206A4D7D956E98AF97725,P,2,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,,10454653,100.0.0.1]]&gt;</directResponse>
    </createCustomerProfileTransactionResponse>