2012-08-17 4 views
0

먼저 this class을 작성해 주셔서 감사합니다. 그것은 응용 프로그램을 구축 할 때 나를 훨씬 쉽게 만들어주었습니다.Authorize.Net-XML - 광고 항목 추가

나는 CIM을 설정 했으므로 사용자 추가, 지불 처리 등의 문제는 발생하지 않지만 광고 항목을 추가하는 데 어려움이 있습니다. GitHub의에 대한 예는 XML 요청 EX를 만드는 데 사용되는 배열의 정적 인구를 사용 : 수동으로 물건을 만드는하지만 동적으로 사용자 입력을 기반으로이 광고 항목을 만드는 오전 경우

'lineItems' => array(
    'itemId' => 'ITEM00001', 
    'name' => 'name of item sold', 
    'description' => 'Description of item sold', 
    'quantity' => '1', 
    'unitPrice' => '6.95', 
    'taxable' => 'true' 
), 
'lineItems' => array(
    'itemId' => 'ITEM00002', 
    'name' => 'other name of item sold', 
    'description' => 'Description of other item sold', 
    'quantity' => '1', 
    'unitPrice' => '1.00', 
    'taxable' => 'true' 
), 

이 잘 작동합니다. 불행히도 키 ('lineItems')가 덮어 쓰여 하나의 광고 항목으로 끝나기 때문에 여러 광고 항목을 배열에 추가 할 수 없습니다.

lineItems 배열을 만든 다음 행운과 함께 병합 해 보았습니다. 바라기를 나는 이것에 대한 간단한 수정을 놓치고있다.

답변

1

응답 해 주셔서 감사합니다. 다시 한번,이 수업의 위대한 작품은 내 인생을 훨씬 쉽게 만들어주었습니다.

여기 내가 단순화를 위해 끝낸 것입니다. 필요한 경우 자세히 설명 할 수 있다고 확신하지만, 나에게 이것은 완벽하게 작동했습니다. 동일한 레벨의 배열에 여러 개의 광고 항목을 전달하는 대신 광고 항목을 자체 배열로 만든 다음 setParamaters()를 수정하여 해당 배열을 반복합니다.

private function setParameters($xml, $array) 
{ 
    if (is_array($array)) 
    { 
     foreach ($array as $key => $value) 
     { 
      if (is_array($value)) 
      { 
       if($key == 'lineItems'){ 
        foreach($value as $lineitems){ 
         $line_item = $xml->addChild('lineItems'); 
         foreach($lineitems as $itemkey => $itemvalue) { 
          $line_item->addChild($itemkey, $itemvalue); 
         } 
        } 
       } 
       else 
       { 
        $xml->addChild($key); 
        $this->setParameters($xml->$key, $value); 
       } 
      } 
      else 
      { 
       $xml->$key = $value; 
      } 
     } 
    } 
} 

이 완벽하게 내 요구에 적합하고 그래서 나는이 lineItems 배열을 중첩 제외하고는 프론트 엔드에 아무것도 변경하지 않았다했다. 그래서 배열 좀 더 같은 외모를 보낸다 :

["lineItems"]=> 
    array(2) { 
    [0]=> 
    array(6) { 
     ["itemId"]=> 
     string(9) "ITEM00010" 
     ["name"]=> 
     string(21) "Blah Blah" 
     ["description"]=> 
     string(21) "Blah Blah Description" 
     ["quantity"]=> 
     string(1) "1" 
     ["unitPrice"]=> 
     string(4) "100" 
     ["taxable"]=> 
     string(5) "false" 
    } 
    [1]=> 
    array(6) { 
     ["itemId"]=> 
     string(9) "ITEM00011" 
     ["name"]=> 
     string(25) "Thing Thing" 
     ["description"]=> 
     string(25) "Thing Thing Description" 
     ["quantity"]=> 
     string(1) "2" 
     ["unitPrice"]=> 
     string(3) "50" 
     ["taxable"]=> 
     string(5) "false" 
    } 
    } 

또한, 누군가를 위해 거기 나는이 한 라인 항목의 배열을 구축 찾고 :

foreach ($services as $key => $service){ 
    $line_items["lineItems"][] = array(
     'itemId'  => 'ITEM000'.$key, 
     'name'   => $service->name, 
     'description' => $service->name, 
     'quantity'  => $service_count[$key], 
     'unitPrice'  => $service->price, 
     'taxable'  => 'false' 
    ); 
} 

그리고 단지에 추가를 내가 AuthnetXML 인스턴스로 전달한 transaction_array.

다시 한번 감사드립니다!

조엘

+0

Joel, 코드 주셔서 감사합니다! 최대한 빨리이 클래스에 추가 할 것입니다. –

0

저는이 수업의 저자입니다. AuthnetXML 클래스에는 현재 그 결과로 나타나는 버그가 있습니다. 이 문제를 해결하려면 핵심 클래스를 변경해야합니다.

아직 리뷰를 할 기회가없는 솔루션을 제공 한 사용자로부터 이메일을 받았습니다. 나는 당신에게 그들이 내게 준 동일한 정보를주지 잘하면 그것은 당신에게 도움이 : 2012-08-21

이 버그가 수정되었습니다

The problem is that you can't have duplicate keys at the same level in an array. If you do the last one entered wins and the rest are overwritten. 

So you need a way to represent repeating items from XML in and array. I decide to use the JSON methods to keep it simple. A quick wat to convert Simple XML to and array is to pass it through JSON. 

$array = json_decode(json_encode($simpleXML), true); 

That will convert XML like this: 

<transactionSettings> 
    <setting> 
    <settingName>allowPartialAuth</settingName> 
    <settingValue>false</settingValue> 
    </setting> 
    <setting> 
    <settingName>duplicateWindow</settingName> 
    <settingValue>0</settingValue> 
    </setting> 
    <setting> 
    <settingName>emailCustomer</settingName> 
    <settingValue>false</settingValue> 
    </setting> 
    <setting> 
    <settingName>recurringBilling</settingName> 
    <settingValue>false</settingValue> 
    </setting> 
    <setting> 
    <settingName>testRequest</settingName> 
    <settingValue>false</settingValue> 
    </setting> 
</transactionSettings> 


To an array like this: 


array(
'transactionSettings' => array( 
    'setting' => array(
    0 => array('settingName' =>'allowPartialAuth' , 'settingValue' => 'false',), 
    1 => array('settingName' => 'duplicateWindow', 'settingValue' => '0',), 
    2 => array('settingName' => 'emailCustomer', 'settingValue' => 'false',), 
    3 => array('settingName' => 'recurringBilling', 'settingValue' => 'false',), 
    4 => array('settingName' => 'testRequest', false,), 
) 
); 


So you need to modify AuthNetXML.class to recognize this format. Just replace your setParameters() method with: 


    private function setParameters($xml, $array) 
    { 
    if (is_array($array)) 
    { 
     $first = true; 

     foreach ($array as $key => $value) 
     { 
     if (is_array($value)) { 

      if(is_numeric($key)) { 
      if($first){ 
       $xmlx = $xml; 
       $first = false; 
      } else { 
       $parent = $xml->xpath('parent::*'); 
       $xmlx = $parent[0]->addChild($xml->getName()); 
      } 

      } else { 

      $xmlx = $xml->addChild($key); 

      } 

      $this->setParameters($xmlx, $value); 
     } 
     else 
     { 
      $xml->$key = $value; 
     } 
     } 
    } 
    } 

UPDATE. 샘플 코드가 업데이트되었습니다.

0

편집 :이 문제를 해결했습니다. lineItems 키과 같이 전달해야합니다 이것은 Authorize.net-XML의 repo에서 샘플을 통해 제공 무슨 차이가

'lineItems' => array(
    'itemId'  => '13', 
    'name'  => 'hello', 
    'description' => 'hello description', 
    'quantity' => '1', 
    'unitPrice' => '55.00' 
), 

참고. 나는 지금 저기로 가서 고침을 제출할 것이다.

원래 질문 : 나는 Authorize.net-XML 클래스와 관련된 비슷한 문제에 직면하고 있습니다. 나는 다음과 같은 오류가 나타납니다 createCustomerProfileTransactionRequest() 방법을 실행할 때 :

The element 'lineItems' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has 
invalid child element 'lineItem' in namespace 
'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. 
List of possible elements expected: 'itemId' in namespace 
'AnetApi/xml/v1/schema/AnetApiSchema.xsd'.' (length=272) 

심지어 지금까지 샘플 입력에 붙여 넣기로 사라 here을 제공 한,하지만 동일한 오류가 발생? 클래스는 다른 방식으로 잘 작동합니다. createTransactionRequest()createCustomerProfileRequest() 메서드를 사용하여 AIM 트랜잭션을 처리하고 문제없이 CIM 프로필을 만듭니다.

다시 말해서, 나는 심지어 GitHub에있는 것과 동일한 샘플 입력을 사용하려고 시도하고 있습니다.

아이디어가 있으십니까?

감사합니다. Jason