description(); } /** * Whether the gateway confirms payments and refunds by itself (no manual buttons in the admin). * * @return bool */ public function confirms_payments() { return false; } /** * Whether the gateway is set up and can take orders. * * @return bool */ abstract public function is_available(); /** * Start the payment for a new order. * * @param Paygrab_Order $order Order (awaiting payment). * @return array{redirect:string}|WP_Error Where to send the buyer next. */ abstract public function start( Paygrab_Order $order ); /** * Methods the buyer can pick within this gateway: [ method => label ]. * * @return array */ public function methods() { return array( $this->id() => $this->label() ); } /** * Label of one method. * * @param string $method Method. * @return string */ public function method_label( $method ) { $methods = $this->methods(); return $methods[ $method ] ?? $this->label(); } /** * Payment instructions for an order awaiting payment (HTML for screens). * * @param Paygrab_Order $order Order. * @return string */ public function instructions_html( Paygrab_Order $order ) { return ''; } /** * Payment instructions for an order awaiting payment (plain text for mail). * * @param Paygrab_Order $order Order. * @return string */ public function instructions_text( Paygrab_Order $order ) { return ''; } /** * When the buyer pays, for the checkout screen and the legal notice. * * @return string */ public function payment_timing() { return ''; } /** * Methods and payment timing in one line, for the buy box. * * @return string */ public function summary() { return implode( paygrab_sep(), $this->methods() ) . ( $this->payment_timing() ? paygrab_open() . $this->payment_timing() . paygrab_close() : '' ); } /** * Fees other than the price, for the legal notice. * * @return string */ public function extra_fees() { return ''; } /** * The note under the payment instructions on the completion screen. * * @param Paygrab_Order $order Order. * @return string Plain text. */ public function complete_note( Paygrab_Order $order ) { return __( 'We email you when we have confirmed your payment (usually within 1–2 business days).', 'paygrab' ); } /** * Whether a buyer may cancel an order awaiting payment by themselves. * * @return bool */ public function buyer_can_cancel() { return true; } } /** * Registry of gateways. */ class Paygrab_Gateways { /** * Request cache. * * @var Paygrab_Gateway[]|null */ private static $all = null; /** * Every registered gateway, keyed by ID. * * @return Paygrab_Gateway[] */ public static function all() { if ( null === self::$all ) { /** * Filters the payment gateways. * * @param Paygrab_Gateway[] $gateways Gateways. */ $list = apply_filters( 'paygrab_gateways', array( new Paygrab_Gateway_Bank_Manual() ) ); self::$all = array(); foreach ( $list as $gateway ) { if ( $gateway instanceof Paygrab_Gateway ) { self::$all[ $gateway->id() ] = $gateway; } } } return self::$all; } /** * One gateway. * * @param string $id Gateway ID. * @return Paygrab_Gateway|null */ public static function get( $id ) { $all = self::all(); return $all[ $id ] ?? null; } /** * Gateways that can take orders now. * * @return Paygrab_Gateway[] */ public static function available() { return array_filter( self::all(), static fn( $g ) => $g->is_available() ); } /** * Whether buyers can pay at least one way (the bank account is entered, or a gateway that PAYGRAB Pro adds is set up). * * @return bool */ public static function ready() { return (bool) self::available(); } /** * Whether bank transfer is the only way to pay that the site offers (PAYGRAB without Pro). * * @return bool */ public static function bank_only() { return array( 'bank_manual' ) === array_keys( self::all() ); } }