Exemple #1
0
 /**
  * {@inheritDoc}
  *
  * @param Capture $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     if (is_array($model['card'])) {
         return;
     }
     if (false == $model['card']) {
         $obtainToken = new ObtainToken($request->getToken());
         $obtainToken->setModel($model);
         $this->gateway->execute($obtainToken);
     }
     $this->gateway->execute(new CreateCharge($model));
 }
 /**
  * @test
  */
 public function shouldSetTokenFromHttpRequestToObtainTokenRequestOnPOST()
 {
     $model = array();
     $templateName = 'aTemplateName';
     $publishableKey = 'aPubKey';
     $gatewayMock = $this->createGatewayMock();
     $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf(GetHttpRequest::class))->will($this->returnCallback(function (GetHttpRequest $request) {
         $request->method = 'POST';
         $request->request = array('stripeToken' => 'theToken');
     }));
     $action = new ObtainTokenAction($templateName);
     $action->setGateway($gatewayMock);
     $action->setApi(new Keys($publishableKey, 'secretKey'));
     $action->execute($obtainToken = new ObtainToken($model));
     $model = $obtainToken->getModel();
     $this->assertEquals('theToken', $model['card']);
 }
 public function testShouldDoNothingIfCustomerSetOnPostExecute()
 {
     $model = new \ArrayObject(['customer' => 'aCustomerId', 'card' => 'theTokenMustBeObtained', 'local' => ['save_card' => true]]);
     $request = new ObtainToken($model);
     $gatewayMock = $this->createGatewayMock();
     $gatewayMock->expects($this->never())->method('execute');
     $context = new Context($gatewayMock, $request, []);
     $extension = new CreateCustomerExtension();
     $extension->onPostExecute($context);
     $this->assertEquals(['customer' => 'aCustomerId', 'card' => 'theTokenMustBeObtained', 'local' => ['save_card' => true]], (array) $request->getModel());
 }