Skip to content

Commit

Permalink
Merge pull request #149 from melisource/feature/PPWP-2013/blocks-meta…
Browse files Browse the repository at this point in the history
…data

Add blocks information in payment metadata
  • Loading branch information
DouglasCorreiaMeli authored Jan 11, 2024
2 parents cf6aaf1 + 12d3735 commit 16bc3e0
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/Entities/Metadata/PaymentMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,9 @@ class PaymentMetadata
* @var PaymentMetadataCpp
*/
public $cpp_extra;

/**
* @var string
*/
public $blocks_payment;
}
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
31 changes: 31 additions & 0 deletions src/Order/OrderMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ class OrderMetadata
*/
private const PIX_ON = 'pix_on';

/**
* @const
*/
private const BLOCKS_PAYMENT = 'blocks_payment';

/**
* @var OrderMeta
*/
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions src/Transactions/AbstractTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 16bc3e0

Please sign in to comment.