-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stripe] add an action to get a credit card token from payment details.
- Loading branch information
Showing
4 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
namespace Payum\Stripe\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\Request\GetCreditCardToken; | ||
|
||
class GetCreditCardTokenAction implements ActionInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
* | ||
* @param GetCreditCardToken $request | ||
*/ | ||
public function execute($request) | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
$model = ArrayObject::ensureArrayObject($request->getModel()); | ||
|
||
$request->token = $model['customer']; | ||
} | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports($request) | ||
{ | ||
return | ||
$request instanceof GetCreditCardToken && | ||
$request->getModel() instanceof \ArrayAccess | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace Payum\Stripe\Tests\Action\Api; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Request\GetCreditCardToken; | ||
use Payum\Core\Tests\GenericActionTest; | ||
use Payum\Stripe\Action\GetCreditCardTokenAction; | ||
|
||
class GetCreditCardTokenActionTest extends GenericActionTest | ||
{ | ||
protected $requestClass = GetCreditCardToken::class; | ||
|
||
protected $actionClass = GetCreditCardTokenAction::class; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldImplementActionInterface() | ||
{ | ||
$rc = new \ReflectionClass(GetCreditCardTokenAction::class); | ||
|
||
$this->assertTrue($rc->implementsInterface(ActionInterface::class)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldDoNothingIfPaymentHasNoCustomerSet() | ||
{ | ||
$model = [ | ||
]; | ||
|
||
$action = new GetCreditCardTokenAction(); | ||
|
||
$action->execute($getCreditCardToken = new GetCreditCardToken($model)); | ||
|
||
self::assertEmpty($getCreditCardToken->token); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldSetCustomerIdAsCardToken() | ||
{ | ||
$model = [ | ||
'customer' => 'theToken', | ||
]; | ||
|
||
$action = new GetCreditCardTokenAction(); | ||
|
||
$action->execute($getCreditCardToken = new GetCreditCardToken($model)); | ||
|
||
self::assertEquals('theToken', $getCreditCardToken->token); | ||
} | ||
} |