支付引擎的 SOAP API 需要多个 RequestParameters,例如 customeraccountname 和 customeraccountnumber:
<soapenv:Body Id="_body">
<req:TransactionRequest>
<req:Currency>EUR</req:Currency>
<req:Services>
<req:Service Name="directdebit" Action="Pay" Version="1">
<req:RequestParameter Name="customeraccountname">Joe Doe</req:RequestParameter>
<req:RequestParameter Name="customeraccountnumber">123456789</req:RequestParameter>
</req:Service>
</req:Services>
</req:TransactionRequest>
</soapenv:Body>
我使用以下 PHP 代码来尝试实现这一点:
<?php
$TransactionRequest = new Body();
$TransactionRequest->Currency = 'EUR';
$TransactionRequest->Services = new Services();
$TransactionRequest->Services->Service = new Service();
$TransactionRequest->Services->Service->Name= 'directdebit';
$TransactionRequest->Services->Service->Action = 'Pay';
$TransactionRequest->Services->Service->Version = 1;
$TransactionRequest->Services->Service->RequestParameter = new RequestParameter();
$TransactionRequest->Services->Service->RequestParameter->Name = 'customeraccountname';
$TransactionRequest->Services->Service->RequestParameter->_ = 'Joe Doe';
$TransactionRequest->Services->Service->RequestParameter = new RequestParameter();
$TransactionRequest->Services->Service->RequestParameter->Name = 'customeraccountnumber';
$TransactionRequest->Services->Service->RequestParameter->_ = '123456789';
//echo var_dump($TransactionRequest);
print_r($TransactionRequest);
class Body
{
public $Currency;
public $Services;
}
class Services
{
public $Global;
public $Service;
}
class Service
{
public $RequestParameter;
public $Name;
public $Action;
public $Version;
}
class RequestParameter
{
public $_;
public $Name;
public $Group;
}
?>
然而,结果对象不包含第一个 RequestParameter:
Body Object
(
[Currency] => EUR
[Services] => Services Object
(
[Global] =>
[Service] => Service Object
(
[RequestParameter] => RequestParameter Object
(
[_] => 123456789
[Name] => customeraccountnumber
[Group] =>
)
[Name] => directdebit
[Action] => Pay
[Version] => 1
)
)
)
我怎样才能达到所需的结果?
期待您的帮助,问候罗伯特