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

feat: add protections in Oneclick authorization flow #249

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ private function handleAuthorization(WC_Order $order, string $paymentTokenId)
$paymentToken = $this->getWcPaymentToken($paymentTokenId);
$amount = $this->getTotalAmountFromOrder($order);

if (!$this->validatePayerMatchesCardInscription($paymentToken)) {
throw new EcommerceException("Datos incorrectos para autorizar la transacción.");
}

$authorizeResponse = $this->oneclickTransbankSdk->authorize(
$order->get_id(),
$amount,
Expand Down Expand Up @@ -703,6 +707,22 @@ private function getTotalAmountFromOrder(WC_Order $order): int
return (int) number_format($order->get_total(), 0, ',', '');
}

/**
* Validate that the user paying for the order is the same as the one who registered the card.
*
* @param WC_Payment_Token_Oneclick $inscriptionData The card inscription data.
*
* @return bool True if the payer matches the card inscription, false otherwise.
*/
private function validatePayerMatchesCardInscription(WC_Payment_Token_Oneclick $paymentToken): bool
{
$currentUser = wp_get_current_user();
$userEmail = $currentUser->user_email;
$inscriptionEmail = $paymentToken->get_email();

return $userEmail == $inscriptionEmail;
}

public function getOneclickPaymentTokenClass()
{
return WC_Payment_Token_Oneclick::class;
Expand Down
Loading