Я новичок в Laravel. Я занимаюсь интеграцией платежей. Заказ успешно получен с данными карты. Я хочу сохранить эти детали в БД. Я использую $ dom для загрузки ответа xml вместо simplexml_load_string.
Вот код, который я написал, чтобы получить значения ответа xml.
public function checkStatusAndUpdateProfileId($transactionId, $response)
{
$details = $this->listPayments($transactionId);
$secret = $details->txn_secret;
$token = $details->payment_token;
$url = env('SMART_PAYS_STATUS_URL');
$amount = $details->transaction_amount;
$fields = array(
'transactionSecret' => $secret,
'token' => $token,
);
$fields_string = '';
foreach ($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$data['raw_xml'] = $xml = curl_exec($ch);
curl_close($ch);
//error_log($xml);
$dom = new \DOMDocument();
$dom->formatOutput = TRUE;
$dom->preserveWhiteSpace = FALSE;
$dom->loadXml($response);
// dd($response);
$err = $dom->getElementsByTagName('return');//errors
if (!empty($err))
// dd($err);
$result = $dom->getElementsByTagName('hostResponseMessage');
$return_code = $dom->getElementsByTagName('hostResponseCode');
$code_for_db = $return_code[0]->nodeValue == "00" ? 'success' : "error";
$amount = $dom->getElementsByTagName('purchaseAmount');
$TxID1 = $dom->getElementsByTagName('transactionReference');
$card_holder = $dom->getElementsByTagName('cardholderName');
$exp_date = $dom->getElementsByTagName('expiry');
$card_type = $dom->getElementsByTagName('cardType');
$last_four = $dom->getElementsByTagName('maskedPAN');
$return_code = Payment::where('id', $transactionId)->update([
'return_code' => $code_for_db,
'return_message' => $result[0]->nodeValue,
'transaction_amount' => !empty($amount) ? $amount : 0.00,
'brand' => $card_type[0]->nodeValue,
'last4' => $last_four[0]->nodeValue,
'holder' => $card_holder[0]->nodeValue,
'expiry' => $exp_date[0]->nodeValue,
]);
//$this->updateTransactionProfile($transactionId, $code_for_db, $result, $amount, $card_type, $last_four, $card_holder, $exp_date);
return $return_code;
}
Вот ответ xml, который генерируется из $ dom-> load Xml ($ response);
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:getWebPaymentResponse xmlns:ns2="http://services.thelogicgroup.biz/EMIS_WEBPAYMENT_3_0"><return><acquirer><ID>V</ID><name>VISA</name></acquirer><authType>AuthAndSettle</authType><authenticationRequest><threeDSMethodNotificationURL>https://pp.eshapay.net/TICORP/pages/acsNotification.jsf</threeDSMethodNotificationURL></authenticationRequest><authenticationResponse><cardScheme>VISA</cardScheme><cavvAlgorithm>NOT_SET</cavvAlgorithm><errorCode>0</errorCode><errorMessage>Card Not Enrolled</errorMessage><merchantID>410</merchantID><status>NOT_ENROLLED</status><threeDSVersionNumber>UNKNOWN</threeDSVersionNumber><xid>RZ8iufAVim0fO+8NLA45zOmj6Ns=</xid></authenticationResponse><authorisationResponse><authcode>D12345</authcode><hostResponseCode>00</hostResponseCode><hostResponseMessage></hostResponseMessage><merchantNo>3333333</merchantNo><paymentMethod>Card</paymentMethod><tid>23290022</tid></authorisationResponse><bank><ID>B</ID><name>Barclays-Dummy-51922203</name></bank><billingAddress><city>Panadura</city><firstName></firstName><lastName></lastName><line1>Gall Road</line1><line3>Panadura</line3><name> </name><postcode>12500</postcode></billingAddress><browser><accept>text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9</accept><javaEnabled>false</javaEnabled><javaScriptEnabled>true</javaScriptEnabled><language>en-US</language><remoteAddress>112.134.44.35</remoteAddress><screenColorDepth>24</screenColorDepth><screenResolution>1291X633</screenResolution><timezone>-330</timezone><userAgent>Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36</userAgent></browser><captures><capture id="2"><amount>3999</amount><outcome>OK</outcome></capture></captures><card><source>keyed</source><maskedPAN>424242******4242</maskedPAN><onlineToken>0000000000012021</onlineToken><updateOnlineToken>true</updateOnlineToken><onlineTokenUpdated>true</onlineTokenUpdated><expiry>2020-10</expiry><cardType>V</cardType></card><cardholderName>Test</cardholderName><configParams><displayBasketDetails>false</displayBasketDetails><merchantStates></merchantStates><storeID>000002</storeID></configParams><confirmCheck1>false</confirmCheck1><confirmCheck2>false</confirmCheck2><currencyCode>GBP</currencyCode><cvResponse><rawCv2>matched</rawCv2><rawAddress>matched</rawAddress><rawPostcode>matched</rawPostcode><authEntity>issuer</authEntity><mappedCV2>1</mappedCV2><mappedAddress>1</mappedAddress><mappedPostcode>1</mappedPostcode><result>Approve</result></cvResponse><environment>ECommerce</environment><purchaseAmount>3999</purchaseAmount><purchaseDescription>Policy</purchaseDescription><requester><enterpriseID>TICORP</enterpriseID><clientID>DE02</clientID><transNo>1628</transNo><version>20</version></requester><responder><name>EMIS-AG</name><version>3.37.3.0 Build:29fa4c9f4b27.PROD</version><releaseDate>10/02/2020</releaseDate><id>TSI-COR301-P1</id></responder><response>validated</response><status>CAPTURED</status><storeResultPage>https://www.golfins.local/smartpays-payment/response/</storeResultPage><totalAmount>3999</totalAmount><transactionReference>8b1387a2-34be-4356-969d-0e511188da96</transactionReference><validCardTypes>International Maestro</validCardTypes><validCardTypes>Visa Debit</validCardTypes><validCardTypes>Maestro</validCardTypes><validCardTypes>Visa Electron</validCardTypes><validCardTypes>VISA</validCardTypes><validCardTypes>Mastercard Debit</validCardTypes><validCardTypes>Mastercard</validCardTypes><validPayment>Card</validPayment></return></ns2:getWebPaymentResponse></soap:Body></soap:Envelope>
Я хочу добавить вышеуказанные значения xml в БД. Когда я передаю значения как $ amount = $ dom-> getElementsByTagName ('purchaseAmount'); он возвращает пустую строку следующим образом.
Пожалуйста, помогите мне решить эту проблему , Большая помощь Спасибо!