Skip to content

Commit

Permalink
Merge pull request #715 from ebanx/fix/value-without-taxes-on-tp
Browse files Browse the repository at this point in the history
Verify if taxes should be applied before showing amount on card thank you page
  • Loading branch information
Anderson Campanha authored Nov 19, 2018
2 parents d112f68 + d012fe7 commit c0693c7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
13 changes: 6 additions & 7 deletions gateways/class-wc-ebanx-credit-card-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public static function thankyou_page( $order ) {
$country = trim( strtolower( get_post_meta( $order->id, '_billing_country', true ) ) );
$currency = $order->get_order_currency();

if ( WC_EBANX_Constants::COUNTRY_BRAZIL === $country ) {
if ( WC_EBANX_Constants::COUNTRY_BRAZIL === $country && WC_EBANX_Helper::should_apply_taxes() ) {
$order_amount += round( ( $order_amount * WC_EBANX_Constants::BRAZIL_TAX ), 2 );
}

Expand Down Expand Up @@ -387,15 +387,14 @@ public static function thankyou_page( $order ) {
* @return array An array of instalment with price, amount, if it has interests and the number
*/
public function get_payment_terms( $country, $amount, $currency_rate ) {
$credit_card_gateway = $this->ebanx->creditCard( $this->get_credit_card_config( $country ) );
$country_full_name = Country::fromIso( $country );
$instalments_terms = $credit_card_gateway->getPaymentTermsForCountryAndValue( $country_full_name, $amount );
$has_taxes_for_local_amount = $this->configs->get_setting_or_default( 'add_iof_to_local_amount_enabled', 'yes' ) === 'yes' ? true : false;
$credit_card_gateway = $this->ebanx->creditCard( $this->get_credit_card_config( $country ) );
$country_full_name = Country::fromIso( $country );
$instalments_terms = $credit_card_gateway->getPaymentTermsForCountryAndValue( $country_full_name, $amount );

foreach ( $instalments_terms as $term ) {
// phpcs:disable
$instalments[] = array(
'price' => $has_taxes_for_local_amount ? ( $term->localAmountWithTax / $currency_rate ) : $term->baseAmount,
'price' => WC_EBANX_Helper::should_apply_taxes() ? ( $term->localAmountWithTax / $currency_rate ) : $term->baseAmount,
'has_interest' => $term->hasInterests,
'number' => $term->instalmentNumber,
// phpcs:enable
Expand Down Expand Up @@ -485,7 +484,7 @@ public function payment_fields() {
'place_order_enabled' => $save_card,
'instalments' => self::get_instalment_title_by_country( $country ),
'id' => $this->id,
'add_tax' => $this->configs->get_setting_or_default( 'add_iof_to_local_amount_enabled', 'yes' ) === 'yes',
'add_tax' => WC_EBANX_Helper::should_apply_taxes(),
'with_interest' => WC_EBANX_Constants::COUNTRY_BRAZIL === $country ? ' com taxas' : '',
),
'woocommerce/ebanx/',
Expand Down
2 changes: 1 addition & 1 deletion gateways/class-wc-ebanx-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public function get_checkout_message( $amount, $currency, $country ) {
$texts = array(
'pt-br' => array(
'INTRO' => 'Total a pagar ',
WC_EBANX_Constants::CURRENCY_CODE_BRL => $this->configs->get_setting_or_default( 'add_iof_to_local_amount_enabled', 'yes' ) === 'yes' ? 'com IOF (0.38%)' : 'em Reais',
WC_EBANX_Constants::CURRENCY_CODE_BRL => WC_EBANX_Helper::should_apply_taxes() ? 'com IOF (0.38%)' : 'em Reais',
),
'es' => array(
'INTRO' => 'Total a pagar en ',
Expand Down
3 changes: 1 addition & 2 deletions gateways/class-wc-ebanx-new-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,7 @@ public function checkout_rate_conversion( $currency, $template = true, $country
$local_amount_with_tax = round( $instalment_terms->instalmentNumber * $instalment_terms->localAmountWithTax, 2 );
}

$has_taxes_with_local_amount = $this->configs->get_setting_or_default( 'add_iof_to_local_amount_enabled', 'yes' ) === 'yes' ? true : false;
$total_local_amount = $has_taxes_with_local_amount ? $local_amount_with_tax : $local_amount;
$total_local_amount = WC_EBANX_Helper::should_apply_taxes() ? $local_amount_with_tax : $local_amount;

$message = $this->get_checkout_message( $total_local_amount, $currency, $country );
$exchange_rate_message = $this->get_exchange_rate_message( $currency, $country );
Expand Down
12 changes: 12 additions & 0 deletions services/class-wc-ebanx-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,16 @@ public static function get_instalments_by_country( $country_abbr ) {
return $credit_card->getInstalmentsByCountry( WC_EBANX_Constants::COUNTRY_NAME_FROM_ABBREVIATION[ $country_abbr ] );
}

/**
*
* Verifies if IOF like taxes should be applied.
*
* @return bool
*/
public static function should_apply_taxes() {
$configs = new WC_EBANX_Global_Gateway();

return $configs->get_setting_or_default( 'add_iof_to_local_amount_enabled', 'yes' ) === 'yes';
}

}

0 comments on commit c0693c7

Please sign in to comment.