我正在使用 2checkout API 在我的应用程序中集成付款。我正在关注他们的API 教程。我对他们的方法做了轻微的修改。下面是教程中未修改的前端代码。
<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" => 'testingtester@2co.com',
"phoneNumber" => '555-555-5555'
),
"shippingAddr" => array(
"name" => 'Testing Tester',
"addrLine1" => '123 Test St',
"city" => 'Columbus',
"state" => 'OH',
"zipCode" => '43123',
"country" => 'USA',
"email" => 'testingtester@2co.com',
"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);
错误
Builder.php 第 2099 行中的 BadMethodCallException:调用未定义的方法 Illuminate\Database\Query\Builder::privateKey()
我在这里做错了什么?