0

I have received XML array from a payment gateway by post method when I echo $request->all()

array:1 ["xmlmsg" => "
<Message date="25/07/2018 21:07:55"
  <Version>1.0</Version>
  <OrderID>97205</OrderID>
  <TransactionType>Purchase</TransactionType>
  <PAN></PAN>
  <PurchaseAmount>10000</PurchaseAmount>
  <Currency>524</Currency>
  <TranDateTime>25/07/2018 21:07:55</TranDateTime>
  <ResponseCode></ResponseCode>
  <ResponseDescription></ResponseDescription>
  <CardHolderName></CardHolderName>
  <Brand></Brand>
  <OrderStatus>CANCELED</OrderStatus>
  <ApprovalCode></ApprovalCode>
  <AcqFee>0</AcqFee>
  <OrderDescription>3 Sisters Package Purchase</OrderDescription>
  <ApprovalCodeScr></ApprovalCodeScr>
  <PurchaseAmountScr>100,00</PurchaseAmountScr>
  <CurrencyScr>NPR</CurrencyScr>
  <OrderStatusScr>CANCELED</OrderStatusScr>
  </Message>
  "]

How do I get OrderID value?

I am using Laravel version 5.6.

Below is my getPaymentSuccess() method;

public function getPaymentSuccess(Request $request)
{
    $getXMLData = $request->all();
    dd($getXMLData);
    return view('sites.order.success');
}

I want harness and to print OrderID value in getPaymentSuccess() method.

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
  • I created a package for Laravel that can help you with this: https://github.com/mtownsend5512/request-xml Follow the instructions and add the middleware and your xml will be merged into the Request object and be accessible just like a json or form request would be. – Mark Oct 23 '18 at 16:24

1 Answers1

0

To get XML attributes use php function simplexml_load_string() Link

public function getPaymentSuccess(Request $request)
{
    $getXMLData = $request->all();
    $xml= simplexml_load_string($getXMLData['xmlmsg']);
    $data = (array)$xml;
    dd($data['OrderID']);
    return view('sites.order.success');
}
Hamelraj
  • 4,676
  • 4
  • 19
  • 42