gruene-seele/app/Http/Controllers/Pay/PayController.php
2025-04-01 10:39:21 +02:00

214 lines
6.7 KiB
PHP

<?php
/*
* clearingtype
elv Debit payment
cc Credit card
rec Invoice
cod Cash on delivery
vor Prepayment
sb Online Bank Transfer
wlt e-wallet
fnc Financing
*/
/*private $payment_methods= [
'wlt#PPE' => 'PayPal',
'cc' => 'CreditCard',
'sb#GPY' => 'giropay',
'sb#PNT' => 'Sofort',
'wlt#PDT' => 'paydirekt',
'fnc' => 'Rechnungskauf',
'pref' => 'Vorauskasse',
];*/
namespace App\Http\Controllers\Pay;
use App\Http\Controllers\Controller;
use App\Models\PaymentTransaction;
use App\Models\ShoppingPayment;
use App\Services\Payone;
use Illuminate\Http\Request;
use Util;
use Yard;
class PayController extends Controller
{
private $default = [];
private $personalData = [];
private $method = [];
private $prepayment = [];
/* private $onlineTransfer = [];
private $creditCard = []; */
private $deliveryData = [];
// private $payment_method;
private $urls = [];
private $shopping_user;
private $shopping_order;
private $shopping_payment;
private $reference;
private $payment_method;
public function __construct() {
}
public function init($shopping_user, $shopping_order){
$this->shopping_user = $shopping_user;
$this->shopping_order = $shopping_order;
$this->default['mode'] = $this->shopping_order->mode;
}
public function getShoppingPayment(){
return $this->shopping_payment;
}
//make Payone payment
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 = [
"reference" => $this->reference, // a unique reference, e.g. order number
"amount" => $amount, // amount in smallest currency unit, i.e. cents
"currency" => $currency,
"param" => $this->shopping_order->id,
];
$this->shopping_payment = ShoppingPayment::create([
'shopping_order_id' => $this->shopping_order->id,
'clearingtype' => $this->method["clearingtype"],
'wallettype' => $this->method["wallettype"],
'onlinebanktransfertype' => $this->method["onlinebanktransfertype"],
'reference' => $this->reference,
'amount' => $amount,
'currency' => $currency,
'mode' => $this->shopping_order->mode,
]);
$this->default['mode'] = $this->shopping_order->mode;
return $this->reference;
}
public function setPersonalData(){
$this->personalData = [
"firstname" => $this->shopping_user->billing_firstname,
"lastname" => $this->shopping_user->billing_lastname, // mandatory
"street" => $this->shopping_user->billing_address,
"zip" => $this->shopping_user->billing_zipcode,
"city" => $this->shopping_user->billing_city,
"country" => ($this->shopping_user->billing_country) ? $this->shopping_user->billing_country->code : "DE", // mandatory
"email" => $this->shopping_user->billing_email,
// "language" => ($this->shopping_user->billing_country) ? strtoupper($this->shopping_user->billing_country->code) : "DE", // mandatory
"language" => "DE",
];
}
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",
"wallettype" => "",
'onlinebanktransfertype' => "",
"request" => "authorization",
];
}
//Rechnungskauf
if($payment_method === 'fnc'){
$this->method = [
"clearingtype" => "fnc",
"wallettype" => "",
'onlinebanktransfertype' => "",
"request" => "authorization",
];
}
//Rechnungskauf
if($payment_method === 'pp'){
$this->method = [
"clearingtype" => "pp",
"wallettype" => "",
'onlinebanktransfertype' => "",
"request" => "CAPTURE",
];
}
}
public function ResponseData($identifier, $payment_for = false){
$request = array_merge($this->default, $this->personalData, $this->deliveryData, $this->method, $this->prepayment, $this->urls);
$payt = PaymentTransaction::create([
'shopping_payment_id' => $this->shopping_payment->id,
'request' => $this->method['request'],
'txid' => 0,
'userid' => 0,
'status' => $this->shopping_payment->clearingtype,
'transmitted_data' => $request,
'txaction' => 'prev',
'mode' => $this->shopping_payment->mode,
]);
//paypal
if($this->payment_method === 'pp'){
switch ($payment_for) {
case 7: //promotion
$paypal = new PayPalController;
$redirect = $paypal->payment($this->shopping_payment, $payt, $identifier, $payment_for, $this->shopping_order->promotion_user_id);
Util::setUserHistoryValue(['status'=>4], $identifier);
return $redirect;
case 8: //shop
$paypal = new PayPalController;
$redirect = $paypal->payment($this->shopping_payment, $payt, $identifier, $payment_for, $this->shopping_order->user_shop_id);
Util::setUserHistoryValue(['status'=>4], $identifier);
return $redirect;
}
}
Util::setUserHistoryValue(['status'=>5], $identifier);
switch ($payment_for) {
case 7: //promotion
return redirect(route('web_promotion_goto', ['thanksorder', $this->shopping_order->promotion_user_id, $payt->id, $this->reference, $identifier]));
break;
case 8: //shop
return redirect(route('web_shop_goto', ['thanksorder', $this->shopping_order->user_shop_id, $payt->id, $this->reference, $identifier]));
break;
default:
return redirect(route('user_checkout_final', [$payt->id, $this->reference, $identifier]));
break;
}
}
}