<?php

declare (strict_types=1);
namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Ucp\Integration;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Ucp\Checkout\Response\CheckoutResponseMapper;
use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Ucp\Enums\UcpVersion;
/**
 * Provides WC Payments configuration and availability for UCP.
 *
 * @phpstan-import-type PaymentHandlerNode from CheckoutResponseMapper
 */
final class WcPaymentConfigProvider
{
    public function is_available(): bool
    {
        return \class_exists('WC_Payments');
    }
    /**
     * @return PaymentHandlerNode
     */
    public function get_google_pay_handler(): array
    {
        if (!\class_exists('WC_Payments')) {
            return [];
        }
        try {
            $mode = \WC_Payments::mode();
            $is_test = $mode->is_test();
            $account = \WC_Payments::get_account_service();
            if (!$account) {
                return [];
            }
            $publishable_key = $account->get_publishable_key($is_test);
            $stripe_account_id = $account->get_stripe_account_id();
            if (!$publishable_key || !$stripe_account_id) {
                return [];
            }
            return ['com.google.pay' => [['id' => 'gpay_wcpay_' . $stripe_account_id, 'version' => UcpVersion::CURRENT, 'spec' => 'https://pay.google.com/gp/p/ucp/' . UcpVersion::CURRENT . '/', 'config' => (object) ['gateway' => 'stripe', 'gateway_merchant_id' => $stripe_account_id, 'stripe_publishable_key' => $publishable_key, 'environment' => $is_test ? 'TEST' : 'PRODUCTION']]]];
        } catch (\Throwable $e) {
            return [];
        }
    }
}
