update order
This commit is contained in:
parent
a193f54502
commit
6aebdb95be
|
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Services\PayPalService as PayPalSvc;
|
use Illuminate\Http\Request;
|
||||||
use Srmklive\PayPal\Services\PayPal as PayPalClient;
|
use Srmklive\PayPal\Services\PayPal as PayPalClient;
|
||||||
|
|
||||||
class PayPalController extends Controller
|
class PayPalController extends Controller
|
||||||
|
|
@ -31,7 +29,7 @@ class PayPalController extends Controller
|
||||||
$provider->setApiCredentials(config('paypal'));
|
$provider->setApiCredentials(config('paypal'));
|
||||||
$paypalToken = $provider->getAccessToken();
|
$paypalToken = $provider->getAccessToken();
|
||||||
|
|
||||||
$response = $provider->createOrder([
|
$order = $provider->createOrder([
|
||||||
"intent" => "CAPTURE",
|
"intent" => "CAPTURE",
|
||||||
"application_context" => [
|
"application_context" => [
|
||||||
"return_url" => route('paypal.payment.success'),
|
"return_url" => route('paypal.payment.success'),
|
||||||
|
|
@ -39,18 +37,52 @@ class PayPalController extends Controller
|
||||||
],
|
],
|
||||||
"purchase_units" => [
|
"purchase_units" => [
|
||||||
0 => [
|
0 => [
|
||||||
"amount" => [
|
'amount' => [
|
||||||
"currency_code" => "USD",
|
'currency_code' => 'EUR',
|
||||||
"value" => "100.00"
|
'value' => '5',
|
||||||
]
|
"breakdown" => [
|
||||||
]
|
"item_total" => [
|
||||||
]
|
"currency_code" => "EUR", "value" => "5",
|
||||||
|
],
|
||||||
|
"shipping" => [
|
||||||
|
"currency_code" => "EUR", "value" => "0",
|
||||||
|
],
|
||||||
|
"tax_total" => [
|
||||||
|
"currency_code" => "EUR", "value" => "0",
|
||||||
|
],
|
||||||
|
"discount" => [
|
||||||
|
"currency_code" => "EUR", "value" => "0",
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'items' => [
|
||||||
|
[
|
||||||
|
'name' => 'photo',
|
||||||
|
'sku' => 'photo001',
|
||||||
|
'quantity' => '3',
|
||||||
|
'unit_amount' => [
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'value' => '1.00',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'oto',
|
||||||
|
'sku' => 'oto001',
|
||||||
|
'quantity' => '2',
|
||||||
|
'unit_amount' => [
|
||||||
|
'currency_code' => 'EUR',
|
||||||
|
'value' => '1.00',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
dd($order);
|
||||||
|
if (isset($order['id']) && null != $order['id']) {
|
||||||
|
|
||||||
if (isset($response['id']) && $response['id'] != null) {
|
foreach ($order['links'] as $links) {
|
||||||
|
if ('approve' == $links['rel']) {
|
||||||
foreach ($response['links'] as $links) {
|
|
||||||
if ($links['rel'] == 'approve') {
|
|
||||||
return redirect()->away($links['href']);
|
return redirect()->away($links['href']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -58,8 +90,11 @@ class PayPalController extends Controller
|
||||||
return redirect(route('cancel.payment'))->with('error', 'Something went wrong.');
|
return redirect(route('cancel.payment'))->with('error', 'Something went wrong.');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
return response([
|
||||||
|
$order['message'] ?? 'Something went wrong.',
|
||||||
|
]);
|
||||||
return redirect(route('create.payment'))
|
return redirect(route('create.payment'))
|
||||||
->with('error', $response['message'] ?? 'Something went wrong.');
|
->with('error', $order['message'] ?? 'Something went wrong.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +122,7 @@ class PayPalController extends Controller
|
||||||
$provider->getAccessToken();
|
$provider->getAccessToken();
|
||||||
$response = $provider->capturePaymentOrder($request['token']);
|
$response = $provider->capturePaymentOrder($request['token']);
|
||||||
|
|
||||||
if (isset($response['status']) && $response['status'] == 'COMPLETED') {
|
if (isset($response['status']) && 'COMPLETED' == $response['status']) {
|
||||||
return redirect(route('paypal'))->with('success', 'Transaction complete.');
|
return redirect(route('paypal'))->with('success', 'Transaction complete.');
|
||||||
} else {
|
} else {
|
||||||
return redirect(route('paypal'))
|
return redirect(route('paypal'))
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
use App\Http\Controllers\PayPalController;
|
use App\Http\Controllers\PayPalController;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Srmklive\PayPal\Services\PayPal as PayPalClient;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
@ -20,3 +21,26 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::post('create-payment', [PayPalController::class, 'index'])->name('payment.create');
|
Route::post('create-payment', [PayPalController::class, 'index'])->name('payment.create');
|
||||||
|
Route::get('invoices', function () {
|
||||||
|
$provider = new PayPalClient;
|
||||||
|
$provider->setApiCredentials(config('paypal'));
|
||||||
|
$provider->getAccessToken();
|
||||||
|
|
||||||
|
$data = json_decode('{
|
||||||
|
"name": "Video Streaming Service",
|
||||||
|
"description": "Video streaming service",
|
||||||
|
"type": "SERVICE",
|
||||||
|
"category": "SOFTWARE",
|
||||||
|
"image_url": "https://example.com/streaming.jpg",
|
||||||
|
"home_url": "https://example.com/home"
|
||||||
|
}', true);
|
||||||
|
|
||||||
|
$product = $provider->setRequestHeader('PayPal-Request-Id', 'create-product-' . time())->createProduct($data);
|
||||||
|
|
||||||
|
$inv = $provider->showOrderDetails('0KX38537YL610435R');
|
||||||
|
// $invoice_no = $provider->generateInvoiceNumber();
|
||||||
|
|
||||||
|
dd(
|
||||||
|
$inv
|
||||||
|
);
|
||||||
|
})->name('payment.invoices');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue