diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 554193b..6a0d2e3 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,36 +2,14 @@ - - - + + + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + - + + + + + + + + - - + + @@ -768,12 +726,12 @@ - + - - - + + + @@ -789,21 +747,6 @@ - - - - - - - - - - - - - - - @@ -887,9 +830,6 @@ - - - @@ -962,13 +902,6 @@ - - - - - - - @@ -986,23 +919,10 @@ - - - - - - - - - - - - - @@ -1034,51 +954,48 @@ - + - - + + - - - - - - - - - - - + - + - + - - - - - + + + + + + + + + - - - - - - + + + + + + + + + @@ -1089,46 +1006,88 @@ + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + - - - - - - - - - - - - + + - - + + + + + + + + + - + diff --git a/app/Http/Controllers/Pay/PayoneController.php b/app/Http/Controllers/Pay/PayoneController.php new file mode 100644 index 0000000..5062397 --- /dev/null +++ b/app/Http/Controllers/Pay/PayoneController.php @@ -0,0 +1,298 @@ +method = [ + "clearingtype" => "wlt", + "wallettype" => $payment_method[1], + "request" => "authorization", + ]; + } + //Online-Überweisung + if($payment_method[0] == 'sb'){ + $this->method = [ + "clearingtype" => "sb", + "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", + ]; + + } + } + } + $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->method, $this->prepayment, $this->url); + // var_dump($request); + // echo "


"; + $response = Payone::sendRequest($request); + /* + * status APPROVED / REDIRECT / ERROR / PENDING + * */ + + //cc + + + 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'] == '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 + + //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(); + //txid + //Payment process ID (PAYONE) + //userid + //Debtor ID (PAYONE) + } + die("error"); + } + + + + + //set for clearingtype + //debit payment + /* + * 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 + 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)", + + ]; + + /*3-D Secure*/ + $this->creditCard['xid'] = "3-D Secure transaction ID"; + + } + + + + +} + + + + diff --git a/app/Http/Controllers/Web/CardController.php b/app/Http/Controllers/Web/CardController.php index 1b3e2d5..2083f90 100755 --- a/app/Http/Controllers/Web/CardController.php +++ b/app/Http/Controllers/Web/CardController.php @@ -69,7 +69,6 @@ class CardController extends Controller // $ShippingCountry = ShippingCountry::where('country_id', 1)->first(); // $selected_country = $ShippingCountry->id; } - $data = [ 'user_shop' => Util::getUserShop(), ]; diff --git a/app/Http/Controllers/Web/CheckoutController.php b/app/Http/Controllers/Web/CheckoutController.php index 2931d8e..41538e4 100755 --- a/app/Http/Controllers/Web/CheckoutController.php +++ b/app/Http/Controllers/Web/CheckoutController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Web; use App\Http\Controllers\Controller; +use App\Http\Controllers\Pay\PayoneController; use App\Models\Product; use Validator; use App\Services\Util; @@ -27,8 +28,6 @@ class CheckoutController extends Controller $user_shop = Util::getUserShop(); - - if(Input::get('selected_country')){ Yard::instance('shopping')->setShippingCountryWithPrice(Input::get('selected_country')); }else{ @@ -43,7 +42,7 @@ class CheckoutController extends Controller public function checkoutFinal(){ - $rules = array( + /*$rules = array( 'billing.firstname'=>'required', 'billing.lastname'=>'required', 'billing.email'=>'required|email', @@ -65,8 +64,16 @@ class CheckoutController extends Controller $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return back()->withErrors($validator)->withErrors($validator)->withInput(Input::all()); + }*/ + + if(Input::get('payment_method')){ + $pay = new PayoneController(Input::get('payment_method')); + $pay->setPrePayment([]); + $pay->setPersonalData([]); + $pay->ResponseData([]); } + $data = [ 'user_shop' => Util::getUserShop(), ]; @@ -74,6 +81,20 @@ class CheckoutController extends Controller } + public function transactionStatus($check){ + + if($check == "cancel"){ + \Session::flash('checkout-error', 'Der Zahlungsvorgang wurde abgebrochen, die Bestellung konnte nicht ausgeführt werden.'); + return $this->checkout(); + } + $pay = new PayoneController([]); + $pay->checkStatus(); + $data = \Request::all(); + var_dump($data); + $data = \Input::all(); + var_dump($data); + die(); + } public function removeCard($rowId){ Yard::instance('shopping')->remove($rowId); diff --git a/app/Services/Payone.php b/app/Services/Payone.php new file mode 100644 index 0000000..d72d608 --- /dev/null +++ b/app/Services/Payone.php @@ -0,0 +1,123 @@ +. + * + * @package Simple PHP Integration + * @link https://www.bspayone.com/ + * @copyright (C) BS PAYONE GmbH 2016, 2018 + * @author Florian Bender + * @author Timo Kuchel + * @author Hannes Reinberger + */ + +namespace App\Services; + + +//require 'vendor/autoload.php'; +use Exception; +use GuzzleHttp\Client; +use Psr\Http\Message\ResponseInterface; + +/** + * Class Payone + */ +class Payone { + + /** + * The URL of the Payone API + */ + const PAYONE_SERVER_API_URL = 'https://api.pay1.de/post-gateway/'; + const PAYONE_CLIENT_API_URL = 'https://secure.pay1.de/client-api//'; + + /** + * performing the HTTP POST request to the PAYONE platform + * + * @param array $request + * @param string $responsetype + * @throws Exception + * @return array|\Psr\Http\Message\StreamInterface Returns an array of response + * parameters in "classic" mode, a Stream for any other mode. + */ + public static function sendRequest($request, $responsetype = "") + { + if ($responsetype === "json") { + // appends the accept: application/json header to the request + // This is used to retrieve structured JSON in the response + $client = new Client(['headers' => ['accept' => 'application/json']]); + } + else { + // if $responsetype is set to anything else than "json", use the standard request + $client = new Client(); + } + +// echo "Requesting..."; + $begin = microtime(true); + + if ($response = $client->request('POST', self::PAYONE_SERVER_API_URL, ['form_params' => $request])) { + + if (implode($response->getHeader('Content-Type')) == 'text/plain; charset=UTF-8'){ + // if the content type is text/plain, parse response into array + $return = self::parseResponse($response); + } else { + // if the content type is anything else, just return the response body + $return = $response->getBody(); + } + + } else { + throw new Exception('Something went wrong during the HTTP request.'); + } + + $end = microtime(true); + $duration = $end - $begin; + /* echo "done.\n"; + echo "Request took " . $duration . " seconds.\n"; + echo "
"; + */ + return $return; + } + + /** + * gets response string an puts it into an array + * + * @param \Psr\Http\Message\ResponseInterface $response + * @throws Exception + * @return array + */ + public static function parseResponse(ResponseInterface $response) + { + $responseArray = array(); + $explode = explode("\n", $response->getBody()); + foreach ($explode as $e) { + $keyValue = explode("=", $e); + if (trim($keyValue[0]) != "") { + if (count($keyValue) == 2) { + $responseArray[$keyValue[0]] = trim($keyValue[1]); + } else { + $key = $keyValue[0]; + unset($keyValue[0]); + $value = implode("=", $keyValue); + $responseArray[$key] = $value; + } + } + } + /*if ($responseArray['status'] == "ERROR") { + $msg = "Payone returned an error:\n" . print_r($responseArray, true); + throw new Exception($msg); + }*/ + return $responseArray; + } +} diff --git a/app/Services/Yard.php b/app/Services/Yard.php index a149604..f6a52de 100644 --- a/app/Services/Yard.php +++ b/app/Services/Yard.php @@ -23,11 +23,18 @@ class Yard extends Cart if($this->getShippingExtra('shipping_price')){ $this->shipping = floatval($this->getShippingExtra('shipping_price')); } + if($this->getShippingExtra('shipping_country_id')){ $this->shipping_country_id = $this->getShippingExtra('shipping_country_id'); } parent::__construct($session, $events); + + if($this->shipping == 0){ + self::instance('shopping')->setShippingCountryWithPrice($this->shipping_country_id); + + } + } public static function getTaxRate() diff --git a/config/payone.php b/config/payone.php new file mode 100755 index 0000000..7aeb050 --- /dev/null +++ b/config/payone.php @@ -0,0 +1,13 @@ + [ + "aid" => '43065',//"your_account_id", + "mid" => '42504',//"your_merchant_id", + "portalid" => '2030693', + "key" => hash("md5", "Zjop5cvP2UeB7Qhy"), // the key has to be hashed as md5 + "mode" => "test", // can be "live" for actual transactions + "api_version" => "3.11", + "encoding" => "UTF-8" + ] +]; diff --git a/resources/views/web/templates/checkout.blade.php b/resources/views/web/templates/checkout.blade.php index 8f82a48..27c4472 100644 --- a/resources/views/web/templates/checkout.blade.php +++ b/resources/views/web/templates/checkout.blade.php @@ -116,7 +116,6 @@ --}} @if ($errors->any()) -
@@ -125,6 +124,18 @@
@endif + + @if (\Session::has('checkout-error')) +
+
+
+ {{ \Session::get('checkout-error') }} +
+
+
+ @endif + +
{!! Form::open(['url' => route('checkout.checkout_card_final'), 'class' => 'row clearfix', 'id'=>'']) !!}
@@ -371,35 +382,48 @@
+
+
+
+
+
+
+
diff --git a/routes/web.php b/routes/web.php index 89ac557..a854f1c 100755 --- a/routes/web.php +++ b/routes/web.php @@ -238,8 +238,9 @@ Route::domain(config('app.checkout_url').config('app.domain'))->group(function ( Route::get('/checkout/card/{identifier}', 'Web\CheckoutController@checkout')->name('checkout.checkout_card'); Route::post('/checkout/card/final', 'Web\CheckoutController@checkoutFinal')->name('checkout.checkout_card_final'); - Route::get('/transaction/status/', 'Web\CheckoutController@transactionStatus')->name('checkout.transaction_status'); - Route::post('/transaction/status/', 'Web\CheckoutController@transactionStatus')->name('checkout.transaction_status'); + Route::get('/transaction/status/{check?}', 'Web\CheckoutController@transactionStatus')->name('checkout.transaction_status'); + Route::post('/transaction/status/{check?}', 'Web\CheckoutController@transactionStatus')->name('checkout.transaction_status'); + }); });