Skip to content

Commit 67ef72d

Browse files
author
Fabian Pechstein
committed
[bug-fix] update CaptureQueueInterface, some state changes
1 parent 20124d0 commit 67ef72d

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-25
lines changed

src/PayoneBundle/Ecommerce/PaymentManager/BsPayone.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
use Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\Cart;
2121
use Pimcore\Bundle\EcommerceFrameworkBundle\CartManager\ICart;
2222
use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
23+
use Pimcore\Bundle\EcommerceFrameworkBundle\Model\AbstractOrder;
2324
use Pimcore\Bundle\EcommerceFrameworkBundle\Model\AbstractPaymentInformation;
2425
use Pimcore\Bundle\EcommerceFrameworkBundle\Model\Currency;
2526
use Pimcore\Bundle\EcommerceFrameworkBundle\OrderManager\OrderAgentInterface;
26-
use Pimcore\Bundle\EcommerceFrameworkBundle\PaymentManager\IStatus;
2727
use Pimcore\Bundle\EcommerceFrameworkBundle\PaymentManager\Payment\AbstractPayment;
2828
use Pimcore\Bundle\EcommerceFrameworkBundle\PaymentManager\Status;
29+
use Pimcore\Bundle\EcommerceFrameworkBundle\PaymentManager\StatusInterface;
2930
use Pimcore\Bundle\EcommerceFrameworkBundle\PaymentManager\V7\Payment\StartPaymentRequest\AbstractRequest;
3031
use Pimcore\Bundle\EcommerceFrameworkBundle\PaymentManager\V7\Payment\StartPaymentResponse\SnippetResponse;
3132
use Pimcore\Bundle\EcommerceFrameworkBundle\PaymentManager\V7\Payment\StartPaymentResponse\StartPaymentResponseInterface;
@@ -888,7 +889,7 @@ private function setupPostParametersFor($paymentType, $cart, $orderIdent, $confi
888889
/**
889890
* @param mixed $response
890891
*
891-
* @return IStatus
892+
* @return StatusInterface
892893
*
893894
* @throws \Exception
894895
*/
@@ -931,7 +932,7 @@ public function handleResponse($response)
931932
$orderIdent,
932933
$response['reference'],
933934
$response['errormessage'],
934-
IStatus::STATUS_CANCELLED,
935+
StatusInterface::STATUS_CANCELLED,
935936
[
936937
'response' => json_encode($response)
937938
]
@@ -943,10 +944,10 @@ public function handleResponse($response)
943944
return $status;
944945
}
945946

946-
$paymentStatus = IStatus::STATUS_CANCELLED;
947+
$paymentStatus = StatusInterface::STATUS_CANCELLED;
947948

948949
//this will throw an exception if there is no such entry in the DB!
949-
$logData = $this->registry->findTranslationLogsForPayoneReference($response['reference']);
950+
$logData = $this->registry->findTransactionLogsForPayoneReference($response['reference']);
950951

951952
$response['clearingtype'] = $logData[Registry::COLUMN_METHOD];
952953

@@ -961,9 +962,12 @@ public function handleResponse($response)
961962

962963
$price = new Price(Decimal::create($authorizedData['price']), new Currency($authorizedData['currency']));
963964

965+
$this->registry->logTransaction($response['reference'], $response['txid'],$response['txaction'], $response);
964966

965-
if ($response['reference'] !== null && (($response['txaction'] == 'appointed') || ($response['txaction'] == 'paid'))) {
966-
$paymentStatus = IStatus::STATUS_CLEARED;
967+
if ($response['reference'] !== null && (($response['txaction'] == 'appointed') )) {
968+
$paymentStatus = StatusInterface::STATUS_AUTHORIZED;
969+
}else if ($response['reference'] !== null && (($response['txaction'] == 'paid'))) {
970+
$paymentStatus = StatusInterface::STATUS_CLEARED;
967971
}
968972

969973
$status = new Status(
@@ -992,7 +996,7 @@ public function handleResponse($response)
992996

993997

994998
if ($orderIdent !== null && (($response['status'] == 'APPROVED'))) {
995-
$paymentStatus = IStatus::STATUS_AUTHORIZED;
999+
$paymentStatus = StatusInterface::STATUS_AUTHORIZED;
9961000
$authorizedData = array_intersect_key($response, $authorizedData);
9971001
$authorizedData['response'] = var_export($response, true);
9981002

@@ -1001,7 +1005,11 @@ public function handleResponse($response)
10011005

10021006
$this->setAuthorizedData($authorizedData);
10031007
}
1004-
1008+
else {
1009+
// failed
1010+
$paymentStatus = AbstractOrder::ORDER_STATE_ABORTED;
1011+
$message = $response['errorDetail'];
1012+
}
10051013

10061014
$status = new Status(
10071015
$orderIdent,
@@ -1012,7 +1020,6 @@ public function handleResponse($response)
10121020
'userId' => $response['userid'],
10131021
'txid' => $response['txid'],
10141022
'response' => print_r($response, true),
1015-
10161023
]
10171024
);
10181025

@@ -1047,7 +1054,7 @@ public function setAuthorizedData(array $authorizedData)
10471054
* @param IPrice $price
10481055
* @param string $reference
10491056
*
1050-
* @return IStatus
1057+
* @return StatusInterface
10511058
*/
10521059
public function executeDebit(PriceInterface $price = null, $reference = null)
10531060
{
@@ -1061,7 +1068,7 @@ public function executeDebit(PriceInterface $price = null, $reference = null)
10611068
* @param string $reference
10621069
* @param $transactionId
10631070
*
1064-
* @return IStatus
1071+
* @return StatusInterface
10651072
*/
10661073
public function executeCredit(PriceInterface $price, $reference, $transactionId)
10671074
{

src/PayoneBundle/Registry/CaptureHandler.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public function __construct( ServerToServerServiceInterface $serverService)
4747
}
4848

4949
/**
50-
* @param $txid
51-
* @param $reference
52-
* @param $amount
53-
* @param $currency
50+
* @param string $txid
51+
* @param string $reference
52+
* @param string $amount
53+
* @param string $currency
5454
* @param array $options
5555
*/
56-
public function addCapture($txid, $reference, $amount, $currency, array $options): void
56+
public function addCapture(string $txid,string $reference,string $amount,string $currency, array $options): void
5757
{
5858

5959
Lock::acquire(self::LOG_LOCK_KEY);
@@ -93,10 +93,13 @@ public function resolveCapture($txid)
9393
}
9494

9595
Lock::acquire(self::LOG_LOCK_KEY);
96+
$now = CarbonImmutable::now();
9697
//build request and send it! updated processed to current timestamp
9798
$params = $this->payone->buildCaptureRequest($txid, $result[self::COLUMN_AMOUNT], $result[self::COLUMN_CURRENCY], json_decode($result[self::COLUMN_DATA], true));
9899
$this->serverService->serverToServerRequest($params);
99100

101+
$db->updateWhere(self::LOG_TABLE_NAME, [self::COLUMN_PROCESSED=> $now ], "id = ". $result['id'] );
102+
100103
Lock::release(self::LOG_LOCK_KEY);
101104
}
102105
}

src/PayoneBundle/Registry/CaptureQueueInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ interface CaptureQueueInterface
1515
{
1616

1717
/**
18-
* @param $txid
19-
* @param $reference
20-
* @param $amount
21-
* @param $currency
18+
* @param string $txid
19+
* @param string $reference
20+
* @param string $amount
21+
* @param string $currency
2222
* @param array $options
2323
*/
24-
public function addCapture($txid, $reference, $amount, $currency, array $options): void;
24+
public function addCapture(string $txid,string $reference,string $amount,string $currency, array $options): void;
2525

2626
/**
2727
* @param $txid

src/PayoneBundle/Registry/IRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ public function findTransactionLogsForInternalId($internalReference);
5959
* @return array|mixed|null
6060
* @throws \Exception
6161
*/
62-
public function findTranslationLogsForPayoneReference($payoneReference);
62+
public function findTransactionLogsForPayoneReference($payoneReference);
6363

6464
}

src/PayoneBundle/Registry/Registry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ public function findTransactionLogsForInternalId($internalReference)
156156
* @return array|mixed|null
157157
* @throws \Exception
158158
*/
159-
public function findTranslationLogsForPayoneReference($payoneReference)
159+
public function findTransactionLogsForPayoneReference($payoneReference)
160160
{
161161

162162
$db = Db::get();
163163
$result = $db->fetchRow(
164-
"SELECT * FROM " . self::LOG_TABLE_NAME . " WHERE `" . self::COLUMN__PAYONE_REFERENCE . "` = ?",
164+
"SELECT * FROM " . self::LOG_TABLE_NAME . " WHERE `" . self::COLUMN__PAYONE_REFERENCE . "` = ? AND (`method` = 'preauthorization' OR `method` = 'authorization') ",
165165
[$payoneReference]
166166
);
167167

0 commit comments

Comments
 (0)