public function execute(ListenerMessage $msg) { $tl = new TaggedLogger('PaymentCaptureAction'); if ($msg instanceof Authorisation) { $jobQueueObj = Configuration::getDefaultConfig()->object('data-store/jobs-adyen'); if ($msg->success) { // Here we need to capture the payment, the job runner will collect the // orphan message $tl->info("Adding Adyen capture job for {$msg->currency} {$msg->amount} " . "with id {$msg->correlationId} and psp reference {$msg->pspReference}."); $job = ProcessCaptureRequestJob::factory($msg); $jobQueueObj->push(json_decode($job->toJson(), true)); } else { // And here we just need to destroy the orphan $tl->info("Adyen payment with correlation id {$msg->correlationId} " . "reported status failed: '{$msg->reason}'. " . 'Queueing job to delete pending records.'); $job = DeletePendingJob::factory('adyen', $msg->merchantReference, $msg->correlationId); $jobQueueObj->push(json_decode($job->toJson(), true)); } } return true; }
public function execute() { $this->logger = new TaggedLogger(__CLASS__); $c = Context::get()->getConfiguration(); // Construct the temporary file path $fileName = basename($this->reportUrl); $this->downloadLoc = $c->val("payment-provider/adyen/accounts/{$this->account}/report-location") . '/' . $fileName; $user = $c->val("payment-provider/adyen/accounts/{$this->account}/report-username"); $pass = $c->val("payment-provider/adyen/accounts/{$this->account}/report-password"); $this->logger->info("Beginning report download from {$this->reportUrl} using username {$user} into {$this->downloadLoc}"); $fp = fopen($this->downloadLoc, 'w'); if (!$fp) { $str = "Could not open {$this->downloadLoc} for writing! Will not download report."; $this->logger->error($str); throw new SmashPigException($str); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->reportUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_USERPWD, "{$user}:{$pass}"); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); curl_close($ch); if ($result === false) { $this->logger->error("Could not download report due to cURL error {$error}"); throw new SmashPigException("Could not download report."); } elseif ($httpCode !== 200) { $this->logger->error("Report downloaded(?), but with incorrect HTTP code: {$httpCode}"); throw new SmashPigException("Could not download report."); } return true; }
public function execute(ListenerMessage $msg) { $tl = new TaggedLogger('CaptureResponseAction'); if ($msg instanceof Capture) { if ($msg->success) { $tl->info("Adding record capture job for {$msg->currency} {$msg->amount} with id {$msg->correlationId} and psp reference {$msg->pspReference}."); $recordJob = RecordCaptureJob::factory($msg); $jobQueue = Configuration::getDefaultConfig()->object('data-store/jobs-adyen'); $jobQueue->push(json_decode($recordJob->toJson(), true)); } else { $tl->warning("Capture failed for payment with reference {$msg->pspReference} and correlation id {$msg->correlationId}.", $msg); } } return true; }
protected function determineAction($dbMessage) { if ($dbMessage && isset($dbMessage['order_id'])) { $this->logger->debug('A valid message was obtained from the pending database.'); } else { $errMessage = "Could not find a processable message for " . "PSP Reference '{$this->pspReference}' and " . "order ID '{$this->merchantReference}'."; $this->logger->warning($errMessage, $dbMessage); return self::ACTION_MISSING; } if (!empty($dbMessage['captured'])) { $this->logger->info("Duplicate PSP Reference '{$this->pspReference}' for order ID '{$this->merchantReference}'.", $dbMessage); return self::ACTION_DUPLICATE; } return $this->getRiskAction($dbMessage); }
public function cancel($pspReference) { $data = new WSDL\cancel(); $data->modificationRequest = new WSDL\ModificationRequest(); $data->modificationRequest->merchantAccount = $this->account; $data->modificationRequest->originalReference = $pspReference; $tl = new TaggedLogger('RawData'); $tl->info('Launching SOAP cancel request', $data); try { $resp = $this->soapClient->cancel($data); } catch (\Exception $ex) { Logger::error('SOAP cancel request threw exception!', null, $ex); return false; } if ($resp->cancelResult->response == '[cancel-received]') { return $resp->cancelResult->pspReference; } else { Logger::error('SOAP cancel request did not work as expected!', $resp); return false; } }