2016-10-17 118 views
0

我正在研究一個magento 2支付模塊,但我被困在一個點,我需要包括第三方支付網關php文件,其中多個類聲明爲類a,類b,class.php文件中的class c 我正在使用require_once('magento_path/class.php'); 但它似乎不起作用 請幫助!Magento 2在模塊中添加多個php文件

--Updated--這裏是我的代碼放置請求樣品gateway--
注:所有變量都只是

 public function placeRequest(TransferInterface $transferObject) 
      { 
       require_once ("ThePaymentGateway/PaymentSystem.php"); 
       $rgeplRequestGatewayEntryPointList = new RequestGatewayEntryPointList(); 
$rgeplRequestGatewayEntryPointList->add("gw1.".$PaymentProcessorFullDomain, 100, 1); 
       $rgeplRequestGatewayEntryPointList->add("https://gw2.".$PaymentProcessorFullDomain, 200, 1); 
       $rgeplRequestGatewayEntryPointList->add("https://gw3.".$PaymentProcessorFullDomain, 300, 1); 
      $cdtCardDetailsTransaction = new CardDetailsTransaction($rgeplRequestGatewayEntryPointList); 

      $cdtCardDetailsTransaction->getMerchantAuthentication()->setMerchantID($MerchantID); 
      $cdtCardDetailsTransaction->getMerchantAuthentication()->setPassword($Password); 

      $cdtCardDetailsTransaction->getTransactionDetails()->getMessageDetails()->setTransactionType("SALE"); 

      $cdtCardDetailsTransaction->getTransactionDetails()->getAmount()->setValue($Amount); 
      $cdtCardDetailsTransaction->getTransactionDetails()->setOrderID($OrderID); 
      $cdtCardDetailsTransaction->getTransactionDetails()->setOrderDescription($OrderDescription); 

      $cdtCardDetailsTransaction->getTransactionDetails()->getTransactionControl()->getEchoCardType()->setValue(true); 
      $cdtCardDetailsTransaction->getTransactionDetails()->getTransactionControl()->getEchoAmountReceived()->setValue(true); 
      $cdtCardDetailsTransaction->getTransactionDetails()->getTransactionControl()->getEchoAVSCheckResult()->setValue(true); 
      $cdtCardDetailsTransaction->getTransactionDetails()->getTransactionControl()->getEchoCV2CheckResult()->setValue(true); 
      $cdtCardDetailsTransaction->getTransactionDetails()->getTransactionControl()->getThreeDSecureOverridePolicy()->setValue(true); 
      $cdtCardDetailsTransaction->getTransactionDetails()->getTransactionControl()->getDuplicateDelay()->setValue(60); 

      $cdtCardDetailsTransaction->getTransactionDetails()->getThreeDSecureBrowserDetails()->getDeviceCategory()->setValue(0); 
      $cdtCardDetailsTransaction->getTransactionDetails()->getThreeDSecureBrowserDetails()->setAcceptHeaders("*/*"); 
      $cdtCardDetailsTransaction->getTransactionDetails()->getThreeDSecureBrowserDetails()->setUserAgent($_SERVER["HTTP_USER_AGENT"]); 

      $cdtCardDetailsTransaction->getCardDetails()->setCardName($CardName); 
      $cdtCardDetailsTransaction->getCardDetails()->setCardNumber($CardNumber); 
      $cdtCardDetailsTransaction->getCardDetails()->setIssueNumber($IssueNumber); 
      $cdtCardDetailsTransaction->getCardDetails()->setCV2($CV2); 
      $cdtCardDetailsTransaction->getCustomerDetails()->getBillingAddress()->setAddress1($Address1); 
      $cdtCardDetailsTransaction->getCustomerDetails()->getBillingAddress()->setAddress2($Address2); 
      $cdtCardDetailsTransaction->getCustomerDetails()->getBillingAddress()->setAddress3($Address3); 
      $cdtCardDetailsTransaction->getCustomerDetails()->getBillingAddress()->setAddress4($Address4); 
      $cdtCardDetailsTransaction->getCustomerDetails()->getBillingAddress()->setCity($City); 
      $cdtCardDetailsTransaction->getCustomerDetails()->getBillingAddress()->setState($State); 
      $cdtCardDetailsTransaction->getCustomerDetails()->getBillingAddress()->setPostCode($PostCode); 
      $cdtCardDetailsTransaction->getCustomerDetails()->setEmailAddress("[email protected]"); 
      $cdtCardDetailsTransaction->getCustomerDetails()->setPhoneNumber("123456789"); 
      $cdtCardDetailsTransaction->getCustomerDetails()->setCustomerIPAddress($_SERVER["REMOTE_ADDR"]); 

      $boTransactionProcessed = $cdtCardDetailsTransaction->processTransaction($cdtrCardDetailsTransactionResult, $todTransactionOutputData); 
      if ($boTransactionProcessed == false) 
       { 
        // could not communicate with the payment gateway 
        $NextFormMode = "PAYMENT_FORM"; 
        $Message = "Couldn't communicate with payment gateway"; 
        PaymentFormHelper::reportTransactionResults($OrderID, 30, $Message, null); 
       } 
       else 
       { 
       echo "Payment Success"; 
       } 
     } 

所有的支付網關類在Paymentsystem.php定義例子由payzone提供,但在這裏require_once似乎不工作

回答

1

Magento有一個方法來開發自己的自定義模塊。如果您不遵循此方法,那麼您將遇到像您正在討論的那樣的路徑錯誤,特別是在您有大量驗證和安全方式的支付模塊內。

我建議看看這個頁面。 http://alanstorm.com/category/magento-2/page/3/

他做了一個框架,稱爲杵,讓這麼容易創建自定義模塊http://alanstorm.com/magento2_pestle_code_generation/

檢查出來。

+0

是的,我已經創建了一個自定義付款模塊指南 – user3719134

+0

我創建自定義付款模塊來連接付費區支付網關,但payzone提供了一個php庫,需要包含在我的模塊中進行連接,但庫包含了很多類一個PHP文件,所以我的問題是如何包括這個文件在我的模塊? – user3719134

+0

好吧,我明白了。那麼我會將這些類添加到我的塊文件中。你可以在同一個php文件中創建類。當你想使用它們時,通過創建一個新實例來啓動它們$ newClass = new Class A ...然後,當你想使用這個對象的方法時,你可以執行$ newClass-> method() ;如果您想了解有關名稱空間的知識,您可以在塊__construct中通過依賴注入添加此類,以便您可以按照Magento的方式進行操作。只需在同一個Block文件中命名新的類 –