<?php

declare(strict_types=1);

namespace Kylin\Pay\Plugin\Stripe\V1\Pay;

use Closure;
use Kylin\Pay\Artful\Contract\PluginInterface;
use Kylin\Pay\Artful\Logger;
use Kylin\Pay\Artful\Rocket;

/**
 * @see https://stripe.com/docs/api/payment_intents/create
 */
class PayPlugin implements PluginInterface
{
    public function assembly(Rocket $rocket, Closure $next): Rocket
    {
        Logger::debug('[Stripe][V1][Pay][PayPlugin] 插件开始装载', ['rocket' => $rocket]);

        $payload = $rocket->getPayload();

        $rocket->mergePayload([
            '_method' => 'POST',
            '_url' => 'v1/payment_intents',
            'amount' => $payload->get('amount'),
            'currency' => $payload->get('currency'),
        ]);

        Logger::info('[Stripe][V1][Pay][PayPlugin] 插件装载完毕', ['rocket' => $rocket]);

        return $next($rocket);
    }
}
