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(ListenerMessage $msg)
 {
     $destinationQueue = $msg->getDestinationQueue();
     if ($destinationQueue) {
         $queue = Context::get()->getConfiguration()->object("data-store/{$destinationQueue}");
         $queueMsg = $msg->normalizeForQueue();
         SourceFields::addToMessage($queueMsg);
         $queue->push($queueMsg);
     } else {
         $class = get_class($msg);
         Logger::warning("Ignoring message of type {$class}", $msg);
     }
     return true;
 }
 /**
  * Will run all the actions that are loaded (from the 'actions' configuration
  * node) and that are applicable to this message type. Will return true
  * if all actions returned true. Otherwise will return false. This implicitly
  * means that the message will be re-queued if any action fails. Therefore
  * all actions need to be idempotent.
  *
  * @returns bool True if all actions were successful. False otherwise.
  */
 public function runActionChain()
 {
     Logger::info("Received new report from Adyen: {$this->pspReference}. Generated: {$this->eventDate}.", $this->reason);
     $jobQueue = BaseQueueConsumer::getQueue('jobs-adyen');
     if (strpos($this->pspReference, 'settlement_detail_report') === 0) {
         $jobObject = DownloadReportJob::factory($this->merchantAccountCode, $this->reason);
         // FIXME: write queue wrapper to do these next two steps
         SourceFields::addToMessage($jobObject);
         $jobArray = json_decode($jobObject->toJson(), true);
         $jobQueue->push($jobArray);
     } else {
         // We don't know how to handle this report yet
         Logger::notice("Do not know how to handle report with name '{$this->pspReference}'");
     }
     return parent::runActionChain();
 }
 public function execute()
 {
     $this->config = Configuration::getDefaultConfig();
     if ($this->is_reject()) {
         // Returning false would cause it to go to the damaged queue, we
         // just want to forget about these.
         return true;
     }
     // XXX Why does everything get made into objects?
     $request = (array) $this->payload;
     // Determine message type.
     if (isset($request['txn_type'])) {
         $txn_type = $request['txn_type'];
     } elseif (isset($request['payment_status']) && in_array($request['payment_status'], array('Reversed', 'Refunded'))) {
         // refund, chargeback, or reversal
         $txn_type = 'refund';
     } else {
         throw new Exception('Invalid PayPal message: ' . json_encode($request));
     }
     $msg_type = null;
     foreach ($this->config->val('messages') as $type => $conf) {
         if (in_array($txn_type, $conf['txn_types'])) {
             $msg_type = $type;
         }
     }
     if (!$msg_type) {
         throw new Exception('Invalid PayPal message type: ' . $txn_type);
     }
     // Transform into new message.
     // FIXME this could just be an array, but we need compat with
     // keyedopaque* until activemq goes away
     $new_msg = new Message();
     // FIXME hacks because the recurring consumer doesn't want
     // a normalized message
     if ($msg_type === 'recurring') {
         foreach ($request as $key => $val) {
             $new_msg->{$key} = $val;
         }
     } else {
         $map = $this->config->val('var_map');
         foreach ($map as $rx => $tx) {
             if (array_key_exists($rx, $request)) {
                 $new_msg->{$tx} = $request[$rx];
             }
         }
         // FIXME: var map can't put one thing in two places
         if (isset($new_msg->contribution_tracking_id)) {
             $new_msg->order_id = $new_msg->contribution_tracking_id;
         }
         // FIXME represent special case as var_map config override?
         if ($msg_type === 'refund') {
             $new_msg->gateway_refund_id = $request['txn_id'];
             $new_msg->gross_currency = $request['mc_currency'];
             if (isset($new_msg->type) && $new_msg->type === 'chargeback_settlement') {
                 $new_msg->type = 'chargeback';
             } else {
                 $new_msg->type = $msg_type;
             }
         }
         // FIXME once recurring uses normalized msg it needs this too
         $new_msg->date = strtotime($new_msg->date);
     }
     $new_msg->gateway = 'paypal';
     SourceFields::addToMessage($new_msg);
     // Save to appropriate queue.
     $this->config->object('data-store/' . $msg_type)->push($new_msg);
     // FIXME random document formats
     if (substr($txn_type, 0, 7) === 'subscr_') {
         $log_id = "subscr_id:{$request['subscr_id']}";
     } else {
         $log_id = "txn_id:{$request['txn_id']}";
     }
     Logger::info("Message {$log_id} pushed to {$msg_type} queue.");
     // TODO It would be nice if push() returned something useful so we
     // could return something here too
     return true;
 }