M
M
My_ReVeReNce2020-08-20 21:11:34
PHP
My_ReVeReNce, 2020-08-20 21:11:34

Getting a confirmation_token in Yandex.Checkout?

Good day to all! I am a teapot in the back-end, I connect Cashier to the site via the API. The question is the following: through this code, I create a request to the Checkout, through which I receive the response log (just below), from where I need to pull out the confirmation_token so that it itself fasts into the js script (I will place it below)

use YandexCheckout\Client;
$client = new Client();
$client->setAuth('shop-id', 'Api-token');
$client->createPayment(
    array(
        'amount' => array(
            'value' => 'Цена',
            'currency' => 'RUB',
        ),
        'confirmation' => array(
            'type' => 'embedded'
        ),
        'capture' => true,
        'description' => 'Описание',
    ),
    uniqid('', true)
    );
$idempotenceKey = uniqid('', true);


Response log:
{
  "id": "айдишник",
  "status": "pending",
  "paid": false,
  "amount": {
    "value": "Цена",
    "currency": "RUB"
  },
  "confirmation": {
    "type": "embedded",
    "confirmation_token": "ТУТ НЕОБХОДИМЫЙ ТОКЕН"
  },
  "created_at": "2020-08-20T17:40:09.629Z",
  "description": "Описание",
  "metadata": {
    "scid": "***"
  },
  "recipient": {
    "account_id": "скрыл",
    "gateway_id": "скрыл"
  },
  "refundable": false,
  "test": false
}

js script
const checkout = new window.YandexCheckout({
    confirmation_token: 'confirmation_token', //Токен, который перед проведением оплаты нужно получить от Яндекс.Кассы
    return_url: '', //Ссылка на страницу завершения оплаты
    error_callback(error) {
        //Обработка ошибок инициализации
    }
});

//Отображение платежной формы в контейнере
checkout.render('payment-form');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
part_os, 2020-09-06
@part_os

Here is my verification method and collection of verification token

**
     * @param YandexMoneyConfirmationPayRequest $yandexRequest
     * @return Order|null
     */
    public function confirmationPay(YandexMoneyConfirmationPayRequest $yandexRequest): ?Order
    {
        $request = $yandexRequest->getRequest();

        $notificationType = $request->post('notification_type');
        $operationId = $request->post('operation_id');
        $amount = $request->post('amount');
        $currency = $request->post('currency');
        $datetime = $request->post('datetime');
        $sender = $request->post('sender');
        $codepro = $request->post('codepro');
        $sha1HashRequest = $request->post('sha1_hash');

        $label = $request->post('label');
        Log::info('Сообщение о подтверждение оплаты orderId: ' . $label);
        Log::info('Сообщение о подтверждение оплаты amount: ' . $amount);
        Log::info('Сообщение о подтверждение оплаты withdraw_amount: ' . $request->post('withdraw_amount'));
        Log::info('Сообщение о подтверждение оплаты datetime: ' . $datetime);


        $notificationSecret = config('app.YANDEX_SECRET');

        Log::info('Сообщение о подтверждение оплаты собираем строку');
        $confirmationPayString = $notificationType . '&' .
            $operationId . '&' .
            $amount . '&' .
            $currency . '&' .
            $datetime . '&' .
            $sender . '&' .
            $codepro . '&' .
            $notificationSecret. '&' .
            $label;

        $sha1 = hash('sha1', $confirmationPayString);

        if ($sha1HashRequest === $sha1) {
            Log::info('Сообщение о подтверждение оплаты hashValid: true');

            if (!is_null($label))  {

                try {
                    $order = $this->orderRepository->findByOrderId($label);
                    $order->payment = true;
                    $order->save();

                    return $order;
                }  catch (ModelNotFoundException $e) {
                    Log::critical('При подтверждение оплаты не найден order by ID : ' . $label);
                    return null;
                }

            } else {
                Log::critical('Сообщение о подтверждение оплаты orderId is null');
            }

        } else {
            Log::info('Сообщение о подтверждение оплаты hashValid: false');
        }

        Log::info('Оплата не подтверждена');

        return null;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question