2010-06-23 2 views
3

PHP의 SoapClient 클래스를 사용하여 버전 번호만으로 Paypal에 빈 호출을하는 간단한 예제를 얻을 수 있습니까? 올바른 WSDL url과 server url을 가지고 있으므로 도움이 필요하지 않습니다. 이것이 내가 가진 것입니다 :페이팔에 대한 간단한 PHP SoapClient 예제가 필요합니다.

public function SOAPcall($function, $args=array()) { 
    $args['Version'] = '63.0'; 
    $args = new SoapVar($args, SOAP_ENC_ARRAY, $function.'_Request'); 
    $args = array(new SoapVar($args, SOAP_ENC_ARRAY, $function.'_Req', 'urn:ebay:api:PayPalAPI')); 
    $results = $this->soapClient->__soapCall($function, $args, array('location' => $this->activeKeys['certificate']), $this->soapOptions); 
} 

나는 모든 것을 보여줄 수는 없으 리라.

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="urn:ebay:api:PayPalAPI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:ebay:apis:eBLBaseComponents"> 
     <SOAP-ENV:Header> 
      <ns1:RequesterCredentials> 
        <ns2:Credentials> 
         <ns2:Username>xxx</ns2:Username> 
         <ns2:Password>xxx</ns2:Password> 
         <ns2:Signature>xxx</ns2:Signature> 
        </ns2:Credentials> 
      </ns1:RequesterCredentials> 
     </SOAP-ENV:Header> 
     <SOAP-ENV:Body> 
      <ns1:GetBalanceReq xsi:type="ns1:GetBalance_Req"> 
        <xsd:string>63.0</xsd:string> 
      </ns1:GetBalanceReq> 
     </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

그것은 다음과 같아야합니다 :

물론
<?xml version=”1.0” encoding=”UTF-8”?> 
<SOAP-ENV:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” 
xmlns:SOAP-ENC=”http://schemas.xmlsoap.org/soap/encoding/” 
xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/” 
xmlns:xsd=”http://www.w3.org/2001/XMLSchema” 
SOAP-ENV:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/” 
><SOAP-ENV:Header> 
<RequesterCredentials xmlns=”urn:ebay:api:PayPalAPI”> 
<Credentials xmlns=”urn:ebay:apis:eBLBaseComponents”> 
<Username>api_username</Username> 
<Password>api_password</Password> 
<Signature/> 
<Subject/> 
</Credentials> 
</RequesterCredentials> 
</SOAP-ENV:Header> 
<SOAP-ENV:Body> 
<specific_api_name_Req xmlns=”urn:ebay:api:PayPalAPI”> 
<specific_api_name_Request> 
<Version xmlns=urn:ebay:apis:eBLBaseComponents”>service_version 
</Version> 
<required_or_optional_fields xsi:type=”some_type_here”> data 
</required_or_optional_fields> 
</specific_api_name_Request> 
</specific_api_name_Req> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

는, 페이팔은 "버전이 지원되지 않습니다"오류가 발생합니다 아래 볼 수있는 요청의 몸은 완전히 잘못 나온다.

답변

6

이 내가 가지고 올 수있는 깨끗한 솔루션입니다 :

$client = new SoapClient('https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl', 
          array('soap_version' => SOAP_1_1)); 

$cred = array('Username' => $username, 
       'Password' => $password, 
       'Signature' => $signature); 

$Credentials = new stdClass(); 
$Credentials->Credentials = new SoapVar($cred, SOAP_ENC_OBJECT, 'Credentials'); 

$headers = new SoapVar($Credentials, 
         SOAP_ENC_OBJECT, 
         'CustomSecurityHeaderType', 
         'urn:ebay:apis:eBLBaseComponents'); 

$client->__setSoapHeaders(new SoapHeader('urn:ebay:api:PayPalAPI', 
              'RequesterCredentials', 
              $headers)); 

$args = array('Version' => '71.0', 
       'ReturnAllCurrencies' => '1'); 

$GetBalanceRequest = new stdClass(); 
$GetBalanceRequest->GetBalanceRequest = new SoapVar($args, 
                SOAP_ENC_OBJECT, 
                'GetBalanceRequestType', 
                'urn:ebay:api:PayPalAPI'); 

$params = new SoapVar($GetBalanceRequest, SOAP_ENC_OBJECT, 'GetBalanceRequest'); 

$result = $client->GetBalance($params); 

echo 'Balance is: ', $result->Balance->_, $result->Balance->currencyID; 

이 글을 쓰는 시점에서, 성공적으로 받아 들여지고 있었다 및 처리, 다음과 같은 XML 요청 문서를 생성 페이팔 :

이 페이지에 다른 의견의 일부에 대응
<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ns1="urn:ebay:apis:eBLBaseComponents" xmlns:ns2="urn:ebay:api:PayPalAPI" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<SOAP-ENV:Header> 
    <ns2:RequesterCredentials> 
    <ns1:Credentials xsi:type="Credentials"> 
    <Username>***</Username> 
    <Password>***</Password> 
    <Signature>***</Signature> 
    </ns1:Credentials> 
    </ns2:RequesterCredentials> 
</SOAP-ENV:Header> 
<SOAP-ENV:Body> 
    <ns2:GetBalanceReq xsi:type="GetBalanceRequest"> 
    <GetBalanceRequest xsi:type="ns2:GetBalanceRequestType"> 
    <ns1:Version>71.0</ns1:Version> 
    <ns2:ReturnAllCurrencies>1</ns2:ReturnAllCurrencies> 
    </GetBalanceRequest> 
    </ns2:GetBalanceReq> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

:

  • OP 에는이 있습니다. PHP doc 라이브러리를 사용하여 예제 XML을 작성했기 때문에 API 문서를 읽어야합니다.
  • PayPal PHP API에는 몇 가지 단점이 있습니다. 가장 큰 단점은 E_STRICT 경고를 사용하여 작동하지 않는 것이 가장 큰 것입니다. 또한 PEAR이 필요합니다. 현재 프로젝트에서 PEAR을 사용하고 있지 않다면 상당히 복잡한 새로운 XML 코드로 드래그하는 것을 의미합니다. 이는 2 ~ 3 개의 간단한 XML 교환을 달성하기 위해 더 복잡하고 잠재적으로 더 많은 위험을 의미합니다. 기본 구현을 위해.
  • NVP API도 꽤 괜찮은 것처럼 보였지만 처벌을받을 자격이 없어서 하드 경로를 선택했습니다. :-)
+0

이런 일을 끝내게되었습니다. NVP는 구현하기가 쉽지만 SOAP만큼이나 아름답지는 않아요. 결국 SOAP보다 복잡 해지는 경향이 있습니다. – Jonah

+0

SoapVar 클래스 사용에 대한 추론을 설명해 주시겠습니까? 당신은 단지 직선 배열을 전달합니다. – Steven

+0

내 코드에서 남긴 메모에 따르면 요청의이 요소에 형식 정보를 추가하기 위해 형식 및 네임 스페이스 세부 정보를 포함시켜야했습니다. 아마도 여러분이 직선 배열을 전달한다면 타입 정보는 추가되지 않을 것입니다 (?). 원래 응답을 올렸을 때 유형 정보가 포함되어 있지 않으면 서버가 혼동되어 "알 수없는 버전"오류가 발생합니다. 어쩌면 Paypal이이 점에서 서버를 좀 덜 엄격하게 만들려고 무언가를 바꿨을 것입니다. 특히 많은 개발자를 끌어들이는 경우 ... – JamesG

5

PayPal here에서 제공하는 API를 확인 했습니까? PHP SOAP API 다운로드에는 direct link이 있습니다.

그리고 여기 PayPal에서 사용을 권장하는 NVP API 링크가 있습니다.

+0

+1 NVP의 경우. 왜 이런 복잡한 일없이 간단하게 작업을 완료 할 수있을 때 복잡한 SOAP를 사용하지 않을까요? – jmort253

+0

NVP : "이 인터페이스는보다 가벼운 스크립트 기반 개발을 선호하는 사용자에게 더 좋습니다." SOAP : "이 인터페이스는 객체 지향 개발을 선호하는 사람들에게 더 좋습니다." OOP는 항상 최후에 승리합니다. 나는 SOAP 작업을 할 수 있었고 나는 그것에 만족했다. – Jonah

관련 문제