/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $configKey = trim($this->_websoccer->getConfig("sofortcom_configkey")); if (!strlen($configKey)) { // user should actually not come here, hence no i18n throw new Exception("Sofort.com configuration key is not configured."); } // verify amount (check if specified in options) $amount = $parameters['amount']; $priceOptions = explode(',', $this->_websoccer->getConfig('premium_price_options')); $validAmount = FALSE; if (count($priceOptions)) { foreach ($priceOptions as $priceOption) { $optionParts = explode(':', $priceOption); $realMoney = trim($optionParts[0]); // credit amount and end here if ($amount == $realMoney) { $validAmount = TRUE; } } } if (!$validAmount) { // amount comes actually from a selection list, hence can be invalid only by cheating -> no i18n throw new Exception("Invalid amount"); } // create transaction model $Sofortueberweisung = new Sofortueberweisung($configKey); $abortOrSuccessUrl = $this->_websoccer->getInternalUrl('premiumaccount', null, TRUE); // use actual notify url $notifyUrl = $this->_websoccer->getInternalActionUrl('sofortcom-notify', 'u=' . $this->_websoccer->getUser()->id, 'home', TRUE); $Sofortueberweisung->setAmount($amount); $Sofortueberweisung->setCurrencyCode($this->_websoccer->getConfig("premium_currency")); $Sofortueberweisung->setReason($this->_websoccer->getConfig("projectname")); $Sofortueberweisung->setSuccessUrl($abortOrSuccessUrl, true); $Sofortueberweisung->setAbortUrl($abortOrSuccessUrl); $Sofortueberweisung->setNotificationUrl($notifyUrl, 'received'); $Sofortueberweisung->sendRequest(); if ($Sofortueberweisung->isError()) { throw new Exception($Sofortueberweisung->getError()); } else { // redirect to payment url $paymentUrl = $Sofortueberweisung->getPaymentUrl(); header('Location: ' . $paymentUrl); exit; } return null; }
<?php require_once dirname(__FILE__) . '/../payment/sofortLibSofortueberweisung.inc.php'; // enter your configuration key – you only can create a new configuration key by creating // a new Gateway project in your account at sofort.com $configkey = '12345:12345:5dbdad2bc861d907eedfd9528127d002'; $Sofortueberweisung = new Sofortueberweisung($configkey); $Sofortueberweisung->setAmount(10.21); $Sofortueberweisung->setCurrencyCode('EUR'); $Sofortueberweisung->setSenderSepaAccount('88888888', '12345678', 'Max Mustermann'); $Sofortueberweisung->setSenderCountryCode('DE'); $Sofortueberweisung->setReason('Testueberweisung', 'Verwendungszweck'); $Sofortueberweisung->setSuccessUrl('http://www.google.de', true); $Sofortueberweisung->setAbortUrl('http://www.google.de'); // $Sofortueberweisung->setNotificationUrl('http://www.google.de', 'loss,pending'); // $Sofortueberweisung->setNotificationUrl('http://www.yahoo.com', 'loss'); // $Sofortueberweisung->setNotificationUrl('http://www.bing.com', 'pending'); // $Sofortueberweisung->setNotificationUrl('http://www.sofort.com', 'received'); // $Sofortueberweisung->setNotificationUrl('http://www.youtube.com', 'refunded'); // $Sofortueberweisung->setNotificationUrl('http://www.youtube.com', 'untraceable'); $Sofortueberweisung->setNotificationUrl('http://www.twitter.com'); $Sofortueberweisung->setCustomerprotection(true); $Sofortueberweisung->sendRequest(); if ($Sofortueberweisung->isError()) { //SOFORT-API didn't accept the data echo $Sofortueberweisung->getError(); } else { //buyer must be redirected to $paymentUrl else payment cannot be successfully completed! $paymentUrl = $Sofortueberweisung->getPaymentUrl(); header('Location: ' . $paymentUrl); }