Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Oct 15, 2017
1 parent f7add2d commit 0ec813d
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 8 deletions.
92 changes: 92 additions & 0 deletions FE/Currency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
namespace Dfe\Stripe\FE;
use Dfe\Stripe\Settings as S;
/**
* 2017-10-15
* «Brazilian Stripe accounts (currently in Preview) can only charge in Brazilian Real»:
* https://github.com/mage2pro/stripe/issues/31
* «Mexican Stripe accounts (currently in Preview) can only charge in Mexican Peso»
* https://github.com/mage2pro/stripe/issues/32
* @final Unable to use the PHP «final» keyword here because of the M2 code generation.
*/
class Currency extends \Df\Directory\FE\Currency {
/**
* 2017-10-15
* @final Unable to use the PHP «final» keyword here because of the M2 code generation.
* @override
* Перекрываем магический метод,
* потому что к магическим методам не применяются плагины, а нам надо применить плагин
* @see \Df\Framework\Plugin\Data\Form\Element\AbstractElement::afterGetComment()
* @used-by \Magento\Config\Block\System\Config\Form\Field::_renderValue()
* https://github.com/magento/magento2/blob/2.2.0-RC1.8/app/code/Magento/Config/Block/System/Config/Form/Field.php#L79-L81
* if ((string)$element->getComment()) {
* $html .= '<p class="note"><span>' . $element->getComment() . '</span></p>';
* }
* @return string|null
*/
function getComment() {return !$this->hasKey() || $this->s()->isMerchantInUS() ?
"<ul class='df-note'><li>The <b>JCB</b>, <b>Discover</b>, and <b>Diners Club</b> bank cards are <b>always charged in USD</b> (<a href='https://github.com/mage2pro/stripe/issues/28' target='_blank' title='«JCB, Discover, and Diners Club cards can only be charged in USD»'>Stripe does not support other currencies for them</a>).</li>
</ul>"
: (!$this->disabled() ? null :
__("The <b>%1</b> Stripe accounts can only charge in <b>%2</b>.",
dftr($this->country(), ['BR' => __('Brazilian'), 'MX' => __('Mexican')])
,df_currency_name($this->currency()
))
)
;}

/**
* 2017-10-15
* @override
* @see \Df\Directory\FE\Currency::getValue()
* @used-by \Df\Framework\Form\Element\Select2::setRenderer()
* @return string|null
*/
function getValue() {return $this->disabled() ? $this->currency() : parent::getValue();}

/**
* 2017-10-15
* @override
* @see \Df\Framework\Form\Element\Select2::enabled()
* @used-by getValue()
* @used-by \Df\Framework\Form\Element\Select2::setRenderer()
* @return bool
*/
final protected function disabled() {return in_array($this->country(), ['BR', 'MX']);}

/**
* 2017-10-15
* @used-by currency()
* @used-by disabled()
* @used-by getComment()
* @return string
*/
private function country() {return dfc($this, function() {return !$this->hasKey() ? null :
$this->s()->merchantCountry()
;});}

/**
* 2017-10-15
* @used-by getComment()
* @used-by getValue()
* @return string
*/
private function currency() {return df_currency_by_country_c($this->country());}

/**
* 2017-10-15
* @used-by country()
* @used-by getComment()
* @return bool
*/
private function hasKey() {return dfc($this, function() {return $this->s()->privateKey(null, false);});}

/**
* 2017-10-15
* @used-by country()
* @used-by getComment()
* @used-by hasKey()
* @return S $s
*/
private function s() {return dfc($this, function() {return dfps($this);});}
}
3 changes: 1 addition & 2 deletions Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ function canCapturePartial() {return true;}
* @used-by \Dfe\Stripe\Currency::_iso3()
* @return string|null
*/
function cardType() {return dfc($this, function() {
/** @var string $r */
function cardType() {return dfc($this, function() {/** @var string $r */
if (!($r = $this->iia(self::$II_CARD_TYPE))) {
/**
* 2017-10-12
Expand Down
10 changes: 9 additions & 1 deletion Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ function init() {\Stripe\Stripe::setApiKey($this->privateKey());}
* @used-by \Dfe\Stripe\Method::minimumAmount()
* @return bool
*/
function isMerchantInUS() {return 'US' === $this->account()->{'country'};}
function isMerchantInUS() {return 'US' === $this->merchantCountry();}

/**
* 2017-10-15
* @used-by isMerchantInUS()
* @used-by \Dfe\Stripe\FE\Currency::country()
* @return string
*/
function merchantCountry() {return $this->account()->{'country'};}

/**
* 2016-03-08 https://stripe.com/docs/api/php#retrieve_account
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage2pro/stripe"
,"version": "2.0.0"
,"version": "2.1.0"
,"description": "The «Stripe» payment extension for Magento 2."
,"type": "magento2-module"
,"homepage": "https://mage2.pro/c/extensions/stripe"
Expand All @@ -11,7 +11,7 @@
"homepage": "https://mage2.pro/users/dmitry_fedyuk",
"role": "Developer"
}]
,"require": {"mage2pro/core": ">=3.2.0", "stripe/stripe-php": "3.*"}
,"require": {"mage2pro/core": ">=3.2.2", "stripe/stripe-php": "3.*"}
,"autoload": {"files": ["registration.php"], "psr-4": {"Dfe\\Stripe\\": ""}}
,"keywords": [
"API"
Expand Down
4 changes: 1 addition & 3 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@
showInDefault='1' showInStore='1' showInWebsite='1'
sortOrder='10'
translate='label'
type='Df\Directory\FormElement\Currency'
type='Dfe\Stripe\FE\Currency'
>
<comment><![CDATA[<ul class='df-note'><li>The <b>JCB</b>, <b>Discover</b>, and <b>Diners Club</b> bank cards are <b>always charged in USD</b> (<a href='https://github.com/mage2pro/stripe/issues/28' target='_blank' title='«JCB, Discover, and Diners Club cards can only be charged in USD»'>Stripe does not support other currencies for them</a>).</li>
</ul>]]></comment>
<label>Payment Currency</label>
<depends><field id='enable'>1</field></depends>
</field>
Expand Down

0 comments on commit 0ec813d

Please sign in to comment.