public function testGetNotification() { $SofortLibNotification = new SofortLibNotification(); $statusNotification = ''; $this->assertFalse($SofortLibNotification->getNotification($statusNotification)); $statusNotification = '<?xml version="1.0" encoding="UTF-8"?> <status_notification> <transaction>1324-1234-5483-4891</transaction> <time>2010-04-14T19:01:08+02:00</time> </status_notification>'; $notification = '1324-1234-5483-4891'; $this->assertEquals($notification, $SofortLibNotification->getNotification($statusNotification)); $statusNotification = '<?xml version="1.0" encoding="UTF-8"?> <status_test> <transaction>1324-1234-5483-4891</transaction> <time>2010-04-14T19:01:08+02:00</time> </status_test>'; $this->assertFalse($SofortLibNotification->getNotification($statusNotification)); $statusNotification = '<?xml version="1.0" encoding="UTF-8"?> <status_notification> <nontransaction>1324-1234-5483-4891</nontransaction> <time>2010-04-14T19:01:08+02:00</time> </status_notification>'; $this->assertFalse($SofortLibNotification->getNotification($statusNotification)); }
/** * Get sofort status with reason * * @return array */ public function getStatusData($rawBody) { $transactionData = array('status' => 'undefined', 'reason' => 'undefined'); $notificationSdk = new SofortLibNotification(); $transactionId = $notificationSdk->getNotification($rawBody); if ($transactionId) { $transactionDataSdk = new SofortLibTransactionData(Mage::getStoreConfig('payment/paymentnetwork_pnsofortueberweisung/cofiguration_key', Mage::app()->getStore()->getStoreId())); $transactionDataSdk->addTransaction($transactionId)->sendRequest(); $transactionData['status'] = $transactionDataSdk->getStatus(); $transactionData['reason'] = $transactionDataSdk->getStatusReason(); $transactionData['amount_refunded'] = $transactionDataSdk->getAmountRefunded(); $transactionData['transaction_id'] = $transactionId; } return $transactionData; }
public function HandleNotifyUrl($eShopId, $status, $ip, $rawPostStream = 'php://input') { $shop_id = static::DecryptShopId($eShopId); $notification = new SofortLibNotification(); $success = $notification->getNotification(file_get_contents($rawPostStream)); if ($success === false) { throw new SofortLibNotificationException($notification); } $transaction = $notification->getTransactionId(); $time = $notification->getTime(); App::uses('SofortComNotification', 'SofortCom.Model'); $SofortComNotification = new SofortComNotification(); $SofortComNotification->Add($transaction, $status, $time, $ip); $transactionData = new SofortLibTransactionData($this->Config['configkey']); $transactionData->addTransaction($transaction); $transactionData->sendRequest(); $transactionData->setNumber(1); call_user_func_array(array($this->Controller, $this->Config['notifyCallback']), array($shop_id, $status, $transaction, $time, $transactionData)); }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $configKey = trim($this->_websoccer->getConfig("sofortcom_configkey")); if (!strlen($configKey)) { throw new Exception("Sofort.com configuration key is not configured."); } // verify user $userId = $parameters['u']; $result = $this->_db->querySelect("id", $this->_websoccer->getConfig("db_prefix") . "_user", "id = %d", $userId); $user = $result->fetch_array(); $result->free(); if (!$user) { throw new Exception("illegal user id"); } // read the notification from php://input (http://php.net/manual/en/wrappers.php.php) $SofortLib_Notification = new SofortLibNotification(); $TestNotification = $SofortLib_Notification->getNotification(file_get_contents('php://input')); // read data $SofortLibTransactionData = new SofortLibTransactionData($configKey); $SofortLibTransactionData->addTransaction($TestNotification); // verify transaction data $SofortLibTransactionData->sendRequest(); if ($SofortLibTransactionData->isError()) { EmailHelper::sendSystemEmail($this->_websoccer, $this->_websoccer->getConfig("systememail"), "Failed Sofort.com payment notification", "Error: " . $SofortLibTransactionData->getError()); throw new Exception($SofortLibTransactionData->getError()); } else { // verify status if ($SofortLibTransactionData->getStatus() != 'received') { EmailHelper::sendSystemEmail($this->_websoccer, $this->_websoccer->getConfig("systememail"), "Failed Sofort.com payment notification: invalid status", "Status: " . $SofortLibTransactionData->getStatus()); throw new Exception("illegal status"); } // credit amount $amount = $SofortLibTransactionData->getAmount(); PremiumDataService::createPaymentAndCreditPremium($this->_websoccer, $this->_db, $userId, $amount, "sofortcom-notify"); } return null; }
/** * Process the callback data from the payment provider */ public function callback($request) { $this->extend('onBeforeCallback'); $data = $this->request->postVars(); $status = "error"; $key = $this->payment_gateway->ConfigKey; $content = file_get_contents('php://input'); // Check if CallBack data exists and install id matches the saved ID if (isset($content)) { $notification = new SofortLibNotification(); $transaction_id = $notification->getNotification($content); $sofort = new SofortLibTransactionData($key); $sofort->addTransaction($transaction_id); $sofort->sendRequest(); switch ($sofort->getStatus()) { case 'received': $status = "paid"; break; case 'loss': $status = "failed"; break; case 'pending': $status = "pending"; break; case 'refunded': $status = "refunded"; break; default: $status = "error"; } $payment_data = ArrayData::array_to_object(array("OrderID" => 0, "PaymentProvider" => "Sofort", "PaymentID" => $notification->getTransactionId(), "Status" => $status, "GatewayData" => $data)); $this->setPaymentData($payment_data); $this->extend('onAfterCallback'); return $this->renderWith(array("Sofort_callback", "Checkout", "Page")); } return $this->httpError(500); }
<?php require_once dirname(__FILE__) . '/../core/sofortLibNotification.inc.php'; require_once dirname(__FILE__) . '/../core/sofortLibTransactionData.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:123456:edc788a4316ce7e2ac0ede037aa623d7'; // read the notification from php://input (http://php.net/manual/en/wrappers.php.php) // this class should be used as a callback function $SofortLib_Notification = new SofortLibNotification(); $TestNotification = $SofortLib_Notification->getNotification(file_get_contents('php://input')); // echo $SofortLib_Notification->getTransactionId(); // echo '<br />'; // echo $SofortLib_Notification->getTime(); // echo '<br />'; $SofortLibTransactionData = new SofortLibTransactionData($configkey); // If SofortLib_Notification returns a transaction_id: $SofortLibTransactionData->addTransaction($TestNotification); //$SofortLibTransactionData->addTransaction(array('00907-01222-50F00112-D86E', '00907-01222-50EFFC79-7E33')); //$SofortLibTransactionData->addTransaction(array('00907-37660-51D2CD5E-8182')); //$SofortLibTransactionData->addTransaction('00907-01222-51ADD8C9-86C8'); // By default without setter Api version 1.0 will be used due to backward compatibility, please // set ApiVersion to latest version. Please note that the response might have a different structure and values // For more details please see our Api documentation on https://www.sofort.com/integrationCenter-ger-DE/integration/API-SDK/ $SofortLibTransactionData->setApiVersion('2.0'); //$SofortLibTransactionData->setTime('2012-11-14T18:00+02:00', '2012-12-13T00:00+02:00'); //$SofortLibTransactionData->setNumber(5, 1); $SofortLibTransactionData->sendRequest(); $output = array(); $methods = array('getAmount' => '', 'getAmountRefunded' => '', 'getCount' => '', 'getPaymentMethod' => '', 'getConsumerProtection' => '', 'getStatus' => '', 'getStatusReason' => '', 'getStatusModifiedTime' => '', 'getLanguageCode' => '', 'getCurrency' => '', 'getTransaction' => '', 'getReason' => array(0, 0), 'getUserVariable' => 0, 'getTime' => '', 'getProjectId' => '', 'getRecipientHolder' => '', 'getRecipientAccountNumber' => '', 'getRecipientBankCode' => '', 'getRecipientCountryCode' => '', 'getRecipientBankName' => '', 'getRecipientBic' => '', 'getRecipientIban' => '', 'getSenderHolder' => '', 'getSenderAccountNumber' => '', 'getSenderBankCode' => '', 'getSenderCountryCode' => '', 'getSenderBankName' => '', 'getSenderBic' => '', 'getSenderIban' => ''); foreach ($methods as $method => $params) {