orders = $orders ?? Orders::reader(); } /** * The facts this provider declares. * * @return array> */ public static function declarations(): array { return array( 'money.unconvertible' => array( 'type' => 'bool', 'label' => 'Amount in a currency with no stored exchange rate', ), ); } /** * The fact, for a write on a refund or an order. * * @param ActionDescriptor $action The classified action. * @return array */ public function __invoke( ActionDescriptor $action ): array { if ( 'read' === $action->action_cat ) { return array(); } if ( null === $action->entity_id ) { $currency = $action->input['currency'] ?? null; return array( 'money.unconvertible' => is_string( $currency ) && '' !== $currency && strtoupper( $currency ) !== $this->currency->base() ); } $order = ( $this->orders )( $action->entity_id ); return null === $order ? array() : array( 'money.unconvertible' => $this->currency->unconvertible( $order ) ); } }