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;
 }
 public function execute(ListenerMessage $msg)
 {
     $tl = new TaggedLogger('ChargebackInitiatedAction');
     if ($msg instanceof ChargebackReversed) {
         // I've never even seen one of these messages so we'll just have to wait
         // and see
         $tl->error("Oh hai! We got a chargeback reversal on pspReference '{$msg->pspReference}' with correlation id '" . "{$msg->correlationId}'! What do we do now?", $msg);
     }
     return true;
 }
コード例 #3
0
 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;
 }