Skip to content

Commit

Permalink
Merge pull request #720 from ebanx/fix/load-currency-from-order
Browse files Browse the repository at this point in the history
Use currency from order in payment by link
  • Loading branch information
Ruanito authored Nov 26, 2018
2 parents 03fb9e1 + 0a9af92 commit 6217760
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions services/class-wc-ebanx-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
2 changes: 1 addition & 1 deletion services/class-wc-ebanx-payment-by-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6217760

Please sign in to comment.