public function execute(ListenerMessage $msg)
 {
     $tl = new TaggedLogger('PaymentCaptureAction');
     if ($msg instanceof Authorisation) {
         $jobQueueObj = Configuration::getDefaultConfig()->object('data-store/jobs-adyen');
         if ($msg->success) {
             // Here we need to capture the payment, the job runner will collect the
             // orphan message
             $tl->info("Adding Adyen capture job for {$msg->currency} {$msg->amount} " . "with id {$msg->correlationId} and psp reference {$msg->pspReference}.");
             $job = ProcessCaptureRequestJob::factory($msg);
             $jobQueueObj->push(json_decode($job->toJson(), true));
         } else {
             // And here we just need to destroy the orphan
             $tl->info("Adyen payment with correlation id {$msg->correlationId} " . "reported status failed: '{$msg->reason}'. " . 'Queueing job to delete pending records.');
             $job = DeletePendingJob::factory('adyen', $msg->merchantReference, $msg->correlationId);
             $jobQueueObj->push(json_decode($job->toJson(), true));
         }
     }
     return true;
 }
 /**
  * @expectedException \SmashPig\Core\RetryableException
  */
 public function testRequeueMessage()
 {
     $auth = KeyedOpaqueStorableObject::fromJsonProxy('SmashPig\\PaymentProviders\\Adyen\\ExpatriatedMessages\\Authorisation', file_get_contents(__DIR__ . '/../Data/auth.json'));
     $job = ProcessCaptureRequestJob::factory($auth);
     $job->execute();
 }
 /**
  * When two authorizations come in with the same merchant reference, we
  * should cancel the second one and leave the donor details in pending.
  */
 public function testDuplicateAuthorisation()
 {
     $api = $this->config->object('payment-provider/adyen/api', true);
     $auth1 = KeyedOpaqueStorableObject::fromJsonProxy('SmashPig\\PaymentProviders\\Adyen\\ExpatriatedMessages\\Authorisation', file_get_contents(__DIR__ . '/../Data/auth.json'));
     $job1 = ProcessCaptureRequestJob::factory($auth1);
     $job1->execute();
     $this->assertEquals(1, count($api->captured), 'Set up failed');
     $auth2 = KeyedOpaqueStorableObject::fromJsonProxy('SmashPig\\PaymentProviders\\Adyen\\ExpatriatedMessages\\Authorisation', file_get_contents(__DIR__ . '/../Data/auth.json'));
     $auth2->pspReference = mt_rand(1000000000, 10000000000);
     $job2 = ProcessCaptureRequestJob::factory($auth2);
     $this->assertTrue($job2->execute(), 'Duplicate auths should not clutter damage queue');
     $this->assertEquals(1, count($api->captured), 'Captured a duplicate!');
     $this->assertEquals($auth2->pspReference, $api->cancelled[0], 'Did not cancel the right authorization');
     $this->assertNotNull($this->pendingDatabase->fetchMessageByGatewayOrderId('adyen', $auth1->merchantReference), 'Capture job should leave donor details in database');
 }