<?php
/**
 * UddoktaPay Payment Gateway Local Gateway Class.
 *
 * This file contains the Local Gateway class for the UddoktaPay Payment Gateway,
 * handling Bangladeshi payment transactions through multiple payment providers.
 *
 * @package UddoktaPayGateway
 * @since 1.0.0
 */

declare (strict_types = 1);

namespace UddoktaPay\UddoktaPayGateway;

// If this file is called directly, abort!!!
defined( 'ABSPATH' ) || exit( 'Direct access is not allowed.' );

/**
 * Local Gateway Class
 *
 * Provides Bangladeshi payment options through UddoktaPay's local payment processors.
 *
 * @since 1.0.0
 */
class LocalGateway extends AbstractGateway {

	/**
	 * Setup general properties for the gateway.
	 *
	 * @return void
	 */
	protected function setup_properties() {
		$this->id           = 'uddoktapay';
		$this->icon         = (string) apply_filters( 'woocommerce_uddoktapay_icon', UDDOKTAPAY_URL . 'assets/images/nirapodpay.png' );
		$this->has_fields   = false;
		$this->method_title = __( 'NirapodPay', 'uddoktapay-gateway' );

		$this->method_description = sprintf(
			/* translators: %s: URL for NirapodPay website */
			'%s<br/><a href="%s" target="_blank">%s</a>',
			__( 'Accept Bangladeshi payments via multiple gateways including bKash, Nagad, Rocket, BanglaQR and more.', 'uddoktapay-gateway' ),
			esc_url( 'https://nirapodpay.com' ),
			__( 'Get your NirapodPay credentials from nirapodpay.com', 'uddoktapay-gateway' )
		);
		$this->supports = array(
			'products',
		);
	}

	/**
	 * Base currency the gateway charges in.
	 *
	 * @return string
	 */
	protected function get_base_currency() {
		return 'BDT';
	}

	/**
	 * Order meta key used to store the payment data.
	 *
	 * @return string
	 */
	protected function get_payment_data_meta_key() {
		return 'uddoktapay_payment_data';
	}

	/**
	 * Default checkout title.
	 *
	 * @return string
	 */
	protected function get_default_title() {
		return __( 'NirapodPay (bKash, Nagad, Rocket, BanglaQR, Cards)', 'uddoktapay-gateway' );
	}

	/**
	 * Default checkout description.
	 *
	 * @return string
	 */
	protected function get_default_description() {
		return __( 'Pay securely with bKash, Nagad, Rocket, BanglaQR, Visa, Mastercard, and other payment methods via NirapodPay.', 'uddoktapay-gateway' );
	}

	/**
	 * Enable/disable field label.
	 *
	 * @return string
	 */
	protected function get_enable_label() {
		return __( 'Enable NirapodPay', 'uddoktapay-gateway' );
	}

	/**
	 * Create a payment through the API for the given order.
	 *
	 * @param \WC_Order $order The order object.
	 * @param array     $metadata Payment metadata.
	 * @return object
	 */
	protected function create_payment_for_order( $order, $metadata ) {
		$webhook_url = $this->build_order_webhook_url( $order );

		return $this->get_api()->create_payment(
			$order->get_total(),
			$order->get_currency(),
			$order->get_billing_first_name(),
			$order->get_billing_email(),
			$order->get_billing_phone(),
			$metadata,
			$webhook_url,
			$order->get_cancel_order_url_raw(),
			$webhook_url,
			$this->exchange_rate
		);
	}
}
