Commit 5457fe82 authored by GiorgosK's avatar GiorgosK

Run phpcbf --standard='Drupal'

parent 7cea6e6d
......@@ -6,4 +6,3 @@ core: 8.x
dependencies:
- commerce:commerce
- commerce:commerce_payment
......@@ -43,10 +43,3 @@ commerce_payment.commerce_payment_gateway.plugin.winbankpayment_redirect:
auto_redirect:
type: boolean
label: 'Auto Redirect'
<?php
/**
* @file
*/
?>
<!DOCTYPE html>
<html lang="en">
......@@ -11,7 +17,7 @@
<div>
<h1>Received</h1>
<?php
foreach($_REQUEST as $key => $value){
foreach ($_REQUEST as $key => $value) {
echo $key . " : " . $value . "<br />\r\n";
}
?>
......
<?php
class TicketSoapServer
{
public function IssueNewTicket($xml)
{
/**
*
*/
class TicketSoapServer {
/**
*
*/
public function IssueNewTicket($xml) {
$result = [];
$IssueNewTicketResult = [
"ResultCode" => "0",
......@@ -13,8 +18,9 @@ class TicketSoapServer
];
return ["IssueNewTicketResult" => $IssueNewTicketResult];
}
}
$options= array('uri'=>'http://localhost:8008/ticket.php');
$server=new SoapServer(NULL,$options);
$options = ['uri' => 'http://localhost:8008/ticket.php'];
$server = new SoapServer(NULL, $options);
$server->setClass('TicketSoapServer');
$server->handle();
......@@ -5,7 +5,6 @@ namespace Drupal\commerce_winbank\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Drupal\commerce_order\Entity\Order;
......@@ -14,10 +13,13 @@ use Drupal\commerce_order\Entity\Order;
*/
class CallbackController extends ControllerBase {
/**
* @var EntityTypeManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
*
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->entityTypeManager = $entityTypeManager;
}
......@@ -36,9 +38,9 @@ class CallbackController extends ControllerBase {
*
* Listen for callbacks from QuickPay and creates any payment specified.
*
* @param Request $request
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return Response
* @return \Symfony\Component\HttpFoundation\Response
*/
public function callback(Request $request) {
$message = $this->processCallback($request);
......@@ -48,11 +50,10 @@ class CallbackController extends ControllerBase {
];
}
/**
* Process the callback from winbank
* Process the callback from winbank.
*/
public function processCallback(Request $request){
public function processCallback(Request $request) {
$action = $request->get("action");
if ($action == "cancel") {
return "You have cancelled your payment";
......@@ -63,7 +64,7 @@ class CallbackController extends ControllerBase {
$ticket_result = $order->getData("IssueNewTicketResult");
$hash = $this->calculateHash($request, $order_id, $ticket_result);
if($hash !== $hashkey) {
if ($hash !== $hashkey) {
$this->createPayment($order, $request, $ticket_result, "Unvalidated");
return "Sorry we were not able to validate your payment";
}
......@@ -72,26 +73,25 @@ class CallbackController extends ControllerBase {
}
/**
* create Payment
* Create Payment.
*/
public function createPayment(Order $order, $request, $ticket_result, $state = "completed"){
public function createPayment(Order $order, $request, $ticket_result, $state = "completed") {
$payment_storage = $this->entityTypeManager->getStorage('commerce_payment');
$payment = $payment_storage->create([
'state' => $state,
'amount' => $order->getBalance(),
'payment_gateway' => $ticket_result["payment_gateway"],
'payment_gateway' => $ticket_result["payment_gateway"],
'order_id' => $order->id(),
'remote_id' => $request->get('TransactionId'),
'remote_state' => $request->get('StatusFlag'),
]);
if($state == "completed"){
if ($state == "completed") {
$payment->setAuthorizedTime(REQUEST_TIME);
$payment->setCompletedTime(REQUEST_TIME);
}
$payment->save();
}
/**
* Calculates hash key by concatenation of values, then uses sha256 algorithm.
*
......@@ -105,7 +105,7 @@ class CallbackController extends ControllerBase {
*
* @return string
*/
public function calculateHash($request, $order_id, $ticket_result){
public function calculateHash($request, $order_id, $ticket_result) {
$concatValues = sprintf(
'%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s',
$ticket_result['TranTicket'],
......@@ -120,7 +120,7 @@ class CallbackController extends ControllerBase {
$request->get('PackageNo'),
$request->get('StatusFlag')
);
return hash_hmac('sha256', $concatValues, $ticket_result['TranTicket'], false);
return hash_hmac('sha256', $concatValues, $ticket_result['TranTicket'], FALSE);
}
/**
......@@ -154,4 +154,5 @@ class CallbackController extends ControllerBase {
}
return $message;
}
}
......@@ -2,14 +2,9 @@
namespace Drupal\commerce_winbank\Plugin\Commerce\PaymentGateway;
use Drupal\commerce_payment\Exception\DeclineException;
use Drupal\commerce_payment\Exception\InvalidResponseException;
use Drupal\commerce_payment\Exception\PaymentGatewayException;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides the Off-site Redirect payment gateway.
*
......
......@@ -7,6 +7,9 @@ use Drupal\commerce_payment\Exception\PaymentGatewayException;
use Drupal\commerce_payment\PluginForm\PaymentOffsiteForm as BasePaymentOffsiteForm;
use Drupal\Core\Form\FormStateInterface;
/**
*
*/
class WinbankPaymentRedirectForm extends BasePaymentOffsiteForm {
/**
......@@ -19,7 +22,7 @@ class WinbankPaymentRedirectForm extends BasePaymentOffsiteForm {
$payment_gateway_plugin = $payment->getPaymentGateway()->getPlugin();
$config = $payment_gateway_plugin->getConfiguration();
$order = $payment->getOrder();
// Format amount
// Format amount.
$amount = sprintf('%0.2f', $order->getTotalPrice()->getNumber());
if ($config['mode'] == 'test') {
......@@ -32,14 +35,14 @@ class WinbankPaymentRedirectForm extends BasePaymentOffsiteForm {
throw new PaymentGatewayException('Merchant ID not provided.');
}
// Get new ticket
// Get new ticket.
try {
$result = $this->getNewTicket($amount, $order->id(), $config);
if ($result->IssueNewTicketResult->ResultCode == 0) {
// save response data for validating response later
$order->setData("IssueNewTicketResult",[
// Save response data for validating response later.
$order->setData("IssueNewTicketResult", [
"ResultCode" => $result->IssueNewTicketResult->ResultCode,
"TranTicket" => $result->IssueNewTicketResult->TranTicket,
"Timestamp" => $result->IssueNewTicketResult->Timestamp,
......@@ -51,15 +54,17 @@ class WinbankPaymentRedirectForm extends BasePaymentOffsiteForm {
]);
$order->save();
} else {
$message = 'There was a problem connecting ot the ticket issuer: '. $result->IssueNewTicketResult->ResultDescription;
}
else {
$message = 'There was a problem connecting ot the ticket issuer: ' . $result->IssueNewTicketResult->ResultDescription;
throw new InvalidResponseException($message);
}
} catch (Exception $e) {
}
catch (Exception $e) {
throw new InvalidResponseException('Could not connect to bank ticket issuer');
}
// Prepare redirect form
// Prepare redirect form.
$data = [
'AcquirerId' => $config['acquirer_id'],
'MerchantId' => $config['merchant_id'],
......@@ -71,15 +76,14 @@ class WinbankPaymentRedirectForm extends BasePaymentOffsiteForm {
];
$form = $this->buildRedirectForm($form, $form_state, $config['paycenter_url'], $data, 'post');
if($config['auto_redirect']){
if ($config['auto_redirect']) {
unset($form['#attached']['library']);
}
return $form;
}
/**
* Soap request to get NewTicket for transaction
* Soap request to get NewTicket for transaction.
*
* @param int $amount
* The order amount.
......@@ -90,14 +94,13 @@ class WinbankPaymentRedirectForm extends BasePaymentOffsiteForm {
*
* @return array
* Object containing the soap service response.
*
*/
public function getNewTicket($amount, $orderid, $config){
//libxml_disable_entity_loader(false);
$options= array(
'location' => $config['tickets_url'],
'uri' => $config['tickets_url']
);
public function getNewTicket($amount, $orderid, $config) {
// libxml_disable_entity_loader(false);
$options = [
'location' => $config['tickets_url'],
'uri' => $config['tickets_url'],
];
$soap = new \SoapClient(NULL, $options);
$ticketRequest = [
'Username' => $config['username'],
......@@ -112,11 +115,12 @@ class WinbankPaymentRedirectForm extends BasePaymentOffsiteForm {
'CurrencyCode' => $config['currency_code'],
'Installments' => 0,
'Bnpl' => '0',
'Parameters' => ''
'Parameters' => '',
];
$xml = [
'Request' => $ticketRequest,
];
$xml = array(
'Request' => $ticketRequest
);
return $soap->IssueNewTicket($xml);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment