mivita/app/Http/Controllers/Pay/PayoneController.php
2019-02-28 18:09:54 +01:00

410 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 PayoneController extends Controller
{
const PREAUTHORIZATION = 'preauthorization';
const AUTHORIZATION = 'authorization';
const CAPTURE = 'capture';
const REFUND = 'refund';
const DEBIT = 'debit';
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;
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"
);*/
}
private function setMethod($payment_method, $cc_ret = []){
if($payment_method){
if(strpos($payment_method, '#')){
$payment_method = explode('#', $payment_method);
//wallet Paypal
if($payment_method[0] == 'wlt'){
$this->method = [
"clearingtype" => "wlt",
"wallettype" => $payment_method[1],
'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"
];
}
}
}
public function ResponseData(){
$request = array_merge($this->default, $this->personalData, $this->deliveryData, $this->method, $this->prepayment, $this->urls);
$response = Payone::sendRequest($request);
/*
* status APPROVED / REDIRECT / ERROR / PENDING
*/
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
$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)
}
if($response['status'] == 'PENDING'){
var_dump($response);
die();
//txid
//Payment process ID (PAYONE)
//userid
//Debtor ID (PAYONE)
}
die("error");
}
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*/
/* * Card type
V Visa
M MasterCard
A American Express
D Diners / Discover
J JCB
O Maestro International
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",
];
}
*/
}