<commit_before><?php defined('BX_DOL') or die('hack attempt');
/**
 * Copyright (c) UNA, Inc - https://una.io
 * MIT License - https://opensource.org/licenses/MIT
 *
 * @defgroup    Payment Payment
 * @ingroup     UnaModules
 *
 * @{
 */

require_once(BX_DIRECTORY_PATH_PLUGINS . 'chargebee/ChargeBee.php');

define('CBEE_MODE_LIVE', 1);
define('CBEE_MODE_TEST', 2);

class BxPaymentProviderChargebee extends BxBaseModPaymentProvider implements iBxBaseModPaymentProvider
{
	protected $_iMode;
	protected $_bCheckAmount;

    function __construct($aConfig)
    {
    	$this->MODULE = 'bx_payment';

        parent::__construct($aConfig);

        $this->_bRedirectOnResult = false;
        $this->_bUseSsl = $this->getOption('ssl') == 'on';
        $this->_sLogFile = BX_DIRECTORY_PATH_LOGS . 'bx_pp_' . $this->_sName . '.log';        

        $this->_iMode = (int)$this->getOption('mode');
        $this->_bCheckAmount = false; // Disabled for easier processing of discounted subscriptions.
    }

    public function initializeCheckout($iPendingId, $aCartInfo)
    {
    	$aItem = array_shift($aCartInfo['items']);
    	if(empty($aItem) || !is_array($aItem))
    		return $this->_sLangsPrefix . 'err_empty_items';

		$aClient = $this->_oModule->getProfileInfo();
		$aVendor = $this->_oModule->getProfileInfo($aCartInfo['vendor_id']);

		$oPage = $this->createHostedPage($iPendingId, $aItem, $aClient, $aVendor);
		if($oPage === false)
			return $this->_sLangsPrefix . 'err_cannot_perform';

		return array(
			'code' => 0,
			'eval' => $this->_oModule->_oConfig->getJsObject('cart') . '.onSubscribeSubmit(oData);',
			'redirect' => $oPage->url
		);
    }

    public function finalizeCheckout(&$aData)
    {
    	$sPageId = bx_process_input($aData['id']);
		$iPendingId = bx_process_input($aData['pending_id'], BX_DATA_INT);

        if(empty($sPageId) || empty($iPendingId))
        	return array('code' => 1, 'message' => $this->_sLangsPrefix . 'err_wrong_data');

		$oPage = $this->retreiveHostedPage($sPageId);
		if($oPage === false)
			return $this->_sLangsPrefix . 'err_cannot_perform';
		
		$aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
        if(!empty($aPending['order']) || !empty($aPending['error_code']) || !empty($aPending['error_msg']) || (int)$aPending['processed'] != 0)
            return array('code' => 3, 'message' => $this->_sLangsPrefix . 'err_already_processed');

		$oCustomer = $oPage->content()->customer();
		$oSubscription = $oPage->content()->subscription();

		$aResult = array(
			'code' => BX_PAYMENT_RESULT_SUCCESS,
        	'message' => $this->_sLangsPrefix . 'cbee_msg_subscribed',
			'pending_id' => $iPendingId,
			'client_name' => _t($this->_sLangsPrefix . 'txt_buyer_name_mask', $oCustomer->firstName, $oCustomer->lastName),
			'client_email' => $oCustomer->email,
			'paid' => false
		);

        //--- Update pending transaction ---//
        $this->_oModule->_oDb->updateOrderPending($iPendingId, array(
            'order' => $oSubscription->id,
            'error_code' => $aResult['code'],
            'error_msg' => _t($aResult['message'])<commit_msg>Ticket #259 - Chargebee<commit_after><?php defined('BX_DOL') or die('hack attempt');
/**
 * Copyright (c) UNA, Inc - https://una.io
 * MIT License - https://opensource.org/licenses/MIT
 *
 * @defgroup    Payment Payment
 * @ingroup     UnaModules
 *
 * @{
 */

require_once(BX_DIRECTORY_PATH_PLUGINS . 'chargebee/ChargeBee.php');

define('CBEE_MODE_LIVE', 1);
define('CBEE_MODE_TEST', 2);

class BxPaymentProviderChargebee extends BxBaseModPaymentProvider implements iBxBaseModPaymentProvider
{
	protected $_iMode;
	protected $_bCheckAmount;

    function __construct($aConfig)
    {
    	$this->MODULE = 'bx_payment';

        parent::__construct($aConfig);

        $this->_bRedirectOnResult = false;
        $this->_bUseSsl = $this->getOption('ssl') == 'on';
        $this->_sLogFile = BX_DIRECTORY_PATH_LOGS . 'bx_pp_' . $this->_sName . '.log';        

        $this->_iMode = (int)$this->getOption('mode');
        $this->_bCheckAmount = false; // Disabled for easier processing of discounted subscriptions.
    }

    public function initializeCheckout($iPendingId, $aCartInfo)
    {
    	$aItem = array_shift($aCartInfo['items']);
    	if(empty($aItem) || !is_array($aItem))
    		return $this->_sLangsPrefix . 'err_empty_items';

		$aClient = $this->_oModule->getProfileInfo();
		$aVendor = $this->_oModule->getProfileInfo($aCartInfo['vendor_id']);

		$oPage = $this->createHostedPage($iPendingId, $aItem, $aClient, $aVendor);
		if($oPage === false)
			return $this->_sLangsPrefix . 'err_cannot_perform';

		return array(
			'code' => 0,
			'eval' => $this->_oModule->_oConfig->getJsObject('cart') . '.onSubscribeSubmit(oData);',
			'redirect' => $oPage->url
		);
    }

    public function finalizeCheckout(&$aData)
    {
    	$sPageId = bx_process_input($aData['id']);
		$iPendingId = bx_process_input($aData['pending_id'], BX_DATA_INT);

        if(empty($sPageId) || empty($iPendingId))
        	return array('code' => 1, 'message' => $this->_sLangsPrefix . 'err_wrong_data');

		$oPage = $this->retreiveHostedPage($sPageId);
		if($oPage === false)
			return $this->_sLangsPrefix . 'err_cannot_perform';
		
		$aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
        if(!empty($aPending['order']) || !empty($aPending['error_code']) || !empty($aPending['error_msg']) || (int)$aPending['processed'] != 0)
            return array('code' => 3, 'message' => $this->_sLangsPrefix . 'err_already_processed');

		$oCustomer = $oPage->content()->customer();
		$oSubscription = $oPage->content()->subscription();

		$aResult = array(
			'code' => BX_PAYMENT_RESULT_SUCCESS,
        	'message' => $this->_sLangsPrefix . 'cbee_msg_subscribed',
			'pending_id' => $iPendingId,
			'customer_id' => $oCustomer->id,
		    'subscription_id' => $oSubscription->id,
			'client_name' => _t($this->_sLangsPrefix . 'txt_buyer_name_mask', $oCustomer->firstName, $oCustomer->lastName),
			'client_email' => $oCustomer->email,
			'paid' => false,
			'trial' => false,
		);

        //--- Update pending transaction ---//
        $this->_oModule->_oDb->updateOrderPending($iPendingId, array(
            'order' => $oSubscription->id,
            'error_code' => $aResult['code'],
            'error_msg' => _t($aResult['message'])
{'fraction_non_alphanumeric': 0.18082618862042088, 'fraction_numerical': 0.002338269680436477, 'mean_word_length': 3.9659442724458205, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 124, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3521014', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2201, 'n_words': 339}