diff --git a/src/Controllers/Card.php b/src/Controllers/Card.php index f52e739c..b03b5fd2 100644 --- a/src/Controllers/Card.php +++ b/src/Controllers/Card.php @@ -7,9 +7,11 @@ use Paytrail\WooCommercePaymentGateway\Gateway; use Paytrail\WooCommercePaymentGateway\Plugin; +use Paytrail\WooCommercePaymentGateway\Exception; use WC_Payment_Tokens; use WP_Error; use WP_HTTP_Response; +use WP_REST_Request; class Card extends AbstractController { @@ -70,7 +72,8 @@ private function validate_request() { if (empty($_SERVER['REQUEST_METHOD'])) { return; } - if ( WP_REST_Request::get_method() != 'POST' ) { + $request = new WP_REST_Request(); + if ( $request->get_method() != 'POST' ) { throw new Exception('Only POST requests are allowed'); } $content_type = WP_REST_Request::get_content_type(); diff --git a/src/Gateway.php b/src/Gateway.php index b3d91fbe..9063c7fd 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -478,6 +478,7 @@ public function saved_payment_methods() { 'id' => [], 'type' => [], 'name' => [], + 'value'=> [], 'class' => [] ], 'div' => ['class' => []], @@ -501,6 +502,7 @@ public function saved_payment_methods() { */ public function get_token_payment_option_html( $html, $token) { if (Plugin::GATEWAY_ID !== $token->get_gateway_id()) { + error_log('Not the expected gateway ID. Returning original HTML.'); return $html; } $html = sprintf( @@ -929,7 +931,12 @@ public function process_payment( $order_id) { $payment = new CitPaymentRequest(); - $payment->setToken($token->get_token()); + if ($token && method_exists($token, 'get_token')) { + $payment->setToken($token->get_token()); + } else { + $this->log('Paytrail: Token value: ' . print_r($token, true), 'debug'); + } + } else { $this->log('Paytrail: init PaymentRequest', 'debug'); $payment = new PaymentRequest();