public function __construct($values) { parent::__construct(); $details = $values['RefundDetails']; $this->setGatewayIds($details['AmazonRefundId']); $this->date = UtcDate::getUtcTimestamp($details['CreationTimestamp']); $this->currency = $details['RefundAmount']['CurrencyCode']; $this->gross = $details['RefundAmount']['Amount']; // TODO: do we need to use FeeRefunded for anything? }
/** * Delete expired messages, optionally by original queue * * @param int $originalDate Oldest original timestamp to keep * @param string|null $queue */ public function deleteOldMessages($originalDate, $queue = null) { $sql = 'DELETE FROM damaged WHERE original_date < :date'; if ($queue) { $sql .= ' AND original_queue = :queue'; } $params = array('date' => UtcDate::getUtcDatabaseString($originalDate)); if ($queue) { $params['queue'] = $queue; } $this->prepareAndExecute($sql, $params); }
public function __construct($values) { parent::__construct(); $details = $values['CaptureDetails']; $this->setGatewayIds($details['AmazonCaptureId']); $captureReferenceId = $details['CaptureReferenceId']; $this->completion_message_id = "amazon-{$captureReferenceId}"; $this->order_id = $captureReferenceId; $parts = explode('-', $captureReferenceId); $this->contribution_tracking_id = $parts[0]; $this->date = UtcDate::getUtcTimestamp($details['CreationTimestamp']); $this->currency = $details['CaptureAmount']['CurrencyCode']; $this->gross = $details['CaptureAmount']['Amount']; $this->fee = $details['CaptureFee']['Amount']; $this->gateway_status = $details['CaptureStatus']['State']; }
/** * @param HeadedCsvReader $csv */ protected function parseLine(HeadedCsvReader $csv) { $status = $csv->currentCol('RefundStatus'); // Only process completed if ($status !== 'Completed') { return; } $msg = array(); $msg['date'] = UtcDate::getUtcTimestamp($csv->currentCol('LastUpdateTimestamp')); $msg['gateway'] = 'amazon'; $msg['gateway_parent_id'] = $csv->currentCol('AmazonCaptureId'); $msg['gateway_refund_id'] = $csv->currentCol('AmazonRefundId'); $msg['gross'] = $csv->currentCol('RefundAmount'); $msg['gross_currency'] = $csv->currentCol('CurrencyCode'); if ($csv->currentCol('RefundType') === 'SellerInitiated') { $msg['type'] = 'refund'; } else { $msg['type'] = 'chargeback'; } $this->fileData[] = $msg; }
/** * @param HeadedCsvReader $csv * @throws OutOfBoundsException */ protected function parseLine(HeadedCsvReader $csv) { $type = $csv->currentCol('TransactionType'); // Only process captures if ($type !== 'Capture') { return; } $msg = array(); $orderId = $csv->currentCol('SellerReferenceId'); $parts = explode('-', $orderId); $msg['contribution_tracking_id'] = $parts[0]; $msg['currency'] = $csv->currentCol('CurrencyCode'); $msg['date'] = UtcDate::getUtcTimestamp($csv->currentCol('TransactionPostedDate')); $msg['fee'] = -1 * $csv->currentCol('TotalTransactionFee'); $msg['gateway'] = 'amazon'; $msg['gateway_txn_id'] = $csv->currentCol('AmazonTransactionId'); $msg['gross'] = $csv->currentCol('TransactionAmount'); $msg['log_id'] = $csv->currentCol('SellerReferenceId'); $msg['payment_method'] = 'amazon'; $this->fileData[] = $msg; }
/** * @param array $message A message from donation queues * @param int $default Value to return when message has no dates * @return int The unix timestamp at which the message was originally * enqueued, or $default if no date information exists */ public static function getOriginalDateOrDefault($message, $default = 0) { // This is the actual queued time if (isset($message['source_enqueued_time'])) { // This is only ever set to the numeric timestamp return $message['source_enqueued_time']; } // Message missing source field might still have a date if (isset($message['date'])) { // This field is sometimes not a timestamp // FIXME: normalize PayPal recurring before queueing! if (is_integer($message['date'])) { return $message['date']; } // Try parsing non-numeric things $parsedTimestamp = UtcDate::getUtcTimestamp($message['date']); if (!is_null($parsedTimestamp)) { return $parsedTimestamp; } } return $default; }
/** * Build and insert a database record from a pending queue message * * @param array $message */ public function storeMessage($message) { $this->validateMessage($message); $dbRecord = array(); // These fields (and date) have their own columns in the database // Copy the values from the message to the record $indexedFields = array('gateway', 'gateway_account', 'gateway_txn_id', 'order_id'); foreach ($indexedFields as $fieldName) { if (isset($message[$fieldName])) { $dbRecord[$fieldName] = $message[$fieldName]; } } $dbRecord['date'] = UtcDate::getUtcDatabaseString($message['date']); // Dump the whole message into a text column $dbRecord['message'] = json_encode($message); if (isset($message['pending_id'])) { $sql = $this->getUpdateStatement($dbRecord); $dbRecord['id'] = $message['pending_id']; } else { $sql = $this->getInsertStatement($dbRecord); } $this->prepareAndExecute($sql, $dbRecord); }
public function testReportAvailable() { $filename = 'settlement_detail_report_2016_10_13.csv'; $account = 'WikimediaTest'; $url = "https://example.com/reports/download/MerchantAccount/{$account}/{$filename}"; $reportAvailable = new ReportAvailable(); $reportAvailable->correlationId = 'adyen-' . mt_rand(); $reportAvailable->merchantAccountCode = $account; $reportAvailable->merchantReference = mt_rand(); $reportAvailable->pspReference = $filename; $reportAvailable->reason = $url; $reportAvailable->eventDate = '2016-10-14T12:06:20.496+02:00'; $reportAvailable->runActionChain(); $job = $this->jobQueue->pop(); $now = UtcDate::getUtcTimestamp(); $diff = abs($job['source_enqueued_time']) - $now; $this->assertTrue($diff < 60, 'Odd enqueued time'); $unsetFields = array('source_enqueued_time', 'source_host', 'source_run_id', 'source_version', 'propertiesExcludedFromExport', 'propertiesExportedAsKeys'); foreach ($unsetFields as $fieldName) { unset($job[$fieldName]); } $expected = array('php-message-class' => 'SmashPig\\PaymentProviders\\Adyen\\Jobs\\DownloadReportJob', 'reportUrl' => $url, 'account' => $account, 'source_name' => 'SmashPig', 'source_type' => 'listener', 'correlationId' => '', 'gateway' => 'adyen'); $this->assertEquals($expected, $job); }
protected function getDate($row) { $local = $row['Creation Date']; $zone = $row['TimeZone']; return UtcDate::getUtcTimestamp($local, $zone); }
/** * Using an AtomicReadBuffer implementation for the backend means that * if this throws an exception, the message will remain on the queue. * * @param array $message * @param Exception $ex */ protected function handleError($message, Exception $ex) { if ($ex instanceof RetryableException) { $now = UtcDate::getUtcTimestamp(); if (!isset($message['source_enqueued_time'])) { $message['source_enqueued_time'] = UtcDate::getUtcTimestamp(); } $expirationDate = $message['source_enqueued_time'] + Configuration::getDefaultConfig()->val('requeue-max-age'); if ($now < $expirationDate) { $retryDate = $now + Configuration::getDefaultConfig()->val('requeue-delay'); $this->sendToDamagedStore($message, $ex, $retryDate); return; } } $this->sendToDamagedStore($message, $ex); }
protected function parseDonation(array $row, array &$msg) { $msg['contribution_tracking_id'] = $this->getContributionTrackingId($row['Invoice']); $msg['country'] = $row['Country']; $msg['currency'] = $row['currency']; $msg['email'] = $row['User Mail']; $msg['settled_fee'] = $row['Fee']; // settled_fee since it's given in USD $msg['gateway_txn_id'] = $row['Reference']; $msg['log_id'] = $row['Invoice']; list($method, $submethod) = ReferenceData::decodePaymentMethod($row['Payment Method Type'], $row['Payment Method']); $msg['payment_method'] = $method; $msg['payment_submethod'] = $submethod; if ($row['Settlement date']) { $msg['settled_date'] = UtcDate::getUtcTimestamp($row['Settlement date']); } if ($row['Amount (USD)']) { $msg['settled_currency'] = 'USD'; $msg['settled_gross'] = $row['Amount (USD)']; } }
public static function generateTestMessage() { $message = array('id' => mt_rand(), 'contribution_tracking_id' => mt_rand(), 'gateway' => 'test_gateway', 'order_id' => mt_rand(), 'gateway_txn_id' => mt_rand(), 'validation_action' => 'process', 'payments_final_status' => 'complete', 'payment_method' => 'cc', 'payment_submethod' => 'jcb', 'country' => 'FR', 'amount' => 1.01, 'currency_code' => 'EUR', 'server' => 'localhost', 'date' => UtcDate::getUtcDatabaseString(time())); return $message; }