Created
July 30, 2018 04:14
-
-
Save gexchai/3c3f2e9cb44aa74194af45e7623f46c9 to your computer and use it in GitHub Desktop.
Prefix SOAP parameter tag name with namespace for EML payments destination ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * EML payments require destination ID to be included inside their request | |
| * Example of how the soap look like for the destination ID | |
| * <eml1:DestinationAccountId i:type="eml2:ExternalAccountIdentifier"> | |
| * <eml2:ExternalAccountId>ABCD1234</eml2:ExternalAccountId> | |
| * </eml1:DestinationAccountId> | |
| * In order to do this. we need to specify the soap evnalop like this | |
| * <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:eml="http://schemas.datacontract.org/2004/07/EML.Services.Base" xmlns:eml1="http://schemas.datacontract.org/2004/07/EML.Services.External.Shared.DTO" xmlns:eml2="http://schemas.datacontract.org/2004/07/EML.DTO.Identifiers" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> | |
| * | |
| * Pay attention to xmlns:i which is what require in order to do i:type="eml2:ExternalAccountIdentifier" | |
| * | |
| * Working example in XML: | |
| * <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:eml="http://schemas.datacontract.org/2004/07/EML.Services.Base" xmlns:eml1="http://schemas.datacontract.org/2004/07/EML.Services.External.Shared.DTO" xmlns:eml2="http://schemas.datacontract.org/2004/07/EML.DTO.Identifiers" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> | |
| * <soapenv:Header/> | |
| * <soapenv:Body> | |
| * <tem:Transfer> | |
| * <!--Optional:--> | |
| * <tem:request> | |
| * <!--Optional:--> | |
| * <eml:SecurityRequest> | |
| * <!--Optional:--> | |
| * <eml:Password>Username</eml:Password> | |
| * <!--Optional:--> | |
| * <eml:Username>Password</eml:Username> | |
| * </eml:SecurityRequest> | |
| * <!--Optional:--> | |
| * <eml1:Amount>75</eml1:Amount> | |
| * <!--Optional:--> | |
| * <eml1:DestinationAccountId i:type="eml2:ExternalAccountIdentifier"> | |
| * <eml2:ExternalAccountId>'.$data['DestinationAccountId'].'</eml2:ExternalAccountId> | |
| * </eml1:DestinationAccountId> | |
| * <eml1:DestinationReference>Transfer to '.$data['DestinationAccountId'].'</eml1:DestinationReference> | |
| * <!--Optional:--> | |
| * <eml1:SourceAccountId> | |
| * <!--Optional:--> | |
| * <eml2:ExternalAccountId>'.$data['ExternalAccountId'].'</eml2:ExternalAccountId> | |
| * </eml1:SourceAccountId> | |
| * <eml1:SourceReference>Transfer from '.$data['ExternalAccountId'].'</eml1:SourceReference> | |
| * </tem:request> | |
| * </tem:Transfer> | |
| * </soapenv:Body> | |
| * </soapenv:Envelope> | |
| */ | |
| public function Transfer($data) | |
| { | |
| $sec = new SecurityRequest(); | |
| $sec->Username = $data['username']; | |
| $sec->Password = $data['password']; | |
| $SourceAccountId = new SourceAccountId(); | |
| $SourceAccountId->ExternalAccountId = $data['ExternalAccountId']; | |
| $objParam = new \stdClass(); | |
| $objParam->request = new \stdClass(); | |
| $objParam->request->SecurityRequest = $sec; | |
| $objParam->request->Amount = $data['Amount']; | |
| $array = []; | |
| /** | |
| * Haven't found any good document about how to create the tag like the sample XML. | |
| * Major issue is the externalaccountid got two and PHP Soap client keeps picking up the wrong one | |
| */ | |
| $string = '<ns3:ExternalAccountId>'.$data['DestinationAccountId'].'</ns3:ExternalAccountId>'; | |
| $array[] = new SoapVar( | |
| $string, | |
| XSD_ANYXML); | |
| $objParam->request->DestinationAccountId =new SoapVar( | |
| $array, | |
| SOAP_ENC_OBJECT, | |
| "ns3:ExternalAccountIdentifier", | |
| null, | |
| "DestinationAccountId", | |
| "http://www.w3.org/2001/XMLSchema-instance"); | |
| if (isset($data['DestinationReference']) && !empty($data['DestinationReference'])) { | |
| $objParam->request->DestinationReference = $data['DestinationReference']; | |
| } else { | |
| $objParam->request->DestinationReference = ""; | |
| } | |
| $objParam->request->SourceAccountId = $SourceAccountId; | |
| if (isset($data['SourceReference']) && !empty($data['SourceReference'])) { | |
| $objParam->request->SourceReference = $data['SourceReference']; | |
| } else { | |
| $objParam->request->SourceReference = ""; | |
| } | |
| /** | |
| * response | |
| * stdClass Object ( [TransferResult] => stdClass Object ( [ErrorCode] => [ExtendedErrorInformation] => [Success] => 1 [TransactionId] => 12345678901 ) ) | |
| */ | |
| try | |
| { | |
| $response = $this->soapClient->Transfer($objParam); | |
| return [ | |
| 'success' => $response->TransferResult->Success, | |
| 'data' => $response->TransferResult->TransactionId | |
| ]; | |
| }catch(Exception $e) | |
| { | |
| return [ | |
| 'success' => false, | |
| 'error' => $e | |
| ]; | |
| } | |
| return $this->checkIsSoapFault($this->soapClient); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment