Skip to content

Commit

Permalink
Merge pull request mercadopago#294 from PluginAndPartners/feature/pix…
Browse files Browse the repository at this point in the history
…-order-details

[WooCommerce][PPWP-207] - Mostrar código pix no painel do cliente para consulta posterior
  • Loading branch information
cleitonaguiarandrade authored Aug 26, 2021
2 parents 59ad56c + 8bd98e0 commit 1b9da0c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 32 deletions.
74 changes: 54 additions & 20 deletions includes/payments/class-wc-woomercadopago-pix-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function __construct() {
$this->notification = new WC_WooMercadoPago_Notification_Webhook( $this );
$this->currency_convertion = true;
add_action( 'woocommerce_email_before_order_table', array(__CLASS__,'get_pix_template'), 20, 4 );
add_action( 'woocommerce_order_details_after_order_table', array(__CLASS__,'get_pix_template_order_details') );
}

/**
Expand Down Expand Up @@ -628,35 +629,68 @@ public static function get_id() {
/**
* Get pix template
*
* @param object $order Order.
* @return string
*/
public function get_pix_template( $order, $sent_to_admin, $plain_text, $email ) {
public static function get_pix_template( $order ) {

$pix_on = get_post_meta( $order->get_id(), 'pix_on' );

$pix_on = (int) array_pop( get_post_meta( $order->get_id(), 'pix_on' ));
$pix_on = (int) array_pop( $pix_on );

if ( 1 === $pix_on ) {

$qr_code = array_pop( get_post_meta( $order->get_id(), 'mp_pix_qr_code' ) );
$qr_image = array_pop( get_post_meta( $order->get_id(), 'mp_pix_qr_base64' ) );
$src = 'data:image/jpeg;base64';
$expiration_date = array_pop( get_post_meta( $order->get_id(), 'checkout_pix_date_expiration') );
$mp_pix_qr_code = get_post_meta( $order->get_id(), 'mp_pix_qr_code' );
$mp_pix_qr_base64 = get_post_meta( $order->get_id(), 'mp_pix_qr_base64' );
$checkout_pix_date_expiration = get_post_meta($order->get_id(), 'checkout_pix_date_expiration');

$qr_code = array_pop( $mp_pix_qr_code );
$qr_image = array_pop( $mp_pix_qr_base64 );
$src = 'data:image/jpeg;base64';
$expiration_date = array_pop( $checkout_pix_date_expiration );

$pix_template = wc_get_template(
'pix/pix-image-template.php',
array(
'src' => $src,
'qr_image' => $qr_image,
'qr_code' => $qr_code,
'expiration_date' => $expiration_date,
'text_expiration_date' => __( 'Code valid for ', 'woocommerce-mercadopago' ),
),
'',
WC_WooMercadoPago_Module::get_templates_path()
);

$pix_template = wc_get_template(
'pix/pix-image-template.php',
array(
'src' => $src,
'qr_image' => $qr_image,
'qr_code' => $qr_code,
'expiration_date' => $expiration_date,
'text_expiration_date' => __( 'Code valid for ', 'woocommerce-mercadopago' ),
),
'',
WC_WooMercadoPago_Module::get_templates_path()
);
return $pix_template;
}

return $pix_template;
}

}
/**
* Get pix template to send via email
*
* @param object $order Order.
* @param bool $sent_to_admin.
* @param bool $plain_text.
* @param $email
* @return string|array
*/
public static function get_pix_template_email( $order, $sent_to_admin, $plain_text, $email ) {

return self::get_pix_template( $order );

}

/**
* Get pix template to show in order details
*
* @param object $order Order.
* @return string|array
*/
public static function get_pix_template_order_details( $order ) {

return self::get_pix_template( $order );

}

Expand Down
19 changes: 7 additions & 12 deletions templates/pix/pix-image-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,13 @@
<small><?php esc_html_e( $text_expiration_date, 'woocommerce-mercadopago' ) . esc_html_e( $expiration_date, 'woocommerce-mercadopago' ); ?></small>
</div>

<div>
<p style="width: 320px;
margin: 0 0 16px;
font-size: 10px;
max-width: 100%;
word-break: break-all;
height: 80px;
display: inline-block;
margin-left: auto;
margin-right: auto;">
<small><?php esc_html_e( $qr_code, 'woocommerce-mercadopago' ); ?></small>
<div style="margin-left: auto;
margin-right: auto;
width: 320px;
word-break: break-word;
font-size: 10px;">
<p>
<?php esc_html_e( $qr_code, 'woocommerce-mercadopago' ); ?>
</p>
</div>
</div>

0 comments on commit 1b9da0c

Please sign in to comment.