public function testFindParent()
 {
     $this->mockClient->returns['getAuthorizationDetails'][] = 'Declined';
     $this->mockClient->returns['getAuthorizationDetails'][] = 'Closed';
     $parentId = AmazonApi::findRefundParentId('P01-0133129-0199515-R019658');
     $this->assertEquals('P01-0133129-0199515-C019658', $parentId, 'Did not get the right refund parent ID');
 }
 public function execute(ListenerMessage $msg)
 {
     // Bail out if not a refund
     if (get_class($msg) !== self::MESSAGE_CLASS) {
         return true;
     }
     $refundId = $msg->getGatewayTransactionId();
     Logger::info("Looking up ID of original transaction for refund {$refundId}");
     try {
         $parentId = AmazonApi::findRefundParentId($refundId);
         $msg->setParentId($parentId);
         return true;
     } catch (SmashPigException $ex) {
         Logger::error($ex->getMessage());
         return false;
     }
 }
 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;
 }