diff --git a/services/class-wc-ebanx-api.php b/services/class-wc-ebanx-api.php index b898680d..e9c5b3d6 100644 --- a/services/class-wc-ebanx-api.php +++ b/services/class-wc-ebanx-api.php @@ -21,27 +21,37 @@ class WC_EBANX_Api { */ protected $configs; + /** + * + * @var string + */ + protected $currency; + /** * EBANX_Api constructor. * * @param WC_EBANX_Global_Gateway $configs + * @param string $currency */ - public function __construct( WC_EBANX_Global_Gateway $configs ) { + public function __construct( WC_EBANX_Global_Gateway $configs, $currency = null ) { $this->configs = $configs; - $this->ebanx = EBANX( $this->get_config(), $this->get_credit_card_config( 'br' ) ); + $this->currency = is_null( $currency ) ? strtoupper( get_woocommerce_currency() ) : $currency; + $this->ebanx = EBANX( $this->get_config( $currency ), $this->get_credit_card_config( 'br' ) ); } /** + * + * @param string $currency * * @return Config */ - private function get_config() { + private function get_config( $currency ) { return new Config( array( 'integrationKey' => $this->configs->settings['live_private_key'], 'sandboxIntegrationKey' => $this->configs->settings['sandbox_private_key'], 'isSandbox' => 'yes' === $this->configs->settings['sandbox_mode_enabled'], - 'baseCurrency' => strtoupper( get_woocommerce_currency() ), + 'baseCurrency' => $this->currency, 'notificationUrl' => esc_url( home_url( '/' ) ), 'redirectUrl' => esc_url( home_url( '/' ) ), 'userValues' => [ diff --git a/services/class-wc-ebanx-payment-by-link.php b/services/class-wc-ebanx-payment-by-link.php index 5f8c4b76..4074460c 100644 --- a/services/class-wc-ebanx-payment-by-link.php +++ b/services/class-wc-ebanx-payment-by-link.php @@ -135,7 +135,7 @@ private static function send_request() { $response = false; try { - $response = ( new WC_EBANX_Api( self::$configs ) )->ebanx()->hosted()->create( $data ); + $response = ( new WC_EBANX_Api( self::$configs, self::$order->get_order_currency() ) )->ebanx()->hosted()->create( $data ); } catch ( Exception $e ) { self::add_error( $e->getMessage() ); self::send_errors();