public function getNotification() { $sum = $this->getSumWithCoeff(); $oSite_Alias = $this->_shopOrder->Shop->Site->getCurrentAlias(); $site_alias = !is_null($oSite_Alias) ? $oSite_Alias->name : ''; $shop_path = $this->_shopOrder->Shop->Structure->getPath(); $shopUrl = 'http://' . $site_alias . $shop_path; $handlerUrl = $shopUrl . "cart/?order_id={$this->_shopOrder->id}"; $successUrl = $handlerUrl . "&payment=success"; $failUrl = $handlerUrl . "&payment=fail"; $cancelUrl = $handlerUrl; /* в режиме разработки переопределить домен для доставки нотификации о платеже */ $handlerUrl = str_replace('hostcms.local', 'hostcms.webhook.begateway.com:8443', $handlerUrl); $oShop_Currency = Core_Entity::factory('Shop_Currency')->find($this->_begateway_currency_id); if (!is_null($oShop_Currency->id)) { $serviceName = 'Оплата счета N ' . $this->_shopOrder->id; $this->_setupLogger(); $transaction = new \beGateway\GetPaymentToken(); /* конвертировать RUR код в RUB */ $currency = $oShop_Currency->code; $currency = $currency == 'RUR' ? 'RUB' : $currency; $transaction->money->setCurrency($currency); $transaction->money->setAmount($sum); $transaction->setDescription($serviceName); $transaction->setTrackingId($this->_shopOrder->id); $transaction->setLanguage('ru'); $transaction->setNotificationUrl($handlerUrl . '&webhook=begateway'); $transaction->setSuccessUrl($successUrl); $transaction->setDeclineUrl($failUrl); $transaction->setFailUrl($cancelUrl); $transaction->setCancelUrl($shopUrl); foreach ($this->_payment_methods as $pm) { $klass = $this->_camelize($pm); $settings = NULL; if (isset($this->_payment_methods_settings[$pm])) { $settings = $this->_payment_methods_settings[$pm]; } if ($pm == 'erip') { $settings['account_number'] = (string) $this->_shopOrder->id; $settings['order_id'] = (int) $this->_shopOrder->id; $settings['service_info'][0] = sprintf($settings['service_info'][0], $this->_shopOrder->id); } $klass = "\\beGateway\\PaymentMethod\\" . $klass; $transaction->addPaymentMethod(new $klass($settings)); } if ($this->_shopOrder->email) { $transaction->customer->setEmail($this->_shopOrder->email); } if ($this->_hideAddress) { $transaction->setAddressHidden(); } $response = $transaction->submit(); if ($response->isSuccess()) { ?> <h1>Оплата заказа</h1> <p>Сумма к оплате составляет <strong><?php echo $sum; ?> <?php echo $oShop_Currency->name; ?> </strong></p> <p>Для оплаты нажмите кнопку "Оплатить".</p> <p style="color: rgb(112, 112, 112);"> Внимание! Нажимая «Оплатить» Вы подтверждаете передачу контактных данных на сервер платежной системы для оплаты. </p> <form action="<?php echo $response->getRedirectUrlScriptName(); ?> " name="pay" method="post"> <input type="hidden" name="token" value="<?php echo $response->getToken(); ?> "> <input type="submit" name="button" value="Оплатить"> </form> <?php } else { ?> <h1>Ошибка создания идентификатора платежа</h1> <p>Вернитесь назад и попробуйте еще раз</p> <?php if ($response->getMessage()) { echo "<p>Причина: " . $response->getMessage(); } ?> <?php } } else { ?> <h1>Не найдена валюта с идентификатором <?php $this->_begateway_currency_id; ?> !</h1><?php } }
<?php require_once __DIR__ . '/../lib/beGateway.php'; require_once __DIR__ . '/test_shop_data.php'; \beGateway\Logger::getInstance()->setLogLevel(\beGateway\Logger::DEBUG); $transaction = new \beGateway\GetPaymentToken(); $cc = new \beGateway\PaymentMethod\CreditCard(); $erip = new \beGateway\PaymentMethod\Erip(array('order_id' => 1234, 'account_number' => '99999999', 'service_no' => '99999999')); $transaction->addPaymentMethod($cc); $transaction->addPaymentMethod($erip); $amount = rand(100, 10000); $transaction->money->setAmount($amount); $transaction->money->setCurrency('BYN'); $transaction->setDescription('test'); $transaction->setTrackingId('my_custom_variable'); $transaction->setLanguage('ru'); $transaction->setNotificationUrl('http://www.example.com/notify'); $transaction->setSuccessUrl('http://www.example.com/success'); $transaction->setDeclineUrl('http://www.example.com/decline'); $transaction->setFailUrl('http://www.example.com/fail'); $transaction->setCancelUrl('http://www.example.com/cancel'); $transaction->customer->setEmail('*****@*****.**'); $transaction->setAddressHidden(); $response = $transaction->submit(); print "Transaction message: " . $response->getMessage() . PHP_EOL; if ($response->isSuccess()) { print "Token: " . $response->getToken() . PHP_EOL; }