first commit

This commit is contained in:
2025-03-12 17:06:23 +01:00
commit 2241f7131f
13185 changed files with 1692479 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
<?php
class stPayNowFrontendActions extends stActions
{
public function executeReturn()
{
$status = $this->getRequestParameter('paymentStatus');
$id = $this->getRequestParameter('id');
$hash_code = $this->getRequestParameter('hash_code');
$order = OrderPeer::retrieveByIdAndHashCode($id, $hash_code);
stPayNow::log("Return from payment for order {$order->getNumber()} with parameters " . stPayNow::logFormat($this->getRequest()->getParameterHolder()->getAll()));
if ($status == 'ERROR')
{
return $this->redirect('@stPayNowFail?id='.$id.'&hash_code='.$hash_code);
}
elseif ($status != 'CONFIRMED')
{
$order->getOrderPayment()->setInProgress(true);
$order->getOrderPayment()->save();
}
else
{
$order->getOrderPayment()->setInProgress(false);
$order->getOrderPayment()->save();
}
$this->smarty = new stSmarty($this->getModuleName());
$this->smarty->assign('status', $status);
}
public function executeFail()
{
$this->smarty = new stSmarty($this->getModuleName());
$webpage = WebpagePeer::retrieveByState('CONTACT');
sfLoader::loadHelpers(array('Helper', 'stUrl'));
$id = $this->getRequestParameter('id');
$hash_code = $this->getRequestParameter('hash_code');
if ($webpage)
{
$this->smarty->assign('contact_url', st_url_for('stWebpageFrontend/index?url='.$webpage->getFriendlyUrl()));
}
$this->smarty->assign('payment_url', st_url_for('@stPaymentPay?id='.$id.'&hash_code='.$hash_code));
}
public function executeProcessPayment()
{
$order = OrderPeer::retrieveByIdAndHashCode($this->getRequestParameter('id'), $this->getRequestParameter('hash'));
$api = new stPayNow();
$url = $api->createPayment($order);
if ($url)
{
stPayNow::log('Success: '. $url);
return $this->renderJSON(array('redirect' => $url));
}
stPayNow::log('Failure: '. $api->getLastError());
return $this->renderJSON(array('redirect' => $this->getController()->genUrl('@stPayNowFail?id='.$order->getId().'&hash_code='.$order->getHashCode())));
}
public function executeNotify()
{
$data = trim(file_get_contents('php://input'));
$headers = getallheaders();
stPayNow::log('Payment notification: '. $data . ' with headers '.stPayNow::logFormat($headers));
if ($this->getRequestParameter('token') != stPayNow::getSecurityToken())
{
stPayNow::log('Wrong shop security token');
$this->getResponse()->setStatusCode(400);
return sfView::HEADER_ONLY;
}
$api = new stPayNow();
$notification = $api->parseStatusNotification($data, $headers);
if (false === $notification)
{
stPayNow::log('Wrong signature');
$this->getResponse()->setStatusCode(400);
return sfView::HEADER_ONLY;
}
$order = OrderPeer::retrieveByNumber($notification['externalId']);
if (!$order)
{
stPayNow::log(sprintf('Order "%s" does not exist', $notification['externalId']));
$this->getResponse()->setStatusCode(400);
return sfView::HEADER_ONLY;
}
elseif ($order->getOrderPayment())
{
$payment = $order->getOrderPayment();
switch ($notification['status'])
{
case 'CONFIRMED':
$payment->setInProgress(false);
$payment->setStatus(true);
$payment->save();
stPayNow::log(sprintf('Payment status for order "%s" updated succesfully', $order->getNumber()));
break;
case 'PENDING':
$payment->setInProgress(true);
break;
case 'REJECTED':
$payment->setInProgress(false);
break;
}
}
else
{
stPayNow::log(sprintf('Payment for order "%s" does not exist', $notification['externalId']));
$this->getResponse()->setStatusCode(400);
return sfView::HEADER_ONLY;
}
return $this->renderText('OK');
}
}

View File

@@ -0,0 +1,31 @@
<?php
class stPayNowFrontendComponents extends sfComponents
{
public function executeShowPayment()
{
stPayment::log('paynow', 'Creating new payment for order: '. $this->order->getNumber());
$api = new stPayNow();
$url = $api->createPayment($this->order);
if (false === $url)
{
stPayment::log('paynow', 'Failure: '. $api->getLastError());
return $this->redirect($this->getController()->genUrl('@stPayNowFail?id='.$this->order->getId().'&hash_code='.$this->order->getHashCode()));
}
stPayment::log('paynow', 'Success: '. $url);
return $this->redirect($url);
}
public function redirect($url)
{
$this->getController()->redirect($url);
throw new sfStopException();
}
}

View File

@@ -0,0 +1,3 @@
<?php
$smarty->display('fail.html');

View File

@@ -0,0 +1,4 @@
<?php
$smarty->display('return.html');

View File

@@ -0,0 +1,23 @@
{set layout="one_column"}
<div id="payment">
<div class="panel panel-default center-block">
<div class="panel-body text-center">
<p>
<img src="/plugins/stPayNowPlugin/images/logo.png" alt="" style="max-width: 150px" />
</p>
<p>
{__ text="Wystąpił problem podczas realizacji płatności." catalogue="stPayment"}
</p>
{if $contact_url}
<p>
<a href="{$contact_url}" class="btn btn-default">
{__ text="Skontaktuj się z nami" catalogue="stPayment"}
</a>
<a href="{$payment_url}" class="btn btn-primary">
{__ text="Spróbuj ponownie" catalogue="stPayment"}
</a>
</p>
{/if}
</div>
</div>
</div>

View File

@@ -0,0 +1,16 @@
{set layout="one_column"}
<div id="payment">
<div class="panel panel-default center-block">
<div class="panel-body text-center">
<p>
<img src="/plugins/stPayNowPlugin/images/logo.png" alt="" style="max-width: 150px" />
</p>
{if $status == 'REJECTED'}
<p>{__ text="Płatność anulowana" catalogue="stPayment"}</p>
{else}
<p>{__ text="Dziękujemy za dokonanie płatności." catalogue="stPayment"}</p>
{/if}
<a href="{$homepage_url}" class="btn btn-primary">{__ text="Wróć do zakupów" catalogue="stBasket"}</a>
</div>
</div>
</div>