فهرست منبع

Ticket #456 - Change subscription functionality.

AntonLV 10 سال پیش
والد
کامیت
695b325c91

+ 5 - 0
modules/boonex/market/template/css/entry.css

@@ -1,3 +1,8 @@
+/*--- Entry Cover ---*/
+.bx-cover .bx-cover-image img {
+	background-position: center center;
+}
+
 /*--- Entry Content ---*/
 div.bx-market-entity-content {}
 

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

@@ -63,9 +63,11 @@ class BxPaymentConfig extends BxBaseModPaymentConfig
         	'subscription' => array(
         		'order_subscription_view' => $this->_sName . '-order-view-subscription',
         		'order_subscription_get_details' => $this->_sName . '-order-get-details-subscription',
+        	    'order_subscription_change_details' => $this->_sName . '-order-change-details-subscription',
         		'order_subscription_get_billing' => $this->_sName . '-order-get-billing-subscription',
         		'order_subscription_change_billing' => $this->_sName . '-order-change-billing-subscription',
         		'form_subscription_change_billing' => $this->_sName . '-form-change-billing-subscription',
+        	    'form_subscription_change_details' => $this->_sName . '-form-change-details-subscription',
         	),
         	'pending' => array(
         		'order_pending_view' => $this->_sName . '-order-view-pending',

+ 6 - 0
modules/boonex/payment/classes/BxPaymentModule.php

@@ -279,6 +279,12 @@ class BxPaymentModule extends BxBaseModPaymentModule
 		echoJson($aResult);
     }
 
+    public function actionSubscriptionChangeDetails($iId)
+    {
+        $aResult = $this->_oTemplate->displaySubscriptionChangeDetails($iId);
+		echoJson($aResult);
+    }
+
     public function actionSubscriptionGetBilling($iId)
     {
         $aResult = $this->_oTemplate->displaySubscriptionGetBilling($iId);

+ 134 - 10
modules/boonex/payment/classes/BxPaymentProviderStripe.php

@@ -20,11 +20,15 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
 	protected $_aIncludeJs;
 	protected $_aIncludeCss;
 
+	protected $_sFormDetails;
+	protected $_sFormDisplayDetailsEdit;
+
     protected $_sFormCard;
 	protected $_sFormDisplayCardAdd;
 
 	protected $_iMode;
 	protected $_bCheckAmount;
+	protected $_bProrate;
 
 	protected $_oCustomer;
 
@@ -35,6 +39,9 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
 
         parent::__construct($aConfig);
 
+        $this->_sFormDetails = 'bx_payment_form_strp_details';
+        $this->_sFormDisplayDetailsEdit = 'bx_payment_form_strp_details_edit';
+
         $this->_sFormCard = 'bx_payment_form_strp_card';
         $this->_sFormDisplayCardAdd = 'bx_payment_form_strp_card_add';
 
@@ -42,6 +49,7 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
         $this->_iMode = (int)$this->getOption('mode');
         $this->_bCheckAmount = $this->getOption('check_amount') == 'on'; 
         $this->_bUseSsl = $this->getOption('ssl') == 'on';
+        $this->_bProrate = false;
         $this->_sLogFile = BX_DIRECTORY_PATH_LOGS . 'bx_pp_' . $this->_sName . '.log';
 
         $this->_aIncludeJs = array(
@@ -141,8 +149,13 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
 
 		switch($aPending['type']) {
 			case BX_PAYMENT_TYPE_SINGLE:
-				$aCustomer = $this->_retrieveCustomer($sCustomerId)->jsonSerialize();
-				$aCharge = $this->_retrieveCharge($sOrderId)->jsonSerialize();
+			    $oCustomer = $this->_retrieveCustomer($sCustomerId);
+				$oCharge = $this->_retrieveCharge($sOrderId);
+				if($oCustomer === false || $oCharge === false)
+				    return array('code' => 4, 'message' => $this->_sLangsPrefix . 'err_cannot_perform');
+				
+				$aCustomer = $oCustomer->jsonSerialize();
+				$aCharge = $oCharge->jsonSerialize();
 				if(empty($aCustomer) || !is_array($aCustomer) || empty($aCharge) || !is_array($aCharge))
 					return array('code' => 4, 'message' => $this->_sLangsPrefix . 'err_cannot_perform');
 
@@ -154,8 +167,13 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
 				break;
 
 			case BX_PAYMENT_TYPE_RECURRING:
-				$aCustomer = $this->_retrieveCustomer($sCustomerId)->jsonSerialize();
-				$aSubscription = $this->_retrieveSubscription($sCustomerId, $sOrderId)->jsonSerialize();
+			    $oCustomer = $this->_retrieveCustomer($sCustomerId);
+				$oSubscription = $this->_retrieveSubscription($sCustomerId, $sOrderId);
+				if($oCustomer === false || $oSubscription === false)
+					return array('code' => 4, 'message' => $this->_sLangsPrefix . 'err_cannot_perform');
+
+				$aCustomer = $oCustomer->jsonSerialize();
+				$aSubscription = $oSubscription->jsonSerialize();
 				if(empty($aCustomer) || !is_array($aCustomer) || empty($aSubscription) || !is_array($aSubscription))
 					return array('code' => 4, 'message' => $this->_sLangsPrefix . 'err_cannot_perform');
 
@@ -217,14 +235,19 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
         $sPrefix = 'bx-payment-strp-';
         return array(
             array('id' => $sPrefix . 'details', 'name' => $sPrefix . 'details', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => "javascript:" . $sJsObject . ".getDetails(this, '" . $aParams['id'] . "')", 'target' => '_self', 'title' => _t('_bx_payment_strp_menu_item_title_details')),
+            array('id' => $sPrefix . 'details_change', 'name' => $sPrefix . 'details_change', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => "javascript:" . $sJsObject . ".changeDetails(this, '" . $aParams['id'] . "')", 'target' => '_self', 'title' => _t('_bx_payment_strp_menu_item_title_details_change')),
             array('id' => $sPrefix . 'billing', 'name' => $sPrefix . 'billing', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => "javascript:" . $sJsObject . ".getBilling(this, '" . $aParams['id'] . "')", 'target' => '_self', 'title' => _t('_bx_payment_strp_menu_item_title_billing')),
-            array('id' => $sPrefix . 'change', 'name' => $sPrefix . 'change', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => "javascript:" . $sJsObject . ".changeBilling(this, '" . $aParams['id'] . "')", 'target' => '_self', 'title' => _t('_bx_payment_strp_menu_item_title_billing_change')),
+            array('id' => $sPrefix . 'billing_change', 'name' => $sPrefix . 'billing_change', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => "javascript:" . $sJsObject . ".changeBilling(this, '" . $aParams['id'] . "')", 'target' => '_self', 'title' => _t('_bx_payment_strp_menu_item_title_billing_change')),
         );
     }
 
     public function getDetailsRecurring($iPendingId, $sCustomerId, $sSubscriptionId)
     {
-        $aSubscription = $this->_retrieveSubscription($sCustomerId, $sSubscriptionId)->jsonSerialize();
+        $oSubscription = $this->_retrieveSubscription($sCustomerId, $sSubscriptionId);
+        if($oSubscription === false)
+            return '';
+
+        $aSubscription = $oSubscription->jsonSerialize();
         if(empty($aSubscription) || !is_array($aSubscription))
             return '';
 
@@ -242,6 +265,49 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
         ));
     }
 
+    public function changeDetailsRecurring($iPendingId, $sCustomerId, $sSubscriptionId)
+    {
+        $oForm = BxDolForm::getObjectInstance($this->_sFormDetails, $this->_sFormDisplayDetailsEdit, $this->_oModule->_oTemplate);
+        $oForm->aFormAttrs['id'] = $this->_oModule->_oConfig->getHtmlIds('subscription', 'form_subscription_change_details');
+        $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . 'subscription_change_details/' . $iPendingId;
+
+        $oForm->aInputs['item_id']['values'] = $this->_getDataChangeDetailsRecurring($iPendingId);
+
+        $oForm->initChecker();
+        if($oForm->isSubmittedAndValid()) {
+            $aResultError = array('code' => 1, 'message' => _t('_bx_payment_strp_err_details_changed'));
+
+            $aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
+            list($iVendorId, $iModuleId, $iItemId, $iItemCount) = $this->_oModule->_oConfig->descriptorS2A($aPending['items']);
+
+            $aItem = $this->_oModule->callGetCartItem($iModuleId, array($oForm->getCleanValue('item_id')));
+    		if(empty($aItem) || !is_array($aItem))
+    			return $aResultError;
+
+            $oSubscription = $this->_retrieveSubscription($sCustomerId, $sSubscriptionId);
+            if($oSubscription === false)
+                return $aResultError;
+
+            $oSubscription->plan = $aItem['name'];
+            $oSubscription->prorate = $this->_bProrate;
+            $oSubscription = $oSubscription->save();
+            if(strcmp($oSubscription->plan->id, $aItem['name']) !== 0)
+                return $aResultError;
+
+            $this->_oModule->_oDb->updateOrderPending($iPendingId, array(
+                'items' => $this->_oModule->_oConfig->descriptorA2S(array($iVendorId, $iModuleId, $aItem['id'], $iItemCount)),
+            ));
+
+            return array('code' => 0, 'message' => _t('_bx_payment_strp_msg_details_changed'));
+        }
+
+        return $this->_oModule->_oTemplate->parseHtmlByName('strp_details_change_recuring.html', array(
+        	'object' => $this->_oModule->_oConfig->getJsObject('subscription'),
+            'form' => $oForm->getCode(),
+            'form_id' => $oForm->aFormAttrs['id'],
+        ));
+    }
+
     public function getBillingRecurring($iPendingId, $sCustomerId, $sSubscriptionId)
     {
         $aCard = $this->_retrieveCard($sCustomerId)->jsonSerialize();
@@ -264,6 +330,8 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
 
         $oForm->initChecker();
         if($oForm->isSubmittedAndValid()) {
+            $aResultError = array('code' => 1, 'message' => _t('_bx_payment_strp_err_billing_changed'));
+
             list($iMonth, $iYear) = explode(' ', $oForm->getCleanValue('card_expire'));
 
         	$aToken = $this->_createToken(array(
@@ -273,20 +341,23 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
                 'cvc' => $oForm->getCleanValue('card_cvv')
             ));
             if(empty($aToken) || !is_array($aToken))
-                return array('code' => 1, 'message' => _t('_bx_payment_strp_err_billing_changed'));
+                return $aResultError;
 
             $aCard = $this->_createCard($sCustomerId, $aToken['id']);
             if(empty($aCard) || !is_array($aCard))
-                return array('code' => 1, 'message' => _t('_bx_payment_strp_err_billing_changed'));
+                return $aResultError;
 
             $oCustomer = $this->_retrieveCustomer($sCustomerId);
+            if($oCustomer === false)
+                return $aResultError;
+
             $oCustomer->default_source = $aCard['id'];
             $oCustomer->save();
 
             return array('code' => 0, 'message' => _t('_bx_payment_strp_msg_billing_changed'));
         }
 
-        return $this->_oModule->_oTemplate->parseHtmlByName('strp_card_recuring.html', array(
+        return $this->_oModule->_oTemplate->parseHtmlByName('strp_billing_change_recuring.html', array(
         	'object' => $this->_oModule->_oConfig->getJsObject('subscription'),
             'form' => $oForm->getCode(),
             'form_id' => $oForm->aFormAttrs['id'],
@@ -455,7 +526,8 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
 		);
 	}
 
-	protected function _retrieveSubscription($sCustomerId, $sSubscriptionId) {
+	protected function _retrieveSubscription($sCustomerId, $sSubscriptionId)
+	{
 		try {
 			$oCustomer = \Stripe\Customer::retrieve($sCustomerId);
 			$oSubscription = $oCustomer->subscriptions->retrieve($sSubscriptionId);
@@ -467,6 +539,18 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
 		return $oSubscription;
 	}
 
+    protected function _listPlans()
+	{
+		try {
+			$oPlans = \Stripe\Plan::all();
+		}
+		catch (Exception $oException) {
+			return $this->_processException('List Plans Error: ', $oException);
+		}
+
+		return $oPlans;
+	}
+
     protected function _createCard($sCustomerId, $sToken)
 	{
 		try {
@@ -610,6 +694,46 @@ class BxPaymentProviderStripe extends BxBaseModPaymentProvider implements iBxBas
 		return array($aPending, $oCharge);
 	}
 
+    protected function _getDataChangeDetailsRecurring($iPendingId)
+    {
+        $aResult = array();
+
+        $aPending = $this->_oModule->_oDb->getOrderPending(array('type' => 'id', 'id' => $iPendingId));
+        list($iVendorId, $iModuleId, $iItemId) = $this->_oModule->_oConfig->descriptorS2A($aPending['items']);
+        if(empty($iModuleId) || empty($iVendorId) || (int)$iVendorId != (int)$aPending['seller_id'])
+            return $aResult;
+
+        $aItems = $this->_oModule->callGetCartItems((int)$iModuleId, array($iVendorId));
+        if(empty($aItems) || !is_array($aItems))
+            return $aResult;
+
+        $oPlans = $this->_listPlans();
+        if($oPlans === false)
+            return $aResult;
+
+        $aPlans = $oPlans->jsonSerialize();
+        if(empty($aPlans) || !is_array($aPlans) || empty($aPlans['data']) || !is_array($aPlans['data']))
+            return $aResult;
+
+        $aPlans = $aPlans['data'];
+
+        $aPlanNames = array();
+        foreach($aPlans as $aPlan)
+            $aPlanNames[] = $aPlan['id'];
+        if(empty($aPlanNames) || !is_array($aPlanNames))
+            return $aResult;
+
+        foreach($aItems as $aItem) {
+            $fPrice = $this->_oModule->_oConfig->getPrice(BX_PAYMENT_TYPE_RECURRING, $aItem);
+            if($fPrice == 0 || (int)$aItem['id'] == (int)$iItemId || !in_array($aItem['name'], $aPlanNames))
+                continue;
+
+            $aResult[] = array('key' => $aItem['id'], 'value' => $aItem['title']);
+        }
+
+        return $aResult;
+    }
+
 	protected function _getVerificationCodeCharge($iVendorId, $iCustomerId, $fAmount, $sCurrency) {
 		return md5(implode('#-#', array(
 			(int)$iVendorId,

+ 6 - 1
modules/boonex/payment/classes/BxPaymentTemplate.php

@@ -127,6 +127,11 @@ class BxPaymentTemplate extends BxBaseModPaymentTemplate
     	return $this->_displaySubscriptionData('get_details', $iId);
     }
 
+    public function displaySubscriptionChangeDetails($iId)
+    {
+    	return $this->_displaySubscriptionData('change_details', $iId);
+    }
+
     public function displaySubscriptionGetBilling($iId)
     {
     	return $this->_displaySubscriptionData('get_billing', $iId);
@@ -375,7 +380,7 @@ class BxPaymentTemplate extends BxBaseModPaymentTemplate
             return array();
         else if(is_array($mixedContent))
             return $mixedContent;
-
+//TODO: Continue from here. Popup Should use correct HTML ID to avoid duplocations. 
         $sKey = 'order_' . BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION . '_' . $sType;
     	$sId = $this->_oConfig->getHtmlIds(BX_PAYMENT_ORDERS_TYPE_SUBSCRIPTION, $sKey);
     	$sTitle = _t($this->_sLangsPrefix . 'popup_title_ods_' . $sKey);

+ 17 - 0
modules/boonex/payment/install/langs/en.xml

@@ -113,6 +113,7 @@
 
     <string name="_bx_payment_popup_title_ods_order_subscription_view"><![CDATA[Subscription]]></string>
     <string name="_bx_payment_popup_title_ods_order_subscription_get_details"><![CDATA[Subscription Details]]></string>
+    <string name="_bx_payment_popup_title_ods_order_subscription_change_details"><![CDATA[Change Subscription Details]]></string>
     <string name="_bx_payment_popup_title_ods_order_subscription_get_billing"><![CDATA[Billing Information]]></string>
     <string name="_bx_payment_popup_title_ods_order_subscription_change_billing"><![CDATA[Change Billing Information]]></string>
 	<string name="_bx_payment_popup_title_ods_order_history_view"><![CDATA[Order]]></string>
@@ -411,11 +412,14 @@
 	<string name="_bx_payment_strp_notify_url_cpt"><![CDATA[Webhooks URL]]></string>
 	<string name="_bx_payment_strp_msg_charged"><![CDATA[Payment was successfully accepted.]]></string>
 	<string name="_bx_payment_strp_msg_subscribed"><![CDATA[Thank you! Subscription created. Please, check your email for further instructions.]]></string>
+	<string name="_bx_payment_strp_msg_details_changed"><![CDATA[Subscription details were changed.]]></string>
+    <string name="_bx_payment_strp_err_details_changed"><![CDATA[Cannot change subscription details. Recheck provided data and try again.]]></string>
 	<string name="_bx_payment_strp_msg_billing_changed"><![CDATA[Billing information was changed.]]></string>
 	<string name="_bx_payment_strp_err_billing_changed"><![CDATA[Cannot change billing information. Recheck provided data and try again.]]></string>
 	<string name="_bx_payment_strp_txt_checkout_with_single"><![CDATA[{0}]]></string>
 	<string name="_bx_payment_strp_txt_checkout_with_recurring"><![CDATA[Checkout with {0}]]></string>
 	<string name="_bx_payment_strp_menu_item_title_details"><![CDATA[Details]]></string>
+	<string name="_bx_payment_strp_menu_item_title_details_change"><![CDATA[Change]]></string>
 	<string name="_bx_payment_strp_menu_item_title_billing"><![CDATA[Billing Info]]></string>
 	<string name="_bx_payment_strp_menu_item_title_billing_change"><![CDATA[Change Billing Info]]></string>	
 	<string name="_bx_payment_strp_txt_plan"><![CDATA[Plan]]></string>
@@ -438,19 +442,32 @@
 	<string name="_bx_payment_strp_txt_card_cvc"><![CDATA[CVC check]]></string>
 	<string name="_bx_payment_strp_txt_card_cvc_passed"><![CDATA[passed]]></string>
 
+    <string name="_bx_payment_form_strp_details"><![CDATA[Stripe: Details Form]]></string>
+    <string name="_bx_payment_form_strp_details_display_edit"><![CDATA[Stripe: Edit Details Display]]></string>
+    <string name="_bx_payment_form_strp_details_input_item_id_sys"><![CDATA[Plan]]></string>
+    <string name="_bx_payment_form_strp_details_input_item_id"><![CDATA[Plan]]></string>
+    <string name="_bx_payment_form_strp_details_input_item_id_err"><![CDATA[You need to select some plan here]]></string>
+    <string name="_bx_payment_form_strp_details_input_submit_sys"><![CDATA[Submit]]></string>
+    <string name="_bx_payment_form_strp_details_input_submit"><![CDATA[Submit]]></string>
+    <string name="_bx_payment_form_strp_details_input_cancel_sys"><![CDATA[Cancel]]></string>
+    <string name="_bx_payment_form_strp_details_input_cancel"><![CDATA[Cancel]]></string>
+
     <string name="_bx_payment_form_strp_card"><![CDATA[Stripe: Card Form]]></string>
     <string name="_bx_payment_form_strp_card_display_add"><![CDATA[Stripe: Add Card Display]]></string>
     <string name="_bx_payment_form_strp_card_input_card_number_sys"><![CDATA[Card Number]]></string>
     <string name="_bx_payment_form_strp_card_input_card_number"><![CDATA[Card Number]]></string>
     <string name="_bx_payment_form_strp_card_input_card_number_inf"><![CDATA[16 digits without spaces describing your card number]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_number_err"><![CDATA[You need to enter card number here]]></string>
     <string name="_bx_payment_form_strp_card_input_card_expire_sys"><![CDATA[Expiry Date]]></string>
     <string name="_bx_payment_form_strp_card_input_card_expire"><![CDATA[Expiry Date]]></string>
     <string name="_bx_payment_form_strp_card_input_card_expire_month"><![CDATA[Month]]></string>
     <string name="_bx_payment_form_strp_card_input_card_expire_year"><![CDATA[Year]]></string>
     <string name="_bx_payment_form_strp_card_input_card_expire_inf"><![CDATA[Use 'mm yyyy' format]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_expire_err"><![CDATA[You need to enter expiry date in specified format here]]></string>
     <string name="_bx_payment_form_strp_card_input_card_cvv_sys"><![CDATA[CVV]]></string>
     <string name="_bx_payment_form_strp_card_input_card_cvv"><![CDATA[CVV]]></string>
     <string name="_bx_payment_form_strp_card_input_card_cvv_inf"><![CDATA[Three digits from the back side of your card.]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_cvv_err"><![CDATA[You need to enter card CVV here]]></string>
     <string name="_bx_payment_form_strp_card_input_submit_sys"><![CDATA[Submit]]></string>
     <string name="_bx_payment_form_strp_card_input_submit"><![CDATA[Submit]]></string>
     <string name="_bx_payment_form_strp_card_input_cancel_sys"><![CDATA[Cancel]]></string>

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

@@ -277,6 +277,7 @@ INSERT INTO `sys_objects_form` (`object`, `module`, `title`, `action`, `form_att
 -- FORMS: Recurly
 ('bx_payment_form_rcrl_card', @sName, '_bx_payment_form_rcrl_card', '', '', 'do_submit', '', '', '', '', '', 0, 1, '', ''),
 -- FORMS: Stripe
+('bx_payment_form_strp_details', @sName, '_bx_payment_form_strp_details', '', '', 'do_submit', '', '', '', '', '', 0, 1, '', ''),
 ('bx_payment_form_strp_card', @sName, '_bx_payment_form_strp_card', '', '', 'do_submit', '', '', '', '', '', 0, 1, '', '');
 
 
@@ -286,6 +287,7 @@ INSERT INTO `sys_form_displays` (`display_name`, `module`, `object`, `title`, `v
 -- FORMS: Recurly
 ('bx_payment_form_rcrl_card_add', @sName, 'bx_payment_form_rcrl_card', '_bx_payment_form_rcrl_card_display_add', 0),
 -- FORMS: Stripe
+('bx_payment_form_strp_details_edit', @sName, 'bx_payment_form_strp_details', '_bx_payment_form_strp_details_display_edit', 0),
 ('bx_payment_form_strp_card_add', @sName, 'bx_payment_form_strp_card', '_bx_payment_form_strp_card_display_add', 0);
 
 INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `checked`, `type`, `caption_system`, `caption`, `info`, `required`, `collapsed`, `html`, `attrs`, `attrs_tr`, `attrs_wrapper`, `checker_func`, `checker_params`, `checker_error`, `db_pass`, `db_params`, `editable`, `deletable`) VALUES
@@ -322,9 +324,14 @@ INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `c
 ('bx_payment_form_rcrl_card', @sName, 'do_cancel', '_bx_payment_form_rcrl_card_input_cancel', '', 0, 'button', '_bx_payment_form_rcrl_card_input_cancel_sys', '', '', 0, 0, 0, 'a:2:{s:7:"onclick";s:45:"$(''.bx-popup-applied:visible'').dolPopupHide()";s:5:"class";s:22:"bx-def-margin-sec-left";}', '', '', '', '', '', '', '', 0, 0),
 
 -- FORMS: Stripe
-('bx_payment_form_strp_card', @sName, 'card_number', '', '', 0, 'text', '_bx_payment_form_strp_card_input_card_number_sys', '_bx_payment_form_strp_card_input_card_number', '_bx_payment_form_strp_card_input_card_number_inf', 1, 0, 0, '', '', '', '', '', '', 'Xss', '', 0, 0),
-('bx_payment_form_strp_card', @sName, 'card_expire', '', '', 0, 'text', '_bx_payment_form_strp_card_input_card_expire_sys', '_bx_payment_form_strp_card_input_card_expire', '_bx_payment_form_strp_card_input_card_expire_inf', 1, 0, 0, '', '', '', '', '', '', 'Xss', '', 0, 0),
-('bx_payment_form_strp_card', @sName, 'card_cvv', '', '', 0, 'text', '_bx_payment_form_strp_card_input_card_cvv_sys', '_bx_payment_form_strp_card_input_card_cvv', '_bx_payment_form_strp_card_input_card_cvv_inf', 1, 0, 0, '', '', '', '', '', '', 'Xss', '', 0, 0),
+('bx_payment_form_strp_details', @sName, 'item_id', '', '', 0, 'select', '_bx_payment_form_strp_details_input_item_id_sys', '_bx_payment_form_strp_details_input_item_id', '', 1, 0, 0, '', '', '', 'Avail', '', '_bx_payment_form_strp_details_input_item_id_err', 'Int', '', 0, 0),
+('bx_payment_form_strp_details', @sName, 'controls', '', 'do_submit,do_cancel', 0, 'input_set', '', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
+('bx_payment_form_strp_details', @sName, 'do_submit', '_bx_payment_form_strp_details_input_submit', '', 0, 'submit', '_bx_payment_form_strp_details_input_submit_sys', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
+('bx_payment_form_strp_details', @sName, 'do_cancel', '_bx_payment_form_strp_details_input_cancel', '', 0, 'button', '_bx_payment_form_strp_details_input_cancel_sys', '', '', 0, 0, 0, 'a:2:{s:7:"onclick";s:45:"$(''.bx-popup-applied:visible'').dolPopupHide()";s:5:"class";s:22:"bx-def-margin-sec-left";}', '', '', '', '', '', '', '', 0, 0),
+
+('bx_payment_form_strp_card', @sName, 'card_number', '', '', 0, 'text', '_bx_payment_form_strp_card_input_card_number_sys', '_bx_payment_form_strp_card_input_card_number', '_bx_payment_form_strp_card_input_card_number_inf', 1, 0, 0, '', '', '', 'Avail', '', '_bx_payment_form_strp_card_input_card_number_err', 'Xss', '', 0, 0),
+('bx_payment_form_strp_card', @sName, 'card_expire', '', '', 0, 'text', '_bx_payment_form_strp_card_input_card_expire_sys', '_bx_payment_form_strp_card_input_card_expire', '_bx_payment_form_strp_card_input_card_expire_inf', 1, 0, 0, '', '', '', 'Avail', '', '_bx_payment_form_strp_card_input_card_expire_err', 'Xss', '', 0, 0),
+('bx_payment_form_strp_card', @sName, 'card_cvv', '', '', 0, 'text', '_bx_payment_form_strp_card_input_card_cvv_sys', '_bx_payment_form_strp_card_input_card_cvv', '_bx_payment_form_strp_card_input_card_cvv_inf', 1, 0, 0, '', '', '', 'Avail', '', '_bx_payment_form_strp_card_input_card_cvv_err', 'Xss', '', 0, 0),
 ('bx_payment_form_strp_card', @sName, 'controls', '', 'do_submit,do_cancel', 0, 'input_set', '', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
 ('bx_payment_form_strp_card', @sName, 'do_submit', '_bx_payment_form_strp_card_input_submit', '', 0, 'submit', '_bx_payment_form_strp_card_input_submit_sys', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
 ('bx_payment_form_strp_card', @sName, 'do_cancel', '_bx_payment_form_strp_card_input_cancel', '', 0, 'button', '_bx_payment_form_strp_card_input_cancel_sys', '', '', 0, 0, 0, 'a:2:{s:7:"onclick";s:45:"$(''.bx-popup-applied:visible'').dolPopupHide()";s:5:"class";s:22:"bx-def-margin-sec-left";}', '', '', '', '', '', '', '', 0, 0);
@@ -364,6 +371,11 @@ INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_fo
 ('bx_payment_form_rcrl_card_add', 'do_cancel', 2147483647, 1, 12),
 
 -- FORMS: Stripe
+('bx_payment_form_strp_details_edit', 'item_id', 2147483647, 1, 1),
+('bx_payment_form_strp_details_edit', 'controls', 2147483647, 1, 2),
+('bx_payment_form_strp_details_edit', 'do_submit', 2147483647, 1, 3),
+('bx_payment_form_strp_details_edit', 'do_cancel', 2147483647, 1, 4),
+
 ('bx_payment_form_strp_card_add', 'card_number', 2147483647, 1, 1),
 ('bx_payment_form_strp_card_add', 'card_expire', 2147483647, 1, 2),
 ('bx_payment_form_strp_card_add', 'card_cvv', 2147483647, 1, 3),

+ 11 - 54
modules/boonex/payment/js/subscriptions.js

@@ -25,76 +25,33 @@ BxPaymentSubscriptions.prototype.init = function(oOptions) {
 };
 
 BxPaymentSubscriptions.prototype.getDetails = function(oLink, iId) {
-	var $this = this;
-    var oDate = new Date();
-
-    this.loadingInButton(oLink, true);
-
-    $.post(
-        this._sActionsUrl + 'subscription_get_details/' + iId + '/',
-        {
-            _t:oDate.getTime()
-        },
-        function(oData){
-        	$this.loadingInButton(oLink, false);
-        	$(".bx-popup-applied:visible").dolPopupHide();
+	this._performRequest(oLink, iId, 'subscription_get_details');
+};
 
-        	$this.processResult(oData);
-        },
-        'json'
-    );
+BxPaymentSubscriptions.prototype.changeDetails = function(oLink, iId) {
+	this._performRequest(oLink, iId, 'subscription_change_details');
 };
 
 BxPaymentSubscriptions.prototype.getBilling = function(oLink, iId) {
-	var $this = this;
-    var oDate = new Date();
-
-    this.loadingInButton(oLink, true);
-
-    $.post(
-        this._sActionsUrl + 'subscription_get_billing/' + iId + '/',
-        {
-            _t:oDate.getTime()
-        },
-        function(oData){
-        	$this.loadingInButton(oLink, false);
-        	$(".bx-popup-applied:visible").dolPopupHide();
-
-        	$this.processResult(oData);
-        },
-        'json'
-    );
+	this._performRequest(oLink, iId, 'subscription_get_billing');
 };
 
 BxPaymentSubscriptions.prototype.changeBilling = function(oLink, iId) {
-	var $this = this;
-    var oDate = new Date();
-
-    this.loadingInButton(oLink, true);
-
-    $.post(
-        this._sActionsUrl + 'subscription_change_billing/' + iId + '/',
-        {
-            _t:oDate.getTime()
-        },
-        function(oData){
-        	$this.loadingInButton(oLink, false);
-        	$(".bx-popup-applied:visible").dolPopupHide();
-
-        	$this.processResult(oData);
-        },
-        'json'
-    );
+	this._performRequest(oLink, iId, 'subscription_change_billing');
 };
 
 BxPaymentSubscriptions.prototype.requestCancelation = function(oLink, iId) {
+	this._performRequest(oLink, iId, 'subscription_cancelation');
+};
+
+BxPaymentSubscriptions.prototype._performRequest = function(oLink, iId, sUri) {
 	var $this = this;
     var oDate = new Date();
 
     this.loadingInButton(oLink, true);
 
     $.post(
-        this._sActionsUrl + 'subscription_cancelation/' + iId + '/',
+        this._sActionsUrl + sUri + '/' + iId + '/',
         {
             _t:oDate.getTime()
         },

+ 0 - 0
modules/boonex/payment/template/strp_card_recuring.html → modules/boonex/payment/template/strp_billing_change_recuring.html


+ 16 - 0
modules/boonex/payment/template/strp_details_change_recuring.html

@@ -0,0 +1,16 @@
+__form__
+<script type="text/javascript">
+    $(document).ready(function () {
+        $("#__form_id__").ajaxForm({ 
+            dataType: "json",
+            beforeSubmit: function (formData, jqForm, options) {
+                bx_loading($("#__form_id__"), true);
+            },
+            success: function(oData) {
+                $(".bx-popup-applied:visible").dolPopupHide();
+
+                __object__.processResult(oData);
+            }
+        });
+    });
+</script>

+ 35 - 0
modules/boonex/russian/data/langs/bx_payment/ru.xml

@@ -113,6 +113,7 @@
 
     <string name="_bx_payment_popup_title_ods_order_subscription_view"><![CDATA[Подписка]]></string>
     <string name="_bx_payment_popup_title_ods_order_subscription_get_details"><![CDATA[Детали подписки]]></string>
+    <string name="_bx_payment_popup_title_ods_order_subscription_change_details"><![CDATA[Изменить детали подписки]]></string>
     <string name="_bx_payment_popup_title_ods_order_subscription_get_billing"><![CDATA[Платежная информация]]></string>
     <string name="_bx_payment_popup_title_ods_order_subscription_change_billing"><![CDATA[Изменить платежную информацию]]></string>
 	<string name="_bx_payment_popup_title_ods_order_history_view"><![CDATA[Заказ]]></string>
@@ -411,6 +412,8 @@
 	<string name="_bx_payment_strp_notify_url_cpt"><![CDATA[URL для получения webhook-ов]]></string>
 	<string name="_bx_payment_strp_msg_charged"><![CDATA[Платеж успешно принят.]]></string>
 	<string name="_bx_payment_strp_msg_subscribed"><![CDATA[Спасибо! Подписка была создана. Пожалуйста, проверьте ваш емэйл для получения дальнейших инструкций.]]></string>
+	<string name="_bx_payment_strp_msg_details_changed"><![CDATA[Детали подписки были изменены.]]></string>
+    <string name="_bx_payment_strp_err_details_changed"><![CDATA[Не могу изменить детали подписки. Перепроверьте данные и попробуйте ещё раз.]]></string>
 	<string name="_bx_payment_strp_msg_billing_changed"><![CDATA[Платежная информация была изменена.]]></string>
     <string name="_bx_payment_strp_err_billing_changed"><![CDATA[Не могу изменить платежную информацию. Перепроверьте данные и попробуйте ещё раз.]]></string>
 	<string name="_bx_payment_strp_txt_checkout_with_single"><![CDATA[{0}]]></string>
@@ -437,6 +440,38 @@
     <string name="_bx_payment_strp_txt_card_expires_mask"><![CDATA[{0} / {1}]]></string>
     <string name="_bx_payment_strp_txt_card_cvc"><![CDATA[Проверка CVC]]></string>
     <string name="_bx_payment_strp_txt_card_cvc_passed"><![CDATA[пройдена]]></string>
+    
+    <string name="_bx_payment_form_strp_details"><![CDATA[Stripe: Форма деталей]]></string>
+    <string name="_bx_payment_form_strp_details_display_edit"><![CDATA[Stripe: Редактирование деталей]]></string>
+    <string name="_bx_payment_form_strp_details_input_item_id_sys"><![CDATA[План]]></string>
+    <string name="_bx_payment_form_strp_details_input_item_id"><![CDATA[План]]></string>
+    <string name="_bx_payment_form_strp_details_input_item_id_err"><![CDATA[Вам необходимо выбрать один из планов]]></string>
+    <string name="_bx_payment_form_strp_details_input_submit_sys"><![CDATA[Отправить]]></string>
+    <string name="_bx_payment_form_strp_details_input_submit"><![CDATA[Отправить]]></string>
+    <string name="_bx_payment_form_strp_details_input_cancel_sys"><![CDATA[Отменить]]></string>
+    <string name="_bx_payment_form_strp_details_input_cancel"><![CDATA[Отменить]]></string>
+
+    <string name="_bx_payment_form_strp_card"><![CDATA[Stripe: Форма карты]]></string>
+    <string name="_bx_payment_form_strp_card_display_add"><![CDATA[Stripe: Добавление карты]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_number_sys"><![CDATA[Номер карты]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_number"><![CDATA[Номер карты]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_number_inf"><![CDATA[16-ти значный номер без пробелов.]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_number_err"><![CDATA[Вам необходимо ввести номер карты]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_expire_sys"><![CDATA[Дата окончания]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_expire"><![CDATA[Дата окончания]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_expire_month"><![CDATA[Месяц]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_expire_year"><![CDATA[Год]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_expire_inf"><![CDATA[Используйте 'mm yyyy' формат ввода.]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_expire_err"><![CDATA[Вам необходимо ввести дату окончания в указанном формате]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_cvv_sys"><![CDATA[CVV]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_cvv"><![CDATA[CVV]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_cvv_inf"><![CDATA[Три цифры, которые Вы можете найти на обратной стороне вашей карты.]]></string>
+    <string name="_bx_payment_form_strp_card_input_card_cvv_err"><![CDATA[Вам необходимо ввести CVV вашей карты]]></string>
+    <string name="_bx_payment_form_strp_card_input_submit_sys"><![CDATA[Отправить]]></string>
+    <string name="_bx_payment_form_strp_card_input_submit"><![CDATA[Отправить]]></string>
+    <string name="_bx_payment_form_strp_card_input_cancel_sys"><![CDATA[Отменить]]></string>
+    <string name="_bx_payment_form_strp_card_input_cancel"><![CDATA[Отменить]]></string>
+    
     <string name="_bx_payment_txt_name_stripe"><![CDATA[Stripe]]></string>
 	<string name="_bx_payment_txt_cart_stripe"><![CDATA[Stripe]]></string>
 </resources>