|
|
|
|
|
|
|
|
if (is_object($folder)) { |
|
|
if (is_object($folder)) { |
|
|
$folder = $f3->get('POST.datapath'); |
|
|
$folder = $f3->get('POST.datapath'); |
|
|
} |
|
|
} |
|
|
|
|
|
if (!is_string($folder)) { |
|
|
|
|
|
$folder = $f3->get('SESSION.checkout_folder'); |
|
|
|
|
|
} |
|
|
if (is_string($folder)) { |
|
|
if (is_string($folder)) { |
|
|
|
|
|
$f3->set('SESSION.checkout_folder', $folder); |
|
|
$this->DB = new \DB\SQL(sprintf("sqlite:%sdatabase.sqlite",$folder)); |
|
|
$this->DB = new \DB\SQL(sprintf("sqlite:%sdatabase.sqlite",$folder)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sak->id = $this->saksnummer; |
|
|
$sak->id = $this->saksnummer; |
|
|
$sak->save(); |
|
|
$sak->save(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($sak->kContact === null) { |
|
|
if ($sak->kContact === null) { |
|
|
$f3->reroute('/checkout/contact'); |
|
|
$f3->reroute('/checkout/contact'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function place_order() { |
|
|
function place_order() { |
|
|
|
|
|
// fails silently, producing potentially weird untrackable faults if more than 10000 orders happen on one day |
|
|
$info = new \DB\SQL\Mapper($this->DB,'info'); |
|
|
$info = new \DB\SQL\Mapper($this->DB,'info'); |
|
|
for ($i=0;$i<9999;$i++) { |
|
|
for ($i=0;$i<9999;$i++) { |
|
|
$candidate = strval(sprintf('%s%04d',date('Ymd'),$i)); |
|
|
$candidate = strval(sprintf('%s%04d',date('Ymd'),$i)); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* buyer has approved all details and decided which payment method to use |
|
|
|
|
|
*/ |
|
|
function buy() { |
|
|
function buy() { |
|
|
|
|
|
// set up environment |
|
|
$f3 = \Base::instance(); |
|
|
$f3 = \Base::instance(); |
|
|
$sak = new \DB\SQL\Mapper($this->DB,'saklist'); |
|
|
$sak = new \DB\SQL\Mapper($this->DB,'saklist'); |
|
|
$info = new \DB\SQL\Mapper($this->DB,'info'); |
|
|
$info = new \DB\SQL\Mapper($this->DB,'info'); |
|
|
$contact = new \DB\SQL\Mapper($this->DB,'contacts'); |
|
|
$contact = new \DB\SQL\Mapper($this->DB,'contacts'); |
|
|
$sak->load(['id=?',$this->saksnummer]); |
|
|
$sak->load(['id=?',$this->saksnummer]); |
|
|
$datapath = $f3->get('POST.datapath'); |
|
|
|
|
|
|
|
|
//$datapath = $f3->get('POST.datapath'); |
|
|
|
|
|
|
|
|
|
|
|
// generate an order number |
|
|
$sak->kInfo = $this->place_order(); |
|
|
$sak->kInfo = $this->place_order(); |
|
|
$sak->status = 1; // 1 := ordernumber is generated |
|
|
$sak->status = 1; // 1 := ordernumber is generated |
|
|
$sak->save(); |
|
|
$sak->save(); |
|
|
|
|
|
|
|
|
|
|
|
// load data needed o finish transaction |
|
|
$info->load(['id=?',$sak->kInfo]); |
|
|
$info->load(['id=?',$sak->kInfo]); |
|
|
$contact->load(['id=?', $sak->kContact]); |
|
|
$contact->load(['id=?', $sak->kContact]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// finish transaction |
|
|
switch ($f3->get('POST.payment')) { |
|
|
switch ($f3->get('POST.payment')) { |
|
|
case 'transfer': |
|
|
case 'transfer': |
|
|
$email = new Email(); |
|
|
$email = new Email(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case 'paypal': |
|
|
case 'paypal': |
|
|
|
|
|
$f3->set('SESSION.xss-token',$f3->get('POST.xss-token')); |
|
|
|
|
|
$f3->reroute('/checkout/paypal'); |
|
|
|
|
|
break; |
|
|
|
|
|
case 'approve': |
|
|
|
|
|
$email = new Email(); |
|
|
|
|
|
$email->load_form_config($f3->get('SESSION.xss-token')); |
|
|
|
|
|
|
|
|
|
|
|
if ($this->email_to_merchant() && |
|
|
|
|
|
$this->email_to_client($contact->email)) { |
|
|
|
|
|
$f3->set('SESSION',[]); |
|
|
|
|
|
header('Content-Type: application/json; charset=utf-8'); |
|
|
|
|
|
echo json_encode(['redirect' => '/checkout/success']); |
|
|
|
|
|
die; |
|
|
|
|
|
} else { |
|
|
|
|
|
header('Content-Type: application/json; charset=utf-8'); |
|
|
|
|
|
echo json_encode(['redirect' => '/checkout/failure']); |
|
|
|
|
|
die; |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
$f3->set('POST.tesst',"asdasd"); |
|
|
|
|
|
header('Content-Type: application/json; charset=utf-8'); |
|
|
|
|
|
echo json_encode($_POST); |
|
|
|
|
|
die; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function api(\Base $f3, $params) { |
|
|
function api(\Base $f3, $params) { |
|
|
|
|
|
|
|
|
$sak = new \DB\SQL\Mapper($this->DB,'saklist'); |
|
|
$sak = new \DB\SQL\Mapper($this->DB,'saklist'); |
|
|
if ($sak->load(['id=?',$this->saksnummer]) !== false) { |
|
|
if ($sak->load(['id=?',$this->saksnummer]) !== false) { |
|
|
switch ($params['method']) { |
|
|
switch ($params['method']) { |
|
|
|
|
|
|
|
|
$sak->status = $this->buy(); |
|
|
$sak->status = $this->buy(); |
|
|
// $sak->save(); |
|
|
// $sak->save(); |
|
|
// $f3->reroute('/checkout/success'); |
|
|
// $f3->reroute('/checkout/success'); |
|
|
|
|
|
break; |
|
|
|
|
|
case "paypalapprove": |
|
|
|
|
|
//$f3->set('POST.payment', 'approve'); |
|
|
|
|
|
$sak->status = $this->buy(); |
|
|
|
|
|
break; |
|
|
default: |
|
|
default: |
|
|
|
|
|
header('Content-Type: application/json; charset=utf-8'); |
|
|
|
|
|
echo json_encode(['test' => 2]); |
|
|
|
|
|
die; |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
header('Content-Type: application/json; charset=utf-8'); |
|
|
|
|
|
echo json_encode(['error' => "no saksnummer"]); |
|
|
|
|
|
die; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|