Question

I am working of CIM (Customer information manager) and i have created customer profile using CIM function. But i want to get customer profile using customer id instead of customer profile id.

 $cim = new AuthnetCIM('***MASKED***', '***MASKED***', AuthnetCIM::USE_DEVELOPMENT_SERVER);
 $cim->setParameter('email', 'fakeemail@example.com');
 $cim->setParameter('description', 'Profile for Joe Smith'); // Optional
 $cim->setParameter('merchantCustomerId', '7789812');

 //create profile function 
 $ss=$cim->createCustomerProfile();

 //and get profile by..
 $profile_id = $cim->getProfileID();
Was it helpful?

Solution

You can't. You can only get the profile using the profile ID. This means you'll want to store that ID in your database and associate it with the customer's record so whenever you need to get their profile you know what their Profile ID is.

OTHER TIPS

Actually it is possible if you must, however I would still recommend storing it if possible, but this alternative might be of help.

Authorize.Net defines a unique customer profile by the composite key (Merchant Customer Id, Email, and Description), thus you must ensure this is unique. The CreateCustomerProfile(..) API method will enforce uniqueness and return an error if you attempt to create the same composite key again, as it should. However, the message in this response will contain the conflicting customer profile id, and since your composite key is unique, and Authorize.Net enforces uniqueness of this composite key, then this must be the Authorize.Net customer profile id of your customer.

Code sample in C#

    private long customerProfileId = 0;

    var customerProfile = new AuthorizeNet.CustomerProfileType()
        { 
            merchantCustomerId = "123456789",  
            email = "user@domain.com",
            description = "John Smith",
        };

    var cpResponse = authorize.CreateCustomerProfile(merchantAuthentication, customerProfile, ValidationModeEnum.none);
    if (cpResponse.resultCode == MessageTypeEnum.Ok)
    {
        customerProfileId = cpResponse.customerProfileId;
    }
    else
    {
        var regex = new Regex("^A duplicate record with ID (?<profileId>[0-9]+) already exists.$", RegexOptions.ExplicitCapture);
        Match match = regex.Match(cpResponse.messages[0].text);
        if (match.Success)
            customerProfileId = long.Parse(match.Groups["profileId"].Value);
        else
            //Raise error.
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top