У меня есть следующее на мой взгляд:
<a href="{{route('payment.paypal')}}">Pay with PayPal</a>
Определил маршрут:
Route::get('pay-with-paypal', 'CheckoutController@payWithPaypal')->name('payment.paypal');
Мой CheckoutController выглядит как показано ниже:
use Srmklive\PayPal\Services\ExpressCheckout;
class CheckoutController extends Controller
{
public function payWithPaypal(){
$provider = new ExpressCheckout;
$data = [];
$data['items'] = [
[
'name' => 'Product 1',
'price' => 9.99,
'qty' => 1
],
[
'name' => 'Product 2',
'price' => 4.99,
'qty' => 2
]
];
$data['invoice_id'] = 1;
$data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
$data['return_url'] = url('/');
$data['cancel_url'] = url('/');
$total = 0;
foreach($data['items'] as $item) {
$total += $item['price']*$item['qty'];
}
$data['total'] = $total;
$response = $provider->setExpressCheckout($data);
// This will redirect user to PayPal
return redirect($response['paypal_link']);
}
}
Мой конфиг выглядит так:
return [
'mode' => 'sandbox', // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
'sandbox' => [
'username' => env('PAYPAL_SANDBOX_API_USERNAME', ''),
'password' => env('PAYPAL_SANDBOX_API_PASSWORD', ''),
'secret' => env('PAYPAL_SANDBOX_API_SECRET', ''),
'certificate' => env('PAYPAL_SANDBOX_API_CERTIFICATE', ''),
'app_id' => 'APP-80W284485P519543T', // Used for testing Adaptive Payments API in sandbox mode
],
'live' => [
'username' => env('PAYPAL_LIVE_API_USERNAME', ''),
'password' => env('PAYPAL_LIVE_API_PASSWORD', ''),
'secret' => env('PAYPAL_LIVE_API_SECRET', ''),
'certificate' => env('PAYPAL_LIVE_API_CERTIFICATE', ''),
'app_id' => '', // Used for Adaptive Payments API
],
'payment_action' => 'Sale', // Can only be 'Sale', 'Authorization' or 'Order'
'currency' => 'USD',
'billing_type' => 'MerchantInitiatedBilling',
'notify_url' => '', // Change this accordingly for your application.
'locale' => '', // force gateway language i.e. it_IT, es_ES, en_US ... (for express checkout only)
'validate_ssl' => true, // Validate SSL when creating api client.
];
Мой .env также настроен:
PAYPAL_SANDBOX_API_USERNAME=example-facilitator_api1.hotmail.com
PAYPAL_SANDBOX_API_PASSWORD=SLU2YLP4B
PAYPAL_SANDBOX_API_SECRET=TF3K8CtWTEmAcRu40.XWAihLRko
PAYPAL_SANDBOX_API_CERTIFICATE=
Когда я нажимаю на ссылку «Pay with PayPal», ничего не происходит.Что-то, что я мог сделать неправильно?
Ссылка: https://github.com/srmklive/laravel-paypal