Skip to content

Commit

Permalink
Merge pull request mewebstudio#66 from nuryagdym/refactor-methods-for…
Browse files Browse the repository at this point in the history
…-better-testing

Refactor methods for better testing
  • Loading branch information
nuryagdym authored Apr 15, 2022
2 parents c3a92b7 + a283159 commit f1dcba4
Show file tree
Hide file tree
Showing 27 changed files with 322 additions and 121 deletions.
3 changes: 2 additions & 1 deletion examples/akbank/_payment_config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Mews\Pos\Entity\Card\AbstractCreditCard;
use Mews\Pos\Gateways\AbstractGateway;

require __DIR__.'/../_main_config.php';
Expand Down Expand Up @@ -105,6 +106,6 @@ function doPayment(\Mews\Pos\PosInterface $pos, string $transaction, ?\Mews\Pos\
12,
'000',
'John Doe',
'visa'
AbstractCreditCard::CARD_TYPE_VISA
),
];
3 changes: 2 additions & 1 deletion examples/finansbank-payfor/_payment_config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Mews\Pos\Entity\Card\AbstractCreditCard;
use Mews\Pos\Gateways\AbstractGateway;

require __DIR__.'/../_main_config.php';
Expand Down Expand Up @@ -98,6 +99,6 @@ function doPayment(\Mews\Pos\PosInterface $pos, string $transaction, ?\Mews\Pos\
1,
'123',
'John Doe',
'visa'
AbstractCreditCard::CARD_TYPE_VISA
),
];
3 changes: 2 additions & 1 deletion examples/garanti/_payment_config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Mews\Pos\Entity\Card\AbstractCreditCard;
use Mews\Pos\Gateways\AbstractGateway;

require __DIR__.'/../_main_config.php';
Expand Down Expand Up @@ -93,6 +94,6 @@ function doPayment(\Mews\Pos\PosInterface $pos, string $transaction, ?\Mews\Pos\
12,
'000',
'John Doe',
'visa'
AbstractCreditCard::CARD_TYPE_VISA
),
];
5 changes: 3 additions & 2 deletions examples/interpos/_payment_config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Mews\Pos\Entity\Card\AbstractCreditCard;
use Mews\Pos\Gateways\AbstractGateway;

require __DIR__.'/../_main_config.php';
Expand Down Expand Up @@ -92,14 +93,14 @@ function doPayment(\Mews\Pos\PosInterface $pos, string $transaction, ?\Mews\Pos\
11,
592,
'John Doe',
'visa'
AbstractCreditCard::CARD_TYPE_VISA
),
'visa2' => new \Mews\Pos\Entity\Card\CreditCardInterPos(
'4090700101174272',
22,
12,
104,
'John Doe',
'visa'
AbstractCreditCard::CARD_TYPE_VISA
),
];
3 changes: 2 additions & 1 deletion examples/vakifbank/_payment_config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Mews\Pos\Entity\Card\AbstractCreditCard;
use Mews\Pos\Gateways\AbstractGateway;

require __DIR__.'/../_main_config.php';
Expand Down Expand Up @@ -90,6 +91,6 @@ function doPayment(\Mews\Pos\PosInterface $pos, string $transaction, ?\Mews\Pos\
11,
454,
'John Doe',
'visa'
AbstractCreditCard::CARD_TYPE_VISA
),
];
2 changes: 1 addition & 1 deletion examples/ykb/3d/_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

require '../_payment_config.php';

$baseUrl = $hostUrl.'/3d/';
$baseUrl = $bankTestsUrl.'/3d/';

$account = AccountFactory::createPosNetAccount(
'yapikredi',
Expand Down
3 changes: 2 additions & 1 deletion examples/ykb/_payment_config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Mews\Pos\Entity\Card\AbstractCreditCard;
use Mews\Pos\Gateways\AbstractGateway;

require __DIR__.'/../_main_config.php';
Expand Down Expand Up @@ -78,6 +79,6 @@ function doPayment(\Mews\Pos\PosInterface $pos, string $transaction, ?\Mews\Pos\
11,
454,
'John Doe',
'visa'
AbstractCreditCard::CARD_TYPE_VISA
),
];
5 changes: 5 additions & 0 deletions src/Entity/Card/AbstractCreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
*/
abstract class AbstractCreditCard
{
public const CARD_TYPE_VISA = 'visa';
public const CARD_TYPE_MASTERCARD = 'master';
public const CARD_TYPE_AMEX = 'amex';
public const CARD_TYPE_TROY = 'troy';

/**
* 16 digit credit card number without spaces
* @var string
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/Card/CreditCardEstPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
class CreditCardEstPos extends AbstractCreditCard
{
private $cardTypeToCodeMapping = [
'visa' => '1',
'master' => '2',
self::CARD_TYPE_VISA => '1',
self::CARD_TYPE_MASTERCARD => '2',
];

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Entity/Card/CreditCardInterPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
class CreditCardInterPos extends AbstractCreditCard
{
private $cardTypeToCodeMapping = [
'visa' => '0',
'master' => '1',
'amex' => '3',
self::CARD_TYPE_VISA => '0',
self::CARD_TYPE_MASTERCARD => '1',
self::CARD_TYPE_AMEX => '3',
];

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Entity/Card/CreditCardVakifBank.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
class CreditCardVakifBank extends AbstractCreditCard
{
private static $cardTypeToCodeMapping = [
'visa' => '100',
'master' => '200',
'troy' => '300',
'amex' => '400',
self::CARD_TYPE_VISA => '100',
self::CARD_TYPE_MASTERCARD => '200',
self::CARD_TYPE_TROY => '300',
self::CARD_TYPE_AMEX => '400',
];

/**
Expand Down
28 changes: 15 additions & 13 deletions src/Gateways/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Mews\Pos\Exceptions\UnsupportedPaymentModelException;
use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\PosInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\Encoder\XmlEncoder;

/**
Expand Down Expand Up @@ -309,18 +310,19 @@ public function setTxType(string $txType)
*/
public function payment($card = null)
{
$request = Request::createFromGlobals();
$this->card = $card;

$model = $this->account->getModel();

if (self::MODEL_NON_SECURE === $model) {
$this->makeRegularPayment();
} elseif (self::MODEL_3D_SECURE === $model) {
$this->make3DPayment();
$this->make3DPayment($request);
} elseif (self::MODEL_3D_PAY === $model) {
$this->make3DPayPayment();
$this->make3DPayPayment($request);
} elseif (self::MODEL_3D_HOST === $model) {
$this->make3DHostPayment();
$this->make3DHostPayment($request);
} else {
throw new UnsupportedPaymentModelException();
}
Expand All @@ -340,9 +342,9 @@ public function makeRegularPayment()
$contents = $this->createRegularPostXML();
}

$this->send($contents);
$bankResponse = $this->send($contents);

$this->response = (object) $this->mapPaymentResponse($this->data);
$this->response = (object) $this->mapPaymentResponse($bankResponse);

return $this;
}
Expand All @@ -353,9 +355,9 @@ public function makeRegularPayment()
public function refund()
{
$xml = $this->createRefundXML();
$this->send($xml);
$bankResponse = $this->send($xml);

$this->response = $this->mapRefundResponse($this->data);
$this->response = $this->mapRefundResponse($bankResponse);

return $this;
}
Expand All @@ -366,9 +368,9 @@ public function refund()
public function cancel()
{
$xml = $this->createCancelXML();
$this->send($xml);
$bankResponse = $this->send($xml);

$this->response = $this->mapCancelResponse($this->data);
$this->response = $this->mapCancelResponse($bankResponse);

return $this;
}
Expand All @@ -380,9 +382,9 @@ public function status()
{
$xml = $this->createStatusXML();

$this->send($xml);
$bankResponse = $this->send($xml);

$this->response = $this->mapStatusResponse($this->data);
$this->response = $this->mapStatusResponse($bankResponse);

return $this;
}
Expand All @@ -394,9 +396,9 @@ public function history(array $meta)
{
$xml = $this->createHistoryXML($meta);

$this->send($xml);
$bankResponse = $this->send($xml);

$this->response = $this->mapHistoryResponse($this->data);
$this->response = $this->mapHistoryResponse($bankResponse);

return $this;
}
Expand Down
26 changes: 11 additions & 15 deletions src/Gateways/EstPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,9 @@ public function check3DHash(array $data): bool
/**
* @inheritDoc
*/
public function make3DPayment()
public function make3DPayment(Request $request)
{
$request = Request::createFromGlobals();


$provisionResponse = null;
if ($this->check3DHash($request->request->all())) {
if ($request->request->get('ProcReturnCode') !== '00') {
/**
Expand All @@ -175,21 +173,19 @@ public function make3DPayment()
*/
}
$contents = $this->create3DPaymentXML($request->request->all());
$this->send($contents);
$provisionResponse = $this->send($contents);
}

$this->response = $this->map3DPaymentData($request->request->all(), $this->data);
$this->response = $this->map3DPaymentData($request->request->all(), $provisionResponse);

return $this;
}

/**
* @inheritDoc
*/
public function make3DPayPayment()
public function make3DPayPayment(Request $request)
{
$request = Request::createFromGlobals();

$this->response = $this->map3DPayResponseData($request->request->all());

return $this;
Expand All @@ -198,9 +194,9 @@ public function make3DPayPayment()
/**
* @inheritDoc
*/
public function make3DHostPayment()
public function make3DHostPayment(Request $request)
{
return $this->make3DPayPayment();
return $this->make3DPayPayment($request);
}

/**
Expand Down Expand Up @@ -253,7 +249,7 @@ public function get3DFormData(): array
/**
* @inheritDoc
*/
public function send($contents)
public function send($contents, ?string $url = null)
{
$client = new Client();

Expand All @@ -263,7 +259,7 @@ public function send($contents)

$this->data = $this->XMLStringToObject($response->getBody()->getContents());

return $this;
return $this->data;
}

/**
Expand All @@ -273,9 +269,9 @@ public function history(array $meta)
{
$xml = $this->createHistoryXML($meta);

$this->send($xml);
$bankResponse = $this->send($xml);

$this->response = $this->mapHistoryResponse($this->data);
$this->response = $this->mapHistoryResponse($bankResponse);

return $this;
}
Expand Down
Loading

0 comments on commit f1dcba4

Please sign in to comment.