public function stage(GatewayType $adapter, $normalized, &$stagedData) { if (empty($normalized['amount']) || empty($normalized['currency_code']) || !is_numeric($normalized['amount'])) { //can't do anything with amounts at all. Just go home. unset($stagedData['amount']); return; } $amount = Amount::round($normalized['amount'], $normalized['currency_code']); $stagedData['amount'] = $amount * 100; }
/** * normalize helper function. * Takes all possible sources for the intended donation amount, and * normalizes them into the 'amount' field. */ protected function setNormalizedAmount() { if ($this->getVal('amount') === 'Other') { $this->setVal('amount', $this->getVal('amountGiven')); } $amountIsNotValidSomehow = !$this->isSomething('amount') || !is_numeric($this->getVal('amount')) || $this->getVal('amount') <= 0; if ($amountIsNotValidSomehow && ($this->isSomething('amountGiven') && is_numeric($this->getVal('amountGiven')))) { $this->setVal('amount', $this->getVal('amountGiven')); } else { if ($amountIsNotValidSomehow && ($this->isSomething('amountOther') && is_numeric($this->getVal('amountOther')))) { $this->setVal('amount', $this->getVal('amountOther')); } } if (!$this->isSomething('amount')) { $this->setVal('amount', '0.00'); } $this->expunge('amountGiven'); $this->expunge('amountOther'); if (!is_numeric($this->getVal('amount'))) { //fail validation later, log some things. $mess = 'Non-numeric Amount.'; $keys = array('amount', 'utm_source', 'utm_campaign', 'email', 'user_ip'); foreach ($keys as $key) { $mess .= ' ' . $key . '=' . $this->getVal($key); } $this->logger->debug($mess); $this->setVal('amount', 'invalid'); return; } $this->setVal('amount', Amount::round($this->getVal('amount'), $this->getVal('currency_code'))); }