* * @param Authorization $authorization The authorization. * @param WC_Order $wc_order The WC order. * * @throws RuntimeException If payment denied. */ protected function handle_authorization_status(Authorization $authorization, WC_Order $wc_order): void { $status = $authorization->status(); $details = $status->details(); if ($details) { $this->add_status_details_note($wc_order, $status->name(), $details->text()); } switch ($status->name()) { case AuthorizationStatus::CREATED: case AuthorizationStatus::PENDING: $wc_order->update_status('on-hold', __('Awaiting payment.', 'woocommerce-paypal-payments')); /** * Fired when PayPal order is authorized. */ do_action('woocommerce_paypal_payments_order_authorized', $wc_order, $authorization); break; case AuthorizationStatus::DENIED: $wc_order->update_status('failed', __('Could not get the payment authorization.', 'woocommerce-paypal-payments')); throw new RuntimeException(__('Payment provider declined the payment, please use a different payment method.', 'woocommerce-paypal-payments')); } } /** * Adds the order note with status details. * * @param WC_Order $wc_order The WC order to which the note will be added. * @param string $status The status name. * @param string $reason The status reason. */ protected function add_status_details_note(WC_Order $wc_order, string $status, string $reason): void { $wc_order->add_order_note(sprintf( /* translators: %1$s - PENDING, DENIED, ... %2$s - text explaining the reason, ... */ __('PayPal order payment is set to %1$s status, details: %2$s', 'woocommerce-paypal-payments'), $status, $reason )); $wc_order->save(); } }