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

Ticket #4971 - Build-in API support: Cancel subscription.

AntonLV 7 месяцев назад
Родитель
Сommit
efc604e346

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

@@ -175,19 +175,22 @@ class BxPaymentModule extends BxBaseModPaymentModule
 
     public function serviceGetSafeServices()
     {
-        $a = parent::serviceGetSafeServices();
-        return array_merge($a, array (
+        return array_merge(parent::serviceGetSafeServices(), [
             'GetBlockJoin' => 'BxPaymentJoin',
+
             'GetBlockCarts' => 'BxPaymentCart',
             'GetBlockCart' => 'BxPaymentCart',
             'GetBlockCartHistory' => 'BxPaymentCart',
+            
             'GetBlockListMy' => 'BxPaymentSubscriptions',
             'GetBlockHistory' => 'BxPaymentSubscriptions',
+            'Cancel' => 'BxPaymentSubscriptions',
+            'CancelByPendingId' => 'BxPaymentSubscriptions',
 
             'GetProviderOptions' => '',
             'InitializeCheckoutApi' => '',
             'StripeV3CreateSessionApi' => ''
-        ));
+        ]);
     }
 
     /**

+ 22 - 4
modules/boonex/payment/classes/BxPaymentSubscriptions.php

@@ -257,15 +257,33 @@ class BxPaymentSubscriptions extends BxBaseModPaymentSubscriptions
 
         return $mixedResult;
     }
-    
-    public function serviceCancel($sOrder)
+
+    public function serviceCancel($sOrder, $bForce = true)
     {
         $aPending = $this->_oModule->_oDb->getOrderPending(['type' => 'order', 'order' => $sOrder]);
         if(empty($aPending) || !is_array($aPending))
             return ['code' => 1, 'message' => _t('_bx_payment_err_not_found_pending')];
-        
+
+        if(!(bool)$bForce && ($mixedResult = $this->_oModule->isAllowedManage($aPending)) !== true)
+            return ['code' => 2, 'message' => $mixedResult];
+
+        if(!$this->cancel((int)$aPending['id']))
+            return ['code' => 3, 'message' => _t('_bx_payment_err_cannot_perform')];
+
+        return ['code' => 0, 'message' => _t('_bx_payment_msg_successfully_performed')];
+    }
+
+    public function serviceCancelByPendingId($iId, $bForce = true)
+    {
+        $aPending = $this->_oModule->_oDb->getOrderPending(['type' => 'id', 'id' => $iId]);
+        if(empty($aPending) || !is_array($aPending))
+            return ['code' => 1, 'message' => _t('_bx_payment_err_not_found_pending')];
+
+        if(!(bool)$bForce && ($mixedResult = $this->_oModule->isAllowedManage($aPending)) !== true)
+            return ['code' => 2, 'message' => $mixedResult];
+
         if(!$this->cancel((int)$aPending['id']))
-            return ['code' => 2, 'message' => _t('_bx_payment_err_cannot_perform')];
+            return ['code' => 3, 'message' => _t('_bx_payment_err_cannot_perform')];
 
         return ['code' => 0, 'message' => _t('_bx_payment_msg_successfully_performed')];
     }