public function testFetchMessageByGatewayOrderId()
 {
     $message = self::getTestMessage();
     $this->db->storeMessage($message);
     $fetched = $this->db->fetchMessageByGatewayOrderId('test', $message['order_id']);
     $this->assertNotNull($fetched, 'Record retrieved by fetchMessageByGatewayOrderId.');
     $expected = $message + array('pending_id' => 1);
     $this->assertEquals($expected, $fetched, 'Fetched record matches stored message.');
 }
 /**
  * We refuse to consume a message and drop it if the corresponding
  * payments_initial row is failed.
  */
 public function testPendingMessageInitialFailed()
 {
     $initRow = PaymentsInitialDatabaseTest::generateTestMessage();
     $initRow['payments_final_status'] = 'failed';
     $initRow['validation_action'] = 'reject';
     $this->paymentsInitialDb->storeMessage($initRow);
     $message = self::generatePendingMessageFromInitial($initRow);
     $consumer = new PendingQueueConsumer('pending', 1000, 1000);
     $consumer->processMessage($message);
     $fetched = $this->pendingDb->fetchMessageByGatewayOrderId($message['gateway'], $message['order_id']);
     $this->assertNull($fetched, 'Message consumed and not stored in the pending database.');
 }
 public function testRecordCapture()
 {
     $verifiedQueue = BaseQueueConsumer::getQueue('verified');
     $verifiedQueue->createTable('verified');
     $capture = KeyedOpaqueStorableObject::fromJsonProxy('SmashPig\\PaymentProviders\\Adyen\\ExpatriatedMessages\\Capture', file_get_contents(__DIR__ . '/../Data/capture.json'));
     $job = RecordCaptureJob::factory($capture);
     $this->assertTrue($job->execute());
     $donorData = $this->pendingDatabase->fetchMessageByGatewayOrderId('adyen', $capture->merchantReference);
     $this->assertNull($donorData, 'RecordCaptureJob left donor data on pending queue');
     $verifiedMessage = $verifiedQueue->pop();
     $this->assertNotNull($verifiedMessage, 'RecordCaptureJob did not send verified message');
     // can we use arraySubset yet?
     $sameKeys = array_intersect(array_keys($verifiedMessage), array_keys($this->pendingMessage));
     foreach ($sameKeys as $key) {
         if ($key === 'gateway_txn_id') {
             $this->assertEquals($capture->originalReference, $verifiedMessage[$key], 'RecordCaptureJob should have set gateway_txn_id');
         } else {
             $this->assertEquals($this->pendingMessage[$key], $verifiedMessage[$key], "Value of key {$key} mutated");
         }
     }
 }
 /**
  * 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');
 }