Skip to content

Commit

Permalink
Merge pull request #1488 from themeum/Authorize-net
Browse files Browse the repository at this point in the history
Changes For Authorize.Net
  • Loading branch information
shewa12 authored Jan 6, 2025
2 parents e52e189 + f58a639 commit 298b1dc
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions ecommerce/PaymentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@

use TUTOR\Input;
use WP_REST_Server;
use WP_REST_Request;

/**
* Payment handler class.
*/
class PaymentHandler {

const AUTHORIZENET = 'authorizenet';
/**
* Register hooks
*
Expand Down Expand Up @@ -45,24 +47,39 @@ public function register_webhook_route() {
'permission_callback' => '__return_true', // Allows public access to the route.
)
);

// Register route for authorizenet.
register_rest_route(
'tutor/v1',
'/ecommerce-webhook/authorizenet',
array(
'methods' => WP_REST_Server::ALLMETHODS,
'callback' => array( $this, 'handle_ecommerce_webhook' ),
'permission_callback' => '__return_true', // Allows public access to the route.
)
);
}

/**
* Webhook request handler
*
* @since 3.0.0
*
* @param WP_REST_Request $request The request object.
*
* @return void
*/
public function handle_ecommerce_webhook() {
public function handle_ecommerce_webhook( WP_REST_Request $request ) {
$webhook_data = (object) array(
'get' => $_GET,
'post' => $_POST,
'server' => $_SERVER,
'stream' => file_get_contents( 'php://input' ),
);

$payment_method = Input::get( 'payment_method', 'paypal' );
$route = $request->get_route() ?? null;
$payment_method = ! is_null( $route ) && strpos( $route, self::AUTHORIZENET ) ? self::AUTHORIZENET : Input::get( 'payment_method', 'paypal' );

$payment_gateways = apply_filters( 'tutor_gateways_with_class', Ecommerce::payment_gateways_with_ref(), $payment_method );

$payment_gateway_class = isset( $payment_gateways[ $payment_method ] )
Expand Down Expand Up @@ -105,7 +122,7 @@ public function load_order_status_template( $template ) {
// Modify the page title.
add_filter(
'document_title_parts',
function( $title ) use ( $placement_status ) {
function ( $title ) use ( $placement_status ) {
$site_title = get_bloginfo( 'name' );

if ( 'success' === $placement_status ) {
Expand Down

0 comments on commit 298b1dc

Please sign in to comment.