Php 如何在Authorize.Net中使用CIM获取客户配置文件?

Php 如何在Authorize.Net中使用CIM获取客户配置文件?,php,payment-gateway,payment,authorize.net,authorize.net-cim,Php,Payment Gateway,Payment,Authorize.net,Authorize.net Cim,我在CIM(客户信息管理器)工作,我使用CIM函数创建了客户概要文件。但是我想使用客户id而不是客户配置文件id来获取客户配置文件 $cim = new AuthnetCIM('***MASKED***', '***MASKED***', AuthnetCIM::USE_DEVELOPMENT_SERVER); $cim->setParameter('email', 'fakeemail@example.com'); $cim->setParameter('descriptio

我在CIM(客户信息管理器)工作,我使用CIM函数创建了客户概要文件。但是我想使用客户id而不是客户配置文件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();

你不能。您只能使用配置文件ID获取配置文件。这意味着您需要将该ID存储在数据库中,并将其与客户记录相关联,以便无论何时需要获取他们的配置文件,您都知道他们的配置文件ID。

实际上,如果必须,这是可能的,但是如果可能,我仍然建议您将其存储,但这一选择可能会有所帮助

Authorize.Net通过复合密钥(商户客户Id、电子邮件和描述)定义唯一的客户配置文件,因此您必须确保这是唯一的。CreateCustomerProfile(..)API方法将强制唯一性,如果您再次尝试创建相同的复合键,则会返回一个错误。但是,此响应中的消息将包含冲突的客户配置文件id,并且由于您的复合密钥是唯一的,并且Authorize.Net强制执行此复合密钥的唯一性,因此这必须是您客户的Authorize.Net客户配置文件id

C语言中的代码示例#

private long customerProfileId=0;
var customerProfile=new AuthorizeNet.CustomerProfileType()
{ 
merchantCustomerId=“123456789”,
电子邮件=”user@domain.com",
description=“约翰·史密斯”,
};
var cpResponse=authorize.CreateCustomerProfile(商品身份验证、customerProfile、ValidationModeEnum.none);
if(cpResponse.resultCode==MessageTypeEnum.Ok)
{
customerProfileId=cpResponse.customerProfileId;
}
其他的
{
var regex=new regex(“^ID为(?[0-9]+)的重复记录已存在。$”,RegexOptions.ExplicitCapture);
Match Match=regex.Match(cpResponse.messages[0].text);
如果(匹配成功)
customerProfileId=long.Parse(match.Groups[“profileId”].Value);
其他的
//提出错误。
}

好的,我能理解。您能否提供一种使用配置文件id而不是所有配置文件获取配置文件的方法。
    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.
    }