Skip to content

Commit

Permalink
2.4.5: #46
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Nov 12, 2017
1 parent 3535148 commit c34c25b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Block/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions Controller/CustomerReturn/Index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
namespace Dfe\Stripe\Controller\CustomerReturn;
use Stripe\Source as lSource;
/**
* 2017-11-07
* Note 1.
Expand Down Expand Up @@ -79,6 +78,6 @@ class Index extends \Df\Payment\CustomerReturn {
* @return string
*/
final protected function isSuccess() {$this->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']
);}
}
12 changes: 12 additions & 0 deletions Facade/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

Expand Down
11 changes: 3 additions & 8 deletions Facade/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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_';
}
2 changes: 1 addition & 1 deletion Init/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;});}

/**
Expand Down
33 changes: 33 additions & 0 deletions Payer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
namespace Dfe\Stripe;
use Dfe\Stripe\Facade\Token as fToken;
use Stripe\Source as lSource;
// 2017-11-12
/** @used-by \Df\StripeClone\P\Charge::request() */
final class Payer extends \Df\StripeClone\Payer {
/**
* 2017-11-12
* Note 1.
* Some Stripe's sources are single-use: https://stripe.com/docs/sources#single-use-or-reusable
* «Stripe API Documentation» → «Payment Methods Supported by the Sources API» → «Single-use or reusable»:
* «If a source can only be used once, this parameter is set to `single_use`
* and a source must be created each time a customer makes a payment.
* Such sources should not be attached to customers and should be charged directly instead.»
* Note 2. «Stripe API Reference» → «Sources» → «The source object» → `usage`:
* «Either `reusable` or `single_use`.
* Whether this source should be reusable or not.
* Some source types may or may not be reusable by construction,
* while other may leave the option at creation.
* If an incompatible value is passed, an error will be returned.»
* https://stripe.com/docs/api#source_object-usage
* @override
* @see \Df\StripeClone\Payer::tokenIsSingleUse()
* @used-by \Df\StripeClone\Payer::cardId()
* @used-by \Df\StripeClone\Payer::customerId()
* @return bool
*/
protected function tokenIsSingleUse() {return dfc($this, function() {return
fToken::isPreviouslyUsedOrTrimmedSource($t = fToken::trimmed($this->token()))
&& 'single_use' === dfe_stripe_source($t)['usage']
;});}
}
5 changes: 4 additions & 1 deletion W/Strategy/Charge3DS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.4.4"
,"version": "2.4.5"
,"description": "Stripe integration with Magento 2"
,"type": "magento2-module"
,"homepage": "https://mage2.pro/c/stripe"
Expand All @@ -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"
Expand Down
19 changes: 18 additions & 1 deletion lib/main.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
<?php
use Dfe\Stripe\Method as M;
use Stripe\Source as lSource;
use Stripe\StripeObject as lO;
/**
* 2017-10-22 Allowing $o to be an array makes my algorithms shorter.
* @used-by \Dfe\Stripe\Facade\Card::__construct()
* @used-by \Dfe\Stripe\Facade\Card::__construct()
* @used-by \Dfe\Stripe\Facade\O::toArray()
* @used-by \Dfe\Stripe\Init\Action::redirectUrl()
* @param lO|array(string => mixed) $o
* @return array(string => mixed)
*/
function dfe_stripe_a($o) {return is_array($o) ? $o : $o->__toArray(true);}
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]);}

0 comments on commit c34c25b

Please sign in to comment.