Skip to content

Commit

Permalink
feat: ✨ Check blocks payment on each gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
DouglasCorreiaMeli committed Jan 10, 2024
1 parent 692cccb commit 12d3735
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/Gateways/BasicGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ public function process_payment($order_id): array
try {
parent::process_payment($order_id);

if (isset($_POST['wc-woo-mercado-pago-basic-new-payment-method'])) {
$this->mercadopago->orderMetadata->markPaymentAsBlocks($order, "yes");
} else {
$this->mercadopago->orderMetadata->markPaymentAsBlocks($order, "no");
}

$this->transaction = new BasicTransaction($this, $order);
$method = $this->mercadopago->hooks->options->getGatewayOption($this, 'method', 'redirect');

Expand Down
6 changes: 6 additions & 0 deletions src/Gateways/CreditsGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ public function process_payment($order_id): array
try {
parent::process_payment($order_id);

if (isset($_POST['wc-woo-mercado-pago-credits-new-payment-method'])) {
$this->mercadopago->orderMetadata->markPaymentAsBlocks($order, "yes");
} else {
$this->mercadopago->orderMetadata->markPaymentAsBlocks($order, "no");
}

$this->transaction = new CreditsTransaction($this, $order);

$this->mercadopago->logs->file->info('Customer being redirected to Mercado Pago.', self::LOG_SOURCE);
Expand Down
2 changes: 2 additions & 0 deletions src/Gateways/CustomGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@ public function process_payment($order_id): array

if (isset($_POST['mercadopago_custom'])) {
$checkout = Form::sanitizeFromData($_POST['mercadopago_custom']);
$this->mercadopago->orderMetadata->markPaymentAsBlocks($order, "no");
} else {
// Blocks data arrives in a different way
$checkout = $this->processBlocksCheckoutData('mercadopago_custom', Form::sanitizeFromData($_POST));
$this->mercadopago->orderMetadata->markPaymentAsBlocks($order, "yes");
}

parent::process_payment($order_id);
Expand Down
7 changes: 6 additions & 1 deletion src/Gateways/PixGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,14 @@ public function process_payment($order_id): array
$order = wc_get_order($order_id);
try {
parent::process_payment($order_id);

$checkout = Form::sanitizeFromData($_POST);

if (isset($_POST['wc-woo-mercado-pago-pix-new-payment-method'])) {
$this->mercadopago->orderMetadata->markPaymentAsBlocks($order, "yes");
} else {
$this->mercadopago->orderMetadata->markPaymentAsBlocks($order, "no");
}

if (!filter_var($order->get_billing_email(), FILTER_VALIDATE_EMAIL)) {
return $this->processReturnFail(
new \Exception('Email not valid on ' . __METHOD__),
Expand Down
10 changes: 7 additions & 3 deletions src/Gateways/TicketGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,18 @@ public function getPaymentFieldsParams(): array
public function process_payment($order_id): array
{
$order = wc_get_order($order_id);
$checkout = [];

try {
parent::process_payment($order_id);
$checkout = Form::sanitizeFromData($_POST['mercadopago_ticket']);

// Blocks data arrives in a different way
if (empty($checkout)) {
if (isset($_POST['mercadopago_ticket'])) {
$checkout = Form::sanitizeFromData($_POST['mercadopago_ticket']);
$this->mercadopago->orderMetadata->markPaymentAsBlocks($order, "no");
} else {
// Blocks data arrives in a different way
$checkout = $this->processBlocksCheckoutData('mercadopago_ticket', Form::sanitizeFromData($_POST));
$this->mercadopago->orderMetadata->markPaymentAsBlocks($order, "yes");
}

if (
Expand Down

0 comments on commit 12d3735

Please sign in to comment.