Skip to content

Commit

Permalink
Use currency from order in payment by link
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruanito Santos committed Nov 23, 2018
1 parent 03fb9e1 commit 0a9af92
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 0a9af92

Please sign in to comment.