Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace wirecard payment page v2 with qenta checkout #23

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_Cancel_Component extends Kwc_Abstract
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Cancel_Component extends Kwc_Abstract
{
public static function getSettings($param = null)
{
$ret = parent::getSettings($param);
$ret['contentSender'] = 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_Cancel_ContentSender';
$ret['contentSender'] = 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Cancel_ContentSender';
return $ret;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Cancel_ContentSender extends Kwf_Component_Abstract_ContentSender_Default
{
public function sendContent($includeMaster)
{
$session = new Kwf_Session_Namespace('kwcShopCart');
if (!$orderId = $session->qentaCartId && isset($_POST['babytuch_orderId'])) {
$orderId = $_POST['babytuch_orderId'];
}
if ($orderId) {
KwcShop_Kwc_Shop_Cart_Orders::setCartOrderId($orderId);
$order = Kwf_Model_Abstract::getInstance(Kwc_Abstract::getSetting($this->_data->parent->parent->parent->componentClass, 'childModel'))
->getReferencedModel('Order')->getCartOrder();
$order->status = 'cart';
$order->save();
unset($session->qentaCartId);
}
Kwf_Util_Redirect::redirect($this->_data->parent->parent->parent->getUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
/**
* set preLoginIgnore for wirecard confirm url in config: preLoginIgnore.wirecardConfirm = url
**/
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_Component extends KwcShop_Kwc_Shop_Cart_Checkout_Payment_Abstract_Component
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Component extends KwcShop_Kwc_Shop_Cart_Checkout_Payment_Abstract_Component
{
public static function getSettings($param = null)
{
$ret = parent::getSettings($param);
$ret['componentName'] = trlKwfStatic('Wirecard');
// Delete confirm because of wirecard dispatch confirm url
$ret['componentName'] = trlKwfStatic('QENTA');
// Delete confirm because of qenta dispatch confirm url
unset($ret['generators']['confirm']);
$ret['generators']['child']['component']['confirmLink'] = 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_ConfirmLink_Component';
$ret['generators']['child']['component']['confirmLink'] = 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_ConfirmLink_Component';
$ret['generators']['cancel'] = array(
'class' => 'Kwf_Component_Generator_Page_Static',
'component' => 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_Cancel_Component',
'component' => 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Cancel_Component',
'name' => trlKwfStatic('Cancel')
);

$ret['generators']['failure'] = array(
'class' => 'Kwf_Component_Generator_Page_Static',
'component' => 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_Failure_Component',
'component' => 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Failure_Component',
'name' => trlKwfStatic('Failure')
);

$ret['generators']['success'] = array(
'class' => 'Kwf_Component_Generator_Page_Static',
'component' => 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_Success_Component',
'component' => 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Success_Component',
'name' => trlKwfStatic('Success')
);

Expand All @@ -38,18 +38,17 @@ public static function getSettings($param = null)
return $ret;
}

public function processWirecardResponse($wirecardResponse)
public function processQentaResponse($qentaResponse)
{
$paymentState = isset($wirecardResponse['payment']['transaction-state']) ? $wirecardResponse['payment']['transaction-state'] : null;
if ($paymentState == 'failed') {
$paymentState = isset($qentaResponse['paymentState']) ? $qentaResponse['paymentState'] : null;
if ($paymentState == 'FAILURE') {
$message = trl('Transaktion ist fehlgeschlagen.');
$message .= ' ' . $paymentResponse['statuses']['status'][0]['description']; // take latest error message
$e = new Kwf_Exception('Wirecard Transaction Failed: '.$message);
$message .= ' ' . $qentaResponse['avsResponseMessage'];
$e = new Kwf_Exception('QENTA Transaction Failed: '.$message);
$e->log();
} else if ($paymentState == 'success') {
$orderId = $wirecardResponse['payment']['request-id'];
} else if ($paymentState == 'SUCCESS') {
$orderRow = Kwf_Model_Abstract::getInstance(Kwc_Abstract::getSetting($this->getData()->parent->parent->componentClass, 'childModel'))
->getReferencedModel('Order')->getRow($orderId);
->getReferencedModel('Order')->getRow($qentaResponse['babytuch_orderId']);

if (!$orderRow) {
throw new Kwf_Exception("Order not found");
Expand Down Expand Up @@ -77,8 +76,8 @@ public function processWirecardResponse($wirecardResponse)
$orderRow->confirm_mail_sent = date('Y-m-d H:i:s');
}
$orderRow->save();
KwcShop_Kwc_Shop_Cart_Orders::setOverriddenCartOrderId($orderId);
if (KwcShop_Kwc_Shop_Cart_Orders::getCartOrderId() == $orderId) {
KwcShop_Kwc_Shop_Cart_Orders::setOverriddenCartOrderId($orderRow->id);
if (KwcShop_Kwc_Shop_Cart_Orders::getCartOrderId() == $orderRow->id) {
KwcShop_Kwc_Shop_Cart_Orders::resetCartOrderId();
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var onReady = require('kwf/commonjs/on-ready');
var $ = require('jQuery');

onReady.onRender('.kwcClass', function(el) {
var form = el.find('form');
form.one('submit', function(e) {
e.preventDefault();
el.find('.kwcBem__process').show();
form.hide();
var config = el.data('options');
$.post(config.confirmOrderUrl, config.params)
.done(function (response) {
form.submit();
});
});
});
110 changes: 110 additions & 0 deletions KwcShop/Kwc/Shop/Cart/Checkout/Payment/Qenta/ConfirmLink/Component.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_ConfirmLink_Component extends Kwc_Abstract
{
public static function getSettings($param = null)
{
$ret = parent::getSettings($param);
$ret['viewCache'] = false;
return $ret;
}

public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer)
{
$ret = parent::getTemplateVars($renderer);
$controllerBaseUrl = Kwc_Admin::getInstance($this->getData()->componentClass)->getControllerUrl();
$ret['wirecardButton'] = $this->_getWirecardButton();
$ret['options'] = array(
'confirmOrderUrl' => "$controllerBaseUrl/json-confirm-order",
'initiatePaymentUrl' => "$controllerBaseUrl/json-initiate-payment",
'params' => array(
'paymentComponentId' => $this->getData()->parent->componentId
)
);
return $ret;
}

//used in trl
public static function buildWirecardButtonHtml($params, $payment, $order, $paymentUrl)
{
$postData = array(
'customerId' => Kwf_Config::getValue('qenta.customerId'),
'consumerBillingFirstname' => $order->firstname,
'consumerBillingLastname' => $order->lastname,
'consumerEmail' => $order->email,
'consumerBillingAddress1' => $order->street,
'consumerBillingCity' => $order->city,
'consumerBillingCountry' => $order->country,
'consumerBillingZipCode' => $order->zip,
'consumerChallengeIndicator' => '04',
'merchantTokenizationFlag' => 'true',
'orderDescription' => $order->firstname . ' ' . $order->lastname . ' (' . $order->zip . ') '.$payment->trlKwf('Order: {0}', $order->number),
'customerStatement' => trl("Bestellung Nr. {$order->number}"), // bank statement
'duplicateRequestCheck' => 'no',
'successUrl' => $payment->getChildComponent('_success')->getAbsoluteUrl(),
'cancelUrl' => $payment->getChildComponent('_cancel')->getAbsoluteUrl(),
'serviceUrl' => $payment->getChildComponent('_cancel')->getAbsoluteUrl(),
'failureUrl' => $payment->getChildComponent('_failure')->getAbsoluteUrl(),
'language' => $payment->getLanguage(),
'amount' => $params['amount'],
'currency' => $params['currency'],
'paymentType' => $params['paymentType'],
'orderReference' => $params['orderId'],
'babytuch_orderId' => $order->id
);
$postData['requestFingerprintOrder'] = self::_getRequestFingerprintOrder($postData);
$postData['requestFingerprint'] = self::_getRequestFingerprint($postData, Kwf_Config::getValue('qenta.secret'));

$ret = "<form action=\"$paymentUrl\" method=\"post\" name=\"form\">\n";
foreach ($postData as $k=>$i) {
if ($k == 'secret') continue;
$ret .= "<input type=\"hidden\" name=\"$k\" value=\"".Kwf_Util_HtmlSpecialChars::filter($i)."\">\n";
}
$ret .= "<input type=\"submit\" value=\"{$payment->trlKwf('Buy now')}\" class=\"submit\">\n";
$ret .= "</form>\n";
return $ret;

}

protected function _getWirecardButton()
{
$order = Kwf_Model_Abstract::getInstance(Kwc_Abstract::getSetting(
$this->getData()->getParentByClass('KwcShop_Kwc_Shop_Cart_Component')->componentClass, 'childModel'
))->getReferencedModel('Order')->getCartOrder();
$total = $this->getData()->getParentByClass('KwcShop_Kwc_Shop_Cart_Checkout_Component')
->getComponent()->getTotal($order);

$payment = $this->getData()->getParentByClass('KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Component');

$params = array(
'amount' => round($total, 2),
'currency' => 'EUR',
'paymentType' => Kwc_Abstract::getSetting($payment->componentClass, 'paymentType'),
'orderId' => $order->id
);
$paymentUrl = Kwf_Config::getValue('qenta.url');

return self::buildWirecardButtonHtml($params, $payment, $order, $paymentUrl);
}

protected static function _getRequestFingerprintOrder($postData)
{
$ret = '';
foreach ($postData as $key => $value) {
$ret .= "{$key},";
}
$ret .= 'requestFingerprintOrder,secret';

return $ret;
}

protected static function _getRequestFingerprint($postData, $secret)
{
$ret = '';
foreach ($postData as $key => $value) {
$ret .= "{$value}";
}
$ret .= "{$secret}";

return hash_hmac('sha512', $ret, $secret);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_ConfirmLink_Controller extends Zend_Controller_Action
{
// is called by js, so it might be that this code isn't called at all
public function jsonConfirmOrderAction()
{
$component = Kwf_Component_Data_Root::getInstance()
->getComponentById($this->_getParam('paymentComponentId'));
$order = Kwf_Model_Abstract::getInstance(Kwc_Abstract::getSetting($component->getParentByClass('KwcShop_Kwc_Shop_Cart_Component')->componentClass, 'childModel'))
->getReferencedModel('Order')->getCartOrder();
if ($order && $component &&
is_instance_of($component->componentClass, 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Component')
) {
$order->payment_component_id = $component->componentId;
$order->checkout_component_id = $component->parent->componentId;
$order->cart_component_class = $component->parent->parent->componentClass;
$order->status = 'processing';
$order->date = date('Y-m-d H:i:s');
$order->save();
$session = new Kwf_Session_Namespace('kwcShopCart');
$session->qentaCartId = $order->id;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_ConfirmLink_Trl_Component extends Kwc_Chained_Trl_Component
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_ConfirmLink_Trl_Component extends Kwc_Chained_Trl_Component
{
public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer)
{
Expand All @@ -24,7 +24,7 @@ protected function _getWirecardButton()
$total = $this->getData()->chained->getParentByClass('KwcShop_Kwc_Shop_Cart_Checkout_Component')
->getComponent()->getTotal($order);

$payment = $this->getData()->getParentByClass('KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_Trl_Component');
$payment = $this->getData()->getParentByClass('KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Trl_Component');

$params = array(
'amount' => round($total, 2),
Expand All @@ -33,10 +33,9 @@ protected function _getWirecardButton()
'orderId' => $order->id
);

$initUrl = Kwc_Admin::getInstance($this->getData()->componentClass)
->getControllerUrl() . '/json-initiate-payment';
$paymentUrl = Kwf_Config::getValue('qenta.url');

return KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_ConfirmLink_Component::buildWirecardButtonHtml($params, $payment, $order, $initUrl);
return KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_ConfirmLink_Component::buildWirecardButtonHtml($params, $payment, $order, $initUrl);
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_ConfirmLink_Trl_Controller extends Zend_Controller_Action
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_ConfirmLink_Trl_Controller extends Zend_Controller_Action
{
// is called by js, so it might be that this code isn't called at all
public function jsonConfirmOrderAction()
Expand All @@ -9,7 +9,7 @@ public function jsonConfirmOrderAction()
$order = Kwf_Model_Abstract::getInstance(Kwc_Abstract::getSetting($component->chained->getParentByClass('KwcShop_Kwc_Shop_Cart_Component')->componentClass, 'childModel'))
->getReferencedModel('Order')->getCartOrder();
if ($order && $component &&
is_instance_of($component->componentClass, 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_Trl_Component')
is_instance_of($component->componentClass, 'KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Trl_Component')
) {
$order->payment_component_id = $component->componentId;
$order->checkout_component_id = $component->parent->componentId;
Expand All @@ -18,7 +18,7 @@ public function jsonConfirmOrderAction()
$order->date = date('Y-m-d H:i:s');
$order->save();
$session = new Kwf_Session_Namespace('kwcShopCart');
$session->wirecardCartId = $order->id;
$session->qentaCartId = $order->id;
}
}
}
19 changes: 19 additions & 0 deletions KwcShop/Kwc/Shop/Cart/Checkout/Payment/Qenta/Failure/Component.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Failure_Component extends Kwc_Editable_Component
{
public static function getSettings($param = null)
{
$ret = parent::getSettings($param);
$ret['flags']['processInput'] = true;
return $ret;
}

public function getNameForEdit()
{
$ret = trlKwf('Shop Error Text');
$subroot = $this->getData()->getSubroot();
if ($subroot && isset($subroot->id)) $ret .= ' (' .$this->getData()->getSubroot()->id . ')';
$ret .= ' ' . Kwf_Trl::getInstance()->trlStaticExecute(Kwc_Abstract::getSetting($this->getData()->parent->componentClass, 'componentName'));
return $ret;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_Success_Component extends Kwc_Editable_Component
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Success_Component extends Kwc_Editable_Component
{
public static function getSettings($param = null)
{
Expand Down Expand Up @@ -32,23 +32,33 @@ protected function _getOrder()

public function processInput($data)
{
Kwf_Exception_Abstract::$logErrors = true; //activate log always, because request comes from wirecard
Kwf_Exception_Abstract::$logErrors = true; //activate log always, because request comes from qenta
ignore_user_abort(true);

if (!isset($_POST['response-base64']))
throw new Kwf_Exception_Client('Invalid request');
if (!$this->_isValidSignature($_POST['response-base64'], $_POST['response-signature-base64']))
throw new Kwf_Exception_Client('Response verification failed');
if (!isset($data['orderNumber'])) {
$home = $this->getData()->getSubroot()->getAbsoluteUrl();
header("Location: $home");
exit;
}

$paymentResponse = json_decode(base64_decode($_POST['response-base64']), true);
$this->getData()->parent->getComponent()->processWirecardResponse($paymentResponse);
if (!$this->_isValidResponse($data)) {
throw new Kwf_Exception_Client(trlKwf('An invalid response was sent.'));
}
$this->getData()->parent->getComponent()->processQentaResponse($data);
}

private function _isValidSignature($responseBase64, $signatureBase64)
private function _isValidResponse($response)
{
$secret = Kwf_Config::getValue('wirecard.secret');
$signature = hash_hmac('sha256', $responseBase64, $secret, true);
return hash_equals($signature, base64_decode($signatureBase64));
$secret = Kwf_Config::getValue('qenta.secret');
$string = '';
foreach ($response as $key => $value) {
if ($key == 'responseFingerprint') continue;
if ($key == 'responseFingerprintOrder') {
$string .= $secret;
}
$string .= "{$value}";
}
return $response['responseFingerprint'] == hash_hmac('sha512', $string, $secret);
}

public function getPlaceholders()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Wirecard_Success_Trl_Component extends Kwc_Chained_Trl_Component
class KwcShop_Kwc_Shop_Cart_Checkout_Payment_Qenta_Success_Trl_Component extends Kwc_Chained_Trl_Component
{
public function getPlaceholders()
{
Expand Down
Loading