Did you dump autoload?
Jan 14, 2018
3
Level 2
How to use non-Laravel package
I use Laravel 5.1 and we use Stripe but now I need to change to checkout.com Checkout.com has one php library: https://github.com/checkout/checkout-php-library
I want to implement into my app. FIrst I run :
composer require checkout/checkout-php-api so I install the library and library is inside vendor/checkout folder
I use OrderController and I create public function checkout:
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";
}
}
Now when I make POST request I get:
FatalErrorException in OrdersController.php line 26: main(): Failed opening required 'vendor\checkout\checkout-php-library\autoload.php' (include_path='.;C:\php\pear')
How to integrate this library into my Laravel project?
update: at frontend I have this code:
<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: '[email protected]',
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>
Please or to participate in this conversation.