@animr

Почему после успешной оплаты юкасса, при получении Notification выдается ошибка?

в чем ошибка подскажите
string(0) ""
Fatal error: Uncaught TypeError: Argument 1 passed to YandexCheckout\Model\Notification\NotificationWaitingForCapture::__construct() must be of the type array, null given, called in /var/www/u0015789/data/www/ddeducate.ru/pay.php on line 52 and defined in /var/www/u0015789/data/www/ddeducate.ru/lib/Model/Notification/NotificationWaitingForCapture.php:72 Stack trace: #0 /var/www/u0015789/data/www/ddeducate.ru/pay.php(52): YandexCheckout\Model\Notification\NotificationWaitingForCapture->__construct(NULL) #1 {main} thrown in /var/www/u0015789/data/www/ddeducate.ru/lib/Model/Notification/NotificationWaitingForCapture.php on line 72


Форма передачи данных:
<form id="kassa-form" class='dar-kassa' action="/payac.php" method="POST">
		    <label for="">ФИО: </label>
		    <input class='' type="fio" name="fio" required placeholder="Ваше ФИО"><br> 
		    <label for="">E-mail: </label>
		    <input class='' type="email" name="email" required placeholder="Ваш E-mail"><br>
		    <input class='dar-oplata-kassa-button' type="submit" name="submit" value="Оплатить">
	</form>


Формирование платежа:
<?Php
    session_start();

    include_once( 'connect_db.php' );
    require __DIR__ . '/lib/autoload.php';

    use YandexCheckout\Client;
    

    $sum    = 3500;
    $fio    = $_POST['fio'];
    $email = $_POST["email"];
    $_SESSION['em'] = $email;
?>
<?Php
if( !empty($sum) && !empty($fio) && !empty($email)) {
    $description = 'ФИО: '.$fio.'<br>E-mail: '.$email;
    $client = new Client();
    $client->setAuth('11111', 'sfjiesifjiejfejfisefjeoifjseoifjseif');
    $payment = $client->createPayment(
        array(
            'amount' => array(
                'value' => $sum,
                'currency' => 'RUB',
            ),
            'confirmation' => array(
                'type' => 'redirect',
                'return_url' => 'https://ddeducate.ru/pay.php',
            ),
            'capture' => true,
            'description' => $description,
        ),
        uniqid('', true)
    );
    header('Location: '. $payment["confirmation"]["confirmation_url"]);
    ?>

    <p>Сейчас вы будете перенаправлены на страницу оплаты, если этого не произошло нажмите на ссылку ниже:</p>
    <p><a href="<?=$payment["confirmation"]["confirmation_url"];?>">Оплатить</a></p>

<?Php } else { ?>
    <p>Произошла ошибка. Попробуйте еще раз.</p>
<?}?>


При успешной оплате:
require __DIR__ . '/lib/autoload.php';
    // Получите данные из POST-запроса от Яндекс.Кассы
    $source = file_get_contents('php://input');
    $requestBody = json_decode($source, true);
    var_dump($source);
    // Создайте объект класса уведомлений в зависимости от события
    // NotificationSucceeded, NotificationWaitingForCapture,
    // NotificationCanceled,  NotificationRefundSucceeded
    use YandexCheckout\Model\Notification\NotificationSucceeded;
    use YandexCheckout\Model\Notification\NotificationWaitingForCapture;
    use YandexCheckout\Model\NotificationEventType;
    use YandexCheckout\Model\PaymentStatus;
    try {
      $notification = ($requestBody['event'] === NotificationEventType::PAYMENT_SUCCEEDED)
        ? new NotificationSucceeded($requestBody)
        : new NotificationWaitingForCapture($requestBody);
    } catch (Exception $e) {
        // Обработка ошибок при неверных данных
    }
    // Получите объект платежа
    $payment = $notification->getObject();
    if($payment->getStatus() === PaymentStatus::SUCCEEDED) {
        $emm = $_SESSION['em'];
        sendMessageEmail( $emm );
        unset( $_SESSION['em'] );
        header("Location: https://t.me/joinchat");
    }


Не понимаю почему $requestBody пустой
  • Вопрос задан
  • 735 просмотров
Пригласить эксперта
Ответы на вопрос 1
Если начать с самого простого, то я бы посмотрел тут -

<input class='' type="fio" name="fio" required placeholder="Ваше ФИО"><br>


Нет такого type fio. Поменяйте на type="text" и попробуйте что получится.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы