AntonLV 5 tahun lalu
induk
melakukan
dbfca4ed78

+ 2 - 2
modules/base/payment/classes/BxBaseModPaymentProvider.php

@@ -187,9 +187,9 @@ class BxBaseModPaymentProvider extends BxDol
      * @throws Exception $e 
      *
      */
-    protected function log($mixedContents)
+    protected function log($mixedContents, $sTitle = '')
     {
-        $this->_oModule->log($mixedContents, $this->_sName);
+        $this->_oModule->log($mixedContents, $this->_sName, $sTitle);
     }
 }
 

+ 46 - 24
modules/boonex/payment/classes/BxPaymentProviderAppleInApp.php

@@ -35,50 +35,72 @@ class BxPaymentProviderAppleInApp extends BxBaseModPaymentProvider implements iB
 
     public function notify()
     {
-        $iResult = $this->_processEvent();
+        $iResult = $this->_processNotification();
         http_response_code($iResult);
     }
     
-    protected function _processEvent()
+    protected function _processNotification()
     {
     	$sInput = @file_get_contents("php://input");
-        $aEvent = json_decode($sInput, true);
-        if(empty($aEvent) || !is_array($aEvent)) 
-                return 404;
+        $aNotification = json_decode($sInput, true);
+        if(empty($aNotification) || !is_array($aNotification)) 
+            return 404;
 
-        $sType = $aEvent['type'];
-        if(!in_array($sType, array('invoice.payment_succeeded', 'charge.refunded', 'customer.subscription.deleted')))
-                return 200;
+        $sType = $aNotification['notification_type'];
+        if(!in_array($sType, array('INITIAL_BUY', 'DID_RENEW', 'REFUND', 'CANCEL')))
+            return 200;
 
-        $this->log('Webhooks: ' . (!empty($sType) ? $sType : ''));
-        $this->log($aEvent);
+        $this->log($aNotification, 'Webhooks: ' . (!empty($sType) ? $sType : ''));
 
-        $sMethod = '_processEvent' . bx_gen_method_name($sType, array('.', '_', '-'));
+        $sMethod = '_processNotification' . bx_gen_method_name(strtolower($sType), array('.', '_', '-'));
     	if(!method_exists($this, $sMethod))
             return 200;
 
-    	return $this->$sMethod($aEvent) ? 200 : 403;
+    	return $this->$sMethod($aNotification) ? 200 : 403;
     }
 
-    protected function _processEventInvoicePaymentSucceeded(&$aEvent)
+    protected function _processNotificationInitialBuy($aNotification)
     {
-        $mixedResult = $this->_getData($aEvent);
-        if($mixedResult === false)
-            return false;
-
-        list($aPending, $oCharge) = $mixedResult;
-        if(empty($aPending) || !is_array($aPending) || empty($oCharge))
-            return false;
+        $sProduct = $aNotification['auto_renew_product_id'];
+
+        //TODO: We need to create 'Pending Transaction' to register this and all future payments.
+
+        /*
+        $iPendingId = $this->_oDb->insertOrderPending($this->_iUserId, BX_PAYMENT_TYPE_RECURRING, $this->_sName, array(
+            'author_id' => 0,
+            'module_id' => 0,
+            'id' => 0,
+            'quantity' => 1
+        ));
+         */
+    }
 
-        $fChargeAmount = (float)$oCharge->amount / 100;
-        $sChargeCurrency = strtoupper($oCharge->currency);
-        if($this->_bCheckAmount && ((float)$aPending['amount'] != $fChargeAmount || strcasecmp($this->_oModule->_oConfig->getDefaultCurrencyCode(), $sChargeCurrency) !== 0))
-            return false;
+    protected function _processNotificationDidRenew(&$aNotification)
+    {
+        $sProduct = $aNotification['auto_renew_product_id'];
 
+        //TODO: We need to get 'PendingId' to register payment.
+  
+        /*
         if($aPending['type'] == BX_PAYMENT_TYPE_RECURRING)
             $this->_oModule->getObjectSubscriptions()->prolong($aPending);
 
         return $this->_oModule->registerPayment($aPending);
+         */
+    }
+
+    protected function _processNotificationRefund(&$aNotification)
+    {
+        $sProduct = $aNotification['auto_renew_product_id'];
+
+        //TODO: We need to get 'PendingId' to process refund.
+    }
+
+    protected function _processNotificationCancel(&$aNotification)
+    {
+        $sProduct = $aNotification['auto_renew_product_id'];
+
+        //TODO: We need to get 'PendingId' to cancel the subscription.
     }
 }