|
|
@@ -27,38 +27,68 @@ class BxPaymentProviderCredits extends BxBaseModPaymentProvider implements iBxBa
|
|
|
$this->_sModuleCredits = $this->_oModule->_oConfig->CNF['MODULE_CREDITS'];
|
|
|
}
|
|
|
|
|
|
- public function initializeCheckout($iPendingId, $aCartInfo, $bRecurring = false, $iRecurringDays = 0)
|
|
|
+ public function initializeCheckout($iPendingId, $aCartInfo, $sRedirect = '')
|
|
|
{
|
|
|
- if(!BxDolModuleQuery::getInstance()->isEnabledByName($this->_sModuleCredits)) {
|
|
|
- $this->_oModule->_oTemplate->displayPageCodeError('_bx_payment_cdt_err_not_available');
|
|
|
- exit;
|
|
|
- }
|
|
|
+ if(!BxDolModuleQuery::getInstance()->isEnabledByName($this->_sModuleCredits))
|
|
|
+ return $this->_sLangsPrefix . 'cdt_err_not_available';
|
|
|
+
|
|
|
+ $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 $this->_sLangsPrefix . 'err_already_processed';
|
|
|
|
|
|
$iSellerId = (int)$aCartInfo['vendor_id'];
|
|
|
- $sCheckoutUrl = BxDolService::call($this->_sModuleCredits, 'get_checkout_url');
|
|
|
+ $sCustomData = $this->_constructCustomData($aCartInfo['vendor_id'], $iPendingId);
|
|
|
$sReturnDataUrl = $this->getReturnDataUrl($iSellerId);
|
|
|
-
|
|
|
-
|
|
|
- $aFormData = array(
|
|
|
- 'currency_code' => $aCartInfo['vendor_currency_code'],
|
|
|
- 'currency_sign' => $aCartInfo['vendor_currency_sign'],
|
|
|
- 'seller' => $iSellerId,
|
|
|
- 'amount' => (float)$aCartInfo['items_price'],
|
|
|
- 'items_count' => count($aCartInfo['items']),
|
|
|
- 'custom' => $this->_constructCustomData($aCartInfo['vendor_id'], $iPendingId),
|
|
|
- 'return_data_url' => $sReturnDataUrl,
|
|
|
- );
|
|
|
-
|
|
|
- $iIndex = 0;
|
|
|
- foreach($aCartInfo['items'] as $aItem) {
|
|
|
- $aFormData['item_title_' . $iIndex] = bx_process_output($aItem['title']);
|
|
|
- $aFormData['item_quantity_' . $iIndex] = $aItem['quantity'];
|
|
|
-
|
|
|
- $iIndex += 1;
|
|
|
- }
|
|
|
|
|
|
- $this->_oModule->_oTemplate->displayPageCodeRedirect($sCheckoutUrl, $aFormData);
|
|
|
- exit;
|
|
|
+ switch($aPending['type']) {
|
|
|
+ case BX_PAYMENT_TYPE_SINGLE:
|
|
|
+ $aFormData = array(
|
|
|
+ 'currency_code' => $aCartInfo['vendor_currency_code'],
|
|
|
+ 'currency_sign' => $aCartInfo['vendor_currency_sign'],
|
|
|
+ 'seller' => $iSellerId,
|
|
|
+ 'amount' => (float)$aCartInfo['items_price'],
|
|
|
+ 'items_count' => count($aCartInfo['items']),
|
|
|
+ 'custom' => $sCustomData,
|
|
|
+ 'return_data_url' => $sReturnDataUrl,
|
|
|
+ );
|
|
|
+
|
|
|
+ $iIndex = 0;
|
|
|
+ foreach($aCartInfo['items'] as $aItem) {
|
|
|
+ $aFormData['item_title_' . $iIndex] = bx_process_output($aItem['title']);
|
|
|
+ $aFormData['item_quantity_' . $iIndex] = $aItem['quantity'];
|
|
|
+
|
|
|
+ $iIndex += 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ $sCheckoutUrl = bx_srv($this->_sModuleCredits, 'get_checkout_url');
|
|
|
+ $this->_oModule->_oTemplate->displayPageCodeRedirect($sCheckoutUrl, $aFormData);
|
|
|
+ exit;
|
|
|
+
|
|
|
+ case BX_PAYMENT_TYPE_RECURRING:
|
|
|
+ $aItem = array_shift($aCartInfo['items']);
|
|
|
+
|
|
|
+ return array(
|
|
|
+ 'code' => 0,
|
|
|
+ 'popup' => array(
|
|
|
+ 'html' =>bx_srv($this->_sModuleCredits, 'get_popup_subscribe', array(array(
|
|
|
+ 'currency_code' => $aCartInfo['vendor_currency_code'],
|
|
|
+ 'currency_sign' => $aCartInfo['vendor_currency_sign'],
|
|
|
+ 'seller' => $iSellerId,
|
|
|
+ 'title' => bx_process_output($aItem['title']),
|
|
|
+ 'amount' => $aItem['price_recurring'],
|
|
|
+ 'period' => $aItem['period_recurring'],
|
|
|
+ 'period_unit' => $aItem['period_unit_recurring'],
|
|
|
+ 'trial' => $aItem['trial_recurring'],
|
|
|
+ 'custom' => $sCustomData,
|
|
|
+ 'return_data_url' => $sReturnDataUrl,
|
|
|
+ ))),
|
|
|
+ 'options' => array(
|
|
|
+ 'closeOnOuterClick' => true,
|
|
|
+ 'removeOnClose' => true
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function finalizeCheckout(&$aData)
|
|
|
@@ -72,7 +102,7 @@ class BxPaymentProviderCredits extends BxBaseModPaymentProvider implements iBxBa
|
|
|
|
|
|
if(!empty($aResult['pending_id']))
|
|
|
$this->_oModule->_oDb->updateOrderPending($aResult['pending_id'], array(
|
|
|
- 'order' => isset($aData['o']) ? $aData['o'] : '',
|
|
|
+ 'order' => $aResult['order'],
|
|
|
'error_code' => $aResult['code'],
|
|
|
'error_msg' => _t($aResult['message'])
|
|
|
));
|
|
|
@@ -80,6 +110,48 @@ class BxPaymentProviderCredits extends BxBaseModPaymentProvider implements iBxBa
|
|
|
return $aResult;
|
|
|
}
|
|
|
|
|
|
+ public function makePayment($mixedPending)
|
|
|
+ {
|
|
|
+ if(!BxDolModuleQuery::getInstance()->isEnabledByName($this->_sModuleCredits))
|
|
|
+ return array('code' => 1, 'message' => $this->_sLangsPrefix . 'cdt_err_not_available');
|
|
|
+
|
|
|
+ if(!is_array($mixedPending))
|
|
|
+ $mixedPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => (int)$mixedPending));
|
|
|
+
|
|
|
+ if(empty($mixedPending) || !is_array($mixedPending))
|
|
|
+ return array('code' => 2, 'message' => $this->_sLangsPrefix . 'err_not_found_pending');
|
|
|
+
|
|
|
+ $iClient = (int)$mixedPending['client_id'];
|
|
|
+ $oClient = BxDolProfile::getInstance($iClient);
|
|
|
+
|
|
|
+ $iSeller = (int)$mixedPending['seller_id'];
|
|
|
+ $oSeller = BxDolProfile::getInstance($iSeller);
|
|
|
+
|
|
|
+ if(!$oClient || !$oSeller)
|
|
|
+ return array('code' => 3, 'message' => $this->_sLangsPrefix . 'err_wrong_data');
|
|
|
+
|
|
|
+ $fAmount = (float)$mixedPending['amount'];
|
|
|
+ if(!bx_srv($this->_sModuleCredits, 'make_payment', array($iClient, $fAmount, $iSeller, $mixedPending['order'])))
|
|
|
+ return array('code' => 4, 'message' => $this->_sLangsPrefix . 'err_cannot_perform');
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function cancelRecurring($iPendingId, $sCustomerId, $sSubscriptionId)
|
|
|
+ {
|
|
|
+ bx_alert($this->MODULE, $this->_sName . '_cancel_subscription', 0, false, array(
|
|
|
+ 'pending_id' => $iPendingId,
|
|
|
+ 'subscription_id' => $sSubscriptionId,
|
|
|
+ ));
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getMenuItemsActionsRecurring($iClientId, $iVendorId, $aParams = array())
|
|
|
+ {
|
|
|
+ return array();
|
|
|
+ }
|
|
|
+
|
|
|
protected function _finalizeCheckout(&$aData)
|
|
|
{
|
|
|
list($iSellerId, $iPendingId) = $this->_deconstructCustomData($aData['c']);
|
|
|
@@ -91,25 +163,47 @@ class BxPaymentProviderCredits extends BxBaseModPaymentProvider implements iBxBa
|
|
|
if(empty($aPending) || !is_array($aPending))
|
|
|
return array('code' => 1, 'message' => $this->_sLangsPrefix . 'err_not_found_pending');
|
|
|
|
|
|
- if(!empty($aPending['order']) || !empty($aPending['error_code']) || !empty($aPending['error_msg']) || (int)$aPending['processed'] != 0)
|
|
|
- return array('code' => 2, 'message' => $this->_sLangsPrefix . 'err_already_processed');
|
|
|
-
|
|
|
if(empty($this->_aOptions) || !BxDolModuleQuery::getInstance()->isEnabledByName($this->_sModuleCredits))
|
|
|
- return array('code' => 3, 'message' => $this->_sLangsPrefix . 'err_incorrect_provider', 'pending_id' => $iPendingId);
|
|
|
-
|
|
|
- $sOrder = $aData['o'];
|
|
|
- if(!BxDolService::call($this->_sModuleCredits, 'validate_checkout', array((int)$aPending['seller_id'], (int)$aPending['client_id'], (float)$aPending['amount'], $sOrder)))
|
|
|
- return array('code' => 4, 'message' => $this->_sLangsPrefix . 'cdt_err_wrong_transaction', 'pending_id' => $iPendingId);
|
|
|
+ return array('code' => 2, 'message' => $this->_sLangsPrefix . 'err_incorrect_provider', 'pending_id' => $iPendingId);
|
|
|
+
|
|
|
+ switch($aPending['type']) {
|
|
|
+ case BX_PAYMENT_TYPE_SINGLE:
|
|
|
+ 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');
|
|
|
+
|
|
|
+ $sOrder = $aData['o'];
|
|
|
+ if(!bx_srv($this->_sModuleCredits, 'validate_checkout', array((int)$aPending['seller_id'], (int)$aPending['client_id'], (float)$aPending['amount'], $sOrder)))
|
|
|
+ return array('code' => 4, 'message' => $this->_sLangsPrefix . 'cdt_err_wrong_transaction', 'pending_id' => $iPendingId);
|
|
|
+
|
|
|
+ $aResult = array(
|
|
|
+ 'message' => $this->_sLangsPrefix . 'cdt_msg_charged',
|
|
|
+ 'order' => !empty($aData['o']) ? $aData['o'] : '',
|
|
|
+ 'paid' => true
|
|
|
+ );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case BX_PAYMENT_TYPE_RECURRING:
|
|
|
+ $sSubscriptionId = bx_process_input($aData['sb']);
|
|
|
+
|
|
|
+ $aResult = array(
|
|
|
+ 'message' => $this->_sLangsPrefix . 'cdt_msg_subscribed',
|
|
|
+ 'customer_id' => bx_process_input($aData['cs']),
|
|
|
+ 'subscription_id' => $sSubscriptionId,
|
|
|
+ 'trial' => (bool)$aData['tr'],
|
|
|
+ 'order' => $sSubscriptionId,
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
$oClient = BxDolProfile::getInstance($aPending['client_id']);
|
|
|
- return array(
|
|
|
+ return array_merge(array(
|
|
|
'code' => BX_PAYMENT_RESULT_SUCCESS,
|
|
|
- 'message' => $this->_sLangsPrefix . 'cdt_msg_processed',
|
|
|
+ 'message' => '',
|
|
|
'pending_id' => $iPendingId,
|
|
|
'client_name' => $oClient->getDisplayName(),
|
|
|
'client_email' => $oClient->getAccountObject()->getEmail(),
|
|
|
- 'paid' => true
|
|
|
- );
|
|
|
+ 'order' => ''
|
|
|
+ ), $aResult);
|
|
|
}
|
|
|
|
|
|
protected function _constructCustomData()
|