diff --git a/Block/Info.php b/Block/Info.php index dd1821c..f56f92a 100644 --- a/Block/Info.php +++ b/Block/Info.php @@ -27,7 +27,7 @@ protected function cardData() { // 2017-11-12 // "An initial reusable source for a card which requires a 3D Secure verification": // https://mage2.pro/t/4893 - $r = lSource::retrieve($initialSourceId); + $r = dfe_stripe_source($initialSourceId); } return $r; } diff --git a/Controller/CustomerReturn/Index.php b/Controller/CustomerReturn/Index.php index 5344ff0..89c1200 100644 --- a/Controller/CustomerReturn/Index.php +++ b/Controller/CustomerReturn/Index.php @@ -1,6 +1,5 @@ s()->init(); return in_array( - lSource::retrieve(df_assert_sne(df_request('source')))['status'], ['chargeable', 'pending'] + dfe_stripe_source(df_assert_sne(df_request('source')))['status'], ['chargeable', 'pending'] );} } \ No newline at end of file diff --git a/Facade/Card.php b/Facade/Card.php index 817dbdd..12c0e23 100644 --- a/Facade/Card.php +++ b/Facade/Card.php @@ -14,6 +14,18 @@ final class Card implements \Df\StripeClone\Facade\ICard { */ function __construct($p) { $p = dfe_stripe_a($p); + /** + * 2017-11-12 + * A derived single-use 3D Secure source does not contain the bank card details, + * so I retrieve the initial source. + * "A derived single-use 3D Secure source": https://mage2.pro/t/4894 + * "An initial reusable source for a card which requires a 3D Secure verification": + * https://mage2.pro/t/4893 + */ + /** @var string|null $initialSourceId */ + if ($initialSourceId = dfa_deep($p, 'three_d_secure/card')) { + $p = dfe_stripe_a(dfe_stripe_source($initialSourceId)); + } $this->_p = Token::isCard($p['id']) ? $p : ['id' => $p['id']] + $p['card'] + $p['owner']; } diff --git a/Facade/Token.php b/Facade/Token.php index 1f73cdf..8d239c7 100644 --- a/Facade/Token.php +++ b/Facade/Token.php @@ -17,6 +17,7 @@ static function isCard($id) {return df_starts_with($id, 'card_');} * @used-by \Dfe\Stripe\Facade\Charge::tokenIsNew() * @used-by \Dfe\Stripe\Init\Action::sourceInitial() * @used-by \Dfe\Stripe\Method::transUrlBase() + * @used-by \Dfe\Stripe\Payer::tokenIsSingleUse() * @param string $id * @return bool */ @@ -31,17 +32,11 @@ static function isPreviouslyUsedOrTrimmedSource($id) {return df_starts_with($id, * @used-by \Dfe\Stripe\Init\Action::sourceInitial() * @used-by \Dfe\Stripe\P\_3DS::p() * @used-by \Dfe\Stripe\P\Reg::v_CardId() + * @used-by \Dfe\Stripe\Payer::tokenIsSingleUse() * @param string|null $id [optional] * @return string */ static function trimmed($id = null) {return dfcf(function($id) {return - df_trim_text_left($id ?: \Df\Payment\Token::get(dfpm(__CLASS__)->ii()), self::NEW_PREFIX) + df_trim_text_left($id ?: \Df\Payment\Token::get(dfpm(__CLASS__)->ii()), 'new_') ;}, [$id]);} - - /** - * 2017-11-12 - * @used-by trimmed() - * @used-by \Dfe\Stripe\W\Strategy\Charge3DS::_handle() - */ - const NEW_PREFIX = 'new_'; } \ No newline at end of file diff --git a/Init/Action.php b/Init/Action.php index 3baa5d4..37b16d8 100644 --- a/Init/Action.php +++ b/Init/Action.php @@ -216,7 +216,7 @@ private function need3DS() {return * @return lSource|null */ private function sourceInitial() {return dfc($this, function() {return - !fToken::isPreviouslyUsedOrTrimmedSource($id = fToken::trimmed()) ? null : lSource::retrieve($id) + !fToken::isPreviouslyUsedOrTrimmedSource($id = fToken::trimmed()) ? null : dfe_stripe_source($id) ;});} /** diff --git a/Payer.php b/Payer.php new file mode 100644 index 0000000..168e28d --- /dev/null +++ b/Payer.php @@ -0,0 +1,33 @@ +token())) + && 'single_use' === dfe_stripe_source($t)['usage'] + ;});} +} \ No newline at end of file diff --git a/W/Strategy/Charge3DS.php b/W/Strategy/Charge3DS.php index e9a6458..97f7c7c 100644 --- a/W/Strategy/Charge3DS.php +++ b/W/Strategy/Charge3DS.php @@ -39,8 +39,11 @@ protected function _handle() { * *) "A derived single-use 3D Secure source": https://mage2.pro/t/4894 * *) "An initial reusable source for a card which requires a 3D Secure verification": * https://mage2.pro/t/4893 + * Note 3. + * I intentionally do not add the «new_» prefix here, + * because this source is single-use, and I do not plan to attach it to the customer anyway. */ - Token::KEY => fToken::NEW_PREFIX . $this->e()->pid() + Token::KEY => $this->e()->pid() /** * 2017-11-12 * We do not need to set the bank card type: @see \Dfe\Stripe\Method::$II_CARD_TYPE diff --git a/composer.json b/composer.json index f598ef8..f2239d6 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "mage2pro/stripe" - ,"version": "2.4.4" + ,"version": "2.4.5" ,"description": "Stripe integration with Magento 2" ,"type": "magento2-module" ,"homepage": "https://mage2.pro/c/stripe" @@ -11,7 +11,7 @@ "homepage": "https://mage2.pro/users/dmitry_fedyuk", "role": "Developer" }] - ,"require": {"mage2pro/core": ">=3.3.7", "mage2pro/phone": ">=1.0.11", "stripe/stripe-php": ">=5.3"} + ,"require": {"mage2pro/core": ">=3.3.8", "mage2pro/phone": ">=1.0.11", "stripe/stripe-php": ">=5.3"} ,"autoload": {"files": ["registration.php"], "psr-4": {"Dfe\\Stripe\\": ""}} ,"keywords": [ "3D Secure" diff --git a/lib/main.php b/lib/main.php index cc43e05..443bce5 100644 --- a/lib/main.php +++ b/lib/main.php @@ -1,11 +1,28 @@ mixed) $o * @return array(string => mixed) */ -function dfe_stripe_a($o) {return is_array($o) ? $o : $o->__toArray(true);} \ No newline at end of file +function dfe_stripe_a($o) {return is_array($o) ? $o : $o->__toArray(true);} + +/** + * 2017-11-12 + * @used-by \Dfe\Stripe\Block\Info::cardData() + * @used-by \Dfe\Stripe\Controller\CustomerReturn\Index::isSuccess() + * @used-by \Dfe\Stripe\Facade\Card::__construct() + * @used-by \Dfe\Stripe\Init\Action::sourceInitial() + * @used-by \Dfe\Stripe\Payer::tokenIsSingleUse() + * @param string $id + * @return lSource + */ +function dfe_stripe_source($id) {return dfcf(function($id) { + dfps(M::class)->init(); return lSource::retrieve($id); +}, [$id]);} \ No newline at end of file