Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('_JEXEC') or die();
- $akpaymentinclude = include_once JPATH_ADMINISTRATOR.'/components/com_akeebasubs/assets/akpayment.php';
- if(!$akpaymentinclude) { unset($akpaymentinclude); return; } else { unset($akpaymentinclude); }
- class plgAkpaymentPaysera extends plgAkpaymentAbstract {
- public function __construct(&$subject, $config = array())
- {
- $config = array_merge($config, array(
- 'ppName' => 'paysera',
- 'ppKey' => 'PLG_AKPAYMENT_PAYSERA_TITLE',
- 'ppImage' => 'https://www.mokejimai.lt/payment/m/m_images/wfiles/i56je3562.png'
- ));
- parent::__construct($subject, $config);
- }
- public function onAKPaymentNew($paymentmethod, $user, $level, $subscription)
- {
- if($paymentmethod != $this->ppName) return false;
- $nameParts = explode(' ', $user->name, 2);
- $firstName = $nameParts[0];
- if(count($nameParts) > 1) {
- $lastName = $nameParts[1];
- } else {
- $lastName = '';
- }
- $slug = F0FModel::getTmpInstance('Levels','AkeebasubsModel')
- ->setId($subscription->akeebasubs_level_id)
- ->getItem()
- ->slug; //reikalingas formuojant nuorodą, kitaip negaus teisingos nuorodos į užsakomą daiktą
- $kuser = F0FModel::getTmpInstance('Users','AkeebasubsModel')
- ->user_id($user->id)
- ->getFirstItem();
- $rootURL = rtrim(JURI::base(),'/');
- $subpathURL = JURI::base(true);
- if(!empty($subpathURL) && ($subpathURL != '/')) {
- $rootURL = substr($rootURL, 0, -1 * strlen($subpathURL));
- }
- $Language = & JFactory::getLanguage();
- $data = (object)array(
- 'projectid' => $this->params->get('project_id'),
- 'sign_password' => $this->params->get('project_password'),
- 'orderid' => $subscription->akeebasubs_subscription_id,
- 'amount' => $subscription->net_amount + $subscription->tax_amount,
- 'currency' => strtoupper(AkeebasubsHelperCparams::getParam('currency','LTL')),
- 'lang' => substr($Language->get('name'), 0, 3),
- 'accepturl' => $rootURL.str_replace('&','&',JRoute::_('index.php?option=com_akeebasubs&view=message&slug='.$slug.'&layout=order&subid='.$subscription->akeebasubs_subscription_id)),
- 'cancelurl' => $rootURL.str_replace('&','&',JRoute::_('index.php?option=com_akeebasubs&view=message&slug='.$slug.'&layout=cancel&subid='.$subscription->akeebasubs_subscription_id)),
- 'callbackurl' => JURI::base().'index.php?option=com_akeebasubs&view=callback&paymentmethod=paysera',
- 'payment' => '',
- 'p_countrycode' => 'LT',
- 'p_firstname' => $firstName,
- 'p_lastname' => $lastName,
- 'p_email' => $user->email,
- 'p_street' => $kuser->address1.''.$kuser->address2,
- 'p_city' => $kuser->city,
- 'p_state' => $kuser->state,
- 'p_zip' => $kuser->zip,
- 'test' => $this->params->get('test')
- );
- require_once('vendor/webtopay/libwebtopay/WebToPay.php');
- try {
- $request = WebToPay::buildRequest(array(
- 'projectid' => $data->projectid,
- 'sign_password' => $data->sign_password,
- 'orderid' => $data->orderid,
- 'amount' => $data->amount*100,
- 'currency' => $data->currency,
- 'lang' => $data->lang,
- 'accepturl' => $data->accepturl,
- 'cancelurl' => $data->cancelurl,
- 'callbackurl' => $data->callbackurl,
- 'payment' => $data->payment,
- 'p_countrycode' => $data->p_countrycode,
- 'p_firstname' => $data->p_firstname,
- 'p_lastname' => $data->p_lastname,
- 'p_email' => $data->p_email,
- 'p_street' => $data->p_street,
- 'p_city' => $data->p_city,
- 'p_state' => $data->p_state,
- 'p_zip' => $data->p_zip,
- 'test' => $data->test
- ));
- } catch (WebToPayException $e) {
- echo get_class($e) . ': ' . $e->getMessage();
- }
- @ob_start();
- include dirname(__FILE__).'/paysera/form.php';
- $html = @ob_get_clean();
- return $html;
- }
- public function onAKPaymentCallback($paymentmethod, $data)
- {
- $isValid = ($paymentmethod != $this->ppName) ? true : false;
- try {
- WebToPay::toggleSS2(true);
- $response = WebToPay::checkResponse($data, array(
- 'projectid' => $this->params->get('project_id'),
- 'sign_password' => $this->params->get('project_password'),
- ));
- echo 'OK';
- $orderId = $response['orderid'];
- $amount = $response['amount'];
- $currency = $response['currency'];
- JLoader::import('joomla.utilities.date');
- // Check if we're supposed to handle this
- //
- // Load the relevant subscription row
- if($response) {
- $id = isset($orderId) ? (int)$orderId : -1;
- $subscription = null;
- if($id > 0) {
- $subscription = F0FModel::getTmpInstance('Subscriptions','AkeebasubsModel')
- ->setId($id)
- ->getItem();
- $isValid = true;
- if( ($subscription->akeebasubs_subscription_id <= 0) || ($subscription->akeebasubs_subscription_id != $id) ) {
- $subscription = null;
- $isValid = false;
- }
- } else {
- $isValid = false;
- }
- if(!$isValid) $response['akeebasubs_failure_reason'] = 'The referenced subscription ID ("transaction_id" field) is invalid';
- }
- switch($response['status'])
- {
- case '1':
- $newStatus = 'C';
- break;
- case '2':
- $newStatus = 'P';
- break;
- case '3':
- $newStatus = 'P';
- break;
- case '0':
- $newStatus = 'X';
- break;
- }
- // Update subscription status (this also automatically calls the plugins)
- $updates = array(
- 'akeebasubs_subscription_id' => $orderId, //$id
- 'processor_key' => $response['requestid'],
- 'state' => $newStatus,
- 'enabled' => 1
- );
- JLoader::import('joomla.utilities.date');
- if($newStatus == 'C') {
- $this->fixDates($subscription, $updates);
- }
- $subscription->save($updates);
- // Run the onAKAfterPaymentCallback events
- JLoader::import('joomla.plugin.helper');
- JPluginHelper::importPlugin('akeebasubs');
- $app = JFactory::getApplication();
- $jResponse = $app->triggerEvent('onAKAfterPaymentCallback',array(
- $subscription
- ));
- //@todo: patikrinti, ar užsakymas su $orderId dar nepatvirtintas (callback gali būti pakartotas kelis kartus)
- //@todo: patikrinti, ar užsakymo suma ir valiuta atitinka $amount ir $currency
- //@todo: patvirtinti užsakymą
- return true;
- } catch (Exception $e) {
- echo get_class($e) . ': ' . $e->getMessage();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment