V
V
Vladimir2016-09-19 22:18:35
Yii
Vladimir, 2016-09-19 22:18:35

How to make xml request in yii2?

Good day! There is an API and it says

Data exchange is carried out by XML requests to the address https://api.privatbank.ua/p24api/pay_pb

As far as I understand, it is necessary to fill in the data in the xml file with the necessary data and somehow throw them at that address) I'm not strong in xml requests, and even more so through the framework. Please tell me where you can read about such requests or maybe there is a video. And it is better for someone not difficult to explain here. Thank you in advance for your answers!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Ivchenkov, 2016-09-19
@Groonya

Most likely it means that you will receive an answer in xml format. Try to make a normal POST request.

A
Andrew, 2016-09-20
@mhthnz

In this case, xml is passed in the body of the request. In this case, it is more convenient to send via curl:

<?php
$url = "https://api.privatbank.ua/p24api/pay_pb";
$xml = '
<?xml version="1.0" encoding="UTF-8"?>
<request version="1.0">
  <merchant>
    <id>75482</id>
    <signature>99730232b2f984c571507a0e74595e777afd0428</signature>
  </merchant>
  <data>
    <oper>cmt</oper>
    <wait>0</wait>
    <test>0</test>
    <payment id="1234567">
      <prop name="b_card_or_acc" value="4627081718568608" />
      <prop name="amt" value="1" />
      <prop name="ccy" value="UAH" />
      <prop name="details" value="test%20merch%20not%20active" />
    </payment>
  </data>
</request>
';

$headers = array(
    "Content-type: text/xml",
    "Content-length: " . strlen($xml),
    "Connection: close",
);

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$data = curl_exec($ch); 
echo $data;
if(curl_errno($ch))
    print curl_error($ch);
else
    curl_close($ch);
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question