|
|
@@ -43,208 +43,269 @@ class BxStripeConnectModule extends BxBaseModConnectModule
|
|
|
*/
|
|
|
public function serviceGetOptionsMode()
|
|
|
{
|
|
|
- return array(
|
|
|
- BX_STRIPE_CONNECT_MODE_LIVE => _t('_bx_stripe_connect_option_mode_live'),
|
|
|
- BX_STRIPE_CONNECT_MODE_TEST => _t('_bx_stripe_connect_option_mode_test'),
|
|
|
- );
|
|
|
+ return [
|
|
|
+ BX_STRIPE_CONNECT_MODE_LIVE => _t('_bx_stripe_connect_option_mode_live'),
|
|
|
+ BX_STRIPE_CONNECT_MODE_TEST => _t('_bx_stripe_connect_option_mode_test'),
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @page service Service Calls
|
|
|
* @section bx_stripe_connect Stripe Connect
|
|
|
* @subsection bx_stripe_connect-other Other
|
|
|
- * @subsubsection bx_stripe_connect-get_options_api_scope get_options_api_scope
|
|
|
+ * @subsubsection bx_stripe_connect-get_options_pmode get_options_pmode
|
|
|
*
|
|
|
- * @code bx_srv('bx_stripe_connect', 'get_options_api_scope', [...]); @endcode
|
|
|
+ * @code bx_srv('bx_stripe_connect', 'get_options_pmode', [...]); @endcode
|
|
|
*
|
|
|
- * Get an array with available API scopes. Is used in forms.
|
|
|
+ * Get an array with available processing modes for payments. Is used in forms.
|
|
|
*
|
|
|
- * @return an array with available scopes represented as key => value pairs.
|
|
|
+ * @return an array with available modes represented as key => value pairs.
|
|
|
*
|
|
|
- * @see BxStripeConnectModule::serviceGetOptionsApiScope
|
|
|
+ * @see BxStripeConnectModule::serviceGetOptionsPmode
|
|
|
*/
|
|
|
/**
|
|
|
- * @ref bx_stripe_connect-get_options_api_scope "get_options_api_scope"
|
|
|
+ * @ref bx_stripe_connect-get_options_pmode "get_options_pmode"
|
|
|
*/
|
|
|
- public function serviceGetOptionsApiScope()
|
|
|
+ public function serviceGetOptionsPmode()
|
|
|
{
|
|
|
- return array(
|
|
|
- 'read_only' => _t('_bx_stripe_connect_option_api_scope_read_only'),
|
|
|
- 'read_write' => _t('_bx_stripe_connect_option_api_scope_read_write'),
|
|
|
- );
|
|
|
+ return [
|
|
|
+ BX_STRIPE_CONNECT_PMODE_DIRECT => _t('_bx_stripe_connect_option_pmode_direct'),
|
|
|
+ //BX_STRIPE_CONNECT_PMODE_PLATFORM => _t('_bx_stripe_connect_option_pmode_platform'),
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @page service Service Calls
|
|
|
- * @section bx_stripe_connect Stripe Connect
|
|
|
- * @subsection bx_stripe_connect-other Other
|
|
|
- * @subsubsection bx_stripe_connect-get_options_pmode_single get_options_pmode_single
|
|
|
- *
|
|
|
- * @code bx_srv('bx_stripe_connect', 'get_options_pmode_single', [...]); @endcode
|
|
|
- *
|
|
|
- * Get an array with available processing modes for single time payments. Is used in forms.
|
|
|
- *
|
|
|
- * @return an array with available modes represented as key => value pairs.
|
|
|
- *
|
|
|
- * @see BxStripeConnectModule::serviceGetOptionsPmodeSingle
|
|
|
- */
|
|
|
- /**
|
|
|
- * @ref bx_stripe_connect-get_options_pmode_single "get_options_pmode_single"
|
|
|
- */
|
|
|
- public function serviceGetOptionsPmodeSingle()
|
|
|
+ public function serviceGetOptionValueMode($iVendorId, $aParams = [])
|
|
|
{
|
|
|
- return array(
|
|
|
- BX_STRIPE_CONNECT_PMODE_DIRECT => _t('_bx_stripe_connect_option_pmode_direct'),
|
|
|
- BX_STRIPE_CONNECT_PMODE_PLATFORM => _t('_bx_stripe_connect_option_pmode_platform'),
|
|
|
- );
|
|
|
+ return _t('_bx_stripe_connect_option_mode_' . $this->_oConfig->getMode());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @page service Service Calls
|
|
|
- * @section bx_stripe_connect Stripe Connect
|
|
|
- * @subsection bx_stripe_connect-other Other
|
|
|
- * @subsubsection bx_stripe_connect-get_options_pmode_recurring get_options_pmode_recurring
|
|
|
- *
|
|
|
- * @code bx_srv('bx_stripe_connect', 'get_options_pmode_recurring', [...]); @endcode
|
|
|
- *
|
|
|
- * Get an array with available processing modes for recurring payments. Is used in forms.
|
|
|
- * Note. Subscriptions (recurring payments) do not currently support the Platform mode.
|
|
|
- *
|
|
|
- * @return an array with available modes represented as key => value pairs.
|
|
|
- *
|
|
|
- * @see BxStripeConnectModule::serviceGetOptionsPmodeRecurring
|
|
|
- */
|
|
|
- /**
|
|
|
- * @ref bx_stripe_connect-get_options_pmode_recurring "get_options_pmode_recurring"
|
|
|
- */
|
|
|
- public function serviceGetOptionsPmodeRecurring()
|
|
|
+ public function serviceGetOptionValueLiveAccountId($iVendorId, $aParams = [])
|
|
|
{
|
|
|
- return array(
|
|
|
- BX_STRIPE_CONNECT_PMODE_DIRECT => _t('_bx_stripe_connect_option_pmode_direct'),
|
|
|
- );
|
|
|
+ $CNF = &$this->_oConfig->CNF;
|
|
|
+
|
|
|
+ $aAccount = $this->_oDb->getAccount(['sample' => 'profile_id', 'profile_id' => $iVendorId]);
|
|
|
+ if(empty($aAccount) || !is_array($aAccount))
|
|
|
+ return '';
|
|
|
+
|
|
|
+ return $aAccount[$CNF['FIELD_LIVE_ACCOUNT_ID']];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function serviceGetOptionValueTestAccountId($iVendorId, $aParams = [])
|
|
|
+ {
|
|
|
+ $CNF = &$this->_oConfig->CNF;
|
|
|
+
|
|
|
+ $aAccount = $this->_oDb->getAccount(['sample' => 'profile_id', 'profile_id' => $iVendorId]);
|
|
|
+ if(empty($aAccount) || !is_array($aAccount))
|
|
|
+ return '';
|
|
|
+
|
|
|
+ return $aAccount[$CNF['FIELD_TEST_ACCOUNT_ID']];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function serviceGetConnectCode($iVendorId, $aParams = [])
|
|
|
+ {
|
|
|
+ return $this->_oTemplate->getConnectCode($iVendorId, $aParams);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @page service Service Calls
|
|
|
- * @section bx_stripe_connect Stripe Connect
|
|
|
- * @subsection bx_stripe_connect-page_blocks Page Blocks
|
|
|
- * @subsubsection bx_stripe_connect-get_block_connect get_block_connect
|
|
|
- *
|
|
|
- * @code bx_srv('bx_stripe_connect', 'get_block_connect', [...]); @endcode
|
|
|
*
|
|
|
- * Get page block with necessary info and actions to connect/disconnect.
|
|
|
- *
|
|
|
- * @return HTML string with block content to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
|
|
|
+ * ACTION METHODS
|
|
|
*
|
|
|
- * @see BxStripeConnectModule::serviceGetBlockConnect
|
|
|
*/
|
|
|
- /**
|
|
|
- * @ref bx_stripe_connect-get_block_connect "get_block_connect"
|
|
|
- */
|
|
|
- public function serviceGetBlockConnect()
|
|
|
+ public function actionNotify()
|
|
|
{
|
|
|
- return $this->_oTemplate->displayBlockConnect();
|
|
|
+ $iResult = $this->_processEvent();
|
|
|
+ http_response_code($iResult);
|
|
|
}
|
|
|
|
|
|
- public function actionDelete()
|
|
|
+ public function actionAccountCreate()
|
|
|
{
|
|
|
- $sError = _t('_bx_stripe_connect_err_perform');
|
|
|
+ $CNF = &$this->_oConfig->CNF;
|
|
|
|
|
|
- $iId = (int)bx_get('id');
|
|
|
- if(empty($iId))
|
|
|
- return echoJson(array('code' => 1, 'message' => $sError));
|
|
|
+ $sError = _t('_bx_stripe_connect_err_perform');
|
|
|
|
|
|
- if(!$this->deleteAccount($iId))
|
|
|
- return echoJson(array('code' => 2, 'message' => $sError));
|
|
|
+ $iId = (int)bx_get('id');
|
|
|
+ if(empty($iId) || $iId != bx_get_logged_profile_id())
|
|
|
+ return echoJson(['code' => 1, 'message' => $sError]);
|
|
|
|
|
|
- echoJson(array('code' => 0, 'id' => $iId, 'reload' => 1));
|
|
|
- }
|
|
|
+ $oProfile = BxDolProfile::getInstance($iId);
|
|
|
+ if(!$oProfile)
|
|
|
+ return echoJson(['code' => 1, 'message' => $sError]);
|
|
|
|
|
|
- public function actionResult()
|
|
|
- {
|
|
|
- if(bx_get('error') !== false)
|
|
|
- $this->_oTemplate->displayErrorOccured(bx_process_input(bx_get('error_description')));
|
|
|
+ $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(),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if(!$oAccount)
|
|
|
+ return echoJson(['code' => 1, 'message' => $sError]);
|
|
|
|
|
|
- $mixedResult = $this->createAccount(bx_process_input(bx_get('code')));
|
|
|
- if($mixedResult !== true)
|
|
|
- $this->_oTemplate->displayErrorOccured($mixedResult);
|
|
|
+ $this->_oDb->insertAccount([
|
|
|
+ 'profile_id' => $iId,
|
|
|
+ $sAccIdField => $oAccount->id
|
|
|
+ ]);
|
|
|
|
|
|
- $this->_oTemplate->displayMsg('_bx_stripe_connect_msg_connected', true);
|
|
|
+ $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',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return echoJson(['code' => 0, 'redirect' => $oAccountLink->url]);
|
|
|
}
|
|
|
|
|
|
- public function actionNotify()
|
|
|
+ public function actionAccountContinue()
|
|
|
{
|
|
|
- $iResult = $this->_processEvent();
|
|
|
- http_response_code($iResult);
|
|
|
+ $CNF = &$this->_oConfig->CNF;
|
|
|
+
|
|
|
+ $sError = _t('_bx_stripe_connect_err_perform');
|
|
|
+
|
|
|
+ $iId = (int)bx_get('id');
|
|
|
+ if(empty($iId) || $iId != bx_get_logged_profile_id())
|
|
|
+ return echoJson(['code' => 1, 'message' => $sError]);
|
|
|
+
|
|
|
+ $sModeUc = strtoupper($this->_oConfig->getMode());
|
|
|
+ $sAccIdField = $CNF['FIELD_' . $sModeUc . '_ACCOUNT_ID'];
|
|
|
+ $sAccDetailsField = $CNF['FIELD_' . $sModeUc . '_DETAILS'];
|
|
|
+
|
|
|
+ $aAccount = $this->_oDb->getAccount(['sample' => 'profile_id', 'profile_id' => $iId]);
|
|
|
+ if(empty($aAccount) || !is_array($aAccount) || $aAccount[$sAccIdField] == '')
|
|
|
+ return echoJson(['code' => 1, 'message' => $sError]);
|
|
|
+
|
|
|
+ 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))
|
|
|
+ return echoJson(['code' => 1, 'message' => $sError]);
|
|
|
+
|
|
|
+ return echoJson(['code' => 0, 'redirect' => $oAccountLink->url]);
|
|
|
}
|
|
|
|
|
|
- public function createAccount($sCode)
|
|
|
+ public function actionAccountDelete()
|
|
|
{
|
|
|
- $CNF = $this->_oConfig->CNF;
|
|
|
-
|
|
|
- $oResult = $this->_request($CNF['URL_API_TOKEN'], array(
|
|
|
- 'client_secret' => $this->_oConfig->getApiSecretKey(),
|
|
|
- 'code' => $sCode,
|
|
|
- 'grant_type' => 'authorization_code'
|
|
|
- ));
|
|
|
-
|
|
|
- if(!empty($oResult->error))
|
|
|
- return bx_process_input($oResult->error_description);
|
|
|
-
|
|
|
- $bResult = $this->_oDb->insertAccount(array(
|
|
|
- 'author' => bx_get_logged_profile_id(),
|
|
|
- 'added' => time(),
|
|
|
- 'user_id' => $oResult->stripe_user_id,
|
|
|
- 'public_key' => $oResult->stripe_publishable_key,
|
|
|
- 'access_token' => $oResult->access_token,
|
|
|
- 'refresh_token' => $oResult->refresh_token
|
|
|
- ));
|
|
|
-
|
|
|
- return $bResult ? $bResult : _t('_bx_stripe_connect_err_perform');
|
|
|
+ $CNF = &$this->_oConfig->CNF;
|
|
|
+
|
|
|
+ $sError = _t('_bx_stripe_connect_err_perform');
|
|
|
+
|
|
|
+ $iId = (int)bx_get('id');
|
|
|
+ if(empty($iId) || $iId != bx_get_logged_profile_id())
|
|
|
+ return echoJson(['code' => 1, 'message' => $sError]);
|
|
|
+
|
|
|
+ $aAccount = $this->_oDb->getAccount(['sample' => 'profile_id', 'profile_id' => $iId]);
|
|
|
+ if(empty($aAccount) || !is_array($aAccount))
|
|
|
+ return echoJson(['code' => 1, 'message' => $sError]);
|
|
|
+
|
|
|
+ $sAccIdField = $CNF['FIELD_' . strtoupper($this->_oConfig->getMode()) . '_ACCOUNT_ID'];
|
|
|
+
|
|
|
+ $oStripe = new \Stripe\StripeClient($this->_oConfig->getApiSecretKey());
|
|
|
+ $oAccount = $oStripe->accounts->delete($aAccount[$sAccIdField], []);
|
|
|
+
|
|
|
+ if(!$oAccount || !$oAccount->deleted)
|
|
|
+ return echoJson(['code' => 2, 'message' => _t('_bx_stripe_connect_err_delete')]);
|
|
|
+
|
|
|
+ $this->_oDb->deleteAccount([
|
|
|
+ 'profile_id' => $iId,
|
|
|
+ $sAccIdField => $oAccount->id
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return echoJson(['code' => 0, 'reload' => 1]);
|
|
|
}
|
|
|
|
|
|
- public function deleteAccount($iId)
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * OTHER METHODS
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function processAlertStripeV3GetButton($iObject, $iSender, $aParams)
|
|
|
{
|
|
|
- $CNF = $this->_oConfig->CNF;
|
|
|
+ $CNF = &$this->_oConfig->CNF;
|
|
|
|
|
|
- $aAccount = $this->_oDb->getAccount(array('type' => 'id', 'id' => $iId));
|
|
|
- if(empty($aAccount) || !is_array($aAccount))
|
|
|
- return false;
|
|
|
+ if(empty($aParams['vendor_id']))
|
|
|
+ return false;
|
|
|
|
|
|
- $oResult = $this->_request($CNF['URL_API_DEAUTHORIZE'], array(
|
|
|
- 'client_id' => $this->_oConfig->getApiId(),
|
|
|
- 'client_secret' => $this->_oConfig->getApiSecretKey(),
|
|
|
- 'stripe_user_id' => $aAccount['user_id'],
|
|
|
- ));
|
|
|
+ $sModeUc = strtoupper($this->_oConfig->getMode());
|
|
|
+ $sAccIdField = $CNF['FIELD_' . $sModeUc . '_ACCOUNT_ID'];
|
|
|
+
|
|
|
+ $aAccount = $this->_oDb->getAccount(['sample' => 'profile_id', 'profile_id' => (int)$aParams['vendor_id']]);
|
|
|
+ if(empty($aAccount) || !is_array($aAccount) || empty($aAccount[$sAccIdField]))
|
|
|
+ return false;
|
|
|
|
|
|
- if(!empty($oResult->error))
|
|
|
- return false;
|
|
|
+ $aParams['public_key'] = $this->_oConfig->getApiPublicKey();
|
|
|
+ $aParams['connected_account_id'] = $aAccount[$sAccIdField];
|
|
|
|
|
|
- return $this->_oDb->deleteAccount(array('id' => $iId));
|
|
|
+ return !empty($aParams['public_key']);
|
|
|
}
|
|
|
|
|
|
- public function processAlertStripeGetButton($iObject, $iSender, $aParams)
|
|
|
+ public function processAlertStripeV3CreateSession($iObject, $iSender, $aParams)
|
|
|
{
|
|
|
- if(empty($aParams['type']))
|
|
|
+ $CNF = &$this->_oConfig->CNF;
|
|
|
+
|
|
|
+ if(empty($aParams['session_params']))
|
|
|
return false;
|
|
|
|
|
|
- $sType = $aParams['type'];
|
|
|
- $sPayMode = $this->_oConfig->getPayMode($sType);
|
|
|
+ try {
|
|
|
+ $sModeUc = strtoupper($this->_oConfig->getMode());
|
|
|
+ $sAccIdField = $CNF['FIELD_' . $sModeUc . '_ACCOUNT_ID'];
|
|
|
+
|
|
|
+ $iVendorId = (int)$aParams['session_params']['metadata']['vendor'];
|
|
|
+ $aAccount = $this->_oDb->getAccount(['sample' => 'profile_id', 'profile_id' => $iVendorId]);
|
|
|
+ if(empty($aAccount) || !is_array($aAccount) || empty($aAccount[$sAccIdField]))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ switch($aParams['session_params']['mode']) {
|
|
|
+ case 'payment':
|
|
|
+ $fAmount = 0;
|
|
|
+ foreach($aParams['session_params']['line_items'] as $aLineItem)
|
|
|
+ $fAmount += (float)$aLineItem['price_data']['unit_amount'] * (int)$aLineItem['quantity'];
|
|
|
+
|
|
|
+ $aParams['session_params']['payment_intent_data'] = [
|
|
|
+ 'application_fee_amount' => $this->_oConfig->getFee(BX_PAYMENT_TYPE_SINGLE, $fAmount)
|
|
|
+ ];
|
|
|
+ break;
|
|
|
|
|
|
- switch($sType) {
|
|
|
- case BX_PAYMENT_TYPE_SINGLE:
|
|
|
- if($sPayMode == BX_STRIPE_CONNECT_PMODE_PLATFORM)
|
|
|
- $aParams['public_key'] = $this->_oConfig->getApiPublicKey();
|
|
|
- break;
|
|
|
+ //TODO: Need to complete create Subscription flow.
|
|
|
+ case 'subscription':
|
|
|
+ $fAmount = 0;
|
|
|
+ foreach($aParams['session_params']['line_items'] as $aLineItem)
|
|
|
+ $fAmount += (float)$aLineItem['price'] * (int)$aLineItem['quantity'];
|
|
|
|
|
|
- case BX_PAYMENT_TYPE_RECURRING:
|
|
|
- //TODO: Perform necessary actions here !WHEN! 'Platform' mode will be available for recurring payments.
|
|
|
- break;
|
|
|
+ $aParams['session_params']['payment_intent_data'] = [
|
|
|
+ 'application_fee_amount' => $this->_oConfig->getFee(BX_PAYMENT_TYPE_SINGLE, $fAmount)
|
|
|
+ ];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ $aParams['session_object'] = BxStripeConnectApi::getInstance()->getStripe()->checkout->sessions->create($aParams['session_params'], [
|
|
|
+ 'stripe_account' => $aAccount[$sAccIdField]
|
|
|
+ ]);
|
|
|
}
|
|
|
+ catch (Exception $oException) {
|
|
|
+ $aParams['session_object'] = null;
|
|
|
|
|
|
- return !empty($aParams['public_key']);
|
|
|
+ return $this->_processException('Create Session Error: ', $oException);
|
|
|
+ }
|
|
|
+
|
|
|
+ return !empty($aParams['session_object']);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Methods related to old Stripe integration (which starts with 'processAlertStripe') are outdated.
|
|
|
+ */
|
|
|
public function processAlertStripeCreateCustomer($iObject, $iSender, $aParams)
|
|
|
{
|
|
|
if(empty($aParams['type']) || empty($aParams['customer_params']['card']))
|
|
|
@@ -401,81 +462,58 @@ class BxStripeConnectModule extends BxBaseModConnectModule
|
|
|
return !empty($aParams['subscription_object']);
|
|
|
}
|
|
|
|
|
|
- protected function _request($sUrl, $aParams = array())
|
|
|
- {
|
|
|
- $sResult = '';
|
|
|
- if(!function_exists('curl_init'))
|
|
|
- return false;
|
|
|
-
|
|
|
- $rConnect = curl_init();
|
|
|
-
|
|
|
- curl_setopt($rConnect, CURLOPT_URL, $sUrl);
|
|
|
- curl_setopt($rConnect, CURLOPT_HEADER, 0);
|
|
|
- curl_setopt($rConnect, CURLOPT_RETURNTRANSFER, 1);
|
|
|
- curl_setopt($rConnect, CURLOPT_FOLLOWLOCATION, 1);
|
|
|
- curl_setopt($rConnect, CURLOPT_POST, 1);
|
|
|
- curl_setopt($rConnect, CURLOPT_POSTFIELDS, http_build_query($aParams));
|
|
|
-
|
|
|
- if(bx_mb_strpos($sUrl, 'https') !== false) {
|
|
|
- curl_setopt($rConnect, CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
- curl_setopt($rConnect, CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
- }
|
|
|
-
|
|
|
- $sResult = curl_exec($rConnect);
|
|
|
- curl_close($rConnect);
|
|
|
-
|
|
|
- return json_decode($sResult);
|
|
|
- }
|
|
|
-
|
|
|
- protected function _processEvent()
|
|
|
- {
|
|
|
- $sInput = @file_get_contents("php://input");
|
|
|
- $aEvent = json_decode($sInput, true);
|
|
|
- if(empty($aEvent) || !is_array($aEvent))
|
|
|
- return 404;
|
|
|
+ protected function _processEvent()
|
|
|
+ {
|
|
|
+ $sInput = @file_get_contents("php://input");
|
|
|
+ $aEvent = json_decode($sInput, true);
|
|
|
+ if(empty($aEvent) || !is_array($aEvent))
|
|
|
+ return 404;
|
|
|
|
|
|
- $sType = $aEvent['type'];
|
|
|
- if(!in_array($sType, array('account.application.deauthorized')))
|
|
|
- return 200;
|
|
|
+ $sType = $aEvent['type'];
|
|
|
+ if(!in_array($sType, ['account.updated']))
|
|
|
+ return 200;
|
|
|
|
|
|
- $this->_log('Webhooks: ' . (!empty($sType) ? $sType : ''));
|
|
|
- $this->_log($aEvent);
|
|
|
+ $this->_log('Webhooks: ' . (!empty($sType) ? $sType : ''));
|
|
|
+ $this->_log($aEvent);
|
|
|
|
|
|
- $sMethod = '_processEvent' . bx_gen_method_name($sType, array('.', '_', '-'));
|
|
|
- if(!method_exists($this, $sMethod))
|
|
|
- return 200;
|
|
|
+ $sMethod = '_processEvent' . bx_gen_method_name($sType, array('.', '_', '-'));
|
|
|
+ if(!method_exists($this, $sMethod))
|
|
|
+ return 200;
|
|
|
|
|
|
return $this->$sMethod($aEvent) ? 200 : 403;
|
|
|
}
|
|
|
|
|
|
- protected function _processEventAccountApplicationDeauthorized(&$aEvent)
|
|
|
- {
|
|
|
- $CNF = $this->_oConfig->CNF;
|
|
|
+ protected function _processEventAccountUpdated(&$aEvent)
|
|
|
+ {
|
|
|
+ $CNF = $this->_oConfig->CNF;
|
|
|
+
|
|
|
+ $sAccountId = '';
|
|
|
+ if(!isset($aEvent['data']['object']['id']) || !($sAccountId = bx_process_input($aEvent['data']['object']['id'])))
|
|
|
+ return false;
|
|
|
|
|
|
- $sApiId = bx_process_input($aEvent['data']['object']['id']);
|
|
|
- if(strcmp($sApiId, $this->_oConfig->getApiId()) != 0)
|
|
|
- return false;
|
|
|
+ $sMode = $this->_oConfig->getMode();
|
|
|
+ $sAccDetailsField = $CNF['FIELD_' . strtoupper($sMode) . '_DETAILS'];
|
|
|
|
|
|
- $sUserId = bx_process_input($aEvent['user_id']);
|
|
|
- if(empty($sUserId))
|
|
|
- return false;
|
|
|
+ $aAccount = $this->_oDb->getAccount(['sample' => 'account_id', $sMode . '_account_id' => $sAccountId]);
|
|
|
+ if((int)$aAccount[$sAccDetailsField] == 0 && $aEvent['data']['object']['details_submitted'])
|
|
|
+ return $this->_oDb->updateAccount([$sAccDetailsField => 1], [$CNF['FIELD_ID'] => $aAccount[$CNF['FIELD_ID']]]);
|
|
|
|
|
|
- return $this->_oDb->deleteAccount(array('user_id' => $sUserId));
|
|
|
- }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
protected function _processException($sMessage, &$oException)
|
|
|
- {
|
|
|
- $aError = $oException->getJsonBody();
|
|
|
+ {
|
|
|
+ $aError = $oException->getJsonBody();
|
|
|
|
|
|
- $sMessage = $aError['error']['message'];
|
|
|
- if(empty($sMessage))
|
|
|
- $sMessage = $oException->getMessage();
|
|
|
+ $sMessage = $aError['error']['message'];
|
|
|
+ if(empty($sMessage))
|
|
|
+ $sMessage = $oException->getMessage();
|
|
|
|
|
|
- $this->_log($sMessage . $aError['error']['message']);
|
|
|
- $this->_log($aError);
|
|
|
+ $this->_log($sMessage . $aError['error']['message']);
|
|
|
+ $this->_log($aError);
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
protected function _getAccount($iPending, $sType)
|
|
|
{
|
|
|
@@ -498,15 +536,15 @@ class BxStripeConnectModule extends BxBaseModConnectModule
|
|
|
return $aAccount;
|
|
|
}
|
|
|
|
|
|
- protected function _log($sContents)
|
|
|
- {
|
|
|
- if (is_array($sContents))
|
|
|
- $sContents = var_export($sContents, true);
|
|
|
- else if (is_object($sContents))
|
|
|
- $sContents = json_encode($sContents);
|
|
|
-
|
|
|
- bx_log('bx_stripe_connect', $sContents);
|
|
|
- }
|
|
|
+ protected function _log($sContents)
|
|
|
+ {
|
|
|
+ if (is_array($sContents))
|
|
|
+ $sContents = var_export($sContents, true);
|
|
|
+ else if (is_object($sContents))
|
|
|
+ $sContents = json_encode($sContents);
|
|
|
+
|
|
|
+ bx_log('bx_stripe_connect', $sContents);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** @} */
|