Automattic\WooCommerce\Gateways\PayPal

WebhookHandler::process_payment_authorization_createdprivateWC 10.5.0

Process the PAYMENT.AUTHORIZATION.CREATED webhook event.

Метод класса: WebhookHandler{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->process_payment_authorization_created( $event ): void;
$event(массив) (обязательный)
The webhook event data.

Список изменений

С версии 10.5.0 Введена.

Код WebhookHandler::process_payment_authorization_created() WC 11.0.1

private function process_payment_authorization_created( array $event ): void {
	$custom_id = $event['resource']['custom_id'] ?? '';
	$order     = PayPalHelper::get_wc_order_from_paypal_custom_id( $custom_id );
	if ( ! $order ) {
		\WC_Gateway_Paypal::log( 'Invalid order. Custom ID: ' . wc_print_r( $custom_id, true ) );
		return;
	}

	// Skip if the payment is already processed.
	if ( PayPalConstants::STATUS_COMPLETED === $order->get_meta( PayPalConstants::PAYPAL_ORDER_META_STATUS, true ) ) {
		return;
	}

	$transaction_id = $event['resource']['id'] ?? null;
	$order->set_transaction_id( $transaction_id );
	$order->update_meta_data( PayPalConstants::PAYPAL_ORDER_META_AUTHORIZATION_ID, $transaction_id );
	$order->update_meta_data( PayPalConstants::PAYPAL_ORDER_META_STATUS, PayPalConstants::STATUS_AUTHORIZED );
	$order->add_order_note(
		sprintf(
			/* translators: %1$s: Transaction ID */
			__( 'PayPal payment authorized. Transaction ID: %1$s. Change payment status to processing or complete to capture funds.', 'woocommerce' ),
			$transaction_id
		)
	);
	$order->update_status( OrderStatus::ON_HOLD );
	$order->save();
}