Преглед изворни кода

Ticket #259 - Subscriptions and Chargebee.

AntonLV пре 10 година
родитељ
комит
381dc99841

+ 1 - 1
install/sql/system.sql

@@ -325,7 +325,7 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 
 (@iCategoryId, 'sys_transcoder_queue_storage', '_adm_stg_cpt_option_sys_transcoder_queue_storage', '', 'checkbox', '', '', '', 50),
 
-(@iCatGeneral, 'sys_default_payment', '_adm_stg_cpt_option_sys_default_payment', 'payment', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:12:"get_payments";s:5:"class";s:21:"TemplPaymentsServices";}', 'Avail', '_adm_stg_err_option_sys_default_payment', 60);
+(@iCategoryId, 'sys_default_payment', '_adm_stg_cpt_option_sys_default_payment', 'payment', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:12:"get_payments";s:5:"class";s:21:"TemplPaymentsServices";}', 'Avail', '_adm_stg_err_option_sys_default_payment', 60);
 
 
 --

+ 10 - 0
modules/base/payment/classes/BxBaseModPaymentProvider.php

@@ -47,11 +47,21 @@ class BxBaseModPaymentProvider extends BxDol
         $this->_bRedirectOnResult = false;
     }
 
+	public function getReturnUrl()
+    {
+		return $this->_oModule->_oConfig->getUrl('URL_RETURN');
+    }
+
     public function getReturnDataUrl($iVendorId)
     {
 		return $this->_oModule->_oConfig->getUrl('URL_RETURN_DATA') . $this->_sName . '/' . $iVendorId;
     }
 
+	public function getNotifyUrl($iVendorId)
+    {
+		return $this->_oModule->_oConfig->getUrl('URL_NOTIFY') . $this->_sName . '/' . $iVendorId;
+    }
+
     /**
      * TODO: Check whether the method is needed or not. 
      * Is used on success only.

+ 1 - 0
modules/boonex/payment/classes/BxPaymentConfig.php

@@ -23,6 +23,7 @@ class BxPaymentConfig extends BxBaseModPaymentConfig
         	'URL_DETAILS' => 'page.php?i=payment-details',
         	'URL_RETURN' => 'page.php?i=payment-cart',
         	'URL_RETURN_DATA' => BX_DOL_URL_ROOT . $this->getBaseUri() . 'finalize_checkout/',
+        	'URL_NOTIFY' => BX_DOL_URL_ROOT . $this->getBaseUri() . 'notify/',
 
         	'KEY_ARRAY_PRICE_SINGLE' => 'price_single',
         	'KEY_ARRAY_PRICE_RECURRING' => 'price_recurring',

+ 7 - 2
modules/boonex/payment/classes/BxPaymentDetails.php

@@ -146,8 +146,13 @@ class BxPaymentDetails extends BxDol
                     break;
 
 				 case 'value':
-				 	if(str_replace($aInput['provider_option_prefix'], '', $aInput['name']) == 'return_url')
-				 		$aForm['inputs'][$aInput['name']]['value'] = $oProvider->getReturnDataUrl($iUserId);
+				 	$sName = str_replace($aInput['provider_option_prefix'], '', $aInput['name']);
+				 	if(!in_array($sName, array('return_data_url', 'notify_url')))
+				 		break;
+
+				 	$sMethod = 'get' . bx_gen_method_name($sName);
+				 	if(method_exists($oProvider, $sMethod))
+						$aForm['inputs'][$aInput['name']]['value'] = $oProvider->$sMethod($iUserId);
 				 	break;
             }
 

+ 3 - 3
modules/boonex/payment/classes/BxPaymentModule.php

@@ -318,7 +318,7 @@ class BxPaymentModule extends BxBaseModPaymentModule
 			$this->registerPayment($aPending);
 
 		if($oProvider->needRedirect()) {
-			header('Location: ' . $this->_oConfig->getUrl('URL_RETURN'));
+			header('Location: ' . $oProvider->getReturnUrl());
 			exit;
 		}
 
@@ -335,13 +335,13 @@ class BxPaymentModule extends BxBaseModPaymentModule
         $this->_oTemplate->displayPageCodeResponse($aResult['message']);
     }
 
-    public function actionProcessEvent($sProvider, $mixedVendorId = "")
+    public function actionNotify($sProvider, $mixedVendorId = "")
     {
     	$oProvider = $this->getObjectProvider($sProvider, $mixedVendorId);
         if($oProvider === false)
         	return $this->_oTemplate->displayPageCodeError($this->_sLangsPrefix . 'err_incorrect_provider');
 
-		$oProvider->processEvent();
+		$oProvider->notify();
     }
 
     public function onProfileJoin($iProfileId)

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

@@ -90,7 +90,7 @@ class BxPaymentProviderChargebee extends BxBaseModPaymentProvider implements iBx
         return $aResult;
     }
 
-    public function processEvent()
+    public function notify()
     {
 		$iResult = $this->_processEvent();
 		http_response_code($iResult);

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

@@ -72,7 +72,7 @@ class BxPaymentProviderPayPal extends BxBaseModPaymentProvider implements iBxBas
                 break;
             case PP_PRC_TYPE_IPN:
                 $aFormData = array_merge($aFormData, array(
-                    'return' => $this->_oConfig->getUrl('URL_RETURN'),
+                    'return' => $this->getReturnUrl(),
                     'notify_url' => $this->getReturnDataUrl($aCartInfo['vendor_id']),
                     'rm' => '1'
                 ));

+ 4 - 3
modules/boonex/payment/install/langs/en.xml

@@ -219,7 +219,7 @@
 	<string name="_bx_payment_pp_token_dsc"><![CDATA[Identity token]]></string>
 	<string name="_bx_payment_pp_sandbox_cpt"><![CDATA[Sandbox]]></string>
 	<string name="_bx_payment_pp_sandbox_dsc"><![CDATA[Sandbox email address]]></string>
-	<string name="_bx_payment_pp_return_url_cpt"><![CDATA[Data return URL]]></string>
+	<string name="_bx_payment_pp_return_data_url_cpt"><![CDATA[Data return URL]]></string>
 	<string name="_bx_payment_pp_err_no_data_given"><![CDATA[No data given.]]></string>
 	<string name="_bx_payment_pp_err_no_vendor_given"><![CDATA[Unknown vendor.]]></string>
 	<string name="_bx_payment_pp_err_not_completed"><![CDATA[Payment is not completed.]]></string>
@@ -249,7 +249,7 @@
 	<string name="_bx_payment_2co_payment_method_ppi"><![CDATA[PayPal(PPI)]]></string>
 	<string name="_bx_payment_2co_secret_word_cpt"><![CDATA[Secret Word]]></string>
 	<string name="_bx_payment_2co_secret_word_dsc"><![CDATA[Secret word is used to calculate a check hash]]></string>
-	<string name="_bx_payment_2co_return_url_cpt"><![CDATA[Data return URL]]></string>
+	<string name="_bx_payment_2co_return_data_url_cpt"><![CDATA[Data return URL]]></string>
 	<string name="_bx_payment_2co_err_no_vendor_given"><![CDATA[Unknown vendor]]></string>
 	<string name="_bx_payment_2co_err_no_data_given"><![CDATA[No data given.]]></string>
 	<string name="_bx_payment_2co_err_wrong_key"><![CDATA[Check key is incorrect.]]></string>
@@ -303,7 +303,8 @@
 	<string name="_bx_payment_cbee_test_site_dsc"><![CDATA[Your site name registered in Chargebee for 'test' mode]]></string>
 	<string name="_bx_payment_cbee_test_api_key_cpt"><![CDATA[API Key (test)]]></string>
 	<string name="_bx_payment_cbee_test_api_key_dsc"><![CDATA[Your Chargebee API Access key for 'test' mode]]></string>
-	<string name="_bx_payment_cbee_return_url_cpt"><![CDATA[Data return URL]]></string>
+	<string name="_bx_payment_cbee_return_data_url_cpt"><![CDATA[Data return URL]]></string>
+	<string name="_bx_payment_cbee_notify_url_cpt"><![CDATA[Webhooks URL]]></string>
 	<string name="_bx_payment_cbee_msg_subscribed"><![CDATA[Subscription was successfully created.]]></string>
 	<string name="_bx_payment_txt_cart_chargebee"><![CDATA[Chargebee]]></string>
 

+ 4 - 3
modules/boonex/payment/install/sql/install.sql

@@ -94,7 +94,7 @@ INSERT INTO `bx_payment_providers_options`(`provider_id`, `name`, `type`, `capti
 (@iProviderId, 'pp_prc_type', 'select', '_bx_payment_pp_prc_type_cpt', '_bx_payment_pp_prc_type_dsc', '1|_bx_payment_pp_prc_type_direct,2|_bx_payment_pp_prc_type_pdt,3|_bx_payment_pp_prc_type_ipn', '', '', '', 4),
 (@iProviderId, 'pp_token', 'text', '_bx_payment_pp_token_cpt', '_bx_payment_pp_token_dsc', '', '', '', '', 5),
 (@iProviderId, 'pp_sandbox', 'text', '_bx_payment_pp_sandbox_cpt', '_bx_payment_pp_sandbox_dsc', '', '', '', '', 6),
-(@iProviderId, 'pp_return_url', 'value', '_bx_payment_pp_return_url_cpt', '', '', '', '', '', 7);
+(@iProviderId, 'pp_return_data_url', 'value', '_bx_payment_pp_return_data_url_cpt', '', '', '', '', '', 7);
 
 
 -- 2Checkout payment provider
@@ -108,7 +108,7 @@ INSERT INTO `bx_payment_providers_options`(`provider_id`, `name`, `type`, `capti
 (@iProviderId, '2co_account_id', 'text', '_bx_payment_2co_account_id_cpt', '_bx_payment_2co_account_id_dsc', '', '', '', '', 3),
 (@iProviderId, '2co_payment_method', 'select', '_bx_payment_2co_payment_method_cpt', '_bx_payment_2co_payment_method_dsc', 'CC|_bx_payment_2co_payment_method_cc,PPI|_bx_payment_2co_payment_method_ppi', '', '', '', 4),
 (@iProviderId, '2co_secret_word', 'text', '_bx_payment_2co_secret_word_cpt', '_bx_payment_2co_secret_word_dsc', '', '', '', '', 5),
-(@iProviderId, '2co_return_url', 'value', '_bx_payment_2co_return_url_cpt', '', '', '', '', '', 6);
+(@iProviderId, '2co_return_data_url', 'value', '_bx_payment_2co_return_data_url_cpt', '', '', '', '', '', 6);
 
 
 -- BitPay payment provider
@@ -136,7 +136,8 @@ INSERT INTO `bx_payment_providers_options`(`provider_id`, `name`, `type`, `capti
 (@iProviderId, 'cbee_live_api_key', 'text', '_bx_payment_cbee_live_api_key_cpt', '_bx_payment_cbee_live_api_key_dsc', '', '', '', '', 4),
 (@iProviderId, 'cbee_test_site', 'text', '_bx_payment_cbee_test_site_cpt', '_bx_payment_cbee_test_site_dsc', '', '', '', '', 5),
 (@iProviderId, 'cbee_test_api_key', 'text', '_bx_payment_cbee_test_api_key_cpt', '_bx_payment_cbee_test_api_key_dsc', '', '', '', '', 6),
-(@iProviderId, 'cbee_return_url', 'value', '_bx_payment_cbee_return_url_cpt', '', '', '', '', '', 7);
+(@iProviderId, 'cbee_return_data_url', 'value', '_bx_payment_cbee_return_data_url_cpt', '', '', '', '', '', 7),
+(@iProviderId, 'cbee_notify_url', 'value', '_bx_payment_cbee_notify_url_cpt', '', '', '', '', '', 8);
 
 -- GRIDS
 INSERT INTO `sys_objects_grid` (`object`, `source_type`, `source`, `table`, `field_id`, `field_order`, `field_active`, `paginate_url`, `paginate_per_page`, `paginate_simple`, `paginate_get_start`, `paginate_get_per_page`, `filter_fields`, `filter_fields_translatable`, `filter_mode`, `sorting_fields`, `sorting_fields_translatable`, `override_class_name`, `override_class_file`) VALUES