Skip to content

Commit

Permalink
Merge pull request #576 from ebanx/feature/instalments-on-local-currency
Browse files Browse the repository at this point in the history
Showing instalments on local currency
  • Loading branch information
gpressutto5 authored Oct 9, 2017
2 parents 7fb99a9 + d670dce commit 9136c08
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function __construct()
{
$this->id = 'ebanx-credit-card-br';
$this->method_title = __('EBANX - Credit Card Brazil', 'woocommerce-gateway-ebanx');
$this->currency_code = WC_EBANX_Constants::CURRENCY_CODE_BRL;

$this->title = 'Cartão de Crédito';
$this->description = 'Pague com cartão de crédito.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function __construct()
{
$this->id = 'ebanx-credit-card-co';
$this->method_title = __('EBANX - Credit Card Colombia', 'woocommerce-gateway-ebanx');
$this->currency_code = WC_EBANX_Constants::CURRENCY_CODE_COP;

$this->title = 'Tarjeta de Crédito';
$this->description = 'Pay with credit card.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ public function payment_fields() {
'currency' => $currency,
'country' => $country,
'instalments_terms' => $instalments_terms,
'currency' => $this->currency_code,
'currency_rate' => round(floatval($this->get_local_currency_rate_for_site($this->currency_code)), 2),
'cards' => (array) $cards,
'cart_total' => $cart_total,
'place_order_enabled' => $save_card,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function __construct()
{
$this->id = 'ebanx-credit-card-mx';
$this->method_title = __('EBANX - Credit Card Mexico', 'woocommerce-gateway-ebanx');
$this->currency_code = WC_EBANX_Constants::CURRENCY_CODE_MXN;

$this->title = 'Tarjeta de Crédito';
$this->description = 'Pay with credit card.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,20 +329,22 @@ public function print_button() {

$instalments_terms = $this->gateway->get_payment_terms($cart_total, $max_instalments, $tax);
$currency = WC_EBANX_Constants::$LOCAL_CURRENCIES[$country];
$ebanx = new WC_EBANX_Gateway();

$args = apply_filters( 'ebanx_template_args', array(
'cards' => $this->cards,
'cart_total' => $cart_total,
'product_id' => $product->id,
'installment_taxes' => $this->instalment_rates,
'currency' => $currency,
'currency_rate' => round(floatval($ebanx->get_local_currency_rate_for_site($currency)), 2),
'label' => __( 'Pay with one click', 'woocommerce-gateway-ebanx' ),
'instalments' => $messages['instalments'],
'instalments_terms' => $instalments_terms,
'nonce' => wp_create_nonce( self::CREATE_ORDER_ACTION ),
'action' => self::CREATE_ORDER_ACTION,
'permalink' => get_permalink($product->id),
'country' => $country,
'currency' => $currency,
'should_show_button' => $this->should_show_button(),
) );

Expand Down
12 changes: 10 additions & 2 deletions woocommerce-gateway-ebanx/templates/instalments.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<!-- Installments -->
<?php if ( count($instalments_terms) > 1 ) : ?>
<?php
$currency = $currency ?: get_woocommerce_currency();
$currency_rate = $currency_rate ?: 1;

if ($currency === WC_EBANX_Constants::CURRENCY_CODE_BRL) {
$currency_rate *= 1 + WC_EBANX_Constants::BRAZIL_TAX;
}

if ( count($instalments_terms) > 1 ) : ?>
<section class="ebanx-form-row">
<label for="ebanx-card-installments"><?php echo $instalments; ?> <span class="required">*</span></label>
<select
Expand All @@ -12,7 +20,7 @@ class="ebanx-instalments ebanx-select-field"
>
<?php foreach ($instalments_terms as $instalment): ?>
<option value="<?php echo $instalment['number'] ?>">
<?php printf( __( '%1$dx of %2$s', 'woocommerce-gateway-ebanx' ), absint( $instalment['number'] ), esc_html( strip_tags( wc_price( $instalment['price'] ) ) ) ); ?>
<?php printf( __( '%1$dx of %2$s', 'woocommerce-gateway-ebanx' ), absint( $instalment['number'] ), esc_html( strip_tags( wc_price( $instalment['price'] * $currency_rate, array('currency' => $currency) ) ) ) ); ?>
<?= $instalment['has_interest'] ? __( 'with interest', 'woocommerce-gateway-ebanx' ) : '' ?>
</option>
<?php endforeach; ?>
Expand Down

0 comments on commit 9136c08

Please sign in to comment.