Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • project/commerce_mercadopago
  • issue/commerce_mercadopago-3367764
  • issue/commerce_mercadopago-3368693
  • issue/commerce_mercadopago-3373628
  • issue/commerce_mercadopago-3429355
5 results
Show changes
Commits on Source (2)
(function ($, Drupal, once) {
Drupal.behaviors.mercadopago_checkout = {
attach: function (context, settings) {
$('.commerce-checkout-flow-multistep-default', context).submit(function(e) {
e.preventDefault();
});
once('mercadopago_checkout', '.mercadopago-buttons-container', context).forEach(function(el) {
var preference_id = $(el).data('preference-id');
const mp = new MercadoPago(drupalSettings.mercadopago_checkout.public_key, {
locale: 'es-AR'
});
const mp = new MercadoPago(drupalSettings.mercadopago_checkout.public_key);
const checkeout = mp.checkout({
preference: {
id: preference_id
},
render: {
container: '.mercadopago-buttons-container',
label: 'Pagar'
label: Drupal.t('Pay')
}
})
});
......
......@@ -7,7 +7,6 @@ use Drupal\commerce_payment\Exception\PaymentGatewayException;
use Drupal\Core\Form\FormStateInterface;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_payment\Entity\PaymentInterface;
use Drupal\commerce_payment\Entity\PaymentMethodInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\commerce_price\Price;
use MercadoPago\MerchantOrder;
......@@ -15,6 +14,7 @@ use MercadoPago\Preference;
use MercadoPago\Payment;
use MercadoPago\Refund;
use MercadoPago\SDK;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides the QuickPay offsite Checkout payment gateway.
......@@ -22,7 +22,7 @@ use MercadoPago\SDK;
* @CommercePaymentGateway(
* id = "mercadopago_redirect_checkout",
* label = @Translation("MercadoPago (Redirect to mercadopago)"),
* display_label = @Translation("MercadoPago"),
* display_label = @Translation("Mercado Pago"),
* forms = {
* "offsite-payment" = "Drupal\commerce_mercadopago\PluginForm\Checkout\PaymentOffsiteForm",
* },
......@@ -32,7 +32,24 @@ use MercadoPago\SDK;
* },
* )
*/
class Checkout extends OffsitePaymentGatewayBase implements SupportsRefundsInterface {
class MercadoPago extends OffsitePaymentGatewayBase implements SupportsRefundsInterface {
/**
* The logger factory.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $loggerFactory;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->loggerFactory = $container->get('logger.factory');
return $instance;
}
/**
* {@inheritdoc}
......@@ -44,6 +61,9 @@ class Checkout extends OffsitePaymentGatewayBase implements SupportsRefundsInter
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
......@@ -66,7 +86,9 @@ class Checkout extends OffsitePaymentGatewayBase implements SupportsRefundsInter
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$values = $form_state->getValue($form['#parents']);
......@@ -125,8 +147,7 @@ class Checkout extends OffsitePaymentGatewayBase implements SupportsRefundsInter
*/
public function onNotify(Request $request) {
SDK::setAccessToken($this->configuration['private_key']);
\Drupal::logger('mercadopago_checkout')->info(print_r($_GET, 1));
$this->loggerFactory->get('mercadopago_checkout')->info(print_r($_GET, 1));
if ($request->query->get('type') == 'payment') {
$mp_payment = Payment::find_by_id($request->query->get('data_id'));
......@@ -147,8 +168,7 @@ class Checkout extends OffsitePaymentGatewayBase implements SupportsRefundsInter
->execute();
if (!$payment_ids) {
$order = \Drupal::entityTypeManager()->getStorage('commerce_order')->load($order_id);
$order = $this->entityTypeManager->getStorage('commerce_order')->load($order_id);
$payment_method = NULL;
......@@ -190,13 +210,12 @@ class Checkout extends OffsitePaymentGatewayBase implements SupportsRefundsInter
$payment->setState('completed');
$payment->setRemoteState($mp_payment->status);
$payment->save();
// $preference->external_reference
}
if ($request->query->get('topic') == 'merchant_order') {
$merchant_order = MerchantOrder::find_by_id($request->query->get('id'));
$preference = Preference::find_by_id($merchant_order->preferenceId);
\Drupal::logger('mercadopago_checkout')->info('External reference: ' . $preference->external_reference);
$this->loggerFactory->get('mercadopago_checkout')->info('External reference: ' . $preference->external_reference);
}
}
......@@ -209,9 +228,7 @@ class Checkout extends OffsitePaymentGatewayBase implements SupportsRefundsInter
}
SDK::setAccessToken($this->configuration['private_key']);
$payment_storage = $this->entityTypeManager->getStorage('commerce_payment');
$payment_ids = $payment_storage->getQuery()
->condition('order_id', $order->id())
->condition('state', 'completed')
......@@ -224,8 +241,6 @@ class Checkout extends OffsitePaymentGatewayBase implements SupportsRefundsInter
return;
}
$merchant_order = MerchantOrder::find_by_id($request->query->get('merchant_order_id'));
$payment_method = NULL;
// If a payment method is already referenced by the order, no need to create
// a new one.
......
......@@ -48,7 +48,7 @@ class PaymentOffsiteForm extends BasePaymentOffsiteForm implements ContainerInje
/** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
$payment = $this->entity;
$return_url = $form['#return_url'];
$form['paypal_smart_payment_buttons'] = $this->builder->build($payment, $return_url, TRUE);
$form['mercadopago_smart_payment_buttons'] = $this->builder->build($payment, $return_url, TRUE);
return $form;
}
......
......@@ -3,8 +3,6 @@
namespace Drupal\commerce_mercadopago;
use Drupal\commerce_payment\Entity\PaymentInterface;
use Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway\CheckoutInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Url;
use MercadoPago\SDK;
......@@ -36,8 +34,7 @@ class SmartPaymentButtonsBuilder implements SmartPaymentButtonsBuilderInterface
/**
* {@inheritdoc}
*/
public function build(PaymentInterface $payment, string $return_url ,$commit) {
$preference_id = $payment->getRemoteId();
public function build(PaymentInterface $payment, string $return_url , bool $commit) {
$order = $payment->getOrder();
$payment_gateway = $payment->getPaymentGateway();
......@@ -52,11 +49,6 @@ class SmartPaymentButtonsBuilder implements SmartPaymentButtonsBuilderInterface
'commerce_payment_gateway' => $payment_gateway->id(),
], ['absolute' => TRUE]);
// $notification_url = Url::fromRoute('commerce_mercadopago.checkout.approve', [
// 'commerce_order' => $order->id(),
// 'commerce_payment_gateway' => $payment_gateway->id(),
// ], ['absolute' => TRUE]);
$preference->back_urls = [
'success' => $return_url,
// 'failure' => '',
......
......@@ -12,15 +12,15 @@ interface SmartPaymentButtonsBuilderInterface {
/**
* Builds the Smart payment buttons.
*
* @param \Drupal\commerce_order\Entity\OrderInterface $payment
* @param \Drupal\commerce_payment\Entity\PaymentInterface $payment
* The payment.
* @param bool $commit
* Set to TRUE if the transaction is Pay Now, or FALSE if the amount
* captured changes after the buyer returns to your site.
* captured changes after the buyer returns to your site. (To be implemented).
*
* @return array
* A renderable array representing the Smart payment buttons.
*/
public function build(PaymentInterface $payment, string $redirect_url, $commit);
public function build(PaymentInterface $payment, string $return_url, bool $commit);
}