Swedbank-SPP / swedbank-payment-portal

Swedbank Payment Portal API library for PHP
Other
36 stars 21 forks source link

BankLinkService::handlePendingUnfinishedResponse() does not remove finished purchases #4

Closed maijs closed 7 years ago

maijs commented 7 years ago

I have a problem with BankLinkService::checkPendingTransactions() where transactions are not being removed from local transaction repository even if response from the gateway indicates that they are successful.

Steps to reproduce:

  1. Initiate a payment with $spp->getBankLinkGateway()->initPayment() with (example) merchant reference ABC.
  2. Complete the payment process, get back to the merchant's store, at which point the callback is executed.
  3. Wait 30 minutes, cron will run $spp->getBankLinkGateway()->checkPendingTransactions(); which will query the gateway for status of transaction with merchant reference ABC. That will trigger the callback in the same manner it did in step 2.
  4. Repeat step 3.

\SwedbankPaymentPortal\BankLink\BankLinkService::handlePendingUnfinishedResponse() has the following code:

$transactionResult = $this->getTransactionResultFromQueryResponse($response);

if ($transactionResult) {
    $callback = $container->getCallback();
    $callback->handleFinishedTransaction($transactionResult, $transactionFrame);
    $this->getTransactionRepository()->remove($merchantReference);
};

$container->addFrame($transactionFrame);
$this->getTransactionRepository()->persist($container);

On successful transaction result transaction with merchant reference is being removed from transaction repository (->remove($merchantReference)), but then again the container which is obtained with the merchant reference is persisted with ->persist($container) which stores the transaction as pending again.

Swedbank-SPP commented 7 years ago

Thanks! Fixed.