Skip to content

Commit

Permalink
Fixed payment card value fields
Browse files Browse the repository at this point in the history
added missing "value" field to the wp_kses that prints out the fields, added error logging & checks for the tokens. Added missing WP_REST_Request & Exception use cases to card php
  • Loading branch information
PanuKar committed Nov 21, 2023
1 parent d1fe598 commit 7df84c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Controllers/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ public function saved_payment_methods() {
'id' => [],
'type' => [],
'name' => [],
'value'=> [],
'class' => []
],
'div' => ['class' => []],
Expand All @@ -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(
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 7df84c2

Please sign in to comment.