public function execute()
 {
     $logger = Logger::getTaggedLogger("corr_id-adyen-{$this->merchantReference}");
     $logger->info("Recording successful capture on account '{$this->account}' with authorization reference " . "'{$this->originalReference}' and order ID '{$this->merchantReference}'.");
     $config = Configuration::getDefaultConfig();
     // Find the details from the payment site in the pending database.
     $logger->debug('Attempting to locate associated message in pending database');
     $db = PendingDatabase::get();
     $dbMessage = $db->fetchMessageByGatewayOrderId('adyen', $this->merchantReference);
     if ($dbMessage && isset($dbMessage['order_id'])) {
         $logger->debug('A valid message was obtained from the pending queue');
         // Add the gateway transaction ID and send it to the completed queue
         $dbMessage['gateway_txn_id'] = $this->originalReference;
         $queueMessage = DonationInterfaceMessage::fromValues($dbMessage);
         SourceFields::addToMessage($queueMessage);
         $config->object('data-store/verified')->push($queueMessage);
         // Remove it from the pending database
         $logger->debug('Removing donor details message from pending database');
         $db->deleteMessage($dbMessage);
     } else {
         // Sometimes we don't have a pending db row because the donor made
         // multiple attempts with the same order ID. It would be nice if
         // Adyen could prevent that, but let's not send a failmail since
         // we'll eventually get the donor details from the payments log
         // when we parse the audit.
         $logger->warning("Could not find donor details for authorization Reference '{$this->originalReference}' " . "and order ID '{$this->merchantReference}'.", $dbMessage);
     }
     return true;
 }
 public function execute(Request $request, Response $response)
 {
     parent::execute($request, $response);
     Logger::info("Starting processing of listener request from {$this->request->getClientIp()}");
     try {
         $this->doIngressSecurity();
         $soapData = $request->getRawRequest();
         $tl = Logger::getTaggedLogger('RawData');
         $tl->info($soapData);
         $response->sendHeaders();
         /* --- Unfortunately because of how PHP handles SOAP requests we cannot do the fully wrapped
         					loop like we could in the REST listener. Instead it is up to the listener itself to
         					do the required call to $this->processMessage( $msg ).
         
         					It is also expected that inside the handle() context that an exception will throw a SOAP
         					fault through $this->server->fault() instead of doing a $response->kill_response() call.
         			*/
         $this->server->setObject($this);
         $this->server->handle($soapData);
         /* We disable output late in the game in case there was a last minute exception that could
         			be handled by the SOAP listener object inside the handle() context. */
         $response->setOutputDisabled();
     } catch (ListenerSecurityException $ex) {
         Logger::notice('Message denied by security policy, death is me.', null, $ex);
         $response->setStatusCode(403, "Not authorized.");
     } catch (\Exception $ex) {
         Logger::error('Listener threw an unknown exception, death is me.', null, $ex);
         $response->setStatusCode(500, "Unknown listener exception.");
     }
     Logger::info('Finished processing listener request');
 }
 public function execute()
 {
     $this->logger = Logger::getTaggedLogger("corr_id-{$this->correlationId}");
     $this->logger->info("Running capture request job on account '{$this->account}' with reference '{$this->pspReference}' " . "and correlation id '{$this->correlationId}'.");
     // Determine if a message exists in the pending database; if it does not then
     // this payment has already been sent to the verified queue, or there is a
     // problem with the database. If it does exist, we need to check
     // $capture_requested in case we have requested a capture but have not yet
     // received notification of capture success. Either case can occur when a
     // donor submits their credit card details multiple times against a single
     // order ID. We should cancel duplicate authorizations, but leave payments
     // with missing donor details open for potential manual capture.
     $this->logger->debug('Attempting to locate associated message in pending database.');
     $db = PendingDatabase::get();
     $dbMessage = $db->fetchMessageByGatewayOrderId('adyen', $this->merchantReference);
     $success = true;
     $action = $this->determineAction($dbMessage);
     switch ($action) {
         case self::ACTION_PROCESS:
             // Attempt to capture the payment
             /**
              * @var AdyenPaymentsInterface
              */
             $api = $this->getApi();
             $this->logger->info("Attempting capture API call for currency '{$this->currency}', " . "amount '{$this->amount}', reference '{$this->pspReference}'.");
             $captureResult = $api->capture($this->currency, $this->amount, $this->pspReference);
             if ($captureResult) {
                 // Success!
                 $this->logger->info("Successfully captured payment! Returned reference: '{$captureResult}'. " . 'Marking pending database message as captured.');
                 $dbMessage['captured'] = true;
                 $db->storeMessage($dbMessage);
             } else {
                 // Some kind of error in the request. We should keep the pending
                 // db entry, complain loudly, and move this capture job to the
                 // damaged queue.
                 $this->logger->error("Failed to capture payment on account '{$this->account}' with reference " . "'{$this->pspReference}' and order id '{$this->merchantReference}'.", $dbMessage);
                 $success = false;
             }
             break;
         case self::ACTION_REJECT:
             $this->cancelAuthorization();
             // Delete the fraudy donor details
             $db->deleteMessage($dbMessage);
             break;
         case self::ACTION_DUPLICATE:
             // We have already captured one payment for this donation attempt, so
             // cancel the duplicate authorization. If there is a pending db entry,
             // leave it intact for the legitimate RecordCaptureJob.
             $this->cancelAuthorization();
             break;
         case self::ACTION_REVIEW:
             // Don't capture the payment right now, but leave the donor details in
             // the pending database in case the authorization is captured via the console.
             break;
         case self::ACTION_MISSING:
             // Missing donor details - retry later
             throw new RetryableException('Missing donor details');
     }
     return $success;
 }
 protected function parseEnvelope(Request $request)
 {
     $requestValues = $request->getValues();
     $secureLog = Logger::getTaggedLogger('RawData');
     $secureLog->info("Incoming message (raw)", $requestValues);
     $messages = array();
     // Can't even check signature without these four
     $required = array('result', 'x_amount', 'x_invoice', 'x_control');
     $missing = array_diff($required, array_keys($requestValues));
     if (count($missing)) {
         $list = implode(',', $missing);
         throw new ListenerDataException("AstroPay message missing required key(s) {$list}.");
     }
     $result = $requestValues['result'];
     if (array_key_exists($result, $this->byResult)) {
         $klass = $this->byResult[$result];
         $message = new $klass();
         $message->constructFromValues($requestValues);
         $secureLog->debug("Found message ", $message);
         $messages[] = $message;
     } else {
         Logger::info("Message ignored: result = {$result}");
     }
     return $messages;
 }
 public function execute()
 {
     $logger = Logger::getTaggedLogger("corr_id-{$this->gateway}-{$this->order_id}");
     $logger->info("Deleting message from pending db where gateway = '{$this->gateway}' " . "and order ID='{$this->order_id}'");
     $deleteParams = array('gateway' => $this->gateway, 'order_id' => $this->order_id);
     PendingDatabase::get()->deleteMessage($deleteParams);
     return true;
 }
 /**
  * Do the actual work of the script.
  */
 public function execute()
 {
     Logger::info('Info log message');
     Logger::debug('Debug log message');
     Logger::notice('Notice...');
     Logger::getTaggedLogger('RawData')->info('This should be tagged RawData');
     Logger::warning('Warning!', array('foo' => 'bar'));
     try {
         $this->throwException();
     } catch (SmashPigException $ex) {
         Logger::error('ERROR!!!!', null, $ex);
     }
 }
 protected function parseEnvelope(Request $request)
 {
     // Symfony's framework gives us each header's value as an array
     // (to account for potential repeated headers?
     // IpnHandler's constructor expects scalar values, so we flatten them
     $headers = array();
     foreach ($request->headers->all() as $header => $annoyingArray) {
         if (count($annoyingArray) !== 1) {
             throw new ListenerDataException("header '{$header}' should have a single value");
         }
         $headers[$header] = $annoyingArray[0];
     }
     $json = $request->getRawRequest();
     $secureLog = Logger::getTaggedLogger('RawData');
     $secureLog->info('Incoming message (raw)', array('headers' => $headers, 'body' => $json));
     $messages = array();
     try {
         $amazonHandlerMessage = AmazonApi::createIpnHandler($headers, $json);
     } catch (\Exception $ex) {
         // FIXYOU: IpnHandler should use exception subclasses or error codes
         // Assuming here that IpnHandler's problem was with the signature
         // We can get away with throwing ListenerSecurityException here
         // because of how RestListener is implemented and because we only
         // process one message per request
         // Bad form, but it would be odd to hold this till doMessageSecurity
         throw new ListenerSecurityException($ex->getMessage());
     }
     $messageValues = $amazonHandlerMessage->toArray();
     $type = $messageValues['NotificationType'];
     if (array_key_exists($type, $this->messageClasses)) {
         $byStatus = $this->messageClasses[$type];
         $status = $this->getMessageStatus($messageValues, $type);
         if (array_key_exists($status, $byStatus)) {
             $klass = $byStatus[$status];
             $message = new $klass($messageValues);
             $secureLog->debug('Created message', $message);
             $messages[] = $message;
         } else {
             Logger::info("Message ignored: status = {$status}");
         }
     } else {
         Logger::info("Message ignored: notificationType = {$type}");
     }
     return $messages;
 }