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 已存在導致的,先把這兩個問題排除。如果還有錯誤,可以打開日誌,看看錯誤代碼是什麼。