Payone, Shop, wizard

This commit is contained in:
Kevin Adametz 2019-03-04 17:05:44 +01:00
parent 446bc4561b
commit 044a6bf253
28 changed files with 996 additions and 814 deletions

View file

@ -0,0 +1,161 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Mail\MailCheckout;
use App\Models\PaymentTransaction;
use App\Models\ShoppingOrder;
use App\Models\ShoppingPayment;
use App\User;
use Illuminate\Support\Facades\Mail;
class PayoneController extends Controller
{
public function __construct()
{
}
public function paymentStatus(){
$data = \Request::all();
// test para
/* $data = [
'key' => '698fb2555f8b2efc74f60b2121421f45',
'txaction' => 'paid',
'clearingtype' => 'wlt',
'userid' => '158006846',
'txid' => '320267294',
'price' => '59.00',
'param' => '18', //$this->shopping_order->id,
'reference' => '15c79ba77992e2',
];
*/
if(!isset($data['key']) || !isset($data['param']) || !isset($data['userid']) || !isset($data['txid']) || !isset($data['reference']) || !isset($data['price'])){
\Log::channel('payone')->error('PaymentStatus: parameter incomplete: '.json_encode($data));
echo "PaymentStatus: parameter incomplete:";
var_dump($data);
die();
}
if($data['key'] != config('payone.defaults.key')) {
\Log::channel('payone')->error('PaymentStatus: Key error: '.json_encode($data));
echo "PaymentStatus: Key error:";
var_dump($data);
die();
}
$shopping_order = ShoppingOrder::find($data['param']);
if(!$shopping_order){
\Log::channel('payone')->error('PaymentStatus: ShoppingOrder not found: '.json_encode($data));
echo "PaymentStatus: ShoppingOrder not found:";
var_dump($data);
die();
}
$shopping_payment = ShoppingPayment::where('reference', $data['reference'])->first();
if(!$shopping_payment){
\Log::channel('payone')->error('PaymentStatus: ShoppingPayment not found: '.json_encode($data));
echo "PaymentStatus: ShoppingPayment not found:";
var_dump($data);
die();
}
if($shopping_payment->shopping_order_id != $shopping_order->id){
\Log::channel('payone')->error('PaymentStatus: ShoppingPayment no realation ShoppingOrder: '.json_encode($data));
echo "PaymentStatus: ShoppingPayment no realation ShoppingOrder:";
var_dump($data);
die();
}
if($data['key'] != config('payone.defaults.key')) {
\Log::channel('payone')->error('PaymentStatus: Key error: '.json_encode($data));
echo "PaymentStatus: ShoppingPayment no realation ShoppingOrder:";
var_dump($data);
die();
}
$price = intval($data['price']*100);
if($shopping_payment->amount != $price){
\Log::channel('payone')->error('PaymentStatus: Price error: '.json_encode($data));
echo "PaymentStatus: Price error:";
var_dump($data);
die();
}
//create transaction
PaymentTransaction::create([
'shopping_payment_id' => $shopping_payment->id,
'request' => 'transaction',
'txid' => $data['txid'],
'userid' => $data['userid'],
'status' => 'PAYONE',
'key' => $data['key'],
'txaction' => $data['txaction'],
'transmitted_data' => $data,
]);
$shopping_order->txaction = $data['txaction'];
$shopping_order->save();
$shopping_payment->txaction = $data['txaction'];
$shopping_payment->save();
if($data['txaction'] == 'failed'){
}
if($data['txaction'] == 'paid'){
$shopping_order->paid = true;
$shopping_order->save();
//if product has actions
if($shopping_order->shopping_order_items && $shopping_order->auth_user_id){
foreach($shopping_order->shopping_order_items as $shopping_order_item){
if($shopping_order_item->product){
if($shopping_order_item->product->action){
$user = User::findOrFail($shopping_order->auth_user_id);
foreach ($shopping_order_item->product->action as $do){
if($shopping_order_item->product->getActionName($do) == 'payment_for_account'){
$user->payment_account = date("Y-m-d H:i:s", strtotime("+1 years"));
$user->wizard = 10;
}
if($shopping_order_item->product->getActionName($do) == 'payment_for_shop'){
$user->payment_shop = date("Y-m-d H:i:s", strtotime("+1 years"));
$user->wizard = 10;
}
$user->save();
}
}
}
}
}
}
if($data['txaction'] == 'appointed'){
}
$billing_email = $shopping_order->shopping_user->billing_email;
$user_shop_email = $shopping_order->user_shop->user->email;
if(!$billing_email){
$billing_email = config('app.checkout_mail');
}
$checkout_mail = config('app.checkout_mail');
if($user_shop_email){
Mail::to($billing_email)->bcc([$user_shop_email, $checkout_mail])->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment));
}else{
Mail::to($billing_email)->bcc($checkout_mail)->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment));
}
print("TSOK");
exit;
}
}

View file

@ -111,40 +111,18 @@ class PayoneController extends Controller
return $this->reference;
}
public function setPersonalData($data){
public function setPersonalData(){
$this->personalData = [
// "salutation" => "Mr.",
// "firstname" => "Henry",
"lastname" => "Player", // mandatory
// "street" => "Royal Street 1",
// "zip" => "24118",
// "city" => "Kiel",
"country" => "DE", // mandatory
//"email" => " info-buyer@mivita.care",
"language" => "de"
"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) ? strtolower($this->shopping_user->billing_country->code) : "DE", // mandatory
];
/* $this->personalData = array(
"salutation" => "Herr",
"title" => "Dr.",
"firstname" => "Paul",
"lastname" => "Neverpayer",
"street" => "Fraunhoferstraße 2-4",
"addressaddition" => "EG",
"zip" => "24118",
"city" => "Kiel",
"country" => "DE",
"email" => "paul.neverpayer@payone.de",
"telephonenumber" => "043125968500",
"birthday" => "19700204",
"language" => "de",
"gender" => "m",
"ip" => "8.8.8.8"
);
*/
/**
* Paydirekt requires both, personal data and shipping data
*/
@ -157,9 +135,6 @@ class PayoneController extends Controller
"shipping_country" => "DE"
);*/
}
private function setMethod($payment_method, $cc_ret = []){

View file

@ -43,23 +43,31 @@ class UserDataController extends Controller
/*if(!$user->account){
$user->account = new UserAccount();
}*/
$rules = array(
'salutation' => 'required',
'last_name' => 'required|max:255',
'country_id' => 'required|integer|min:1',
'first_name'=>'required',
'last_name'=>'required',
'address'=>'required',
'zipcode'=>'required',
'city' => 'required',
'email' => 'required|string|email|max:255|exists:users,email',
'email-confirm' => 'required|same:email',
);
if(!Input::get('same_as_billing')){
$rules = array_merge($rules, [
'shipping_firstname'=>'required',
'shipping_lastname'=>'required',
'shipping_address'=>'required',
'shipping_zipcode'=>'required',
'shipping_city' => 'required',
'shipping_salutation' => 'required'
if(Input::get('company') == 1){
$rules['company_name'] = 'required|max:255';
$rules['company_country_id'] = 'required|integer|min:1';
]);
}
$data = [
'user' => $user,
];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {

View file

@ -7,6 +7,7 @@ use App\Models\UserShop;
use App\Models\UserShopOnSite;
use App\Repositories\UserRepository;
use Auth;
use Cviebrock\EloquentSluggable\Services\SlugService;
use Input;
use Response;
use Validator;
@ -370,22 +371,19 @@ class UserShopController extends Controller
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
$messages = $validator->messages();
//$messages = $validator->messages();
return Response::json(array(
'success' => false,
'errors' => $validator->getMessageBag()->toArray()
));
}
return Response::json(array(
'success' => true,
));
$slug = SlugService::createSlug(UserShop::class, 'slug', Input::get('user_shop_name'));
return Response::json(array(
'success' => true,
'preview_user_shop_name' => "http://".$slug.".".config('app.domain'),
));
}
}

View file

@ -35,6 +35,8 @@ class CardController extends Controller
$image = $product->images->first()->slug;
}
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product_slug, 'weight' => $product->weight]);
Yard::instance('shopping')->reCalculateShippingPrice();
\Session()->flash('show-card-after-add', true);
}
@ -54,6 +56,8 @@ class CardController extends Controller
}
$quantity = Input::get('quantity') ? Input::get('quantity') : 1;
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
Yard::instance('shopping')->reCalculateShippingPrice();
\Session()->flash('show-card-after-add', true);
}
return back();
@ -66,8 +70,7 @@ class CardController extends Controller
if(Input::get('selected_country')){
Yard::instance('shopping')->setShippingCountryWithPrice(Input::get('selected_country'));
}else{
// $ShippingCountry = ShippingCountry::where('country_id', 1)->first();
// $selected_country = $ShippingCountry->id;
Yard::instance('shopping')->reCalculateShippingPrice();
}
$data = [
'user_shop' => Util::getUserShop(),
@ -81,6 +84,7 @@ class CardController extends Controller
if(isset($data['quantity'])){
foreach ($data['quantity'] as $rowId => $qty){
Yard::instance('shopping')->update($rowId, $qty);
Yard::instance('shopping')->reCalculateShippingPrice();
}
}else{
$this->deleteCard();

View file

@ -5,16 +5,13 @@ namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Pay\PayoneController;
use App\Mail\MailCheckout;
use App\Models\PaymentTransaction;
use App\Models\ShoppingOrder;
use App\Models\ShoppingOrderItem;
use App\Models\ShoppingPayment;
use App\Models\ShoppingUser;
use App\User;
use Illuminate\Session\SessionManager;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Mail;
use Validator;
use App\Services\Util;
use Yard;
@ -167,7 +164,7 @@ class CheckoutController extends Controller
$amount = intval(floatval(Yard::instance('shopping')->totalWithShipping(2, '.', ',')) *100);
$reference = $pay->setPrePayment(Input::get('payment_method'), $amount, 'EUR', $cc_ret);
$this->putPayments('payment_reference', $reference);
$pay->setPersonalData([]);
$pay->setPersonalData();
return $pay->ResponseData();
}
@ -231,127 +228,6 @@ class CheckoutController extends Controller
return view('web.templates.checkout-final', $data);
}
public function paymentStatus(){
$data = \Request::all();
// test para
$data = [
'key' => '698fb2555f8b2efc74f60b2121421f45',
'txaction' => 'paid',
'clearingtype' => 'wlt',
'userid' => '158006846',
'txid' => '320267294',
'price' => '59.00',
'param' => '18', //$this->shopping_order->id,
'reference' => '15c79ba77992e2',
];
if(!isset($data['key']) || !isset($data['param']) || !isset($data['userid']) || !isset($data['txid']) || !isset($data['reference']) || !isset($data['price'])){
\Log::channel('payone')->error('PaymentStatus: parameter incomplete: '.json_encode($data));
abort(404);
}
if($data['key'] != config('payone.defaults.key')) {
\Log::channel('payone')->error('PaymentStatus: Key error: '.json_encode($data));
abort(404);
}
$shopping_order = ShoppingOrder::find($data['param']);
if(!$shopping_order){
\Log::channel('payone')->error('PaymentStatus: ShoppingOrder not found: '.json_encode($data));
abort(404);
}
$shopping_payment = ShoppingPayment::where('reference', $data['reference'])->first();
if(!$shopping_payment){
\Log::channel('payone')->error('PaymentStatus: ShoppingPayment not found: '.json_encode($data));
abort(404);
}
if($shopping_payment->shopping_order_id != $shopping_order->id){
\Log::channel('payone')->error('PaymentStatus: ShoppingPayment no realation ShoppingOrder: '.json_encode($data));
abort(404);
}
if($data['key'] != config('payone.defaults.key')) {
\Log::channel('payone')->error('PaymentStatus: Key error: '.json_encode($data));
abort(404);
}
$price = intval($data['price']*100);
if($shopping_payment->amount != $price){
\Log::channel('payone')->error('PaymentStatus: Price error: '.json_encode($data));
abort(404);
}
//create transaction
PaymentTransaction::create([
'shopping_payment_id' => $shopping_payment->id,
'request' => 'transaction',
'txid' => $data['txid'],
'userid' => $data['userid'],
'status' => 'PAYONE',
'key' => $data['key'],
'txaction' => $data['txaction'],
'transmitted_data' => $data,
]);
$shopping_order->txaction = $data['txaction'];
$shopping_order->save();
$shopping_payment->txaction = $data['txaction'];
$shopping_payment->save();
if($data['txaction'] == 'failed'){
}
if($data['txaction'] == 'paid'){
$shopping_order->paid = true;
$shopping_order->save();
//if product has actions
if($shopping_order->shopping_order_items && $shopping_order->auth_user_id){
foreach($shopping_order->shopping_order_items as $shopping_order_item){
if($shopping_order_item->product){
if($shopping_order_item->product->action){
$user = User::findOrFail($shopping_order->auth_user_id);
foreach ($shopping_order_item->product->action as $do){
if($shopping_order_item->product->getActionName($do) == 'payment_for_account'){
$user->payment_account = date("Y-m-d H:i:s", strtotime("+1 years"));
$user->wizard = 10;
}
if($shopping_order_item->product->getActionName($do) == 'payment_for_shop'){
$user->payment_shop = date("Y-m-d H:i:s", strtotime("+1 years"));
$user->wizard = 10;
}
$user->save();
}
}
}
}
}
}
if($data['txaction'] == 'appointed'){
}
$billing_email = $shopping_order->shopping_user->billing_email;
$user_shop_email = $shopping_order->user_shop->user->email;
if(!$billing_email){
$billing_email = config('app.checkout_mail');
}
$checkout_mail = config('app.checkout_mail');
if($user_shop_email){
Mail::to($billing_email)->bcc([$user_shop_email, $checkout_mail])->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment));
}else{
Mail::to($billing_email)->bcc($checkout_mail)->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment));
}
die("ok");
}
private function makeShoppingUser($data){
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;

View file

@ -33,6 +33,9 @@ class SiteController extends Controller
return view('web.index', $data);
}
public function domainCheck(){
die("checked");
}
public function site($site, $subsite = false, $product_slug = false)
{

View file

@ -181,7 +181,7 @@ class WizardController extends Controller
//add to DB
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
$path = str_replace('http', 'https', $path);
//$path = str_replace('http', 'https', $path);
return redirect()->secure($path);