Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed payment card value fields #120

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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