【发布时间】:2018-01-17 06:48:29
【问题描述】:
我使用 Laravel 5.1,我们使用 Stripe,但现在我需要更改为 checkout.com Checkout.com 有一个 php 库:https://github.com/checkout/checkout-php-library
我想在我的应用中实现。我首先运行:
composer require checkout/checkout-php-api
所以我安装了库,库在 vendor/checkout 文件夹内
我使用 OrderController 并创建公共功能结帐:
require_once 'vendor\checkout\checkout-php-library\autoload.php';
use com\checkout;
class OrdersController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function payment() {
return view('front.checkout');
}
public function checkout(Request $request) {
$data = $request->all();
$apiClient = new ApiClient('sk_test_aaaaaa-5116-999-9270-999999999');
// create a charge serive
$charge = $apiClient->chargeService();
try {
/** @var ResponseModels\Charge $ChargeRespons **/
$ChargeResponse = $charge->verifyCharge($data['cko-card-token']);
} catch (com\checkout\helpers\ApiHttpClientCustomException $e) {
echo 'Caught exception Message: ', $e->getErrorMessage(), "\n";
echo 'Caught exception Error Code: ', $e->getErrorCode(), "\n";
echo 'Caught exception Event id: ', $e->getEventId(), "\n";
}
}
现在当我发出 POST 请求时,我得到:
OrdersController.php 第 26 行中的 FatalErrorException:main():失败 打开所需的 'vendor\checkout\checkout-php-library\autoload.php' (include_path='.;C:\php\pear')
如何将此库集成到我的 Laravel 项目中?
更新: 在前端我有这个代码:
<script src="https://cdn.checkout.com/js/frames.js"></script>
<form id="payment-form" method="POST" action="{{url()}}/checkout">
{!! csrf_field() !!}
<div class="frames-container">
<!-- form will be added here -->
</div>
<!-- add submit button -->
<button id="pay-now-button" type="submit" disabled>Pay now</button>
</form>
<script>
var paymentForm = document.getElementById('payment-form');
var payNowButton = document.getElementById('pay-now-button');
Frames.init({
publicKey: 'pk_test_aaaaaaaaa-000-41d9-9999-999999999',
containerSelector: '.frames-container',
customerName: 'John Smith',
billingDetails: {
addressLine1: '623 Slade Street',
addressLine2: 'Apartment 8',
postcode: '31313',
email: 'asd@asd.asd',
country: 'US',
city: 'Hinesville',
phone: { number: '9125084652' }
},
cardValidationChanged: function () {
// if all fields contain valid information, the Pay now
// button will be enabled and the form can be submitted
payNowButton.disabled = !Frames.isCardValid();
},
cardSubmitted: function () {
payNowButton.disabled = true;
// display loader
}
});
paymentForm.addEventListener('submit', function (event) {
event.preventDefault();
Frames.submitCard()
.then(function (data) {
Frames.addCardToken(paymentForm, data.cardToken);
paymentForm.submit();
})
.catch(function (err) {
// catch the error
});
});
</script>
【问题讨论】:
-
我运行 composer dump-autoload 得到了这个文件夹结构:screencast.com/t/dMz7oubLLn
-
转到包的根目录并运行 composer install
-
我运行但没有composer.json文件
-
repo 上有一个 composer.json 文件
-
抱歉,这是我得到的:screencast.com/t/REqxid6Fku
标签: php laravel package integration-testing checkout