Skip to content
Snippets Groups Projects
PxIPN.php 2.73 KiB
<?php
/**
 * PxIPN controller class.
 *
 * PxPay IPN endpoint, replacement for CiviCRM's 'extern/pxIPN.php'.
 *
 * @since 0.1
 */

namespace CiviCRM_WP_REST\Controller;

class PxIPN extends Base {

	/**
	 * The base route.
	 *
	 * @since 0.1
	 * @var string
	 */
	protected $rest_base = 'pxIPN';

	/**
	 * Registers routes.
	 *
	 * @since 0.1
	 */
	public function register_routes() {

		register_rest_route( $this->get_namespace(), $this->get_rest_base(), [
			[
				'methods' => \WP_REST_Server::ALLMETHODS,
				'callback' => [ $this, 'get_item' ]
			]
		] );

	}

	/**
	 * Get items.
	 *
	 * @since 0.1
	 * @param WP_REST_Request $request
	 */
	public function get_item( $request ) {

		/**
		 * Filter payment processor params.
		 *
		 * @since 0.1
		 * @param array $params
		 * @param WP_REST_Request $request
		 */
		$params = apply_filters(
			'civi_wp_rest/controller/pxIPN/params',
			$this->get_payment_processor_args( $request ),
			$request
		);

		// log notification
		\Civi::log()->alert( 'payment_notification processor_name=Payment_Express', $params );

		try {

			$result = \CRM_Core_Payment_PaymentExpressIPN::main( ...$params );

		} catch ( \CRM_Core_Exception $e ) {

			\Civi::log()->error( $e->getMessage() );
			\Civi::log()->error( 'error data ', [ 'data' => $e->getErrorData() ] );
			\Civi::log()->error( 'REQUEST ', [ 'params' => $params ] );