我正在使用2checkout API將支付集成到我的應用程序中。我正在關注他們的API Tutorial。我對他們的方法做了輕微的修改。以下是教程中未修改的前端代碼。如何將普通的PHP庫添加到Laravel中?
<form id="myCCForm" action="payment.php" method="post">
<input id="token" name="token" type="hidden" value="">
<div>
<label>
<span>Card Number</span>
</label>
<input id="ccNo" type="text" size="20" value="" autocomplete="off" required />
</div>
<div>
<label>
<span>Expiration Date (MM/YYYY)</span>
</label>
<input type="text" size="2" id="expMonth" required />
<span>/</span>
<input type="text" size="2" id="expYear" required />
</div>
<div>
<label>
<span>CVC</span>
</label>
<input id="cvv" size="4" type="text" value="" autocomplete="off" required />
</div>
<input type="submit" value="Submit Payment">
我改變了線<form id="myCCForm" action="payment.php" method="post">
到<form id="myCCForm" action="{{route('postPayment)}}" method="post">
和在上述形式也加入CSRF令牌字段。
這件事情工作正常。
第二部分是我想在Laravel應用程序中處理的服務器端腳本。在教程中,這是用payment.php編寫的。該腳本是工作在payment.php不錯,但我想它寫在控制器如下:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\TwoCheckout;
class PaymentsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$twoCheckOut = TwoCheckout::find(1);
return view('payment')->with('twoCheckOut',$twoCheckOut);
}
public function process()
{
require_once("2checkout-php/lib/Twocheckout.php");
Twocheckout::privateKey('6CC34113-3588-4B09-8ECB-958C0B3299F3');
Twocheckout::sellerId('901303383');
Twocheckout::sandbox(true);
try {
$charge = Twocheckout_Charge::auth(array(
"sellerId" => "901303383",
"merchantOrderId" => "123",
"token" => 'Y2U2OTdlZjMtOGQzMi00MDdkLWJjNGQtMGJhN2IyOTdlN2Ni',
"currency" => 'USD',
"total" => '10.00',
"billingAddr" => array(
"name" => 'Testing Tester',
"addrLine1" => '123 Test St',
"city" => 'Columbus',
"state" => 'OH',
"zipCode" => '43123',
"country" => 'USA',
"email" => '[email protected]',
"phoneNumber" => '555-555-5555'
),
"shippingAddr" => array(
"name" => 'Testing Tester',
"addrLine1" => '123 Test St',
"city" => 'Columbus',
"state" => 'OH',
"zipCode" => '43123',
"country" => 'USA',
"email" => '[email protected]',
"phoneNumber" => '555-555-5555'
)
), 'array');
if ($charge['response']['responseCode'] == 'APPROVED') {
echo "Thanks for your Order!";
}
} catch (Twocheckout_Error $e) {
$e->getMessage();
}
}
}
的問題在下面幾行發生。
require_once("2checkout-php/lib/Twocheckout.php");
Twocheckout::privateKey('6CC34113-3588-4B09-8ECB-958C0B3299F3');
Twocheckout::sellerId('901303383');
Twocheckout::sandbox(true);
錯誤
BadMethodCallException在Builder.php線2099: 調用未定義的方法照亮\數據庫\查詢\生成器::專用密鑰()
我是什麼在這裏做錯了嗎?
將模型的名稱從TwoCheckout更改爲TwoCheckoutAccount ...另一個錯誤是針對'Twocheckout :: privateKey('6CC34113-3588-4B09-8ECB-958C0B3299F3');'* Class'App \ Http \ Controllers \ Twocheckout 'not found * –
這是因爲它是在控制器命名空間裏面解析的,它是'App \ Http \ Controllers'。你可以添加一個'使用Twocheckout;'語句來指定應該在全局命名空間中解析該類。 – Bogdan
謝謝Bogdan :) –