WooCommerce Authorize.net CIM Gateway 可以让 WooCommerce 支持信用卡付款,服务提供方是 authorize.net 。最近安装了这个插件,需要区分用户的国籍,让不同国家的用户要付款到不同的 authorize.net 账户,用 sandbox 测试多个账户时,遇到一些问题,特此记录。

注册 Authorize.net Sandbox 账户

注册过程比较简单,到 https://developer.authorize.net/sandbox/按照提示注册一个账户即可,注册的邮箱将用来接收账单。

注册完成后,页面会直接显示测试所需要的 API Login IDAPI Transaction Key,把这两个填到后台的 Test Mode API Login ID 和 Test Mode API Transaction Key 选项中,并勾选 Enable Test Mode,就可以打开 sandbox 模式,如果想查看具体的报错信息,Debug Mode 一项选择 Show on Checkout Page 。

authorize-settings

注意:API Login ID 和 API Transaction Key 大概需要 15 分钟才能生效,最好等一段时间再测试,免得浪费感情。

如何测试 API LoginID 和 Transaction Key 是否生效

用下面这个链接来测试

https://test.authorize.net/gateway/transact.dll?xhttp://www.solagirl.net/wp-admin/post-new.php_version=3.1&x_type=AUTH_ONLY&x_amount=1.99&x_card_num=4111111111111111&x_exp_date=0615&x_delim_data=TRUE&x_relay_response=FALSE&x_login=YourLoginID2&x_tran_key=YourTransactionKey

把 YourLoginID 和 YourTransactionKey 替换成你的信息,如果测试没问题,会返回类似下面的结果

1,1,1,This transaction has been approved.,44T3RS,Y,2202999995,,,1.29,CC,auth_only,,,,,,,,,,,,,,,,,,,,,,,,,,36911DEB95158332EC06F4B618EDD7AB,,2,,,,,,,,,,,XXXX1111,Visa,,,,,,,,,,,,,,,,

确认信息生效后,即可进行付款测试了。

重新生成 Transaction Key

登陆 sandbox,到 settings » Security Settings » API Login ID and Transaction Key 中重新生成。需要提供 Secret Question,通常是 Simon 。

transaction-key

测试过程中遇到的问题

Duplicate customer ID

这个问题的意思是,customer ID 已经存在了。每个用户付款成功后,都会生成一个 customer ID,这个 ID 同时记录在 WordPress 数据库和 Authorize.net 的数据库中。

如果,因为某种原因,WordPress 数据库里的 customer ID 丢失了(比如编辑 user profile 时直接给删了),结账时却使用相同信息,就会产生重复 ID 的问题。

这时你可以到 sandbox 的 Customer Information Manager 中 Profile ID 一栏,看一下是否有这个 customer ID,如果有的话,点击它,进入详细信息中删掉即可。

profile-id

大多数问题都是 Login ID 未生效 profile ID 已存在导致的,先把这两个问题排除。如果还有错误,可以打开日志,看看错误代码是什么。