diff --git a/src/Entities/Metadata/PaymentMetadata.php b/src/Entities/Metadata/PaymentMetadata.php index 83f749f06..3f623c170 100644 --- a/src/Entities/Metadata/PaymentMetadata.php +++ b/src/Entities/Metadata/PaymentMetadata.php @@ -117,4 +117,9 @@ class PaymentMetadata * @var PaymentMetadataCpp */ public $cpp_extra; + + /** + * @var string + */ + public $blocks_payment; } diff --git a/src/Gateways/BasicGateway.php b/src/Gateways/BasicGateway.php index 6095602d0..fd39fa3a3 100644 --- a/src/Gateways/BasicGateway.php +++ b/src/Gateways/BasicGateway.php @@ -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'); diff --git a/src/Gateways/CreditsGateway.php b/src/Gateways/CreditsGateway.php index c0fbf3882..67fdbaeb6 100644 --- a/src/Gateways/CreditsGateway.php +++ b/src/Gateways/CreditsGateway.php @@ -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); diff --git a/src/Gateways/CustomGateway.php b/src/Gateways/CustomGateway.php index 29388f7bb..7fc00f8af 100644 --- a/src/Gateways/CustomGateway.php +++ b/src/Gateways/CustomGateway.php @@ -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); diff --git a/src/Gateways/PixGateway.php b/src/Gateways/PixGateway.php index 2af871a0a..62bda2301 100644 --- a/src/Gateways/PixGateway.php +++ b/src/Gateways/PixGateway.php @@ -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__), diff --git a/src/Gateways/TicketGateway.php b/src/Gateways/TicketGateway.php index 5e61eaf7c..95003e3c4 100644 --- a/src/Gateways/TicketGateway.php +++ b/src/Gateways/TicketGateway.php @@ -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 ( diff --git a/src/Order/OrderMetadata.php b/src/Order/OrderMetadata.php index 8375c9328..b175cbc30 100644 --- a/src/Order/OrderMetadata.php +++ b/src/Order/OrderMetadata.php @@ -81,6 +81,11 @@ class OrderMetadata */ private const PIX_ON = 'pix_on'; + /** + * @const + */ + private const BLOCKS_PAYMENT = 'blocks_payment'; + /** * @var OrderMeta */ @@ -439,4 +444,30 @@ public function updatePaymentsOrderMetadata(\WC_Order $order, array $paymentsId) } } } + + /** + * Update an order's payments metadata + * + * @param \WC_Order $order + * @param array $paymentsId + * + * @return void + */ + public function markPaymentAsBlocks(\WC_Order $order, string $value) + { + $this->orderMeta->update($order, self::BLOCKS_PAYMENT, $value); + } + + /** + * Update an order's payments metadata + * + * @param \WC_Order $order + * @param array $paymentsId + * + * @return void + */ + public function getPaymentBlocks(\WC_Order $order) + { + return $this->orderMeta->get($order, self::BLOCKS_PAYMENT); + } } diff --git a/src/Transactions/AbstractTransaction.php b/src/Transactions/AbstractTransaction.php index c0ba64753..35ae17482 100644 --- a/src/Transactions/AbstractTransaction.php +++ b/src/Transactions/AbstractTransaction.php @@ -248,6 +248,7 @@ public function getInternalMetadata(): PaymentMetadata $metadata->cpp_extra = new PaymentMetadataCpp(); $metadata->cpp_extra->platform_version = $this->mercadopago->woocommerce->version; $metadata->cpp_extra->module_version = MP_VERSION; + $metadata->blocks_payment = $this->mercadopago->orderMetadata->getPaymentBlocks($this->order); return $metadata; }