【问题标题】:Authorize.NET create customer profile with test.authorize.net?Authorize.NET 使用 test.authorize.net 创建客户资料?
【发布时间】:2016-01-05 13:33:57
【问题描述】:

在 authorize.net 中,是否可以使用https://test.authorize.net/gateway/transact.dll 页面创建客户资料 + 客户付款资料(测试模式)? 我需要返回客户 profileid 和 paymentprofileid(s) 才能进行离线付款。

在使用客户付款资料创建客户资料并调用 charge customer profile 后,我可以使用 API (C#) 执行此操作。但我不希望用户在我的网站中输入卡详细信息,需要使用 Authorize.NET UI 来完成并获得响应。

这样可以吗?

【问题讨论】:

标签: c# asp.net-mvc authorize.net


【解决方案1】:

是的,可以使用 Authorize.NET 进行令牌 API 信用卡交易。 详情可参见in this CIM guide 文档(第 4 章)。

  • 第 1 步 - 使用 API 创建客户资料。 (只是基本客户 详情)
  • 第 2 步 - 获取配置文件的令牌* (getHostedProfilePageRequest)。这就是我卡住的地方,“谜 API 调用”,我在下面分享代码。
  • 第 3 步 - 创建一个表单 在下面发一个帖子。 (这会将客户引导到托管的 添加/编辑付款方式或送货地址的表格)
  • 第 4 步 - 尝试 查询客户的客户付款资料,您会发现 添加的付款资料。

表格的格式,

    <form method="post" action="https://test.authorize.net/
     profile/manage">
      <input type="hidden" name="token"
         value="pfGaUNntoTxZYeqqYDjGCQ4qyCHcsXGXLJ2i7MPCEiH6CH5n5qKqcl8EB
            iTClxu01BSeH5eZg7LVUVVzw5kJKVMitQ3pyMB5UZCduMWd6Ku9aT2gyFm69EKMG
            fyWPmI4p+Bb4XXXXXXXXXXXXWlM6f2xd7aRu1XBn0WXoPxK1j9FMGX2CNCoCB
            p3cOXB7"/>
      <input type="submit" value="Manage payment and shipping
      information"/>
     </form>

这是我为“getHostedProfilePageRequest”的神秘 API 调用找到的代码,该代码在 Github 的 C# SDK 中不可用。它在soap 客户端中可用,但此代码只是通过http 发送XML 请求(听起来很像Web 服务)。

public static string GetHostedSessionKey(UInt32 customerProfileID, Uri callingPage)
    {
        try
        {
            //build a path to IframeCommunicator from the calling page
            string communicatorPath = String.Format("{0}://{1}:{2}", callingPage.Scheme, callingPage.Host, callingPage.Port);
            string[] segments = callingPage.Segments;
            //replace the very last entry with contentx/IframeCommunicator.html
            segments[segments.GetUpperBound(0)] = "/contentx/IframeCommunicator.html";
            foreach (string s in segments)
                communicatorPath += s;

            string requestXML = String.Format("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                                "<getHostedProfilePageRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" +
                                                    "<merchantAuthentication>" +
                                                        "<name>{0}</name>" +
                                                        "<transactionKey>{1}</transactionKey>" +
                                                    "</merchantAuthentication>" +
                                                    "<customerProfileId>{2}</customerProfileId>" +
                                                    "<hostedProfileSettings>" +
                                                        "<setting>" +
                                                            "<settingName>hostedProfilePageBorderVisible</settingName>" +
                                                            "<settingValue>false</settingValue>" +
                                                        "</setting>" +
                                                        "<setting>" +
                                                            "<settingName>hostedProfileIFrameCommunicatorUrl</settingName>" +
                                                            "<settingValue>{3}</settingValue>" +
                                                        "</setting>" +
                                                    "</hostedProfileSettings>" +
                                                "</getHostedProfilePageRequest>",
                                            {your merchant login ID},
                                            {your merchant transaction key},
                                            customerProfileID,
                                            communicatorPath);
         string XMLURL = "https://apitest.authorize.net/xml/v1/request.api";
            System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(XMLURL);
            req.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
            req.KeepAlive = false;
            req.Timeout = 30000; //30 seconds
            req.Method = "POST";
            byte[] byte1 = null;
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byte1 = encoding.GetBytes(requestXML);
            req.ContentType = "text/xml";
            req.ContentLength = byte1.Length;
            System.IO.Stream reqStream = req.GetRequestStream();
            reqStream.Write(byte1, 0, byte1.Length);
            reqStream.Close();

            System.Net.WebResponse resp = req.GetResponse();
            System.IO.Stream read = resp.GetResponseStream();
            System.IO.StreamReader io = new System.IO.StreamReader(read, new         System.Text.ASCIIEncoding());
            string data = io.ReadToEnd();
            resp.Close();

            //parse out value
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(data);
            XmlNodeList token = doc.GetElementsByTagName("token");
            return token[0].InnerText;
        }
        catch (System.Exception ex)
        {
            Utility.NotifyOnException(ex, String.Format("profID={0}", customerProfileID));
            return null;
        }
    }

找到这个代码here

【讨论】:

    猜你喜欢
    • 2018-02-21
    • 2021-08-02
    • 1970-01-01
    • 2018-02-08
    • 2012-11-13
    • 1970-01-01
    • 2013-09-18
    • 2012-10-30
    • 2013-03-17
    相关资源
    最近更新 更多