'PaymentReceiptResponse', ReceiptType::REFUND => 'RefundReceiptResponse', ReceiptType::SIMPLE => 'SimpleReceiptResponse', ); /** * @param array $data * * @return AbstractReceiptResponse */ public function factory($data) { if (array_key_exists('type', $data)) { if (array_key_exists('refund_id', $data)) { $type = ReceiptType::REFUND; } elseif (array_key_exists('payment_id', $data)) { $type = ReceiptType::PAYMENT; } else { $type = ReceiptType::SIMPLE; } } else { throw new \InvalidArgumentException( 'Parameter type not specified in ReceiptResponseFactory.factory()' ); } if (!is_string($type)) { throw new \InvalidArgumentException('Invalid receipt type value in receipt factory'); } if (!in_array($type, ReceiptType::getValidValues())) { throw new \InvalidArgumentException('Invalid receipt data type "' . $type . '"'); } $className = __NAMESPACE__ . '\\' . $this->typeClassMap[$type]; return new $className($data); } }