簡介
本篇紀錄如何開發一個 IVR 整合 Authorize.net 使用電話作刷卡付款的系統。
文章索引
開發 PHP 連結 Authorize.net
步驟流程:
(https://developer.authorize.net/inte...inutes/#custom)
- 從官方新增一個測試帳號
- 下載 SDK
- 編寫 PHP 程式
- 電子交易測試及驗證
編寫 PHP 程式
make_payment.php:
reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown. (click for details)Callstack:
at User:alang/Private_Zone/Asterisk_開發筆記/IVR_開發:整合_Authorize.net_Payment_Gateway
MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException: reference to undefined name 'syntax' Exception of type 'MindTouch.Deki.Script.Runtime.DekiScriptUndefinedNameException' was thrown.
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptVar expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptVar.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Evaluate (MindTouch.Deki.Script.Expr.DekiScriptAccess expr, DekiScriptExpressionEvaluationState state, Boolean evaluateProperties) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptAccess expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptAccess.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptCall expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptCall.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptSequence expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Expr.DekiScriptSequence.VisitWith[DekiScriptExpressionEvaluationState,Range] (IDekiScriptExpressionVisitor`2 visitor, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
at MindTouch.Deki.Script.Compiler.DekiScriptExpressionEvaluation.Visit (MindTouch.Deki.Script.Expr.DekiScriptReturnScope expr, DekiScriptExpressionEvaluationState state) [0x00000] in <filename unknown>:0
另一個較完整的開發案例:
http://community.developer.authorize...ing/ba-p/10768
Tips:
* 如果使用的是測試帳號,請增加第三個參數 true
$payment = new AuthnetAIM('myapilogin', 'mYtRaNsaCTiOnKEy', true);
電子交易測試及驗證
執行 PHP 交易程式後,如果輸出訊息:
Success! The test credit card has been charged!
Transaction ID: 2160634394
看到這樣訊息表示,信用卡交易完成,請前往官方網頁:https://test.authorize.net/,登入帳號密碼後,選擇
Home > REPORTS > Transaction Detail > Unsettled Transactions
報表內應該要出現剛剛完成的交易項目。
開發 IVR 的 PHP-AGI
IVR Script:
We accept mastercard or visa credit card. Please select how you would like to pay. For credit card press 1.
Press 1 ->
- Please enter card number
- Please press the four digit expiration date of your card.
- Please press the amount that you would like to pay, For example for $125.65 press 12565, followed by the hash or pound key.
- The Card Number you entered is XXXXXX ,and the amount you entered for the payment is $XXX.XX, If these are correct press 1 otherwise press 2 .
-- Press 1
- One moment while your payment is processed.
- If tansaction approved.
- Your transaction ID is XXXXX.
- Your payment of $XXXX has posted to your account.
- Thank you for using our automated payment system. Goodbye.
- If transaction failed
- Sorry, this transaction failed.
FAQ
Q:執行 PHP 後總是出現錯誤:response reason code: 87?
Ans: 測試用的帳號有分兩種類型:Card Not Present(CNP) 與 Card Present(CP),開發 PHP 時,必須使用不同的函數:
// for CNP account, 本篇教學以此類型為主
$transaction = new AuthorizeNetAIM('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY');
$transaction->amount = '9.99';
$transaction->card_num = '4007000000027';
$transaction->exp_date = '10/16';
// for CP account
$transaction = new AuthorizeNetCP('YOUR_API_LOGIN_ID', 'YOUR_TRANSACTION_KEY');
$transaction->amount = '9.99';
$transaction->setTrack1Data('%B4111111111111111^CARDUSER/JOHN^1803101000000000020000831000000?');
$transaction->device_type = '4';