payment Card first 4 payments inc. mails
This commit is contained in:
parent
c20deac3fe
commit
6e3adac4d7
38 changed files with 3063 additions and 921 deletions
|
|
@ -1,12 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Pay;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Payone;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
/*
|
||||
* clearingtype
|
||||
elv Debit payment
|
||||
|
|
@ -18,8 +11,27 @@ 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 PayoneController extends Controller
|
||||
{
|
||||
|
|
@ -30,210 +42,264 @@ class PayoneController extends Controller
|
|||
const REFUND = 'refund';
|
||||
const DEBIT = 'debit';
|
||||
|
||||
|
||||
private $default = [];
|
||||
|
||||
private $personalData = [];
|
||||
private $deliveryData = [];
|
||||
|
||||
private $method = [];
|
||||
private $prepayment = [];
|
||||
private $onlineTransfer = [];
|
||||
private $creditCard = [];
|
||||
|
||||
private $url = [];
|
||||
/* private $onlineTransfer = [];
|
||||
private $creditCard = []; */
|
||||
private $deliveryData = [];
|
||||
|
||||
|
||||
// private $payment_method;
|
||||
private $urls = [];
|
||||
|
||||
private $shopping_user;
|
||||
private $shopping_order;
|
||||
private $shopping_payment;
|
||||
|
||||
private $reference;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
$this->default = \Config::get('payone.defaults');
|
||||
}
|
||||
|
||||
|
||||
public function init($shopping_user, $shopping_order){
|
||||
$this->shopping_user = $shopping_user;
|
||||
$this->shopping_order = $shopping_order;
|
||||
}
|
||||
|
||||
public function getShoppingPayment(){
|
||||
return $this->shopping_payment;
|
||||
}
|
||||
|
||||
//make Payone payment
|
||||
public function setPrePayment($payment_method, $amount, $currency, $cc_ret = []){
|
||||
|
||||
$this->reference = substr(uniqid(true), 0, 16);
|
||||
$this->setMethod($payment_method, $cc_ret);
|
||||
|
||||
$this->urls = [
|
||||
'successurl' => route('checkout.transaction_status', ['success', $this->reference]),
|
||||
'errorurl' => route('checkout.transaction_status', ['error', $this->reference]),
|
||||
'backurl' => route('checkout.transaction_status', ['cancel', $this->reference]),
|
||||
];
|
||||
|
||||
$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,
|
||||
]);
|
||||
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
public function setPersonalData($data){
|
||||
|
||||
$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"
|
||||
];
|
||||
|
||||
|
||||
/* $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
|
||||
*/
|
||||
/* $this->deliveryData = array(
|
||||
"shipping_firstname" => "Paul",
|
||||
"shipping_lastname" => "Neverpayer",
|
||||
"shipping_street" => "Hamburger Allee 26-28",
|
||||
"shipping_zip" => "60486",
|
||||
"shipping_city" => "Frankfurt am Main",
|
||||
"shipping_country" => "DE"
|
||||
);*/
|
||||
|
||||
|
||||
|
||||
public function __construct($payment_method = null) {
|
||||
|
||||
}
|
||||
|
||||
private function setMethod($payment_method, $cc_ret = []){
|
||||
|
||||
if($payment_method){
|
||||
|
||||
if(strpos($payment_method, '#')){
|
||||
$payment_method = explode('#', $payment_method);
|
||||
//wallet
|
||||
//wallet Paypal
|
||||
if($payment_method[0] == 'wlt'){
|
||||
$this->method = [
|
||||
"clearingtype" => "wlt",
|
||||
"wallettype" => $payment_method[1],
|
||||
"request" => "authorization",
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "authorization"
|
||||
];
|
||||
}
|
||||
//Online-Überweisung
|
||||
if($payment_method[0] == 'sb'){
|
||||
$this->method = [
|
||||
"clearingtype" => "sb",
|
||||
"wallettype" => "",
|
||||
"onlinebanktransfertype" => $payment_method[1], // this is the type for Sofort.com
|
||||
"bankcountry" => "DE", // we need to know the country of the customer's bank, i.e. of the invoice address
|
||||
"request" => "authorization",
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
//Rechnungskauf
|
||||
/* if($payment_method[0]== 'fnc'){
|
||||
$this->method = [
|
||||
"clearingtype" => "fnc",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "",
|
||||
"financingtype" => "PYV",
|
||||
"request" => "genericpayment",
|
||||
"add_paydata[action]" => "pre_check",
|
||||
"add_paydata[payment_type]" => "Payolution-Invoicing",
|
||||
];
|
||||
}
|
||||
*/
|
||||
}
|
||||
//vorkasse
|
||||
if($payment_method == 'vor'){
|
||||
$this->method = [
|
||||
"clearingtype" => "vor",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "preauthorization",
|
||||
];
|
||||
}
|
||||
//CreditCard
|
||||
if($payment_method == 'cc'){
|
||||
//need the $cc_ret
|
||||
$this->method = [
|
||||
"clearingtype" => "cc",
|
||||
"wallettype" => "",
|
||||
'onlinebanktransfertype' => "",
|
||||
"request" => "authorization",
|
||||
"pseudocardpan" => $cc_ret['pseudocardpan']
|
||||
//"xid" => "3-D Secure transaction ID"
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
$this->default = \Config::get('payone.defaults');
|
||||
$this->url['successurl'] = route('checkout.transaction_status', ['success']);
|
||||
$this->url['errorurl'] = route('checkout.transaction_status', ['error']);
|
||||
$this->url['backurl'] = route('checkout.transaction_status', ['cancel']);
|
||||
|
||||
}
|
||||
|
||||
//make Payone payment
|
||||
|
||||
public function setPrePayment($data){
|
||||
|
||||
/* $this->prepayment = [
|
||||
"clearingtype" => "sb", // sb means online bank transfer
|
||||
"reference" => time(), // a unique reference, e.g. order number
|
||||
"amount" => "10000", // amount in smallest currency unit, i.e. cents
|
||||
"currency" => "EUR",
|
||||
"request" => "preauthorization", // create account receivable and instantly book the amount
|
||||
"onlinebanktransfertype" => "PNT", // this is the type for Sofort.com
|
||||
"bankcountry" => "DE", // we need to know the country of the customer's bank, i.e. of the invoice add
|
||||
//"request" => "preauthorization" // create account receivable
|
||||
];*/
|
||||
|
||||
$this->prepayment = [
|
||||
"reference" => time(), // a unique reference, e.g. order number
|
||||
"amount" => "10000", // amount in smallest currency unit, i.e. cents
|
||||
"currency" => "EUR",
|
||||
|
||||
|
||||
/* "clearingtype" => "wlt", // sb means online bank transfer
|
||||
"wallettype" => "PPE",
|
||||
"request" => "authorization",
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* "request" => "preauthorization",
|
||||
"cardpan" => "4301111100070203",
|
||||
"cardexpiredate" => "2105",
|
||||
"cardtype" => "V",
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
//"pseudocardpan" => "9410009000000005606",
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function creditCardCheck($data){
|
||||
|
||||
$this->prepayment = [
|
||||
"request" => "creditcardcheck", // create account receivable and instantly book the amount
|
||||
"cardpan" => "4111111111111111",
|
||||
"cardexpiredate" => "2105",
|
||||
"cardtype" => "V",
|
||||
"cardcvc2" => "123",
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
public function setPersonalData($data){
|
||||
|
||||
$this->personalData = [
|
||||
// "salutation" => "Mr.",
|
||||
// "firstname" => "Henry",
|
||||
"lastname" => "Payer", // mandatory
|
||||
// "street" => "Royal Street 1",
|
||||
// "zip" => "24118",
|
||||
// "city" => "Kiel",
|
||||
"country" => "DE", // mandatory
|
||||
// "email" => "henry.viii@tudor.gov.uk",
|
||||
"language" => "de"
|
||||
];
|
||||
}
|
||||
|
||||
public function setDeliverylData($data){
|
||||
$this->deliveryData = [
|
||||
"shipping_company" => "Mr.",
|
||||
"shipping_firstname" => "Henry",
|
||||
"shipping_lastname" => "Tudor",
|
||||
"shipping_street" => "Royal Street 1",
|
||||
"shipping_zip" => "24118",
|
||||
"shipping_city" => "Kiel",
|
||||
"shipping_country" => "DE",
|
||||
];
|
||||
}
|
||||
|
||||
public function checkStatus(){
|
||||
// again, the default values will be needed
|
||||
$capture = array(
|
||||
"request" => "capture",
|
||||
"txid" => "your_txid",
|
||||
"sequencenumber" => "previous_sequencenumber_plus_one", // get this from the last received transactionsstatus
|
||||
"amount" => "your_amount", // you can either capture the full amount of the tx, or less
|
||||
"currency" => "EUR"
|
||||
);
|
||||
$request = array_merge($this->default, $capture);
|
||||
$response = Payone::sendRequest($request);
|
||||
|
||||
}
|
||||
|
||||
public function ResponseData(){
|
||||
|
||||
|
||||
$request = array_merge($this->default, $this->personalData, $this->deliveryData, $this->method, $this->prepayment, $this->urls);
|
||||
|
||||
|
||||
|
||||
$request = array_merge($this->default, $this->personalData, $this->method, $this->prepayment, $this->url);
|
||||
// var_dump($request);
|
||||
// echo "<br><br><br>";
|
||||
$response = Payone::sendRequest($request);
|
||||
/*
|
||||
* status APPROVED / REDIRECT / ERROR / PENDING
|
||||
* */
|
||||
|
||||
//cc
|
||||
|
||||
var_dump($response);
|
||||
die();
|
||||
if ($response["status"] == "REDIRECT") { // this happens when the card needs a 3d secure verification
|
||||
header("Location: " . $response["redirecturl"]); // or other redirect method
|
||||
} elseif ($response["status"] == "APPROVED") { // no 3d secure verification required, transaction went through
|
||||
echo "Thank you for your purchase.";
|
||||
var_dump($response);
|
||||
die();
|
||||
} else {
|
||||
echo "There has been an error processing your request.";
|
||||
var_dump($response);
|
||||
die();
|
||||
*/
|
||||
if($response['status'] == 'ERROR'){
|
||||
PaymentTransaction::create([
|
||||
'shopping_payment_id' => $this->shopping_payment->id,
|
||||
'request' => $this->method['request'],
|
||||
'errorcode' => $response['errorcode'],
|
||||
'errormessage' => $response['errormessage'],
|
||||
'customermessage' => $response['customermessage'],
|
||||
'status' => $response['status'],
|
||||
]);
|
||||
\Session::flash('errormessage', $response['errormessage']);
|
||||
\Session::flash('customermessage', $response['customermessage']);
|
||||
return redirect(route('checkout.checkout_card'));
|
||||
}
|
||||
|
||||
|
||||
if($response['status'] == 'REDIRECT'){
|
||||
PaymentTransaction::create([
|
||||
'shopping_payment_id' => $this->shopping_payment->id,
|
||||
'request' => $this->method['request'],
|
||||
'txid' => $response['txid'],
|
||||
'userid' => $response['userid'],
|
||||
'status' => $response['status'],
|
||||
]);
|
||||
return redirect()->away($response["redirecturl"]);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
if($response['status'] == 'APPROVED'){
|
||||
// header("Location: " . $response["redirecturl"]); // or other redirect method
|
||||
var_dump($response);
|
||||
die();
|
||||
//txid
|
||||
//Payment process ID (PAYONE)
|
||||
//userid
|
||||
//Debtor ID (PAYONE)
|
||||
}
|
||||
if($response['status'] == 'REDIRECT'){
|
||||
header("Location: " . $response["redirecturl"]); // or other redirect method
|
||||
$payt = PaymentTransaction::create([
|
||||
'shopping_payment_id' => $this->shopping_payment->id,
|
||||
'request' => $this->method['request'],
|
||||
'txid' => $response['txid'],
|
||||
'userid' => $response['userid'],
|
||||
'status' => $response['status'],
|
||||
'transmitted_data' => $response,
|
||||
]);
|
||||
|
||||
if($payt->shopping_payment->clearingtype == "vor"){
|
||||
//vorkasse
|
||||
return redirect(route('checkout.transaction_approved', [$payt->id, $this->reference]));
|
||||
exit;
|
||||
}
|
||||
|
||||
if($payt->shopping_payment->clearingtype == "cc"){
|
||||
//creditcard
|
||||
return redirect(route('checkout.transaction_approved', [$payt->id, $this->reference]));
|
||||
exit;
|
||||
}
|
||||
|
||||
var_dump($response);
|
||||
die();
|
||||
//txid
|
||||
//Payment process ID (PAYONE)
|
||||
//userid
|
||||
//Debtor ID (PAYONE)
|
||||
//redirecturl
|
||||
//Redirect URL
|
||||
}
|
||||
if($response['status'] == 'ERROR'){
|
||||
var_dump($response);
|
||||
die();
|
||||
//errorcode
|
||||
//Error number
|
||||
//errormessage
|
||||
//Error message for the merchant
|
||||
//customermessage
|
||||
// Error message for the end customer
|
||||
}
|
||||
|
||||
|
||||
if($response['status'] == 'PENDING'){
|
||||
var_dump($response);
|
||||
die();
|
||||
|
|
@ -248,54 +314,92 @@ class PayoneController extends Controller
|
|||
|
||||
|
||||
|
||||
public function checkCreditCard($data)
|
||||
{
|
||||
$this->prepayment = [
|
||||
"request" => "creditcardcheck", // create account receivable and instantly book the amount
|
||||
"cardholder" => $data['cc_cardholder_first']." ".$data['cc_cardholder_last'],
|
||||
"cardpan" => $data['cc_cardpan'],
|
||||
"cardexpiredate" => substr($data['cc_cardexpireyear'], -2) . $data['cc_cardexpiremonth'],
|
||||
"cardtype" => $data['cc_cardtype'],
|
||||
"cardcvc2" => $data['cc_cardcvc2'],
|
||||
"storecarddata" => 'yes',
|
||||
"language" => 'de',
|
||||
];
|
||||
$request = array_merge($this->default, $this->prepayment);
|
||||
$response = Payone::sendRequest($request);
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* public function checkStatus(){
|
||||
// again, the default values will be needed
|
||||
$capture = array(
|
||||
"request" => "capture",
|
||||
"txid" => "your_txid",
|
||||
"sequencenumber" => "previous_sequencenumber_plus_one", // get this from the last received transactionsstatus
|
||||
"amount" => "your_amount", // you can either capture the full amount of the tx, or less
|
||||
"currency" => "EUR"
|
||||
);
|
||||
$request = array_merge($this->default, $capture);
|
||||
$response = Payone::sendRequest($request);
|
||||
|
||||
} */
|
||||
|
||||
|
||||
//set for clearingtype
|
||||
//debit payment
|
||||
/*
|
||||
*
|
||||
* ["clearing_bankaccount"]=> string(10) "2599100003"
|
||||
["clearing_bankcode"]=> string(8) "12345678"
|
||||
["clearing_bankcountry"]=> string(2) "DE"
|
||||
["clearing_bankname"]=> string(8) "Testbank"
|
||||
["clearing_bankaccountholder"]=> string(11) "Test Nutzer"
|
||||
["clearing_bankcity"]=> string(4) "Kiel"
|
||||
["clearing_bankiban"]=> string(22) "DE00123456782599100003"
|
||||
["clearing_bankbic"]=> string(8) "TESTTEST" }
|
||||
*/
|
||||
/*
|
||||
* PNT Sofortbanking (DE, AT, CH, NL)
|
||||
GPY giropay (DE)
|
||||
EPS eps – online transfer (AT)
|
||||
PFF PostFinance E-Finance (CH)
|
||||
PFC PostFinance Card (CH)
|
||||
IDL iDEAL (NL)
|
||||
P24 Przelewy24 (PL)
|
||||
BCT Bancontact*/
|
||||
/*
|
||||
* iban
|
||||
* bic
|
||||
* bankcountry*/
|
||||
public function setOnlineTransfer($data){
|
||||
/*
|
||||
* PNT Sofortbanking (DE, AT, CH, NL)
|
||||
GPY giropay (DE)
|
||||
EPS eps – online transfer (AT)
|
||||
PFF PostFinance E-Finance (CH)
|
||||
PFC PostFinance Card (CH)
|
||||
IDL iDEAL (NL)
|
||||
P24 Przelewy24 (PL)
|
||||
BCT Bancontact*/
|
||||
$this->onlineTransfer = [
|
||||
"onlinebanktransfertype" => "PNT",
|
||||
"bankcountry" => "DE",
|
||||
// "iban" => "",
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function setCreditCard(){
|
||||
/*
|
||||
* Card type
|
||||
/* * Card type
|
||||
V Visa
|
||||
M MasterCard
|
||||
A American Express
|
||||
D Diners / Discover
|
||||
J JCB
|
||||
O Maestro International
|
||||
*/
|
||||
$this->creditCard = [
|
||||
"cardpan" => "number",
|
||||
"cardtype" => "V",
|
||||
"cardexpiredate" => "YYMM",
|
||||
// "cardcvc2" => "Credit verification number (CVC)",
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function setDeliverylData($data){
|
||||
$this->deliveryData = [
|
||||
"shipping_company" => "Mr.",
|
||||
"shipping_firstname" => "Henry",
|
||||
"shipping_lastname" => "Tudor",
|
||||
"shipping_street" => "Royal Street 1",
|
||||
"shipping_zip" => "24118",
|
||||
"shipping_city" => "Kiel",
|
||||
"shipping_country" => "DE",
|
||||
];
|
||||
|
||||
/*3-D Secure*/
|
||||
$this->creditCard['xid'] = "3-D Secure transaction ID";
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,6 @@ class CardController extends Controller
|
|||
|
||||
$user_shop = Util::getUserShop();
|
||||
|
||||
|
||||
do {
|
||||
$identifier = Util::getToken();
|
||||
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
||||
|
|
@ -113,6 +112,11 @@ class CardController extends Controller
|
|||
return redirect()->secure($path);
|
||||
}
|
||||
|
||||
public function backToShop(){
|
||||
$this->deleteCard();
|
||||
return redirect(url('/'));
|
||||
|
||||
}
|
||||
public function removeCard($rowId){
|
||||
|
||||
Yard::instance('shopping')->remove($rowId);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,15 @@ namespace App\Http\Controllers\Web;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Pay\PayoneController;
|
||||
use App\Models\Product;
|
||||
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 Illuminate\Session\SessionManager;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Validator;
|
||||
use App\Services\Util;
|
||||
use Yard;
|
||||
|
|
@ -13,17 +21,20 @@ use Input;
|
|||
|
||||
class CheckoutController extends Controller
|
||||
{
|
||||
private $session;
|
||||
private $instance;
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(SessionManager $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
$this->instance = sprintf('%s.%s', 'cart', 'payments');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function checkout(){
|
||||
|
||||
$user_shop = Util::getUserShop();
|
||||
|
|
@ -34,82 +45,366 @@ class CheckoutController extends Controller
|
|||
// $ShippingCountry = ShippingCountry::where('country_id', 1)->first();
|
||||
// $selected_country = $ShippingCountry->id;
|
||||
}
|
||||
|
||||
$shopping_user = ShoppingUser::findOrNew($this->getPayments('shopping_user_id'));
|
||||
if($shopping_user->same_as_billing === NULL){
|
||||
$shopping_user->same_as_billing = true;
|
||||
}
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'shopping_user' => $shopping_user,
|
||||
];
|
||||
return view('web.templates.checkout', $data);
|
||||
}
|
||||
|
||||
public function checkoutFinal(){
|
||||
|
||||
/*$rules = array(
|
||||
'billing.firstname'=>'required',
|
||||
'billing.lastname'=>'required',
|
||||
'billing.email'=>'required|email',
|
||||
'billing.address'=>'required',
|
||||
'billing.zipcode'=>'required',
|
||||
'billing.city' => 'required',
|
||||
/*
|
||||
$rules = array(
|
||||
'billing_salutation' => 'required',
|
||||
'billing_firstname'=>'required',
|
||||
'billing_lastname'=>'required',
|
||||
'billing_email'=>'required|email',
|
||||
'billing_address'=>'required',
|
||||
'billing_zipcode'=>'required',
|
||||
'billing_city' => 'required',
|
||||
'accepted_data_checkbox' => 'accepted',
|
||||
'billing.salutation => 'required'
|
||||
);
|
||||
|
||||
if(!Input::get('shipping.same_as_billing')){
|
||||
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'
|
||||
'shipping_firstname'=>'required',
|
||||
'shipping_lastname'=>'required',
|
||||
'shipping_address'=>'required',
|
||||
'shipping_zipcode'=>'required',
|
||||
'shipping_city' => 'required',
|
||||
'shipping_salutation' => 'required'
|
||||
|
||||
]);
|
||||
}
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return back()->withErrors($validator)->withErrors($validator)->withInput(Input::all());
|
||||
}*/
|
||||
}
|
||||
*/
|
||||
|
||||
$data = Input::all();
|
||||
//make User
|
||||
$shopping_user = $this->makeShoppingUser($data);
|
||||
//make Order and Items
|
||||
$shopping_order = $this->makeShoppingOrder($shopping_user);
|
||||
|
||||
//check credit Card
|
||||
if(Input::get('payment_method')){
|
||||
$pay = new PayoneController(Input::get('payment_method'));
|
||||
$pay->setPrePayment([]);
|
||||
$cc_ret = [];
|
||||
//need precheck the card
|
||||
if(Input::get('payment_method') == 'cc'){
|
||||
$pay = new PayoneController();
|
||||
$cc_ret = $pay->checkCreditCard($data);
|
||||
if($cc_ret['status'] == 'ERROR' || $cc_ret['status'] == 'INVALID'){
|
||||
/* PaymentTransaction::create([
|
||||
'shopping_payment_id' => //is no shopping_payment_id at this moment,
|
||||
'request' => 'creditcardcheck,
|
||||
'errorcode' => $cc_ret['errorcode'],
|
||||
'errormessage' => $cc_ret['errormessage'],
|
||||
'customermessage' => $cc_ret['customermessage'],
|
||||
'status' => $response['status'],
|
||||
]);*/
|
||||
\Session::flash('cc-error', 1);
|
||||
\Session::flash('errormessage', $cc_ret['errormessage']);
|
||||
\Session::flash('customermessage', $cc_ret['customermessage']);
|
||||
return redirect(route('checkout.checkout_card'))->withInput(Input::all());
|
||||
exit;
|
||||
}
|
||||
if($cc_ret['status'] == 'VALID'){
|
||||
/*
|
||||
* array(4) { ["status"]=> string(5) "VALID" ["pseudocardpan"]=> string(19) "9410010000169020567" ["cardtype"]=> string(1) "V" ["truncatedcardpan"]=> string(16) "411111XXXXXX1111" }
|
||||
* application through http post
|
||||
* get this to the prepayment
|
||||
* */
|
||||
}
|
||||
}
|
||||
|
||||
//other
|
||||
$pay = new PayoneController();
|
||||
$pay->init($shopping_user, $shopping_order);
|
||||
$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->ResponseData([]);
|
||||
return $pay->ResponseData();
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
public function transactionStatus($status, $reference){
|
||||
|
||||
$shopping_order_id = $this->getPayments('shopping_order_id');
|
||||
|
||||
$ShoppingPayment = ShoppingPayment::where('shopping_order_id', $shopping_order_id)->where('reference', $reference)->first();
|
||||
if(!$ShoppingPayment){
|
||||
//TODO log this
|
||||
\Session::flash('checkout-error', 'Der Zahlungsvorgang konnte nicht abgeschlossen werden, die Zahlung wurde nicht gefunden: '.$reference);
|
||||
return redirect(route('checkout.checkout_card'));
|
||||
}
|
||||
$ShoppingPayment->status = $status;
|
||||
$ShoppingPayment->save();
|
||||
|
||||
if($status == "success"){
|
||||
|
||||
Yard::instance('shopping')->destroy();
|
||||
$this->destroy();
|
||||
|
||||
$payt = $ShoppingPayment->payment_transactions->last();
|
||||
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'order_reference' => $reference,
|
||||
'pay_trans' => $payt,
|
||||
];
|
||||
return view('web.templates.checkout-final', $data);
|
||||
}
|
||||
if($status == "cancel"){
|
||||
\Session::flash('checkout-error', 'Der Zahlungsvorgang wurde abgebrochen, die Bestellung konnte nicht ausgeführt werden.');
|
||||
return redirect(route('checkout.checkout_card'));
|
||||
|
||||
}
|
||||
if($status == "error"){
|
||||
\Session::flash('checkout-error', 'Der Zahlungsvorgang wurde abgebrochen, die Bestellung konnte nicht ausgeführt werden.');
|
||||
return redirect(route('checkout.checkout_card'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function transactionApproved($transactionId, $reference) {
|
||||
|
||||
$payt = PaymentTransaction::findOrFail($transactionId);
|
||||
if($payt->shopping_payment->reference != $reference){
|
||||
abort(404);
|
||||
}
|
||||
Yard::instance('shopping')->destroy();
|
||||
$this->destroy();
|
||||
//vor
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'order_reference' => $payt->shopping_payment->reference,
|
||||
'pay_trans' => $payt,
|
||||
];
|
||||
return view('web.templates.checkout-final', $data);
|
||||
}
|
||||
|
||||
|
||||
public function transactionStatus($check){
|
||||
public function paymentStatus(){
|
||||
|
||||
$data = \Request::all();
|
||||
var_dump($data);
|
||||
$data = \Input::all();
|
||||
var_dump($data);
|
||||
die();
|
||||
if($check == "cancel"){
|
||||
|
||||
\Session::flash('checkout-error', 'Der Zahlungsvorgang wurde abgebrochen, die Bestellung konnte nicht ausgeführt werden.');
|
||||
return $this->checkout();
|
||||
// test para
|
||||
|
||||
$data = [
|
||||
'key' => '698fb2555f8b2efc74f60b2121421f45',
|
||||
'txaction' => 'appointed',
|
||||
'clearingtype' => 'vor',
|
||||
'userid' => '157787236',
|
||||
'txid' => '319655873',
|
||||
'price' => '13.80',
|
||||
'param' => '6', //$this->shopping_order->id,
|
||||
'reference' => '15c76c0d470cf9',
|
||||
];
|
||||
|
||||
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);
|
||||
}
|
||||
$pay = new PayoneController([]);
|
||||
$pay->checkStatus();
|
||||
|
||||
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($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");
|
||||
}
|
||||
|
||||
public function removeCard($rowId){
|
||||
Yard::instance('shopping')->remove($rowId);
|
||||
return back();
|
||||
private function makeShoppingUser($data){
|
||||
|
||||
$data['same_as_billing'] = isset($data['same_as_billing']) ? true : false;
|
||||
$data['accepted_data_checkbox'] = isset($data['accepted_data_checkbox']) ? true : false;
|
||||
|
||||
$shopping_user = false;
|
||||
if($this->getPayments('shopping_user_id')){
|
||||
$shopping_user = ShoppingUser::find($this->getPayments('shopping_user_id'));
|
||||
if($shopping_user){
|
||||
$shopping_user->fill($data);
|
||||
$shopping_user->save();
|
||||
}
|
||||
}
|
||||
if(!$shopping_user){
|
||||
$shopping_user = ShoppingUser::create($data);
|
||||
}
|
||||
$this->putPayments('shopping_user_id', $shopping_user->id);
|
||||
|
||||
return $shopping_user;
|
||||
}
|
||||
|
||||
public function deleteCard(){
|
||||
private function makeShoppingOrder($shopping_user){
|
||||
|
||||
Yard::instance('shopping')->destroy();
|
||||
return back();
|
||||
|
||||
$user_shop = Util::getUserShop();
|
||||
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
||||
'user_shop_id' => $user_shop->id,
|
||||
'total' => Yard::instance('shopping')->total(2, '.', ','),
|
||||
'shipping' => Yard::instance('shopping')->shipping(2, '.', ','),
|
||||
'subtotal' => Yard::instance('shopping')->subtotalWithShipping(2, '.', ','),
|
||||
'tax_rate' => Yard::getTaxRate(),
|
||||
'tax' => Yard::instance('shopping')->subtotalWithShipping(2, '.', ','),
|
||||
'total_shipping' => Yard::instance('shopping')->totalWithShipping(2, '.', ','),
|
||||
'weight' => Yard::instance('shopping')->weight(),
|
||||
];
|
||||
$shopping_order= false;
|
||||
if($this->getPayments('shopping_order_id')){
|
||||
$shopping_order = ShoppingOrder::find($this->getPayments('shopping_order_id'));
|
||||
if($shopping_order){
|
||||
$shopping_order->fill($data);
|
||||
$shopping_order->save();
|
||||
}
|
||||
}
|
||||
if(!$shopping_order){
|
||||
$shopping_order = ShoppingOrder::create($data);
|
||||
}
|
||||
$this->putPayments('shopping_order_id', $shopping_order->id);
|
||||
|
||||
|
||||
$items = Yard::instance('shopping')->content();
|
||||
|
||||
|
||||
$shopping_order->shopping_order_items()->each(function($model) use ($items, $shopping_order) {
|
||||
foreach ($items as $item) {
|
||||
if ($model->row_id === $item->rowId) {
|
||||
$model->fill([
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'row_id' => $item->rowId,
|
||||
'product_id' => $item->id,
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
'slug' => $item->options->slug,
|
||||
])->save();
|
||||
return;
|
||||
}
|
||||
}
|
||||
return $model->delete();
|
||||
});
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (!ShoppingOrderItem::where('shopping_order_id', $shopping_order->id)->where('row_id', $item->rowId)->count())
|
||||
ShoppingOrderItem::create([
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'row_id' => $item->rowId,
|
||||
'product_id' => $item->id,
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
'slug' => $item->options->slug
|
||||
]);
|
||||
};
|
||||
|
||||
return $shopping_order;
|
||||
}
|
||||
|
||||
private function putPayments($key, $value){
|
||||
$content = $this->getContent();
|
||||
$content->put($key, $value);
|
||||
$this->session->put($this->instance, $content);
|
||||
|
||||
}
|
||||
private function getPayments($key){
|
||||
$content = $this->getContent();
|
||||
if ($content->has($key)){
|
||||
return $content->get($key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private function getContent()
|
||||
{
|
||||
if (is_null($this->session->get($this->instance))) {
|
||||
return new Collection([]);
|
||||
}
|
||||
return $this->session->get($this->instance);
|
||||
}
|
||||
|
||||
|
||||
public function destroy()
|
||||
{
|
||||
$this->session->remove($this->instance);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue