2012-02-12 5 views
0

지불 모듈을 개발 중입니다. Magento System에서는 어디서나 적절한 설명서를 찾을 수 없습니다.Magento 캡처 방법이 작동하지 않습니다.

이제는 Payment Method Model의 캡처 방법에 문제가 있습니다. 도와주세요.

REST API에 대한 CURL 요청이 생성 및 전송되지 않는 이유를 알 수 없습니다. 처음 2 ~ 3 줄만 실행합니다. 나는 아래 코드를 작성하는 방법이 옳다고 생각하지 않는다. 최선의 방법을 제안 해주세요. 주문을 한 후에 코드에 주어진대로 "정보 인스턴스를 얻었습니다"와 금액을 로그 파일에 저장합니다. Mage :: Log()라는 다른 데이터는 시스템 로그 파일에 나타나지 않습니다.

나는 Config.xml 파일이 된 system.xml 파일이

<?xml version="1.0"?> 
<config> 
    <sections> 
     <payment> 
      <groups> 
       <cashondelivery translate="label" module="cashondelivery"> 
        <label>Company Cash On delivery</label> 
        <sort_order>670</sort_order> 
        <show_in_default>1</show_in_default> 
        <show_in_website>1</show_in_website> 
        <show_in_store>0</show_in_store> 
        <fields> 
         <active translate="label"> 
          <label>Enabled</label> 
          <frontend_type>select</frontend_type> 
          <source_model>adminhtml/system_config_source_yesno</source_model> 
          <sort_order>1</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>0</show_in_store> 
         </active> 
         <order_status translate="label"> 
          <label>New order status</label> 
          <frontend_type>select</frontend_type> 
          <source_model>adminhtml/system_config_source_order_status_processing</source_model> 
          <sort_order>4</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>0</show_in_store> 
         </order_status> 
         <title translate="label"> 
          <label>Title</label> 
          <frontend_type>text</frontend_type> 
          <sort_order>2</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>0</show_in_store> 
         </title> 
        </fields> 
       </cashondelivery> 
      </groups> 
     </payment> 
    </sections> 
</config> 

등처럼이

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Company_Cashondelivery> 
<!-- declare module's version information for database updates --> 
      <version>0.1.0</version> 
     </Company_Cashondelivery> 
    </modules> 
    <global> 
<!-- declare model group for new module --> 
     <models> 
<!-- model group alias to be used in Mage::getModel('newmodule/...') --> 
      <cashondelivery> 
<!-- base class name for the model group --> 
       <class>Company_Cashondelivery_Model</class> 
      </cashondelivery>  
     </models> 
     <helpers> 
      <cashondelivery> 
       <class>Company_Cashondelivery_Helper</class> 
      </cashondelivery> 
     </helpers> 
<!-- declare resource setup for new module --> 
     <resources> 
<!-- resource identifier --> 
      <cashondelivery_setup> 
<!-- specify that this resource is a setup resource and used for upgrades --> 
       <setup> 
<!-- which module to look for install/upgrade files in --> 
        <module>Company_Cashondelivery</module> 
       </setup> 
<!-- specify database connection for this resource --> 
       <connection> 
<!-- do not create new connection, use predefined core setup connection --> 
        <use>core_setup</use> 
       </connection> 
      </cashondelivery_setup> 
      <cashondelivery_write> 
       <connection> 
        <use>core_write</use> 
       </connection> 
      </cashondelivery_write> 
      <cashondelivery_read> 
       <connection> 
       <use>core_read</use> 
       </connection> 
      </cashondelivery_read> 
     </resources> 
    </global> 

<!-- declare default configuration values for this module --> 
    <default> 
     <payment> 
      <cashondelivery> 
       <active>1</active> 
       <model>cashondelivery/createorder</model> 
       <order_status>pending</order_status> 
       <payment_action>authorize_capture</payment_action> 
       <title>Company</title>     
      </cashondelivery> 
     </payment> 
    </default> 
</config> 

처럼이

<?php 
class Company_Cashondelivery_Model_Createorder extends Mage_Payment_Model_Method_Abstract 
{ 
    protected $_code = 'cashondelivery'; 
    protected $_canCapture = true; 
    protected $_canUseCheckout = true; 
    public function capture(Varien_Object $payment, $amount) 
    { 
       $paymentInfo = $this->getInfoInstance(); 
       Mage::Log('Got Info Instance'); //This is shown in Log file. 
       Mage::Log($amount); //This is shown in Log file 
       Mage::Log($payment);     
        $xml='<?xml version="1.0" encoding="utf-8" ?>'. 
         '<transaction>'. 
         '<customerDetails>'. 
         '<address>This is, address, Purple Talk, 600100</address>'. //I dont know how to get Address as string here 
         '<contactNo>'.$paymentInfo->getOrder()->getBillingAddress()->getTelephone().'</contactNo>'. 
         '<email>'.$paymentInfo->getOrder()->getBillingAddress()->email().'</email>'. 
         '<firstName>'.$paymentInfo->getOrder()->getBillingAddress()->getFirstName().'</firstName>'. 
         '<lastName>'.$paymentInfo->getOrder()->getBillingAddress()->getLastName().'</lastName>'. 
         '</customerDetails>'. 
         '<orderDetails>'. 
         '<pincode>'.$paymentInfo->getOrder()->getBillingAddress()->getPostCode().'</pincode>'. 
         '<clientOrderID>'.$paymentInfo->getOrder()->getIncrementId().'</clientOrderID>'. 
         '<deliveryDate>20-7-20111</deliveryDate>'. 
         '<orderAmount>'.$amount.'</orderAmount>'. 
         '<productDetails>'; 
        Mage::Log($xml);//This is not there in log file  
        foreach ($paymentInfo->getOrder()->getAllItems() as $item) 
         { 
          $xml.='<productDetails>'. 
          '<productID>'.$item->getProductId().'</productID>'. 
          '<productQuantity>'.$item->getQtyOrdered().'</productQuantity>'. 
          '<unitCost>'.$item->getPrice().'</unitCost>'. 
          '</productDetails>'; 
         } 
         $xml.='</orderDetails>'. 
         '<additionalInformation>'. 
         '<parameters>'. 
         '<name>Some Name</name>'. 
         '<value>Some Value</value>'. 
         '</parameters>'. 
         '<parameters>'. 
         '<name>Some Name2</name>'. 
         '<value>Some value2</value>'. 
         '</parameters>'. 
         '</additionalInformation>'. 
         '</transaction>'; 
         Mage::Log($xml); 
         $url = "http://services.abc.com/rest/service/createOrder"; 
         Mage::Log('Loading url : '.$url); //This is not there in Log; 
         $ch = curl_init($url) ; 
         curl_setopt($ch, CURLOPT_HEADER,true); 
         curl_setopt($ch, CURLOPT_POST, true); 
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
         curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 
         curl_setopt($ch, CURLOPT_HTTPHEADER, array('username:xxxxx','password:xxxxxx','Content-Type:application/xml')); 
         $response = curl_exec($ch); 
         Mage::Log($response); //This is not there in Log file; 
        return $this;  
    }  
} 
?> 

같은 지불 방법 코드가 /module/Company_Cashondelivery.xml은 다음과 같습니다.

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Company_Cashondelivery> 
      <active>true</active> 
      <codePool>local</codePool> 
     </Company_Cashondelivery> 
    </modules> 
    <depends> 
     <Mage_Payment /> 
    </depends> 
</config> 

내가 무엇이든지 명확하지 않으면 알려주세요. 코드에서

답변

0

문제는 Mag :: Log ($ payment)이었습니다. 제거하고 마술처럼 작동했습니다.

0

문제는이 라인에 어떤 이메일() 함수는`사용할 수는 없습니다 '<email>'.$paymentInfo->getOrder()->getBillingAddress()->email().'</email>'. '$ paymentInfo-> getOrder() -.> getBillingAddress() -> 가령 getMail().' ' . 이메일을 다시 얻으려면.

이 오류는 상점 소유자 이메일로 발송됩니다. localhost에서 개발하고 있다면 smtp의 일부 에뮬레이션을 사용하도록 권장합니다 (예 : 이기기 위해) http://www.toolheap.com/test-mail-server-tool/ 그리고 나서 Magento가 보낸 모든 이메일을 볼 수 있습니다.

두 번째 메모. 추악한 컬 대신 Magento와 함께 제공되는 Varien_Http_Client (Zend_Http_Client)를 사용할 수 있습니다. 내 게시물의 예를 볼 수 있습니다 - https://stackoverflow.com/a/9233290/858586

+0

오, 미안하지만 오타였습니다. 나는 실제 코드에서만 getEmail()을 사용했다. BTW 내부 변수가없는 $ xml 데이터를 하드 코딩했습니다. 여전히 CURL은 작동하지 않습니다. 요청이 API로 전송되지 않았습니다 – naquiuddin

+0

cURL 코드가 Magento가없는 독립 실행 형 코드에서 작동합니까? –

+0

예 독립형 코드에서 작동합니다. 이미 확인했습니다. – naquiuddin

관련 문제