298 lines
8.2 KiB
PHP
298 lines
8.2 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Pay;
|
||
|
||
use App\Http\Controllers\Controller;
|
||
use App\Services\Payone;
|
||
use Illuminate\Http\Request;
|
||
|
||
|
||
/*
|
||
* clearingtype
|
||
elv Debit payment
|
||
cc Credit card
|
||
rec Invoice
|
||
cod Cash on delivery
|
||
vor Prepayment
|
||
sb Online Bank Transfer
|
||
wlt e-wallet
|
||
fnc Financing
|
||
*/
|
||
|
||
|
||
|
||
class PayoneController extends Controller
|
||
{
|
||
|
||
|
||
private $default = [];
|
||
|
||
private $personalData = [];
|
||
private $deliveryData = [];
|
||
|
||
private $method = [];
|
||
private $prepayment = [];
|
||
private $onlineTransfer = [];
|
||
private $creditCard = [];
|
||
|
||
private $url = [];
|
||
|
||
|
||
public function __construct($payment_method = null) {
|
||
|
||
if($payment_method){
|
||
|
||
if(strpos($payment_method, '#')){
|
||
$payment_method = explode('#', $payment_method);
|
||
//wallet
|
||
if($payment_method[0] == 'wlt'){
|
||
$this->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 "<br><br><br>";
|
||
$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";
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|