Просмотр исходного кода

Ticket #5006 - Stripe Connect: Update integration.

AntonLV 1 год назад
Родитель
Сommit
eb05d4dab9

+ 1 - 1
modules/boonex/payment/classes/BxPaymentProviderStripeV3.php

@@ -733,7 +733,7 @@ class BxPaymentProviderStripeV3 extends BxPaymentProviderStripeBasic implements
     {
         $oSession = $this->_retrieveSession($sId);
         if($oSession === false)
-            return array();
+            return false;
 
         $aSession = $oSession->jsonSerialize();
         if(empty($aSession) || !is_array($aSession))

+ 11 - 0
modules/boonex/russian/data/langs/bx_stripe_connect/ru.xml

@@ -14,8 +14,18 @@
     <string name="_bx_stripe_connect_option_pmode_direct"><![CDATA[Прямой]]></string>
     <string name="_bx_stripe_connect_option_pmode_platform"><![CDATA[Платформа]]></string>
 
+    <!-- PAGES and BLOCKS -->
+    <string name="_bx_stripe_connect_page_title_sys_connected_activity"><![CDATA[Активность подключенного аккаунта]]></string>
+    <string name="_bx_stripe_connect_page_title_connected_activity"><![CDATA[Активность подключенного аккаунта]]></string>
+    <string name="_bx_stripe_connect_page_block_title_payments"><![CDATA[Платежи]]></string>
+    <string name="_bx_stripe_connect_page_block_title_balances"><![CDATA[Остатки]]></string>
+    <string name="_bx_stripe_connect_page_block_title_notifications"><![CDATA[Уведомления]]></string>
+    <string name="_bx_stripe_connect_page_block_title_warning"><![CDATA[Предупреждение]]></string>
+
     <!-- MENUS -->
     <string name="_bx_stripe_connect_menu_item_title_accounts"><![CDATA[Аккаунты]]></string>
+    <string name="_bx_stripe_connect_menu_item_title_system_connected_activity"><![CDATA[Связанная деятельность]]></string>
+    <string name="_bx_stripe_connect_menu_item_title_connected_activity"><![CDATA[Связанная деятельность]]></string>
         
     <!-- GRIDS -->
     <string name="_bx_stripe_connect_grid_column_title_profile_id"><![CDATA[Профиль]]></string>
@@ -31,6 +41,7 @@
     <string name="_bx_stripe_connect_btn_account_create"><![CDATA[Создать подключенную учетную запись]]></string>
     <string name="_bx_stripe_connect_btn_account_delete"><![CDATA[Удалить подключенную учетную запись]]></string>
     <string name="_bx_stripe_connect_btn_account_continue"><![CDATA[Продолжить создание учетной записи]]></string>
+    <string name="_bx_stripe_connect_msg_create_account"><![CDATA[Сначала вам необходимо <a href="{0}"><b>создать</b></a> подключенную учетную запись.]]></string>
     <string name="_bx_stripe_connect_err_delete"><![CDATA[Невозможно удалить аккаунт.]]></string>
     <string name="_bx_stripe_connect_err_perform"><![CDATA[Не удается выполнить действие. Пожалуйста сообщите.]]></string>
     <string name="_bx_stripe_connect_log"><![CDATA[Stripe Connect]]></string>

+ 102 - 0
modules/boonex/stripe_connect/classes/BxStripeConnectApi.php

@@ -51,6 +51,25 @@ class BxStripeConnectApi extends BxDol
         return $this->_oStripe;
     }
 
+    public function createAccount($sEmail)
+    {        
+        $oAccount = null;
+
+        try {
+            $oAccount = $this->getStripe()->accounts->create([
+                'type' => $this->_oModule->_oConfig->getAccountType(),
+                'email' => $sEmail,
+            ]);
+        }
+        catch (Exception $oException) {
+            $oAccount = null;
+
+            return $this->_processException('Create Account Error: ', $oException);
+        }
+
+        return $oAccount;
+    }
+
     public function retrieveAccount($sAccountId)
     {
         try {
@@ -62,6 +81,89 @@ class BxStripeConnectApi extends BxDol
 
         return $oAccount;
     }
+    
+    public function deleteAccount($sAccountId)
+    {        
+        $oAccount = null;
+
+        try {
+            $oAccount = $this->getStripe()->accounts->delete($sAccountId, []);
+        }
+        catch (Exception $oException) {
+            $oAccount = null;
+
+            return $this->_processException('Delete Account Error: ', $oException);
+        }
+
+        return $oAccount;
+    }
+
+    public function createAccountLinks($sAccountId, $sRefreshLink, $sReturnLink)
+    {
+        $oAccountLink = null;
+
+        try {
+            $oAccountLink = $this->getStripe()->accountLinks->create([
+                'account' => $sAccountId,
+                'refresh_url' => $sRefreshLink,
+                'return_url' => $sReturnLink,
+                'type' => 'account_onboarding',
+            ]);
+        }
+        catch (Exception $oException) {
+            $oAccountLink = null;
+
+            return $this->_processException('Create Account Links Error: ', $oException);
+        }
+
+        return $oAccountLink;
+    }
+
+    /**
+     * https://docs.stripe.com/connect/get-started-connect-embedded-components
+     */
+    public function createAccountSessions($sAccountId)
+    {
+        $oAccountSession = null;
+
+        try {
+            $oAccountSession = $this->getStripe()->accountSessions->create([
+                'account' => $sAccountId,
+                'components' => [
+                    'balances' => [
+                        'enabled' => true,
+                        'features' => [
+                            'instant_payouts' => true,
+                            'standard_payouts' => true,
+                            'edit_payout_schedule' => true,
+                            'external_account_collection' => true
+                        ],
+                    ],
+                    'notification_banner' => [
+                        'enabled' => true,
+                        'features' => [
+                            'external_account_collection' => true
+                        ]
+                    ],
+                    'payments' => [
+                        'enabled' => true,
+                        'features' => [
+                            'refund_management' => true,
+                            'dispute_management' => true,
+                            'capture_payments' => true,
+                        ],
+                    ],
+                ]
+            ]);
+        }
+        catch (Exception $oException) {
+            $oAccountSession = null;
+
+            return $this->_processException('Create Account Session Error: ', $oException);
+        }
+
+        return $oAccountSession;
+    }
 
     protected function _processException($sMessage, &$oException)
     {

+ 18 - 1
modules/boonex/stripe_connect/classes/BxStripeConnectConfig.php

@@ -9,7 +9,7 @@
  * @{
  */
 
-class BxStripeConnectConfig extends BxBaseModConnectConfig
+class BxStripeConnectConfig extends BxBaseModGeneralConfig
 {
     protected $_oDb;
 
@@ -69,10 +69,19 @@ class BxStripeConnectConfig extends BxBaseModConnectConfig
 
         $this->_aJsClasses = [
             'main' => 'BxStripeConnectMain',
+            'embeds' => 'BxStripeConnectEmbeds',
         ];
 
         $this->_aJsObjects = [
             'main' => 'oStripeConnectMain',
+            'embeds' => 'oBxStripeConnectEmbeds',
+        ];
+
+        $sPrefix = str_replace('_', '-', $this->_sName);
+        $this->_aHtmlIds = [
+            'balances' => $sPrefix . '-balances',
+            'notification-banner' => $sPrefix . '-notification-banner',
+            'payments' => $sPrefix . '-payments',
         ];
 
         $this->_sAccountType = 'standard'; //'express'
@@ -134,6 +143,14 @@ class BxStripeConnectConfig extends BxBaseModConnectConfig
 
         return $iResult;
     }
+
+    public function getHtmlIds($sKey = '')
+    {
+        if(empty($sKey))
+            return $this->_aHtmlIds;
+
+        return isset($this->_aHtmlIds[$sKey]) ? $this->_aHtmlIds[$sKey] : '';
+    }
 }
 
 /** @} */

+ 1 - 1
modules/boonex/stripe_connect/classes/BxStripeConnectDb.php

@@ -80,7 +80,7 @@ class BxStripeConnectDb extends BxBaseModConnectDb
         if(!isset($aSet[$CNF['FIELD_CHANGED']]))
             $aSet[$CNF['FIELD_CHANGED']] = time();
 
-        return (int)$this->query("REPLACE INTO `" . $CNF['TABLE_ENTRIES'] . "` SET " . $this->arrayToSQL($aSet)) > 0;
+        return (int)$this->query("INSERT INTO `" . $CNF['TABLE_ENTRIES'] . "` SET " . $this->arrayToSQL($aSet)) > 0;
     }
 
     public function updateAccount($aSet, $aWhere)

+ 65 - 82
modules/boonex/stripe_connect/classes/BxStripeConnectModule.php

@@ -15,7 +15,7 @@ define('BX_STRIPE_CONNECT_MODE_TEST', 'test');
 define('BX_STRIPE_CONNECT_PMODE_DIRECT', 'direct');
 define('BX_STRIPE_CONNECT_PMODE_PLATFORM', 'platform');
 
-class BxStripeConnectModule extends BxBaseModConnectModule
+class BxStripeConnectModule extends BxBaseModGeneralModule
 {
     function __construct(&$aModule)
     {
@@ -106,6 +106,30 @@ class BxStripeConnectModule extends BxBaseModConnectModule
         return $this->_oTemplate->getConnectCode($iVendorId, $aParams);
     }
 
+    public function serviceGetBlockPayments()
+    {
+        if(!isLogged())
+            return '';
+
+        return $this->_oTemplate->getBlockPayments();
+    }
+
+    public function serviceGetBlockBalances()
+    {
+        if(!isLogged())
+            return '';
+
+        return $this->_oTemplate->getBlockBalances();
+    }
+
+    public function serviceGetBlockNotifications()
+    {
+        if(!isLogged())
+            return '';
+
+        return $this->_oTemplate->getBlockNotifications();
+    }
+
     /**
      * 
      * ACTION METHODS
@@ -133,13 +157,8 @@ class BxStripeConnectModule extends BxBaseModConnectModule
 
         $sAccIdField = $CNF['FIELD_' . strtoupper($this->_oConfig->getMode()) . '_ACCOUNT_ID'];
 
-        //TODO: Replace with call to $this->_oConfig->getStripe() method.
-        $oStripe = new \Stripe\StripeClient($this->_oConfig->getApiSecretKey());
-        $oAccount = $oStripe->accounts->create([
-            'type' => $this->_oConfig->getAccountType(),
-            'email' => $oProfile->getAccountObject()->getEmail(),
-        ]);
-
+        $oApi = BxStripeConnectApi::getInstance();        
+        $oAccount = $oApi->createAccount($oProfile->getAccountObject()->getEmail());
         if(!$oAccount)
             return echoJson(['code' => 1, 'message' => $sError]);
 
@@ -149,12 +168,9 @@ class BxStripeConnectModule extends BxBaseModConnectModule
         ]);
 
         $sLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=payment-details');
-        $oAccountLink = $oStripe->accountLinks->create([
-            'account' => $oAccount->id,
-            'refresh_url' => $sLink,
-            'return_url' => $sLink,
-            'type' => 'account_onboarding',
-        ]);
+        $oAccountLink = $oApi->createAccountLinks($oAccount->id, $sLink, $sLink);
+        if(!$oAccountLink)
+            return echoJson(['code' => 1, 'message' => $sError]);
 
         return echoJson(['code' => 0, 'redirect' => $oAccountLink->url]);
     }
@@ -180,17 +196,9 @@ class BxStripeConnectModule extends BxBaseModConnectModule
         if((int)$aAccount[$sAccDetailsField] != 0)
             return echoJson(['code' => 0]);
 
-        $oStripe = new \Stripe\StripeClient($this->_oConfig->getApiSecretKey());
-
         $sLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=payment-details');
-        $oAccountLink = $oStripe->accountLinks->create([
-            'account' => $aAccount[$sAccIdField],
-            'refresh_url' => $sLink,
-            'return_url' => $sLink,
-            'type' => 'account_onboarding',
-        ]);
-
-        if(empty($oAccountLink))
+        $oAccountLink = BxStripeConnectApi::getInstance()->createAccountLinks($aAccount[$sAccIdField], $sLink, $sLink);
+        if(!$oAccountLink)
             return echoJson(['code' => 1, 'message' => $sError]);
 
         return echoJson(['code' => 0, 'redirect' => $oAccountLink->url]);
@@ -212,9 +220,7 @@ class BxStripeConnectModule extends BxBaseModConnectModule
 
         $sAccIdField = $CNF['FIELD_' . strtoupper($this->_oConfig->getMode()) . '_ACCOUNT_ID'];
 
-        $oStripe = new \Stripe\StripeClient($this->_oConfig->getApiSecretKey());
-        $oAccount = $oStripe->accounts->delete($aAccount[$sAccIdField], []);
-
+        $oAccount = BxStripeConnectApi::getInstance()->deleteAccount($aAccount[$sAccIdField]);
         if(!$oAccount || !$oAccount->deleted)
             return echoJson(['code' => 2, 'message' => _t('_bx_stripe_connect_err_delete')]);
 
@@ -226,11 +232,42 @@ class BxStripeConnectModule extends BxBaseModConnectModule
         return echoJson(['code' => 0, 'reload' => 1]);
     }
 
+    public function actionAccountSessionCreate($iProfileId)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!$iProfileId || ($iProfileId != $this->_iProfileId && !isAdmin()))
+            $iProfileId = $this->_iProfileId;
+        if(!$iProfileId)
+            return echoJson(['code' => 1]);
+
+        $sModeUc = strtoupper($this->_oConfig->getMode());
+        $sAccIdField = $CNF['FIELD_' . $sModeUc . '_ACCOUNT_ID'];
+
+        $aAccount = $this->_oDb->getAccount(['sample' => 'profile_id', 'profile_id' => $iProfileId]);
+        if(empty($aAccount) || !is_array($aAccount) || $aAccount[$sAccIdField] == '')
+            return echoJson(['code' => 1]);
+
+        $oAccountSession = BxStripeConnectApi::getInstance()->createAccountSessions($aAccount[$sAccIdField]);
+        if(!$oAccountSession)
+            return echoJson(['code' => 1]);
+
+        return echoJson([
+            'code' => 0,
+            'secret' => $oAccountSession->client_secret
+        ]);
+    }
+
     /**
      * 
      * OTHER METHODS
      * 
-     */   
+     */
+    public function hasAccount($iVendorId)
+    {
+        return $this->_oDb->hasAccount($iVendorId, $this->_oConfig->getMode());
+    }
+
     public function processAlertStripeV3GetButton($iObject, $iSender, $aParams)
     {
         $CNF = &$this->_oConfig->CNF;
@@ -309,39 +346,6 @@ class BxStripeConnectModule extends BxBaseModConnectModule
         return !empty($aParams['session_object']);
     }
 
-    /**
-     * Methods related to old Stripe integration (which starts with 'processAlertStripe') are outdated.
-     */
-    public function processAlertStripeV3RetrieveCustomer($iObject, $iSender, $aParams)
-    {
-        if(empty($aParams['type']) || empty($aParams['customer_id']))
-            return false;
-
-        $sPayMode = $this->_oConfig->getPayMode();
-
-        try {
-            switch($sPayMode) {
-                case BX_STRIPE_CONNECT_PMODE_DIRECT:
-                    /*
-                     * Do nothing in this case because a Customer 
-                     * should be retreived from Connected Stripe account.
-                     */
-                    break;
-
-                case BX_STRIPE_CONNECT_PMODE_PLATFORM:
-                    $aParams['customer_object'] = BxStripeConnectApi::getInstance()->getStripe()->customers->retrieve($aParams['customer_id']);
-                    break;
-            }
-        }
-        catch (Exception $oException) {
-            $aParams['customer_object'] = null;
-
-            return $this->_processException('Retrieve Customer Error: ', $oException);
-        }
-
-        return !empty($aParams['customer_object']);
-    }
-
     protected function _processEvent()
     {
         $sInput = @file_get_contents("php://input");
@@ -395,27 +399,6 @@ class BxStripeConnectModule extends BxBaseModConnectModule
         return false;
     }
 
-    protected function _getAccount($iPending, $sType)
-    {
-        $aPending = BxDolPayments::getInstance()->getPendingOrdersInfo(array('id' => $iPending));
-        if(!empty($aPending) && is_array($aPending) && count($aPending) == 1)
-            $aPending = array_shift($aPending);
-
-        if(empty($aPending) || !is_array($aPending) || $aPending['type'] != $sType)
-            return false;
-
-        $iSeller = (int)$aPending['seller_id'];
-        $oSeller = BxDolProfile::getInstance($iSeller);
-        if(!$oSeller)
-            return false;
-
-        $aAccount = $this->_oDb->getAccount(array('type' => 'author', 'author' => $iSeller));
-        if(empty($aAccount) || !is_array($aAccount))
-            return false;
-
-        return $aAccount;
-    }
-
     protected function _log($sContents)
     {
         if (is_array($sContents))

+ 53 - 0
modules/boonex/stripe_connect/classes/BxStripeConnectPageActivity.php

@@ -0,0 +1,53 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    StripeConnect Stripe Connect
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxStripeConnectPageActivity extends BxTemplPage
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    public function __construct($aObject, $oTemplate = false)
+    {
+        parent::__construct($aObject, $oTemplate);
+
+        $this->_sModule = 'bx_stripe_connect';
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
+
+        $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
+        if($oMenuSubmenu) {
+            $sMenuSubmenu = 'sys_account_dashboard';
+            $oMenuSubmenu->setObjectSubmenu($sMenuSubmenu, array('title' => _t('_sys_menu_item_title_account_dashboard'), 'link' => '', 'icon' => ''));
+
+            BxDolMenu::getObjectInstance($sMenuSubmenu)->setSelected($this->_sModule, 'connected-activity');
+        }
+    }
+
+    public function getCode ()
+    {
+        $sResult = parent::getCode();
+
+        if(!isLogged() || !$this->isAvailablePage() || !$this->isVisiblePage())
+            return $sResult;
+        
+        $iProfileId = bx_get_logged_profile_id();
+        if(!$this->_oModule->hasAccount($iProfileId)) {
+            $this->_oTemplate->displayMsg([
+                'title' => _t('_bx_stripe_connect_page_block_title_warning'), 
+                'content' => _t('_bx_stripe_connect_msg_create_account', BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=payment-details'))
+            ]);
+            exit;
+        }
+
+        return $this->_oModule->_oTemplate->getJsCodeEmbeds($iProfileId) . $sResult;
+    }
+}
+
+/** @} */

+ 51 - 1
modules/boonex/stripe_connect/classes/BxStripeConnectTemplate.php

@@ -24,7 +24,7 @@ class BxStripeConnectTemplate extends BxBaseModGeneralTemplate
     {
         $CNF = &$this->_oConfig->CNF;
 
-        $sJsObject = $this->_oConfig->getJsObject('main');        
+        $sJsObject = $this->_oConfig->getJsObject('main');
  
         $sModeUc = strtoupper($this->_oConfig->getMode());
         $sAccIdField = $CNF['FIELD_' . $sModeUc . '_ACCOUNT_ID'];
@@ -67,6 +67,56 @@ class BxStripeConnectTemplate extends BxBaseModGeneralTemplate
         ]);
     }
 
+    public function getJsCodeEmbeds($iProfileId)
+    {
+        $this->addJs([
+            'https://connect-js.stripe.com/v1.0/connect.js',
+            'embeds.js'
+        ]);
+
+        return $this->getJsCode('embeds', [
+            'aHtmlIds' => $this->_oConfig->getHtmlIds(),
+            'sPublicKey' => $this->_oConfig->getApiPublicKey(),
+            'iProfileId' => $iProfileId
+        ], [
+            'wrap' => true,
+            'mask' => "if(window['{object}'] == undefined) {var} {object} = new {class}({params});"
+        ]);
+    }
+
+    public function getBlockPayments()
+    {
+        $sEmbed = 'payments';
+
+        return $this->parseHtmlByName('embed_block.html', [
+            'js_object' => $this->_oConfig->getJsObject('embeds'),
+            'html_id' => $this->_oConfig->getHtmlIds($sEmbed),
+            'embed' => $sEmbed
+        ]);
+    }
+
+    public function getBlockBalances()
+    {
+        $sEmbed = 'balances';
+
+        return $this->parseHtmlByName('embed_block.html', [
+            'js_object' => $this->_oConfig->getJsObject('embeds'),
+            'html_id' => $this->_oConfig->getHtmlIds($sEmbed),
+            'embed' => $sEmbed
+        ]);
+    }
+    
+    public function getBlockNotifications()
+    {
+        $sEmbed = 'notification-banner';
+
+        return $this->parseHtmlByName('embed_block.html', [
+            'js_object' => $this->_oConfig->getJsObject('embeds'),
+            'html_id' => $this->_oConfig->getHtmlIds($sEmbed),
+            'embed' => $sEmbed
+        ]);
+    }
+
     public function displayProfileLink($mixedProfile)
     {
     	if(!is_array($mixedProfile))

+ 12 - 1
modules/boonex/stripe_connect/install/langs/en.xml

@@ -16,9 +16,19 @@
     <string name="_bx_stripe_connect_option_fee_single"><![CDATA[One-time fee (in cents, percent)]]></string>
     <string name="_bx_stripe_connect_option_fee_recurring"><![CDATA[Subscription fee (percent only)]]></string>
 
+    <!-- PAGES and BLOCKS -->
+    <string name="_bx_stripe_connect_page_title_sys_connected_activity"><![CDATA[Connected Account Activity]]></string>
+    <string name="_bx_stripe_connect_page_title_connected_activity"><![CDATA[Connected Account Activity]]></string>
+    <string name="_bx_stripe_connect_page_block_title_payments"><![CDATA[Payments]]></string>
+    <string name="_bx_stripe_connect_page_block_title_balances"><![CDATA[Balances]]></string>
+    <string name="_bx_stripe_connect_page_block_title_notifications"><![CDATA[Notifications]]></string>
+    <string name="_bx_stripe_connect_page_block_title_warning"><![CDATA[Warning]]></string>
+
     <!-- MENUS -->
     <string name="_bx_stripe_connect_menu_item_title_accounts"><![CDATA[Accounts]]></string>
-        
+    <string name="_bx_stripe_connect_menu_item_title_system_connected_activity"><![CDATA[Connected Activity]]></string>
+    <string name="_bx_stripe_connect_menu_item_title_connected_activity"><![CDATA[Connected Activity]]></string>
+                
     <!-- GRIDS -->
     <string name="_bx_stripe_connect_grid_column_title_profile_id"><![CDATA[Profile]]></string>
     <string name="_bx_stripe_connect_grid_column_title_live_account_id"><![CDATA[Account ID (live)]]></string>
@@ -33,6 +43,7 @@
     <string name="_bx_stripe_connect_btn_account_create"><![CDATA[Create Connected Account]]></string>
     <string name="_bx_stripe_connect_btn_account_delete"><![CDATA[Delete Connected Account]]></string>
     <string name="_bx_stripe_connect_btn_account_continue"><![CDATA[Continue with Account Creation]]></string>
+    <string name="_bx_stripe_connect_msg_create_account"><![CDATA[You need to <a href="{0}"><b>create</b></a> a connected account first.]]></string>
     <string name="_bx_stripe_connect_err_delete"><![CDATA[Cannot delete account.]]></string>
     <string name="_bx_stripe_connect_err_perform"><![CDATA[Cannot perform the action. Please report.]]></string>
     <string name="_bx_stripe_connect_log"><![CDATA[Stripe Connect]]></string>

+ 7 - 1
modules/boonex/stripe_connect/install/sql/disable.sql

@@ -7,7 +7,13 @@ DELETE FROM `tot`, `toc`, `to` USING `sys_options_types` AS `tot` LEFT JOIN `sys
 
 -- PAGES
 DELETE FROM `sys_objects_page` WHERE `module` = @sName;
-DELETE FROM `sys_pages_blocks` WHERE `module` = @sName;
+DELETE FROM `sys_pages_blocks` WHERE `module` = @sName OR `object` IN('bx_stripe_connect_activity');
+
+
+-- MENUS
+DELETE FROM `sys_objects_menu` WHERE `module` = @sName;
+DELETE FROM `sys_menu_sets` WHERE `module` = @sName;
+DELETE FROM `sys_menu_items` WHERE `module` = @sName; -- OR `set_name` IN();
 
 
 -- GRIDS

+ 17 - 2
modules/boonex/stripe_connect/install/sql/enable.sql

@@ -22,6 +22,22 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_stripe_connect_fee_recurring', '', @iCategId, '_bx_stripe_connect_option_fee_recurring', 'digit', '', '', 80, '');
 
 
+-- PAGES
+INSERT INTO `sys_objects_page`(`object`, `uri`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 
+('bx_stripe_connect_activity', 'connected-activity', '_bx_stripe_connect_page_title_sys_connected_activity', '_bx_stripe_connect_page_title_connected_activity', @sName, 12, 2147483647, 0, '', '', '', '', 0, 1, 0, 'BxStripeConnectPageActivity', 'modules/boonex/stripe_connect/classes/BxStripeConnectPageActivity.php');
+
+INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES 
+('bx_stripe_connect_activity', 2, @sName, '_bx_stripe_connect_page_block_title_payments', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:17:"bx_stripe_connect";s:6:"method";s:18:"get_block_payments";}', 0, 0, 1, 1),
+('bx_stripe_connect_activity', 3, @sName, '_bx_stripe_connect_page_block_title_balances', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:17:"bx_stripe_connect";s:6:"method";s:18:"get_block_balances";}', 0, 0, 1, 1),
+('bx_stripe_connect_activity', 3, @sName, '_bx_stripe_connect_page_block_title_notifications', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:17:"bx_stripe_connect";s:6:"method";s:23:"get_block_notifications";}', 0, 0, 1, 2);
+
+
+-- MENUS
+SET @iAccountDashboardMenuOrder = (SELECT IFNULL(MAX(`order`), 0) FROM `sys_menu_items` WHERE `set_name`='sys_account_dashboard' LIMIT 1);
+INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `editable`, `order`) VALUES
+('sys_account_dashboard', @sName, 'connected-activity', '_bx_stripe_connect_menu_item_title_system_connected_activity', '_bx_stripe_connect_menu_item_title_connected_activity', 'page.php?i=connected-activity', '', '', 'cc-stripe col-blue1', '', '', 2147483646, 1, 0, 1, @iAccountDashboardMenuOrder + 1);
+
+
 -- GRIDS: Manage
 INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `field_id`, `field_order`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_mode`, `sorting_fields`, `visible_for_levels`, `override_class_name`, `override_class_file`) VALUES
 ('bx_stripe_connect_accounts', 'Sql', 'SELECT * FROM `bx_stripe_connect_accounts`', 'bx_stripe_connect_accounts', 'id', '', '', 20, NULL, 'start', '', 'live_account_id,test_account_id', 'auto', 'live_account_id,test_account_id', 128, 'BxStripeConnectGridAccounts', 'modules/boonex/stripe_connect/classes/BxStripeConnectGridAccounts.php');
@@ -49,5 +65,4 @@ SET @iHandler := LAST_INSERT_ID();
 
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_payment', 'stripe_v3_get_button', @iHandler),
-('bx_payment', 'stripe_v3_create_session', @iHandler),
-('bx_payment', 'stripe_v3_retrieve_customer', @iHandler);
+('bx_payment', 'stripe_v3_create_session', @iHandler);

+ 1 - 2
modules/boonex/stripe_connect/install/sql/install.sql

@@ -12,8 +12,7 @@ CREATE TABLE IF NOT EXISTS `bx_stripe_connect_accounts` (
   `test_account_id` varchar(64) NOT NULL default '',
   `test_details` tinyint(4) NOT NULL default '0',
   PRIMARY KEY (`id`),
-  UNIQUE KEY `profile_id` (`profile_id`),
-  UNIQUE KEY `live_account_id` (`live_account_id`)
+  UNIQUE KEY `profile_id` (`profile_id`)
 );
 
 -- Logs Objects

+ 79 - 0
modules/boonex/stripe_connect/js/embeds.js

@@ -0,0 +1,79 @@
+function BxStripeConnectEmbeds(oOptions) {
+    this._sActionsUri = oOptions.sActionUri;
+    this._sActionsUrl = oOptions.sActionUrl;
+    this._sObjName = oOptions.sObjName == undefined ? 'oStripeConnectEmbeds' : oOptions.sObjName;
+    this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'slide' : oOptions.sAnimationEffect;
+    this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
+    this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
+
+    this._sPublicKey = oOptions.sPublicKey;
+    this._iProfileId = oOptions.iProfileId;
+
+    this._oStripeConnect = null;
+
+    this.init();
+}
+
+BxStripeConnectEmbeds.prototype.init = function() {
+    var $this = this;
+
+    window.StripeConnect = window.StripeConnect || {};
+
+    StripeConnect.onLoad = () => {
+        $this._oStripeConnect = StripeConnect.init({
+            publishableKey: $this._sPublicKey,
+            fetchClientSecret: function() {
+                var sSecret = '';
+
+                $.ajax({
+                    url: $this._sActionsUrl + 'account_session_create/' + $this._iProfileId,
+                    async: false, 
+                    dataType: 'json',
+                    success: function (oData) {
+                        if(parseInt(oData.code) != 0)
+                            return;
+
+                        sSecret = oData.secret
+                    }
+                });
+
+                return sSecret;
+            }
+        });
+      };
+};
+
+BxStripeConnectEmbeds.prototype.load = function(sEmbed) {
+    var $this = this;
+    var oContainer = $('#' + this._aHtmlIds[sEmbed]);
+
+    this.loadingInContainer(oContainer, true);
+
+    var fCreate = function() {
+        if(!$this._oStripeConnect) {
+            setTimeout(fCreate, 1000);
+            return;
+        }
+
+        oContainer.html($this._oStripeConnect.create(sEmbed));
+    };
+
+    $(document).ready(fCreate);
+};
+
+BxStripeConnectEmbeds.prototype.loadingInButton = function(e, bShow) {
+    if($(e).length)
+        bx_loading_btn($(e), bShow);
+    else
+        bx_loading($('body'), bShow);
+};
+
+BxStripeConnectEmbeds.prototype.loadingInBlock = function(e, bShow) {
+    var oParent = $(e).length ? $(e).parents('.bx-db-container:first') : $('body'); 
+    bx_loading(oParent, bShow);
+};
+
+BxStripeConnectEmbeds.prototype.loadingInContainer = function(e, bShow) {
+    var oContainer = $(e).length ? $(e) : $('body'); 
+    bx_loading(oContainer, bShow);
+};

+ 2 - 0
modules/boonex/stripe_connect/template/embed_block.html

@@ -0,0 +1,2 @@
+<div id="__html_id__"></div>
+<script>__js_object__.load('__embed__');</script>