promotion 1.0
This commit is contained in:
parent
1cc8e025a1
commit
570d428b1c
60 changed files with 1596 additions and 272 deletions
|
|
@ -59,6 +59,8 @@ class PayController extends Controller
|
|||
|
||||
private $reference;
|
||||
|
||||
private $payment_method;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
|
@ -77,6 +79,7 @@ class PayController extends Controller
|
|||
public function setPrePayment($payment_method, $amount, $currency, $ret = []){
|
||||
|
||||
$this->reference = $this->shopping_order->created_at->format('Ym').$this->shopping_order->id;//substr(uniqid('m', false), 0, 16);
|
||||
$this->payment_method = $payment_method;
|
||||
$this->setMethod($payment_method, $ret);
|
||||
|
||||
$this->prepayment = [
|
||||
|
|
@ -86,7 +89,6 @@ class PayController extends Controller
|
|||
"param" => $this->shopping_order->id,
|
||||
|
||||
];
|
||||
|
||||
$this->shopping_payment = ShoppingPayment::create([
|
||||
'shopping_order_id' => $this->shopping_order->id,
|
||||
'clearingtype' => $this->method["clearingtype"],
|
||||
|
|
@ -119,6 +121,15 @@ class PayController extends Controller
|
|||
private function setMethod($payment_method, $ret = []){
|
||||
|
||||
//vorkasse
|
||||
if($payment_method === 'non'){
|
||||
$this->method = [
|
||||
"clearingtype" => "non",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "authorization",
|
||||
];
|
||||
}
|
||||
|
||||
if($payment_method === 'vor'){
|
||||
$this->method = [
|
||||
"clearingtype" => "vor",
|
||||
|
|
@ -138,12 +149,21 @@ class PayController extends Controller
|
|||
];
|
||||
}
|
||||
|
||||
//Rechnungskauf
|
||||
if($payment_method === 'pp'){
|
||||
$this->method = [
|
||||
"clearingtype" => "pp",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "CAPTURE",
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function ResponseData($identifier){
|
||||
public function ResponseData($identifier, $payment_for = false){
|
||||
|
||||
$request = array_merge($this->default, $this->personalData, $this->deliveryData, $this->method, $this->prepayment, $this->urls);
|
||||
//RECHNUNG MIV
|
||||
|
||||
$payt = PaymentTransaction::create([
|
||||
'shopping_payment_id' => $this->shopping_payment->id,
|
||||
|
|
@ -155,10 +175,26 @@ class PayController extends Controller
|
|||
'txaction' => 'prev',
|
||||
'mode' => $this->shopping_payment->mode,
|
||||
]);
|
||||
//paypal
|
||||
if($this->payment_method === 'pp'){
|
||||
$paypal = new PayPalController;
|
||||
$redirect = $paypal->payment($this->shopping_payment, $payt, $identifier, $this->shopping_order->promotion_user_id);
|
||||
Util::setUserHistoryValue(['status'=>4], $identifier);
|
||||
return $redirect;
|
||||
|
||||
}
|
||||
|
||||
Util::setUserHistoryValue(['status'=>5], $identifier);
|
||||
return redirect(route('user_checkout_final', [$payt->id, $this->reference, $identifier]));
|
||||
switch ($payment_for) {
|
||||
case 4: //promotion
|
||||
return redirect(route('web_promotion_goto', ['thanksorder', $this->shopping_order->promotion_user_id, $payt->id, $this->reference, $identifier]));
|
||||
break;
|
||||
|
||||
default:
|
||||
return redirect(route('user_checkout_final', [$payt->id, $this->reference, $identifier]));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
95
app/Http/Controllers/Pay/PayPalController.php
Normal file
95
app/Http/Controllers/Pay/PayPalController.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Pay;
|
||||
use Request;
|
||||
use App\Models\PromotionUser;
|
||||
use App\Models\PaymentTransaction;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Srmklive\PayPal\Services\PayPal as PayPalClient;
|
||||
|
||||
|
||||
class PayPalController extends Controller
|
||||
{
|
||||
|
||||
public function payment($shopping_payment, $payt, $identifier, $promotion_user_id)
|
||||
{
|
||||
$provider = new PayPalClient;
|
||||
// Through facade. No need to import namespaces
|
||||
|
||||
$provider = \PayPal::setProvider();
|
||||
$provider->setApiCredentials(config('paypal'));
|
||||
$provider->setAccessToken($provider->getAccessToken());
|
||||
$provider->setCurrency('EUR');
|
||||
|
||||
$order = $provider->createOrder([
|
||||
"intent"=> "CAPTURE",
|
||||
"purchase_units"=> [
|
||||
[
|
||||
"reference_id" => $shopping_payment->reference,
|
||||
"shopping_order_id" => $shopping_payment->shopping_order_id,
|
||||
"amount"=> [
|
||||
"currency_code"=> "USD",
|
||||
"value"=> ($shopping_payment->amount / 100)
|
||||
],
|
||||
'description' => 'test'
|
||||
]
|
||||
],
|
||||
'application_context' => [
|
||||
'cancel_url' => route('cancel.paypal_payment', [$promotion_user_id, $payt->id, $shopping_payment->reference, $identifier]),
|
||||
'return_url' => route('success.paypal_payment', [$promotion_user_id, $payt->id, $shopping_payment->reference, $identifier])
|
||||
]
|
||||
|
||||
]);
|
||||
$payt->key = $order['id'];
|
||||
$payt->save();
|
||||
return redirect($order['links'][1]['href'])->send();
|
||||
|
||||
}
|
||||
|
||||
public function paymentSuccess($id, $transactionId=false, $reference=false, $identifier=false)
|
||||
{
|
||||
$PromotionUser = PromotionUser::findOrFail($id);
|
||||
$payt = PaymentTransaction::findOrFail($transactionId);
|
||||
if($payt->shopping_payment->reference != $reference){
|
||||
abort(404);
|
||||
}
|
||||
// Init PayPal
|
||||
$provider = \PayPal::setProvider();
|
||||
$provider->setApiCredentials(config('paypal'));
|
||||
$provider->setAccessToken($provider->getAccessToken());
|
||||
|
||||
// Get PaymentOrder using our transaction ID
|
||||
$order = $provider->capturePaymentOrder($payt->key);
|
||||
if(isset($order['type'])){
|
||||
abort(403, 'PayPal Type: '.$order['type']);
|
||||
}
|
||||
|
||||
if(!isset($order['status']) || $order['status'] !== "COMPLETED"){
|
||||
abort(403, 'Error: Order Status ');
|
||||
}
|
||||
|
||||
if(Request::get('token') !== $payt->key){
|
||||
abort(403, 'Error: PayPal token');
|
||||
}
|
||||
$payt->request = $order['status'];
|
||||
$payt->save();
|
||||
return redirect(route('web_promotion_goto', ['thanksorder', $id, $payt->id, $reference, $identifier]));
|
||||
|
||||
}
|
||||
|
||||
public function paymentCancel($id, $transactionId=false, $reference=false, $identifier=false)
|
||||
{
|
||||
$PromotionUser = PromotionUser::findOrFail($id);
|
||||
|
||||
return redirect(url($PromotionUser->url));
|
||||
dd('Your payment has been declend. The payment cancelation page goes here!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue